Skip to content

Commit 667c564

Browse files
committed
Defer comprehension implicit-arg recast to __init__
The inlined recast and deferring to __init__ for the rare '.0' comprehension argument perform identically, so keep the simpler version that does not duplicate __init__'s logic.
1 parent eb05e27 commit 667c564

1 file changed

Lines changed: 5 additions & 6 deletions

File tree

Lib/inspect.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2735,12 +2735,11 @@ def _from_valid_args(cls, name, kind, default, annotation):
27352735
# the name comes from a code object's co_varnames -- always a valid,
27362736
# non-keyword identifier -- and the kind is one of the module-level
27372737
# _ParameterKind constants. Skips the validation done in __init__.
2738-
if name[0] == '.' and name[1:].isdigit():
2739-
# Implicit argument generated by a comprehension; recast '.N' as
2740-
# 'implicitN' and treat it as positional-only, as __init__ does
2741-
# (see gh-issue 19611).
2742-
kind = _POSITIONAL_ONLY
2743-
name = 'implicit' + name[1:]
2738+
# Implicit comprehension arguments ('.0') are rare and need the
2739+
# recast __init__ performs, so defer those to it rather than
2740+
# duplicate the logic here.
2741+
if name[0] == '.':
2742+
return cls(name, kind=kind, default=default, annotation=annotation)
27442743
self = cls.__new__(cls)
27452744
self._name = name
27462745
self._kind = kind

0 commit comments

Comments
 (0)