Skip to content

Commit 613358a

Browse files
committed
Fix false positive for constrained NamedTuple self types
1 parent b41157b commit 613358a

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

mypy/checker.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1785,14 +1785,18 @@ def require_correct_self_argument(self, func: Type, defn: FuncDef) -> bool:
17851785
# and incorrectly rejected.
17861786
#
17871787
# Skip this check for constrained generic NamedTuple tuple self types.
1788+
has_constrained_typevar = False
1789+
if isinstance(ref_type, TupleType):
1790+
for item in ref_type.items:
1791+
if isinstance(item, TypeVarType) and item.values:
1792+
has_constrained_typevar = True
1793+
break
1794+
17881795
skip_namedtuple_constrained_check = (
17891796
isinstance(ref_type, TupleType)
17901797
and isinstance(arg_type, TupleType)
1791-
and ref_type.partial_fallback.type.tuple_type is not None
1792-
and any(
1793-
isinstance(item, TypeVarType) and item.values
1794-
for item in ref_type.items
1795-
)
1798+
and ref_type.partial_fallback.type.is_named_tuple
1799+
and has_constrained_typevar
17961800
)
17971801

17981802
if (

0 commit comments

Comments
 (0)