bpo-36290: Fix keytword collision handling in AST node constructors (GH-12382)

(cherry picked from commit c73914a562)

Co-authored-by: Rémi Lapeyre <remi.lapeyre@lenstra.fr>
This commit is contained in:
Miss Islington (bot) 2020-05-24 14:32:32 -07:00 committed by GitHub
parent 46c1b9c7b5
commit 1a4e9e6f35
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 68 additions and 8 deletions

View file

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