Skip to content

Commit

Permalink
Don't add fictional parameters to NamedTuple._make() (#15578)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexWaygood committed Jul 3, 2023
1 parent 5e4d097 commit 49d95cf
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
7 changes: 1 addition & 6 deletions mypy/semanal_namedtuple.py
Expand Up @@ -605,16 +605,11 @@ def make_init_arg(var: Var) -> Argument:

add_method("__new__", ret=selftype, args=[make_init_arg(var) for var in vars], is_new=True)
add_method("_asdict", args=[], ret=ordereddictype)
special_form_any = AnyType(TypeOfAny.special_form)
add_method(
"_make",
ret=selftype,
is_classmethod=True,
args=[
Argument(Var("iterable", iterable_type), iterable_type, None, ARG_POS),
Argument(Var("new"), special_form_any, EllipsisExpr(), ARG_NAMED_OPT),
Argument(Var("len"), special_form_any, EllipsisExpr(), ARG_NAMED_OPT),
],
args=[Argument(Var("iterable", iterable_type), iterable_type, None, ARG_POS)],
)

self_tvar_expr = TypeVarExpr(
Expand Down
4 changes: 2 additions & 2 deletions test-data/unit/check-newsemanal.test
Expand Up @@ -992,7 +992,7 @@ class SubO(Out): pass

o: SubO

reveal_type(SubO._make) # N: Revealed type is "def (iterable: typing.Iterable[Any], *, new: Any =, len: Any =) -> Tuple[Tuple[builtins.str, __main__.Other, fallback=__main__.In], __main__.Other, fallback=__main__.SubO]"
reveal_type(SubO._make) # N: Revealed type is "def (iterable: typing.Iterable[Any]) -> Tuple[Tuple[builtins.str, __main__.Other, fallback=__main__.In], __main__.Other, fallback=__main__.SubO]"
reveal_type(o._replace(y=Other())) # N: Revealed type is "Tuple[Tuple[builtins.str, __main__.Other, fallback=__main__.In], __main__.Other, fallback=__main__.SubO]"
[builtins fixtures/tuple.pyi]

Expand All @@ -1009,7 +1009,7 @@ o: Out
reveal_type(o) # N: Revealed type is "Tuple[Tuple[builtins.str, __main__.Other, fallback=__main__.In], __main__.Other, fallback=__main__.Out]"
reveal_type(o.x) # N: Revealed type is "Tuple[builtins.str, __main__.Other, fallback=__main__.In]"
reveal_type(o.x.t) # N: Revealed type is "__main__.Other"
reveal_type(Out._make) # N: Revealed type is "def (iterable: typing.Iterable[Any], *, new: Any =, len: Any =) -> Tuple[Tuple[builtins.str, __main__.Other, fallback=__main__.In], __main__.Other, fallback=__main__.Out]"
reveal_type(Out._make) # N: Revealed type is "def (iterable: typing.Iterable[Any]) -> Tuple[Tuple[builtins.str, __main__.Other, fallback=__main__.In], __main__.Other, fallback=__main__.Out]"
[builtins fixtures/tuple.pyi]

[case testNewAnalyzerIncompleteRefShadowsBuiltin1]
Expand Down

0 comments on commit 49d95cf

Please sign in to comment.