diff options
author | Guido van Rossum <guido@python.org> | 2019-02-20 18:08:23 -0800 |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2019-03-05 11:36:11 -0800 |
commit | 0e2403f2f95a21912972422564de37cbe129c195 (patch) | |
tree | 82d360e7f4c9ea6e2d385c86bf11154de713b717 /Python/pythonrun.c | |
parent | d8b3a98c9098c66a714fd5593e1928af0ffbc631 (diff) | |
download | cpython-git-0e2403f2f95a21912972422564de37cbe129c195.tar.gz |
Work towards feature_version support
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
Diffstat (limited to 'Python/pythonrun.c')
-rw-r--r-- | Python/pythonrun.c | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/Python/pythonrun.c b/Python/pythonrun.c index 906877a0a8..ae6778d8a5 100644 --- a/Python/pythonrun.c +++ b/Python/pythonrun.c @@ -105,6 +105,7 @@ PyRun_InteractiveLoopFlags(FILE *fp, const char *filename_str, PyCompilerFlags * if (flags == NULL) { flags = &local_flags; local_flags.cf_flags = 0; + local_flags.cf_feature_version = PY_MINOR_VERSION; } v = _PySys_GetObjectId(&PyId_ps1); if (v == NULL) { @@ -1165,6 +1166,7 @@ Py_SymtableStringObject(const char *str, PyObject *filename, int start) return NULL; flags.cf_flags = 0; + flags.cf_feature_version = PY_MINOR_VERSION; mod = PyParser_ASTFromStringObject(str, filename, start, &flags, arena); if (mod == NULL) { PyArena_Free(arena); @@ -1204,6 +1206,7 @@ PyParser_ASTFromStringObject(const char *s, PyObject *filename, int start, &iflags); if (flags == NULL) { localflags.cf_flags = 0; + localflags.cf_feature_version = PY_MINOR_VERSION; flags = &localflags; } if (n) { @@ -1249,6 +1252,7 @@ PyParser_ASTFromFileObject(FILE *fp, PyObject *filename, const char* enc, start, ps1, ps2, &err, &iflags); if (flags == NULL) { localflags.cf_flags = 0; + localflags.cf_feature_version = PY_MINOR_VERSION; flags = &localflags; } if (n) { |