[proxy] github.com← back | site home | direct (HTTPS) ↗ | proxy home | ◑ dark◐ light

bpo-35975: Support parsing earlier minor versions of Python 3 by gvanrossum · Pull Request #12086 · python/cpython

gvanrossum

Visible behavior:

- Issue error for `X @ Y` (matrix multiply) if c_feature_version < 5

- Add optional feature_version kw arg to ast.parse() (default -1 which
  implies PY_MINOR_VERSION)

- Add feature_version: int = -1 to compile() (via Argument Clinic);
  this sets cf_feature_version to the given value if >= 0, else
  defaults to PY_MINOR_VERSION

Implementation:

- Add PyAST_obj2mod_ex(): like PyAST_obj2mod() but with feature_version arg;
  the latter calls the former with PY_MINOR_VERSION

- Add cf_feature_version to PyCompilerFlags structure;
  initialized to PY_MINOR_VERSION everywhere

- Add c_feature_version to struct compiling; initialize from
  cf_feature_version

- Add 'c' argument to get_operator()

- In builtin eval() and exec(), default to PY_MINOR_VERSION

TODO:

- Put version-dependent ASYNC/AWAIT keyword scanning back

- Reject async functions, await expressions, and async for/with in minor versions < 5

- Reject async comprehensions in minor versions < 6

- Reject underscores in numeric literals in minor versions < 6

- Reject variable annotations in minor versions < 6

- Reject `X @= Y` in minor versions < 5

This is everything currently in typeshed except await expressions (but
it does reject async functions etc.):

    - Reject async functions and async for/with in minor versions < 5

    - Reject async comprehensions in minor versions < 6

    - Reject underscores in numeric literals in minor versions < 6

    - Reject variable annotations in minor versions < 6

    - Reject `X @= Y` in minor versions < 5

This adds:
- Add ASYNC/AWAIT tokens back to Grammar and regenerate
- Recognize async/await keywords conditionally if feature_version < 7
- Reject await expressions if feature_version < 5
- Docs for ASYNC/AWAIT tokens and for ast.parse(..., feature_version=N)

The PyST_Object header in parsermodule.c became one int larger
because it contains a PyCompilerFlags struct, which grew extra
space for the st_feature_version field.  Took me long enough!

… not regular keywords

gvanrossum changed the title bpo-35975: [WIP] Support parsing earlier minor versions of Python 3 bpo-35975: Support parsing earlier minor versions of Python 3

Mar 5, 2019

zware deleted the feature-version branch

April 10, 2019 02:26