News for hackers. Stuff that matters.
Re:PyPy gets funding from Mozilla for Python 3.5 support by hyperbovine on Tuesday August 09, 2016 @03:04PM (#12256990)
Weird how suddenly everyone seems to have coalesced around 3.5. I myself have experienced this just recently -- the new async stuff is too nice to pass up. Really looking forward to new formatted string literals in 3.6 as well! One of those ideas that's so obvious in hindsight, you can't believe it took us this long to come up with it.
Re:PyPy gets funding from Mozilla for Python 3.5 support by cs702 on Tuesday August 09, 2016 @03:45PM (#12257245)
Not weird. This phenomenon is literally called a "tipping point," and it has been well documented in many different settings and disciplines. Example:

https://en.wikipedia.org/wiki/Tipping_point_(sociology)

We're at the tipping point between Python 2.7 and 3.x.

Re:PyPy gets funding from Mozilla for Python 3.5 support by plorkyeran on Tuesday August 09, 2016 @03:10PM (#12257032)
One of the arguments against switching to Python 3 has always been that you just don't gain enough to justify the hassle, so maybe 3.5 finally hit that critical mass of things people really want.
Re:PyPy gets funding from Mozilla for Python 3.5 support by StavrosK on Tuesday August 09, 2016 @03:24PM (#12257118)
Don't gain enough? Static type checking and asyncio? Sign me up!
Re:PyPy gets funding from Mozilla for Python 3.5 support by pinaraf on Tuesday August 09, 2016 @03:26PM (#12257134)
Static checking ? Python 3.5 Asyncio ? Python 3.4

If these had been available in Python 3.2 or even better 3.0, the switch would have been far easier for corporate users that need benefits before accepting the cost of change...

Re:PyPy gets funding from Mozilla for Python 3.5 support by raverbashing on Tuesday August 09, 2016 @04:10PM (#12257371)
3.4. gave a good virtualenv by default. That helps a lot
Re:PyPy gets funding from Mozilla for Python 3.5 support by brianwawok on Tuesday August 09, 2016 @04:39PM (#12257557)
I still use normal virtualenv, what am I missing by not using pyenv?
Re:PyPy gets funding from Mozilla for Python 3.5 support by raverbashing on Tuesday August 09, 2016 @04:43PM (#12257573)
3.4 gave us pip installed by default https://docs.python.org/3/library/venv.html

Before that it would give you an empty venv, not even setuptools

Yes, you can use the Python 2 virtualenv on Py 3 but I remember that there were some problems

Re:PyPy gets funding from Mozilla for Python 3.5 support by takeda on Tuesday August 09, 2016 @05:35PM (#12257871)
The usage is essentially the same, just a different command. Huge benefit though is that if you have Python 3.4+ installed you already have the virtual env and pip installed, so things are much simpler.
Re:PyPy gets funding from Mozilla for Python 3.5 support by StavrosK on Tuesday August 09, 2016 @04:38PM (#12257546)
Which one is that? I'm not aware of it.
Re:PyPy gets funding from Mozilla for Python 3.5 support by captainmuon on Tuesday August 09, 2016 @05:12PM (#12257732)

    python -m venv
I'm not sure what the differences are to old virtualenv, but the biggest feature is that it works out of the box as long as you have Python > 3.4. No more googling "how to install virtualenv" or "easy_install pip; pip install virtualenv" stuff.
Re:PyPy gets funding from Mozilla for Python 3.5 support by rspeer on Tuesday August 09, 2016 @11:30PM (#12259337)
Unless you're on Ubuntu, where they ship a non-functional version of venv and require you to "sudo apt install" python-venv to get the working version, defeating the entire point of a simple module in the stdlib that lets you manage your Python environment as a user.

The big improvement on 16.04 is at least the error message explains what's going on.

Re:PyPy gets funding from Mozilla for Python 3.5 support by brettcannon on Tuesday August 09, 2016 @05:19PM (#12257765)
Re:PyPy gets funding from Mozilla for Python 3.5 support by takeda on Tuesday August 09, 2016 @05:52PM (#12257969)
in addition to what other wrote you also have pyvenv command which is much convenient way of using it in cli (the usage is same as of virtualenv).
Re:PyPy gets funding from Mozilla for Python 3.5 support by 912312312 on Tuesday August 09, 2016 @03:39PM (#12257205)
I would say: Optional type checking outsourced to a third party tool (mypy) that catches perhaps 90% of the errors if you are lucky.
Re:PyPy gets funding from Mozilla for Python 3.5 support by eeZi on Tuesday August 09, 2016 @07:06PM (#12258321)
You still need something like MyPy to actually validate types. What happened is that there's now a standard for typing annotations - now, PyCharm, MyPy, Wing IDE and anyone else can share the same syntax.
Re:PyPy gets funding from Mozilla for Python 3.5 support by yeukhon on Tuesday August 09, 2016 @05:45PM (#12257918)
I am disappointed in Python core developers when they decided to accept static typing to Python 3. It bothers me more than the formatting PEP.
Re:PyPy gets funding from Mozilla for Python 3.5 support by twblalock on Tuesday August 09, 2016 @06:24PM (#12258142)
It's optional. How can that possibly bother you? Don't use it if you don't like it.
Re:PyPy gets funding from Mozilla for Python 3.5 support by catdog on Tuesday August 09, 2016 @07:10PM (#12258337)
It's not only optional, it does nothing by default. What was introduced into python is a standardized way to do type annotations. It consists mostly of a new standard library module and as far as i know it doesn't even introduce changes to the language as it uses comments, additional files and the rarely used function annotations. The interpreter happily ignores them anyways but external tools like mypy don't have to invent their own incompatible syntax.
Re:PyPy gets funding from Mozilla for Python 3.5 support by twblalock on Tuesday August 09, 2016 @08:36PM (#12258706)
I was more excited about them when I believed they were actually enforced. I guess they help with static analysis in IDEs, but you can still get type errors at runtime, so Python is still missing out on the main advantage of static typing.
Re:PyPy gets funding from Mozilla for Python 3.5 support by hendzen on Tuesday August 09, 2016 @09:04PM (#12258804)
there is a type checker available: http://mypy-lang.org/
Re:PyPy gets funding from Mozilla for Python 3.5 support by viraptor on Tuesday August 09, 2016 @09:10PM (#12258824)
> as far as i know it doesn't even introduce changes to the language as it uses comments

That's not the case. See for example https://www.python.org/dev/peps/pep-0484/#type-definition-sy...

Re:PyPy gets funding from Mozilla for Python 3.5 support by xapata on Tuesday August 09, 2016 @06:37PM (#12258197)
Because I'll need to support people that use it and explain it to newbies who read it. More work to do, without much benefit (to me; I understand it has much benefit to some people).
Re:PyPy gets funding from Mozilla for Python 3.5 support by StavrosK on Tuesday August 09, 2016 @07:44PM (#12258466)
It's only without benefit if you don't write Python. Otherwise, it's like having tests that take almost no effort to write. What's not to love about it?
Re:PyPy gets funding from Mozilla for Python 3.5 support by xapata on Tuesday August 09, 2016 @09:00PM (#12258793)
Edward Tufte might call it chart junk. It reduces the information to ink ratio. I generally get by just fine by choosing good names, so I don't need extra type checking beyond the standard duck typing.
Re:PyPy gets funding from Mozilla for Python 3.5 support by yeukhon on Tuesday August 09, 2016 @10:11PM (#12259065)
Why add static typing to a language long stood for duck typing? There should really be one way to write in Python.
Re:PyPy gets funding from Mozilla for Python 3.5 support by srean on Tuesday August 09, 2016 @11:25PM (#12259323)
A few things.

i) its not a type checker. It cannot actually ensure type correctness. So may be a more appropriate description would be "a very smart linter".

ii) Its optional

iii) even when switched on it does nothing unless you are explicitly using its features

iv) The "there is only one way to do things in Python" is just vapid marketing. It is not true and has never been true.

Re:PyPy gets funding from Mozilla for Python 3.5 support by dagw on Wednesday August 10, 2016 @03:38AM (#12260087)
"there is only one way to do things in Python" is just vapid marketing.

It's not even that, the actual quote is "There should be one, and preferably only one, obvious way to do things". The whole "there is only one way to do it" was a joke response to Perl's "There's more than one way to do it" motto.

Re:PyPy gets funding from Mozilla for Python 3.5 support by antod on Wednesday August 10, 2016 @06:42AM (#12260674)
The explicit version: "There should be an obvious way to do something. Ideally only one way will be obvious."

The original version was too implicit. Unless you are Dutch.

Re:PyPy gets funding from Mozilla for Python 3.5 support by coderzach on Tuesday August 09, 2016 @10:35PM (#12259153)
I've had great experiences with optional static typing from tools like flow[1] and mypy. I've found you can gain most of the bug catching and readability benefits of static typing, while having the power of dynamic typing when come across a truly dynamic problem.
Re:PyPy gets funding from Mozilla for Python 3.5 support by zepolen on Tuesday August 09, 2016 @06:43PM (#12258219)
It's been almost a decade, a lot of bugs, annoyances and slowness has been ironed out. Most important libraries are py3, which is a biggie, and py3 changes were backported via __future__ to py2 so you can easily begin getting used to the syntax in current apps.

So now that you are used to using print("hello") instead of print "hello" and not having to use u'whatever' all over the place - it was a perfect time to experiment with toy apps in python 3, since they are mostly backward compatible with python 2 without all the 2to3 nonsense. Even ubuntu made it default.

Which leads us to asyncio, the killer feature - people were prepped to move...but didn't have a really compelling reason to...until now.

Re:PyPy gets funding from Mozilla for Python 3.5 support by didip on Tuesday August 09, 2016 @04:27PM (#12257459)
Totally not weird at all.

Users need very compelling reason to switch off any kind of platform. And usually one of the compelling reason is better performance.

The reception towards Python 3 would have been very different had it launched with everything Python 3.5 currently have, more performant GIL, OrderedDict, decimal operations, the new asyncio, etc.

Re:PyPy gets funding from Mozilla for Python 3.5 support by kbenson on Tuesday August 09, 2016 @03:15PM (#12257067)
> One of those ideas that's so obvious in hindsight, you can't believe it took us this long to come up with it.

If by "come up with" you mean finally acquiesced after decades and decided that string interpolation wasn't such a bad idea... sure.

Re:PyPy gets funding from Mozilla for Python 3.5 support by StavrosK on Tuesday August 09, 2016 @03:23PM (#12257110)
What's the difference between `"%s" % foo` and `"{}".format(foo)`? Why is one interpolation and the other not?
Re:PyPy gets funding from Mozilla for Python 3.5 support by kevin_thibedeau on Tuesday August 09, 2016 @06:43PM (#12258221)
The format() method is more capable as it plays nice with heterogeneous duck-typed objects. It is type aware and you can supply your own custom formatters through __format__ methods that can receive parameters from the format string.

% will spew TypeErrors if you don't get the format specifier right.

Re:PyPy gets funding from Mozilla for Python 3.5 support by nemetroid on Tuesday August 09, 2016 @03:31PM (#12257164)
Python 3.6 is adding `f"{foo}"`, which is rather different than the previous offerings.
Re:PyPy gets funding from Mozilla for Python 3.5 support by kbenson on Tuesday August 09, 2016 @03:45PM (#12257241)
Yes, but to clarify, it's only rather different than previous python offerings. There exist things more or less equivalent in other languages, so it's not as if there's much of a reason it took this long.
Re:PyPy gets funding from Mozilla for Python 3.5 support by nilved on Tuesday August 09, 2016 @03:49PM (#12257267)
Wow that is horrible.
Re:PyPy gets funding from Mozilla for Python 3.5 support by allendoerfer on Tuesday August 09, 2016 @05:30PM (#12257840)
I really hate the fact that there are now 3 ways to do it. And that it looks like PHP.

To be honest, to me the "%" seems the most pythonic way to do it. Format does not seem easier to understand to me . String formatting just cannot be transformed to natural language. I at least don't think "I need to format this string", I think "this variable needs to be in there", in the in there might as well be called "%". I think ["a is %s" % a for a in all_as] just fits.

Although named parameters are nicer with format. In no way should there be a third way to do it. Isn't that the basic principle of Python, to care about things like this? I mean this whole Python 3 problem was to a small extend caused by people rather having an incompatible syntax than two ways to print a string. Going through these troubles and then inflating the language with new syntax for the same thing seems like a waste.

Re:PyPy gets funding from Mozilla for Python 3.5 support by kbenson on Tuesday August 09, 2016 @06:16PM (#12258100)
In that respect, don't list comprehensions fall under the same category of multiple ways to do something? They didn't exist in the language until 2.0[1], and it's just a convenient way to encode a couple for loops, is it not[2]? At some point you have to accept that it's a trade-off, and the more complex the topic, the less well served it will be by only one or two ways to do it. In this case, there were actually already three ways to do it, since you could always use plain string concatenation with `+`. If python were truly about one way to do it more than anything else, that would be the only way to build complex strings from variables, but since convenience is also important, numerous shortcuts were deemed acceptable and implemented.

1: https://en.wikipedia.org/wiki/History_of_Python#Version_2.0

2: And for my money, significantly more confusing (and less powerful) than something like Perl's `map`.

Re:PyPy gets funding from Mozilla for Python 3.5 support by allendoerfer on Tuesday August 09, 2016 @06:39PM (#12258202)
List comprehension is the one obvious way to do do a quick map, a for loop would be used for more complex stuff and side effects. A real map is more niche but probably necessary when doing eval stuff or stylisticly nicer in a module where you do several functional tasks.

String concatenation has one use-case where it is the obvious way, too, namely when you have to concatenate already existing strings without modification, since "%s%s" % (a, b) is just stupid, beyond that you would use string formatting.

Maybe there are unique obvious use-cases for the different formatting options as well, but I don't know them. I give you, that "%" is bad for named arguments, but why wouldn't you just improve that then? I think they do the exact same thing and are good for the exact same contexts. If somebody knows more than me, I would be very happy to be proven wrong.

Re:PyPy gets funding from Mozilla for Python 3.5 support by kbenson on Tuesday August 09, 2016 @07:26PM (#12258385)
> I give you, that "%" is bad for named arguments, but why wouldn't you just improve that then?

Perhaps they should. I'm not making a case specifically for the proposed strategy (interpolation), just that if they are going to implement it, that it took this long is odd, and somewhat laughable. Personally, I think the named string format is superior to this new feature in many respects except the most simplistic of cases, but I don't often write python, so my opinion may be colored by that.

Re:PyPy gets funding from Mozilla for Python 3.5 support by dagw on Wednesday August 10, 2016 @03:44AM (#12260112)
List comprehension are interesting and really come into their own when seen as part of the whole family of comprehensions. In addition to list comprehensions, you also have set, dict and generator comprehensions that all share the same syntax.
Re:PyPy gets funding from Mozilla for Python 3.5 support by icebraining on Tuesday August 09, 2016 @06:41PM (#12258211)
Python also has map(), but the lack of lightweight block syntax (like Perl's and Ruby's) makes it more cumbersome to use. I don't see how list comprehensions are less powerful, though.
Re:PyPy gets funding from Mozilla for Python 3.5 support by kbenson on Tuesday August 09, 2016 @07:57PM (#12258539)
> Python also has map(), but the lack of lightweight block syntax (like Perl's and Ruby's) makes it more cumbersome to use.

Yes. Additionally, I prefer the clear directionality of control and transform denoted by the dual capabilities of `map` and `grep` over list comprehensions, especially when chaining. Even better, IMO, is Perl 6's ability to use the feed operator to go left-to-right, so if the map block can be read the same direction as the flow of list items.[1] Having to scan back and forth to determine what is happening is a real detriment to the readability of these types of expressions, IMO.

> I don't see how list comprehensions are less powerful, though.

You're correct. Not strictly less powerful, just that the single expression for transforming the item may require multiple comprehensions where a single slightly more complex map block could get away with a temporary variable. Given that I dislike the way multiple list comprehensions read, this may be a bigger deal for me than most.

1: E.g. my @new = ( @original ==> grep { ... } ==> map { ... } ==> sort { ... } );

Re:PyPy gets funding from Mozilla for Python 3.5 support by zardeh on Tuesday August 09, 2016 @08:32PM (#12258691)
just checking to be sure, your example is essentially

original.filter(...).map(...).sort(), which in python would be `sorted([... for x in original if ...], ...)`.

I'll agree that sometimes the functional/chainable approach is nicer, but often it also isn't necessary

Re:PyPy gets funding from Mozilla for Python 3.5 support by kbenson on Tuesday August 09, 2016 @09:30PM (#12258907)
> just checking to be sure, your example is essentially original.filter(...).map(...).sort()

Yes, a method chaining format (such as Ruby and JS, and which can be enabled with a module in Perl) does approximate the control flow I'm referring to, The only different to the feed operator in Perl 6 is that the feed works on a per-item basis, allowing the list to be lazily generated, which also means it's a closer approximation to how you would code it in a for loop, as statements are done in succession on each item.

E.g.

    my @source = 1..Inf;
    my @elevensies = ( @source ==> map { $_*11 } );
    my @odd-elevensies = ( @elevensies ==> grep *%2 );
    my @root-of-odd-elevensies = ( @odd-elevensies ==> map *.sqrt );
Although in this case the left feed operator may be clearer.

> which in python would be `sorted([... for x in original if ...], ...)`.

> I'll agree that sometimes the functional/chainable approach is nicer, but often it also isn't necessary

Well, the example I gave was simplistic and to show direction. A more complex example would require a comprehension of a comprehension, which is where I start to have real issues with the format, and which is not represented from that example, which wasn't meant to illustrate that particular problem.

Re:PyPy gets funding from Mozilla for Python 3.5 support by icebraining on Wednesday August 10, 2016 @02:06AM (#12259794)
Your example translated to Python is also lazily generated (it uses the lazy equivalent of list comprehensions, called generator expressions):

  source = count(1)
  elevensies = (x * 11 for x in source)
  odd_elevensies = (x for x in elevensies if x%2)
  root_of_odd_elevensies = (math.sqrt(x) for x in odd_elevensies)
To me, the examples seem fairly equivalent, with the exception that Python's is, in my opinion, more readable for a newbie, since it doesn't require knowing map() or grep() - just for loops and ifs.
Re:PyPy gets funding from Mozilla for Python 3.5 support by kbenson on Wednesday August 10, 2016 @03:36AM (#12260080)
I was aware of generators in python, but I wasn't aware of the lazy lest comprehensions, which is very nice.

I agree list comprehensions in the simple form are easier for a newbie to recognize, but I also like the way map and filter make you think about your actions, and think they are clearer in the less trivial cases (as I mentioned above). I say "filter" because while I am completely familiar with that terminology, I accept that it's an unneeded departure from the common terminology for that task.

Re:PyPy gets funding from Mozilla for Python 3.5 support by icebraining on Wednesday August 10, 2016 @04:16AM (#12260231)
Well, map and filter may be more clear in certain cases, but I still don't see how they are more powerful. Seems like you can do a 1-for-1 translation between the two.
Re:PyPy gets funding from Mozilla for Python 3.5 support by kbenson on Wednesday August 10, 2016 @10:19AM (#12261916)
Oh, that's because you must have missed a few comments back where I agreed with you and backed out on any claim they were strictly more powerful. ;)
Re:PyPy gets funding from Mozilla for Python 3.5 support by icebraining on Wednesday August 10, 2016 @10:48AM (#12262156)
Ah, uh, sorry ;)
Re:PyPy gets funding from Mozilla for Python 3.5 support by Florin_Andrei on Tuesday August 09, 2016 @03:46PM (#12257249)
> Weird how suddenly everyone seems to have coalesced around 3.5

I wonder if v3.5 being included in Ubuntu 16.04 LTS has helped there a little.

Re:PyPy gets funding from Mozilla for Python 3.5 support by JustSomeNobody on Tuesday August 09, 2016 @05:03PM (#12257682)
I wouldn't think. Its more likely that 3.5 just hits all the right bullet points and people are excited about it.
Re:PyPy gets funding from Mozilla for Python 3.5 support by ben_jones on Tuesday August 09, 2016 @06:52PM (#12258258)
I'll be impressed by the new async features when they abstract the manual declaration of the event_loop in ways similar to Elixir or Golang. That's still a very confusing part for me and I find it hard to implement async properly into my programs in such a way that it's worth the added complexity.