5 ms·
Notable parts of this release (IMO): * Data classes (https://docs.python.org/3.7/library/dataclasses.html https://docs.python.org/3.7/library/dataclasses.html)
by luhn 8y ago
Notable parts of this release (IMO):
* Data classes (https://docs.python.org/3.7/library/dataclasses.html https://docs.python.org/3.7/library/dataclasses.html)
* New breakpoint() builtin (https://docs.python.org/3.7/library/functions.html#breakpoint https://docs.python.org/3.7/library/functions.html#breakpoin...)
* Dictionaries preserve insertion order. (Implemented in 3.6, but now is part of the official spec.)
- welder 8y agoData classes are awesome! No more boilerplate __init__(self) methods needed. Another notable part of this release is type annotations: https://www.python.org/dev/peps/pep-0560/ https://www.python.org/dev/peps/pep-0560/
- johnramsden 8y agoI love python typing, and have been using it extensively in 3.6. Great to see it in the CPython core! I've been looking forward to trying data classes, should be nice to avoid unnecessary code.
- kossae 8y ago> The typing module is one of the heaviest and slowest modules in the standard library even with all the optimizations made. Have you noticed any decreases in performance using core typing?
- kbd 8y agoFor those wondering, like I was, where that quote comes from, it's from PEP 560 "Core support for typing module and generic types" - https://www.python.org/dev/peps/pep-0560/ https://www.python.org/dev/peps/pep-0560/
- lysp 8y agoNot a python coder, but from my understanding they are essentially auto-constructors?
- extralego 8y agoTechnically, no, but that is how they are written. __init__ was always called after the instance was already created. I think it was originally useful for managing inheritance and baseclass initialization, which can be handled other less hard-coded ways now. I could be wrong.
- jihadjihad 8y agoIs the breakpoint builtin analogous to binding.pry in Ruby? If so...that is amazing!
- Buttons840 8y agoYes, it's quite similar. It's not THAT amazing though since it's just a convenience function over pdb.set_trace() which has been in the Python standard library for a very long time (2 decades or more).
- eesmith 8y agoOut of curiosity, I looked it up. According to a 'git annotate' of pdb.py, "def set_trace():" was added by Guido van Rossum on 1994-08-01 at 11:34:53 - almost 24 years ago.
- icebraining 8y agoYeah, the main advantage seems to be that you can configure the debugger to use externally (I often "pip install ipdb" just to use IPython's shell instead of the default).
- robertAngst 8y agoWow, I'm tempted to make the switch tomorrow but I literally just wrote tons of boilerplate today....
- deleted 8y ago[deleted]
- deleted 8y ago[deleted]
- mrfusion 8y agoData classes look cool. Maybe replacing named tuples in my future code? They always felt awkward to work with. Will data classes save a ton of memory since you’re specifying the types?
- pseudalopex 8y agoData classes are just regular classes with some methods generated for you. For now you still have to specify __slots__ manually to save memory.
- mrfusion 8y agoSo what’s the point of specifying the types?
- eesmith 8y agoOver the last few years Python has gained a type annotation system. The primary goals are to improve testing, improve documentation (the type information is more likely to stay synchronized than docstring annotations), and improve user-feedback in environments like an IDE or Jupyter notebook. These are called "type hints" because they are not enforced by the Python runtime.
- j88439h84 8y agoCan anyone explain why you'd want to use dataclasses over attrs in real code? Attrs does everything they do and more. "Data Classes are intentionally less powerful than attrs. There is a long list of features that were sacrificed for the sake of simplicity and while the most obvious ones are validators, converters, and __slots__, it permeates throughout all APIs." See: http://www.attrs.org/en/stable/why.html#data-classes http://www.attrs.org/en/stable/why.html#data-classes
- Spiritus 8y agoBecause they’re in the standard library, and convenient. I would never use a third-party package just for some syntactic sugar.
- j88439h84 8y agoI don't understand the inconvenience. Isn't it just adding `attrs` to requirements.txt once for the whole project, and then you get more features ever after?
- lozenge 8y agoThat assumes you have a project. Some people write scripts in Python to use in the shell.
- icebraining 8y agovenvs work fine in the shell. See pipsi for automatic creation/management of the necessary venvs.
- eesmith 8y agoSome people write simple programs which they then (say) email to others, or put on a blog post, or on a gist, or a SO answer. If the simple program depends only on core Python, then they don't also have to say "oh, and also install ...".
- tmaly 8y agoI have been looking to translate Moo/Mouse type stuff in Perl to a Python equivalent. I think Data Classes will definitely bring me closer to this.
- bostik 8y ago> Dictionaries preserve insertion order. (Implemented in 3.6, but now is part of the official spec.) That is a terrible decision. Call me a heretic. Yes, I know it's a side effect of bringing in the bitmap index version from PyPy. Yes, I am aware that collections.OrderedDict is now an alias to internal dictionary type. And yes, I do understand that randomising the key traversal order could incur a performance penalty. But a dictionary where keys come out in anything other than unspecified order is a subtle trap just waiting to blow up. I personally prefer golang's map behaviour - keys are always in unspecified order, and the order is different even between calls.
- uranusjr 8y agoPersonally I feel it is perfectly in line with one of Python’s core mentality, “We’re all grown-ups here.” The bahaviour is like Python lacking real access control: If you don’t think about it, it does not matter[#]; if you need it, it’s incredibly useful. You may not like it, and that’s fine, we agree to disagree. [#]: Well, usually it doesn’t matter, and when it does, you have other ways to achieve similar results.