11

Python 3.8 introduces assignment expressions, described in PEP 572. Is there a way to test this new feature in Python 3.7.x?

In the past, new language features have been backported to earlier Python versions using __future__ imports.

  • Is there a __future__ import for assignment expressions?
  • If yes, what is the feature name?
  • If no, are there plans to add it? (3.7 is going to be around for a while)
Zero Piraeus
  • 47,176
  • 24
  • 135
  • 148
Daniel Mahler
  • 6,213
  • 3
  • 40
  • 82
  • 2
    At least not now: https://docs.python.org/3/library/__future__.html – Sraw Jul 30 '18 at 01:57
  • 1
    I've started working on a terrible-idea backport with a similar approach as https://github.com/asottile/future-fstrings, though it's slightly more difficult to enable due to bytecode rewriting being necessary. Here's my current progress: https://twitter.com/codewithanthony/status/1017584595292729345 – Anthony Sottile Jul 30 '18 at 02:27
  • 1
    `__future__` is only used for things that break backwards compatibility, which assignment expressions are not. – jwodder Jul 30 '18 at 02:42

1 Answers1

11

There is no __future__ import for assignment expressions in Python 3.7 – and adding one in a micro (or "bugfix") release is prohibited by PEP 6:

Prohibitions

Bug fix releases are required to adhere to the following restrictions:

  1. There must be zero syntax changes. All .pyc and .pyo files must work (no regeneration needed) with all bugfix releases forked off from a major release.

Applicability of Prohibitions

The above prohibitions and not-quite-prohibitions apply both for a final release to a bugfix release (for instance, 2.4 to 2.4.1) and for one bugfix release to the next in a series (for instance 2.4.1 to 2.4.2).

Since assignment expressions constitute a change to the syntax of Python, there's no way they can be added to a future 3.7.x release of Python without breaking this prohibition.

Zero Piraeus
  • 47,176
  • 24
  • 135
  • 148
  • 1
    "[A]ssignment expressions constitute a change to the syntax of Python" – only in scripts which explicitly `import` the feature; it's not clear to me but that prohibition seems to be directed at changes to the global "standard" syntax. Besides, the new syntax is such that it would have been illegal and unintelligible to the compiler before, so it wouldn't have been in use. However, I'll grant you that all current `__future__` features were added at minor versions, so there's no precedent (though it could be coincidence), and I can't speak to how it affects `.pyc` or `.pyo` files… – JuSTMOnIcAjUSTmONiCAJusTMoNICa Jan 02 '20 at 17:20