News for hackers. Stuff that matters.
Re:Python 3.7 released by luhn on Wednesday June 27, 2018 @08:59PM (#17413221)
Notable parts of this release (IMO):

* Data classes (https://docs.python.org/3.7/library/dataclasses.html)

* New breakpoint() builtin (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.)

Re:Python 3.7 released by welder on Wednesday June 27, 2018 @09:04PM (#17413249)
Data 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/

Re:Python 3.7 released by johnramsden on Wednesday June 27, 2018 @09:14PM (#17413317)
I 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.

Re:Python 3.7 released by kossae on Wednesday June 27, 2018 @09:45PM (#17413447)
> 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?

Re:Python 3.7 released by kbd on Wednesday June 27, 2018 @10:03PM (#17413519)
For 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/
Re:Python 3.7 released by lysp on Wednesday June 27, 2018 @10:28PM (#17413613)
Not a python coder, but from my understanding they are essentially auto-constructors?
Re:Python 3.7 released by extralego on Wednesday June 27, 2018 @11:04PM (#17413754)
Technically, 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.
Re:Python 3.7 released by bostik on Thursday June 28, 2018 @04:49PM (#17420368)
> 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.

Re:Python 3.7 released by uranusjr on Saturday June 30, 2018 @06:09AM (#17430231)
Personally 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.

Re:Python 3.7 released by j88439h84 on Thursday June 28, 2018 @12:15AM (#17414020)
Can 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

Re:Python 3.7 released by Spiritus on Thursday June 28, 2018 @02:09AM (#17414473)
Because they’re in the standard library, and convenient. I would never use a third-party package just for some syntactic sugar.
Re:Python 3.7 released by j88439h84 on Thursday June 28, 2018 @03:54AM (#17414916)
I 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?
Re:Python 3.7 released by michaelmcmillan on Thursday June 28, 2018 @07:07AM (#17415842)
Simple != easy. It is easy to add another dependency, but you've just added another piece to the puzzle that needs to be maintained.
Re:Python 3.7 released by lozenge on Thursday June 28, 2018 @04:30AM (#17415073)
That assumes you have a project. Some people write scripts in Python to use in the shell.
Re:Python 3.7 released by icebraining on Thursday June 28, 2018 @08:35AM (#17416321)
venvs work fine in the shell. See pipsi for automatic creation/management of the necessary venvs.
Re:Python 3.7 released by eesmith on Thursday June 28, 2018 @10:19AM (#17417036)
Some 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 ...".

Re:Python 3.7 released by JustSomeNobody on Thursday June 28, 2018 @04:02PM (#17420011)
It's one more thing that can break in production.
Re:Python 3.7 released by mrfusion on Wednesday June 27, 2018 @11:38PM (#17413887)
Data 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?

Re:Python 3.7 released by pseudalopex on Wednesday June 27, 2018 @11:56PM (#17413959)
Data classes are just regular classes with some methods generated for you. For now you still have to specify __slots__ manually to save memory.
Re:Python 3.7 released by mrfusion on Thursday June 28, 2018 @10:00AM (#17416901)
So what’s the point of specifying the types?
Re:Python 3.7 released by eesmith on Thursday June 28, 2018 @10:25AM (#17417100)
Over 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.

Re:Python 3.7 released by jihadjihad on Wednesday June 27, 2018 @09:07PM (#17413273)
Is the breakpoint builtin analogous to binding.pry in Ruby? If so...that is amazing!
Re:Python 3.7 released by Buttons840 on Wednesday June 27, 2018 @09:23PM (#17413353)
Yes, 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).
Re:Python 3.7 released by eesmith on Thursday June 28, 2018 @03:30AM (#17414799)
Out 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.
Re:Python 3.7 released by icebraining on Thursday June 28, 2018 @08:37AM (#17416330)
Yeah, 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).
Re:Python 3.7 released by tmaly on Thursday June 28, 2018 @01:05PM (#17418646)
I 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.
Re:Python 3.7 released by robertAngst on Wednesday June 27, 2018 @09:57PM (#17413492)
Wow, I'm tempted to make the switch tomorrow but I literally just wrote tons of boilerplate today....