mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
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:
parent
46c1b9c7b5
commit
1a4e9e6f35
5 changed files with 68 additions and 8 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue