diff options
author | Rémi Lapeyre <remi.lapeyre@lenstra.fr> | 2020-05-24 23:12:57 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-24 22:12:57 +0100 |
commit | c73914a562580ae72048876cb42ed8e76e2c83f9 (patch) | |
tree | c2530e91a3790121ef7d4a4650a0bdc7c91f1eeb /Lib/ast.py | |
parent | 59f5022b5d3e5fcc60ac61cc256b627decf8ee68 (diff) | |
download | cpython-c73914a562580ae72048876cb42ed8e76e2c83f9.tar.gz cpython-c73914a562580ae72048876cb42ed8e76e2c83f9.zip |
bpo-36290: Fix keytword collision handling in AST node constructors (GH-12382)
Diffstat (limited to 'Lib/ast.py')
-rw-r--r-- | Lib/ast.py | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/Lib/ast.py b/Lib/ast.py index 52e51b48587..6a5b39e270b 100644 --- a/Lib/ast.py +++ b/Lib/ast.py @@ -524,6 +524,13 @@ class _ABC(type): return type.__instancecheck__(cls, inst) def _new(cls, *args, **kwargs): + for key in kwargs: + if key not in cls._fields: + # arbitrary keyword arguments are accepted + continue + pos = cls._fields.index(key) + if pos < len(args): + raise TypeError(f"{cls.__name__} got multiple values for argument {key!r}") if cls in _const_types: return Constant(*args, **kwargs) return Constant.__new__(cls, *args, **kwargs) |