Live data from Hacker News

Python 3.7 released

python.org

41–50 of 56 posts

Re: Python 3.7 released

#41
Love data classes! Would've been even cooler if they could've been made immutable.

Oops, never mind: "It is not possible to create truly immutable Python objects. However, by passing frozen=True to the dataclass() decorator you can emulate immutability. In that case, dataclasses will add __setattr__() and __delattr__() methods to the class. These methods will raise a FrozenInstanceError when invoked."

Re: Python 3.7 released

#42
post #38

Earlier quoted context omitted.

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?

That assumes you have a project. Some people write scripts in Python to use in the shell.

venvs work fine in the shell. See pipsi for automatic creation/management of the necessary venvs.

Re: Python 3.7 released

#43

Earlier quoted context omitted.

Is the breakpoint builtin analogous to binding.pry in Ruby? If so...that is amazing!

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).

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

#44

Hey, does anyone know where to find information about how python's releases are structured? For example, 3.6 exists and 3.7 is released. Without looking at the release details, should I be upgrading? Should I assume that it will break stuff, or assume that it won't, or should I make no assumptions? Etc...

3.6 to 3.7 is a minor release, only supposed to have new features, and not break existing code. Obviously, the probability of bugs is higher than in a micro release (e.g. 3.6.2 to 3.6.3), which only contains bugfixes. But I can't remember code from 2.6 breaking on 2.7, nor code from 3.5 breaking on 3.6.

Re: Python 3.7 released

#45

Earlier quoted context omitted.

I'm not a python dev, but isn't less dependencies generally better? Or is attrs in Python natively already?

Attrs isn't in python natively. Not sure why less dependencies would be better though.

Every dependency is one more thing that can go wrong in my mind. I always drop them at every opportunity.

There are some exceptions. Like I really don't want form building to be in the standard library, and I don't want to write it myself.

It is nice when your package manager only takes a short manage to fetch and build though, and you can have more confidence that any mistakes will be your own (under your control) rather than someone else's.

Re: Python 3.7 released

#46

Earlier quoted context omitted.

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?

Data classes are just regular classes with some methods generated for you. For now you still have to specify __slots__ manually to save memory.

So what’s the point of specifying the types?

Re: Python 3.7 released

#47
post #38

Earlier quoted context omitted.

That assumes you have a project. Some people write scripts in Python to use in the shell.

venvs work fine in the shell. See pipsi for automatic creation/management of the necessary venvs.

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

#48

Earlier quoted context omitted.

Data classes are just regular classes with some methods generated for you. For now you still have to specify __slots__ manually to save memory.

So what’s the point of specifying the types?

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

#49

Hey, does anyone know where to find information about how python's releases are structured? For example, 3.6 exists and 3.7 is released. Without looking at the release details, should I be upgrading? Should I assume that it will break stuff, or assume that it won't, or should I make no assumptions? Etc...

3.6 to 3.7 is a minor release, only supposed to have new features, and not break existing code. Obviously, the probability of bugs is higher than in a micro release (e.g. 3.6.2 to 3.6.3), which only contains bugfixes. But I can't remember code from 2.6 breaking on 2.7, nor code from 3.5 breaking on 3.6.

Only point releases are support to avoid breaking code (though they sometime do).

Minor release may break code, though it should be rare. Python 3.7 reserves 'async' and 'await' as keywords so assignments like "async = 3", which worked in 3.6, will now fail.

Python has a deprecation warning system which can detect cases like this, but it must be enabled:

  % python -Wall
  Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 05:52:31)
  [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
  Type "help", "copyright", "credits" or "license" for more information.
  >>> async = 3
  :1: DeprecationWarning: 'async' and 'await' will become
  reserved keywords in Python 3.7

Re: Python 3.7 released

#50
post #8

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.)

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.
Post reply on HN