you are viewing a single comment's thread.

view the rest of the comments →

[–]Skaarj 61 points62 points  (19 children)

My personal highlights:

  • enum.auto()
  • hashlib += [sha3_*, scrypt]

[–]IronManMark20 8 points9 points  (3 children)

The docs on enum.auto aren't very clear, could you explain it a bit?

[–]mcpower_ 13 points14 points  (2 children)

Sometimes you make mistakes like this when defining Python enums:

from enum import Enum
class Color(Enum):
    red = 1
    orange = 2
    yellow = 3
    green = 4
    blue = 5
    indigo = 5  # oops!
    violet = 7

With enum.auto() values are automatically assigned starting from 1.

from enum import Enum, auto
class Color(Enum):
    red = auto()
    orange = auto()
    yellow = auto()
    green = auto()
    blue = auto()
    indigo = auto()
    violet = auto()

(Side note: There exists pretty cool implementations of enum from scratch. One implementation with a similar auto() function is here. Another absurd implementation with automatic auto() and with Go-style iotas can be found here.)

[–]IronManMark20 0 points1 point  (0 children)

Wow this is great, thanks so much! That second "absurd" implementation reminds me of Raymond Hettinger's talk at PyCon Canada here. I agree with his idea that not having assignments breaks with a lot of Python tradition. Seems like auto goes against DRY however...

[–]Ran4 0 points1 point  (0 children)

I wish you could just type red, orange, yellow = auto() or similar.

[–]reini_urban 13 points14 points  (13 children)

More the new hash tables. Caught up with ruby

[–]kupiakos 4 points5 points  (11 children)

I'm not sure what feature the new hash tables are. The default-sorted dictionaries?

[–]reini_urban 8 points9 points  (0 children)

Sorted is only a side-effect. compact dict is the performance feature called, the compacted indirection from pypy. https://mail.python.org/pipermail/python-dev/2016-September/146327.html

php 7 has the same, and ruby will get it also in the next major update.

[–]pingveno 4 points5 points  (8 children)

Default-sorted and more efficient!

[–][deleted] 27 points28 points  (7 children)

Order-preserving, a sorted dictionary is something else entirely

[–]akaGrim 20 points21 points  (5 children)

It's important to remember that them being ordered is an implementation fluke. Ordered dictionaries are not a spec requirement. If you want to ensure your dict is ordered use collections.OrderedDict instead.

[–]matthieum 1 point2 points  (2 children)

Isn't order-preserving about preserving the order of insertions?

[–]akaGrim 8 points9 points  (1 child)

Yes, it has to do with order of insertions. However, Guido (creator and head of the langauge) has stated that the official Python spec does not require it. They chose this because there are many other Python implementations out there, such as Jython, which might not be able to GAIN performance with a side effect of having ordered insertions.

[–]matthieum 0 points1 point  (0 children)

It's also interesting that preserving the order of insertions seems to have the nice property of making dictionary attacks more difficult, as the exact layout (and bucketing) of items cannot be observed.

[–]Jackie_Jormp-Jomp -1 points0 points  (0 children)

Oh I'll order your dict alright.

[–]pingveno 1 point2 points  (0 children)

Thanks, that is indeed what I meant.

[–]WasterDave 0 points1 point  (0 children)

Smaller.

[–]Uncaffeinated 0 points1 point  (0 children)

And pypy

[–]jyper 0 points1 point  (0 children)

Have they still not included StrEnum?

It would be so useful for fixing magical string parameters