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

This commit is contained in:
Rémi Lapeyre 2020-05-24 23:12:57 +02:00 committed by GitHub
parent 59f5022b5d
commit c73914a562
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)