mypy icon indicating copy to clipboard operation
mypy copied to clipboard

Fix special cases of kwargs + TypeVarTuple

Open A5rocks opened this issue 1 year ago • 5 comments

Fixes https://github.com/python/mypy/issues/16522. This PR adds special casing for TypeVarTuple inference in the face of kwargs, though I believe the general case requires providing multiple possible constraints (e.g. "constraint a OR constraint b OR constraint C") which either isn't possible or I don't know how to.

This PR also fixes the subtyping of e.g. def f(a: int) -> None being a subtype of def g(*args: Unpack[tuple[Any, ...]]).

TODO:

  • [x] check if this impacts other issues (I think subtyping fix might)
    • Fixes #16662.
  • [ ] add a test case
  • [x] resolve conflicts

A5rocks avatar Jul 10 '24 05:07 A5rocks

cc @ilevkivskyi since I saw your changes w/r/t typevartuples when glancing over the merge conflicts. Maybe you'll have an idea of whether this Any-tuple thing is worth anything.

A5rocks avatar Jul 10 '24 05:07 A5rocks

Diff from mypy_primer, showing the effect of this PR on open source code:

aioredis (https://github.com/aio-libs/aioredis)
- aioredis/exceptions.py:14: error: Duplicate base class "TimeoutError"  [misc]
- aioredis/utils.py:45: error: Unused "type: ignore" comment  [unused-ignore]
- aioredis/connection.py:455: error: Type of variable becomes "Any | None" due to an unfollowed import  [no-any-unimported]
- aioredis/connection.py:933: error: Unsupported right operand type for in ("bytes | memoryview | int")  [operator]
- aioredis/connection.py:934: error: Item "memoryview" of "bytes | memoryview | int" has no attribute "split"  [union-attr]
- aioredis/connection.py:934: error: Item "int" of "bytes | memoryview | int" has no attribute "split"  [union-attr]
- aioredis/connection.py:1201: error: Unused "type: ignore" comment  [unused-ignore]
- aioredis/connection.py:1201: error: TypedDict key must be a string literal; expected one of ("username", "password", "connection_class", "host", "port", ...)  [literal-required]
- aioredis/connection.py:1201: note: Error code changed to literal-required; "type: ignore" comment may be out of date
- aioredis/connection.py:1205: error: Unused "type: ignore" comment  [unused-ignore]
- aioredis/connection.py:1205: error: TypedDict key must be a string literal; expected one of ("username", "password", "connection_class", "host", "port", ...)  [literal-required]
- aioredis/connection.py:1205: note: Error code changed to literal-required; "type: ignore" comment may be out of date
- aioredis/client.py:94: error: Unused "type: ignore" comment  [unused-ignore]
- aioredis/client.py:146: error: Signature of "update" incompatible with supertype "MutableMapping"  [override]
- aioredis/client.py:146: note:      Superclass:
- aioredis/client.py:146: note:          @overload
- aioredis/client.py:146: note:          def update(self, SupportsKeysAndGetItem[Any, Any], /, **kwargs: Any) -> None
- aioredis/client.py:146: note:          @overload
- aioredis/client.py:146: note:          def update(self, Iterable[tuple[Any, Any]], /, **kwargs: Any) -> None
- aioredis/client.py:146: note:          @overload
- aioredis/client.py:146: note:          def update(self, **kwargs: Any) -> None
- aioredis/client.py:146: note:      Subclass:
- aioredis/client.py:146: note:          def update(self, data: Any) -> Any
- aioredis/client.py:4114: error: Incompatible types in assignment (expression has type "dict[bytes | str | memoryview, Any | None]", variable has type "dict[bytes | str | memoryview, Callable[[dict[str, str]], Awaitable[None]]]")  [assignment]
- aioredis/client.py:4158: error: Argument 1 to "update" of "MutableMapping" has incompatible type "dict[bytes | str | memoryview, Any | None]"; expected "SupportsKeysAndGetItem[bytes | str | memoryview, Callable[[dict[str, str]], Awaitable[None]]]"  [arg-type]
- aioredis/client.py:4172: error: Incompatible types in assignment (expression has type "dict[bytes | str | memoryview, Callable[[dict[str, str]], Awaitable[None]]]", variable has type "dict[Any, Any | None]")  [assignment]
+ /tmp/mypy_primer/new_mypy/venv/lib/python3.12/site-packages/mypy/typeshed/stdlib/asyncio/base_events.pyi:70: error: INTERNAL ERROR -- Please try using mypy master on GitHub:
+ https://mypy.readthedocs.io/en/stable/common_issues.html#using-a-development-mypy-build
+ Please report a bug at https://github.com/python/mypy/issues
+ version: 1.12.0+dev.ddc7a59967ff82a280ef72b2bfac008e3adc80c5
+ note: use --pdb to drop into pdb
+ Traceback (most recent call last):
+   File "", line 8, in <module>
+     sys.exit(console_entry())
+   File "/__main__.py", line 15, in console_entry
+     main()
+   File "/main.py", line 103, in main
+     res, messages, blockers = run_build(sources, options, fscache, t0, stdout, stderr)
+   File "/main.py", line 187, in run_build
+     res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
+   File "/build.py", line 193, in build
+     result = _build(
+   File "/build.py", line 268, in _build
+     graph = dispatch(sources, manager, stdout)
+   File "/build.py", line 2950, in dispatch
+     process_graph(graph, manager)
+   File "/build.py", line 3348, in process_graph
+     process_stale_scc(graph, scc, manager)
+   File "/build.py", line 3449, in process_stale_scc
+     graph[id].type_check_first_pass()
+   File "/build.py", line 2314, in type_check_first_pass
+     self.type_checker().check_first_pass()
+   File "/checker.py", line 483, in check_first_pass
+     self.accept(d)
+   File "/checker.py", line 591, in accept
+     stmt.accept(self)
+   File "/nodes.py", line 1183, in accept
+     return visitor.visit_class_def(self)
+   File "/checker.py", line 2417, in visit_class_def
+     self.accept(defn.defs)
+   File "/checker.py", line 591, in accept
+     stmt.accept(self)
+   File "/nodes.py", line 1264, in accept
+     return visitor.visit_block(self)
+   File "/checker.py", line 2883, in visit_block
+     self.accept(s)
+   File "/checker.py", line 591, in accept
+     stmt.accept(self)
+   File "/nodes.py", line 819, in accept
+     return visitor.visit_func_def(self)
+            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/checker.py", line 1043, in visit_func_def
+     self._visit_func_def(defn)
+   File "/checker.py", line 1054, in _visit_func_def
+     found_method_base_classes = self.check_method_override(defn)
+                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/checker.py", line 1977, in check_method_override
+     result = self.check_method_or_accessor_override_for_base(
+              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/checker.py", line 2015, in check_method_or_accessor_override_for_base
+     if self.check_method_override_for_base_with_name(defn, name, base):
+        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/checker.py", line 2131, in check_method_override_for_base_with_name
+     self.check_override(
+   File "/checker.py", line 2250, in check_override
+     if not is_subtype(override, original, ignore_pos_arg_names=True):
+            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/subtypes.py", line 185, in is_subtype
+     return _is_subtype(left, right, subtype_context, proper_subtype=False)
+            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/subtypes.py", line 350, in _is_subtype
+     return left.accept(SubtypeVisitor(orig_right, subtype_context, proper_subtype))
+            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/types.py", line 1971, in accept
+     return visitor.visit_callable_type(self)
+            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/subtypes.py", line 713, in visit_callable_type
+     return is_callable_compatible(
+            ^^^^^^^^^^^^^^^^^^^^^^^
+   File "/subtypes.py", line 1537, in is_callable_compatible
+     unified = unify_generic_callable(left, right, ignore_return=ignore_return)
+               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/subtypes.py", line 1871, in unify_generic_callable
+     cs = mypy.constraints.infer_constraints(
+          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/constraints.py", line 317, in infer_constraints
+     return _infer_constraints(template, actual, direction, skip_neg_op)
+            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/constraints.py", line 410, in _infer_constraints
+     return template.accept(ConstraintBuilderVisitor(actual, direction, skip_neg_op))
+            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/types.py", line 1971, in accept
+     return visitor.visit_callable_type(self)
+            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/constraints.py", line 1089, in visit_callable_type
+     assert not other or arg.required
+            ^^^^^^^^^^^^^^^^^^^^^^^^^
+ AssertionError: 

AutoSplit (https://github.com/Toufool/AutoSplit)
+ /tmp/mypy_primer/new_mypy/venv/lib/python3.12/site-packages/mypy/typeshed/stdlib/asyncio/base_events.pyi:70: error: INTERNAL ERROR -- Please try using mypy master on GitHub:
+ https://mypy.readthedocs.io/en/stable/common_issues.html#using-a-development-mypy-build
+ Please report a bug at https://github.com/python/mypy/issues
+ version: 1.12.0+dev.ddc7a59967ff82a280ef72b2bfac008e3adc80c5
+ note: use --pdb to drop into pdb
- src/utils.py:92:5: error: Module has no attribute "windll"  [attr-defined]
- src/utils.py:108:5: error: Module has no attribute "startfile"  [attr-defined]
- src/capture_method/CaptureMethodBase.py:43:9: error: Returning Any from function declared to return "bool"  [no-any-return]
- src/capture_method/BitBltCaptureMethod.py:53:17: error: Module has no attribute "windll"  [attr-defined]
- src/capture_method/__init__.py:8:1: error: Module "_ctypes" has no attribute "COMError"  [attr-defined]
- src/user_profile.py:45:6: error: Invalid statement in TypedDict definition; expected "field_name: field_type"  [misc]
- src/user_profile.py:146:47: error: Argument 3 to "set_hotkey" has incompatible type "object"; expected "str"  [arg-type]
- src/region_selection.py:297:13: error: Redundant cast to "int"  [redundant-cast]
- src/region_selection.py:298:13: error: Redundant cast to "int"  [redundant-cast]
- src/region_selection.py:299:17: error: Redundant cast to "int"  [redundant-cast]
- src/region_selection.py:300:18: error: Redundant cast to "int"  [redundant-cast]
- src/menu_bar.py:33:40: error: Class cannot subclass "Ui_AboutAutoSplitWidget" (has type "Any")  [misc]
- src/menu_bar.py:50:48: error: Class cannot subclass "Ui_UpdateChecker" (has type "Any")  [misc]
- src/menu_bar.py:121:43: error: Class cannot subclass "Ui_SettingsWidget" (has type "Any")  [misc]
- src/AutoSplit.py:61:30: error: Class cannot subclass "Ui_MainWindow" (has type "Any")  [misc]
+ Traceback (most recent call last):
+   File "", line 8, in <module>
+     sys.exit(console_entry())
+   File "/__main__.py", line 15, in console_entry
+     main()
+   File "/main.py", line 103, in main
+     res, messages, blockers = run_build(sources, options, fscache, t0, stdout, stderr)
+   File "/main.py", line 187, in run_build
+     res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
+   File "/build.py", line 193, in build
+     result = _build(
+   File "/build.py", line 268, in _build
+     graph = dispatch(sources, manager, stdout)
+   File "/build.py", line 2950, in dispatch
+     process_graph(graph, manager)
+   File "/build.py", line 3348, in process_graph
+     process_stale_scc(graph, scc, manager)
+   File "/build.py", line 3449, in process_stale_scc
+     graph[id].type_check_first_pass()
+   File "/build.py", line 2314, in type_check_first_pass
+     self.type_checker().check_first_pass()
+   File "/checker.py", line 483, in check_first_pass
+     self.accept(d)
+   File "/checker.py", line 591, in accept
+     stmt.accept(self)
+   File "/nodes.py", line 1183, in accept
+     return visitor.visit_class_def(self)
+   File "/checker.py", line 2417, in visit_class_def
+     self.accept(defn.defs)
+   File "/checker.py", line 591, in accept
+     stmt.accept(self)
+   File "/nodes.py", line 1264, in accept
+     return visitor.visit_block(self)
+   File "/checker.py", line 2883, in visit_block
+     self.accept(s)
+   File "/checker.py", line 591, in accept
+     stmt.accept(self)
+   File "/nodes.py", line 819, in accept
+     return visitor.visit_func_def(self)
+            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/checker.py", line 1043, in visit_func_def
+     self._visit_func_def(defn)
+   File "/checker.py", line 1054, in _visit_func_def
+     found_method_base_classes = self.check_method_override(defn)
+                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/checker.py", line 1977, in check_method_override
+     result = self.check_method_or_accessor_override_for_base(
+              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/checker.py", line 2015, in check_method_or_accessor_override_for_base
+     if self.check_method_override_for_base_with_name(defn, name, base):
+        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/checker.py", line 2131, in check_method_override_for_base_with_name
+     self.check_override(
+   File "/checker.py", line 2250, in check_override
+     if not is_subtype(override, original, ignore_pos_arg_names=True):
+            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/subtypes.py", line 185, in is_subtype
+     return _is_subtype(left, right, subtype_context, proper_subtype=False)
+            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/subtypes.py", line 350, in _is_subtype
+     return left.accept(SubtypeVisitor(orig_right, subtype_context, proper_subtype))
+            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/types.py", line 1971, in accept
+     return visitor.visit_callable_type(self)
+            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/subtypes.py", line 713, in visit_callable_type
+     return is_callable_compatible(
+            ^^^^^^^^^^^^^^^^^^^^^^^
+   File "/subtypes.py", line 1537, in is_callable_compatible
+     unified = unify_generic_callable(left, right, ignore_return=ignore_return)
+               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/subtypes.py", line 1871, in unify_generic_callable
+     cs = mypy.constraints.infer_constraints(
+          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/constraints.py", line 317, in infer_constraints
+     return _infer_constraints(template, actual, direction, skip_neg_op)
+            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/constraints.py", line 410, in _infer_constraints
+     return template.accept(ConstraintBuilderVisitor(actual, direction, skip_neg_op))
+            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/types.py", line 1971, in accept
+     return visitor.visit_callable_type(self)
+            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/constraints.py", line 1089, in visit_callable_type
+     assert not other or arg.required
+            ^^^^^^^^^^^^^^^^^^^^^^^^^
+ AssertionError: 

dd-trace-py (https://github.com/DataDog/dd-trace-py)
+ /tmp/mypy_primer/new_mypy/venv/lib/python3.12/site-packages/mypy/typeshed/stdlib/asyncio/base_events.pyi:70: error: INTERNAL ERROR -- Please try using mypy master on GitHub:
+ https://mypy.readthedocs.io/en/stable/common_issues.html#using-a-development-mypy-build
+ Please report a bug at https://github.com/python/mypy/issues
+ version: 1.12.0+dev.ddc7a59967ff82a280ef72b2bfac008e3adc80c5
+ note: use --pdb to drop into pdb
- ddtrace/sourcecode/setuptools_auto.py:9: error: Unused "type: ignore" comment  [unused-ignore]
- docs/conf.py:578: error: Return type "Node" of "run" incompatible with return type "Sequence[Node]" in supertype "Directive"  [override]
- docs/conf.py:626: error: Need type annotation for "result"  [var-annotated]
- docs/conf.py:692: error: Incompatible return value type (got "list[Node]", expected "Node")  [return-value]
- ddtrace/internal/utils/time.py:101: error: Unused "type: ignore" comment, use narrower [method-assign] instead of [assignment] code  [unused-ignore]
- ddtrace/internal/utils/time.py:113: error: Unused "type: ignore" comment, use narrower [method-assign] instead of [assignment] code  [unused-ignore]
- ddtrace/internal/utils/time.py:130: error: Unused "type: ignore" comment, use narrower [method-assign] instead of [assignment] code  [unused-ignore]
- ddtrace/internal/periodic.py:71: error: Call to abstract method "_stop_service" of "Service" with trivial body via super() is unsafe  [safe-super]
- ddtrace/internal/gitmetadata.py:77: error: Item "None" of "list[Any] | None" has no attribute "__iter__" (not iterable)  [union-attr]
- ddtrace/settings/config.py:548: note: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs  [annotation-unchecked]
- ddtrace/sampler.py:313: note: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs  [annotation-unchecked]
- ddtrace/_trace/tracer.py:1110: error: Unused "type: ignore" comment, use narrower [method-assign] instead of [assignment] code  [unused-ignore]
- ddtrace/appsec/_deduplications.py:16: note: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs  [annotation-unchecked]
- ddtrace/appsec/_processor.py:289: error: Unused "type: ignore" comment  [unused-ignore]
- ddtrace/appsec/_processor.py:289: error: Unpacking a string is disallowed  [misc]
- ddtrace/appsec/_processor.py:289: note: Error code "misc" not covered by "type: ignore" comment
- ddtrace/commands/ddtrace_run.py:19: error: Unused "type: ignore" comment  [unused-ignore]
- ddtrace/profiling/recorder.py:52: error: Unused "type: ignore" comment, use narrower [method-assign] instead of [assignment] code  [unused-ignore]
- ddtrace/profiling/collector/_lock.py:332: error: Call to abstract method "_start_service" of "Service" with trivial body via super() is unsafe  [safe-super]
- ddtrace/profiling/collector/_lock.py:337: error: Call to abstract method "_stop_service" of "Service" with trivial body via super() is unsafe  [safe-super]
- ddtrace/internal/ci_visibility/coverage.py:40: error: Unused "type: ignore[assignment, misc]" comment  [unused-ignore]
- ddtrace/internal/ci_visibility/coverage.py:115: error: Unused "type: ignore" comment  [unused-ignore]
- ddtrace/internal/ci_visibility/coverage.py:151: error: Unused "type: ignore" comment  [unused-ignore]
- ddtrace/internal/ci_visibility/coverage.py:171: error: Unused "type: ignore" comment  [unused-ignore]
- ddtrace/internal/symbol_db/symbols.py:350: error: Redundant cast to "Scope | None"  [redundant-cast]
- ddtrace/debugging/_function/discovery.py:172: error: Incompatible return value type (got "dict[str | Any, FunctionType | Any]", expected "dict[str, FullyNamedFunction]")  [return-value]
- ddtrace/llmobs/_integrations/langchain.py:291: error: Incompatible return value type (got "tuple[Any | str, Any] | Any", expected "str")  [return-value]
- ddtrace/debugging/_encoding.py:152: note: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs  [annotation-unchecked]
- ddtrace/debugging/_probe/remoteconfig.py:266: note: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs  [annotation-unchecked]
+ Traceback (most recent call last):
+   File "", line 8, in <module>
+     sys.exit(console_entry())
+   File "/__main__.py", line 15, in console_entry
+     main()
+   File "/main.py", line 103, in main
+     res, messages, blockers = run_build(sources, options, fscache, t0, stdout, stderr)
+   File "/main.py", line 187, in run_build
+     res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
+   File "/build.py", line 193, in build
+     result = _build(
+   File "/build.py", line 268, in _build
+     graph = dispatch(sources, manager, stdout)
+   File "/build.py", line 2950, in dispatch
+     process_graph(graph, manager)
+   File "/build.py", line 3348, in process_graph
+     process_stale_scc(graph, scc, manager)
+   File "/build.py", line 3449, in process_stale_scc
+     graph[id].type_check_first_pass()
+   File "/build.py", line 2314, in type_check_first_pass
+     self.type_checker().check_first_pass()
+   File "/checker.py", line 483, in check_first_pass
+     self.accept(d)
+   File "/checker.py", line 591, in accept
+     stmt.accept(self)
+   File "/nodes.py", line 1183, in accept
+     return visitor.visit_class_def(self)
+   File "/checker.py", line 2417, in visit_class_def
+     self.accept(defn.defs)
+   File "/checker.py", line 591, in accept
+     stmt.accept(self)
+   File "/nodes.py", line 1264, in accept
+     return visitor.visit_block(self)
+   File "/checker.py", line 2883, in visit_block
+     self.accept(s)
+   File "/checker.py", line 591, in accept
+     stmt.accept(self)
+   File "/nodes.py", line 819, in accept
+     return visitor.visit_func_def(self)
+            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/checker.py", line 1043, in visit_func_def
+     self._visit_func_def(defn)
+   File "/checker.py", line 1054, in _visit_func_def
+     found_method_base_classes = self.check_method_override(defn)
+                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/checker.py", line 1977, in check_method_override
+     result = self.check_method_or_accessor_override_for_base(
+              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/checker.py", line 2015, in check_method_or_accessor_override_for_base
+     if self.check_method_override_for_base_with_name(defn, name, base):
+        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/checker.py", line 2131, in check_method_override_for_base_with_name
+     self.check_override(
+   File "/checker.py", line 2250, in check_override
+     if not is_subtype(override, original, ignore_pos_arg_names=True):
+            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/subtypes.py", line 185, in is_subtype
+     return _is_subtype(left, right, subtype_context, proper_subtype=False)
+            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/subtypes.py", line 350, in _is_subtype
+     return left.accept(SubtypeVisitor(orig_right, subtype_context, proper_subtype))
+            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/types.py", line 1971, in accept
+     return visitor.visit_callable_type(self)
+            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/subtypes.py", line 713, in visit_callable_type
+     return is_callable_compatible(
+            ^^^^^^^^^^^^^^^^^^^^^^^
+   File "/subtypes.py", line 1537, in is_callable_compatible
+     unified = unify_generic_callable(left, right, ignore_return=ignore_return)
+               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/subtypes.py", line 1871, in unify_generic_callable
+     cs = mypy.constraints.infer_constraints(
+          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/constraints.py", line 317, in infer_constraints
+     return _infer_constraints(template, actual, direction, skip_neg_op)
+            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/constraints.py", line 410, in _infer_constraints
+     return template.accept(ConstraintBuilderVisitor(actual, direction, skip_neg_op))
+            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/types.py", line 1971, in accept
+     return visitor.visit_callable_type(self)
+            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/constraints.py", line 1089, in visit_callable_type
+     assert not other or arg.required
+            ^^^^^^^^^^^^^^^^^^^^^^^^^
+ AssertionError: 

cloud-init (https://github.com/canonical/cloud-init)
+ /tmp/mypy_primer/new_mypy/venv/lib/python3.12/site-packages/mypy/typeshed/stdlib/asyncio/base_events.pyi:70: error: INTERNAL ERROR -- Please try using mypy master on GitHub:
+ https://mypy.readthedocs.io/en/stable/common_issues.html#using-a-development-mypy-build
+ Please report a bug at https://github.com/python/mypy/issues
+ version: 1.12.0+dev.ddc7a59967ff82a280ef72b2bfac008e3adc80c5
+ note: use --pdb to drop into pdb
- cloudinit/url_helper.py:283: error: Unused "type: ignore" comment  [unused-ignore]
- cloudinit/net/sysconfig.py:999: note: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs  [annotation-unchecked]
- cloudinit/net/openbsd.py:13: error: Signature of "write_config" incompatible with supertype "BSDRenderer"  [override]
- cloudinit/net/openbsd.py:13: note:      Superclass:
- cloudinit/net/openbsd.py:13: note:          def write_config(self, target: Any = ...) -> Any
- cloudinit/net/openbsd.py:13: note:      Subclass:
- cloudinit/net/openbsd.py:13: note:          def write_config(self) -> Any
- cloudinit/distros/__init__.py:167: note: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs  [annotation-unchecked]
- cloudinit/distros/__init__.py:171: note: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs  [annotation-unchecked]
- cloudinit/distros/aosc.py:110: error: Signature of "update_package_sources" incompatible with supertype "Distro"  [override]
- cloudinit/distros/aosc.py:110: note:      Superclass:
- cloudinit/distros/aosc.py:110: note:          def update_package_sources(self, *, force: Any = ...) -> Any
- cloudinit/distros/aosc.py:110: note:      Subclass:
- cloudinit/distros/aosc.py:110: note:          def update_package_sources(self) -> Any
- cloudinit/distros/alpine.py:278: note: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs  [annotation-unchecked]
- cloudinit/sources/DataSourceOracle.py:143: note: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs  [annotation-unchecked]
- cloudinit/sources/DataSourceAzure.py:334: note: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs  [annotation-unchecked]
- cloudinit/sources/DataSourceAzure.py:1835: note: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs  [annotation-unchecked]
- cloudinit/config/cc_ubuntu_pro.py:229: note: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs  [annotation-unchecked]
- cloudinit/config/cc_ubuntu_pro.py:237: note: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs  [annotation-unchecked]
- cloudinit/config/cc_growpart.py:298: note: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs  [annotation-unchecked]
- cloudinit/config/cc_apt_configure.py:615: note: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs  [annotation-unchecked]
- cloudinit/config/cc_apt_configure.py:616: note: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs  [annotation-unchecked]
- tests/unittests/test_templating.py:268: note: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs  [annotation-unchecked]
- tests/unittests/test_net.py:3559: error: Statement is unreachable  [unreachable]
- tests/unittests/config/test_cc_write_files.py:141: error: Argument 1 to "load_binary_file" has incompatible type "str | Any | bytes"; expected "str | PathLike[Any]"  [arg-type]
- tests/unittests/config/test_cc_ubuntu_drivers.py:84: note: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs  [annotation-unchecked]
- cloudinit/cmd/devel/hotplug_hook.py:83: note: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs  [annotation-unchecked]
+ Traceback (most recent call last):
+   File "", line 8, in <module>
+     sys.exit(console_entry())
+   File "/__main__.py", line 15, in console_entry
+     main()
+   File "/main.py", line 103, in main
+     res, messages, blockers = run_build(sources, options, fscache, t0, stdout, stderr)
+   File "/main.py", line 187, in run_build
+     res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
+   File "/build.py", line 193, in build
+     result = _build(
+   File "/build.py", line 268, in _build
+     graph = dispatch(sources, manager, stdout)
+   File "/build.py", line 2950, in dispatch
+     process_graph(graph, manager)
+   File "/build.py", line 3348, in process_graph
+     process_stale_scc(graph, scc, manager)
+   File "/build.py", line 3449, in process_stale_scc
+     graph[id].type_check_first_pass()
+   File "/build.py", line 2314, in type_check_first_pass
+     self.type_checker().check_first_pass()
+   File "/checker.py", line 483, in check_first_pass
+     self.accept(d)
+   File "/checker.py", line 591, in accept
+     stmt.accept(self)
+   File "/nodes.py", line 1183, in accept
+     return visitor.visit_class_def(self)
+   File "/checker.py", line 2417, in visit_class_def
+     self.accept(defn.defs)
+   File "/checker.py", line 591, in accept
+     stmt.accept(self)
+   File "/nodes.py", line 1264, in accept
+     return visitor.visit_block(self)
+   File "/checker.py", line 2883, in visit_block
+     self.accept(s)
+   File "/checker.py", line 591, in accept
+     stmt.accept(self)
+   File "/nodes.py", line 819, in accept
+     return visitor.visit_func_def(self)
+            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/checker.py", line 1043, in visit_func_def
+     self._visit_func_def(defn)
+   File "/checker.py", line 1054, in _visit_func_def
+     found_method_base_classes = self.check_method_override(defn)
+                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/checker.py", line 1977, in check_method_override
+     result = self.check_method_or_accessor_override_for_base(
+              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/checker.py", line 2015, in check_method_or_accessor_override_for_base
+     if self.check_method_override_for_base_with_name(defn, name, base):
+        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/checker.py", line 2131, in check_method_override_for_base_with_name
+     self.check_override(
+   File "/checker.py", line 2250, in check_override
+     if not is_subtype(override, original, ignore_pos_arg_names=True):
+            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

... (truncated 4907 lines) ...```

github-actions[bot] avatar Jul 10 '24 05:07 github-actions[bot]

Diff from mypy_primer, showing the effect of this PR on open source code:

Expression (https://github.com/cognitedata/Expression)
+ expression/core/option.py:434: error: Invalid self argument "Option[tuple[*_P]]" to attribute function "starmap" with type "Callable[[Option[tuple[*_P]], Callable[[VarArg(*_P)], _TResult]], Option[_TResult]]"  [misc]

core (https://github.com/home-assistant/core)
- Warning: unused section(s) in mypy.ini: [mypy-tests.*]
+ homeassistant/components/nuki/__init__.py:174: error: INTERNAL ERROR -- Please try using mypy master on GitHub:
+ https://mypy.readthedocs.io/en/stable/common_issues.html#using-a-development-mypy-build
+ Please report a bug at https://github.com/python/mypy/issues
+ version: 1.12.0+dev.9181063bdb7ddad7a116daddae341e60ab92623b
+ homeassistant/components/nuki/__init__.py:174: : note: use --pdb to drop into pdb
+ Traceback (most recent call last):
+   File "", line 8, in <module>
+     sys.exit(console_entry())
+   File "/__main__.py", line 15, in console_entry
+     main()
+   File "/main.py", line 103, in main
+     res, messages, blockers = run_build(sources, options, fscache, t0, stdout, stderr)
+   File "/main.py", line 187, in run_build
+     res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
+   File "/build.py", line 193, in build
+     result = _build(
+   File "/build.py", line 268, in _build
+     graph = dispatch(sources, manager, stdout)
+   File "/build.py", line 2950, in dispatch
+     process_graph(graph, manager)
+   File "/build.py", line 3348, in process_graph
+     process_stale_scc(graph, scc, manager)
+   File "/build.py", line 3449, in process_stale_scc
+     graph[id].type_check_first_pass()
+   File "/build.py", line 2314, in type_check_first_pass
+     self.type_checker().check_first_pass()
+   File "/checker.py", line 483, in check_first_pass
+     self.accept(d)
+   File "/checker.py", line 591, in accept
+     stmt.accept(self)
+   File "/nodes.py", line 819, in accept
+     return visitor.visit_func_def(self)
+   File "/checker.py", line 1043, in visit_func_def
+     self._visit_func_def(defn)
+   File "/checker.py", line 1047, in _visit_func_def
+     self.check_func_item(defn, name=defn.name)
+   File "/checker.py", line 1120, in check_func_item
+     self.check_func_def(defn, typ, name, allow_empty)
+   File "/checker.py", line 1352, in check_func_def
+     self.accept(item.body)
+   File "/checker.py", line 591, in accept
+     stmt.accept(self)
+   File "/nodes.py", line 1264, in accept
+     return visitor.visit_block(self)
+   File "/checker.py", line 2883, in visit_block
+     self.accept(s)
+   File "/checker.py", line 591, in accept
+     stmt.accept(self)
+   File "/nodes.py", line 1587, in accept
+     return visitor.visit_try_stmt(self)
+   File "/checker.py", line 4736, in visit_try_stmt
+     self.visit_try_without_finally(s, try_frame=bool(s.finally_body))
+   File "/checker.py", line 4772, in visit_try_without_finally
+     self.accept(s.body)
+   File "/checker.py", line 591, in accept
+     stmt.accept(self)
+   File "/nodes.py", line 1264, in accept
+     return visitor.visit_block(self)
+   File "/checker.py", line 2883, in visit_block
+     self.accept(s)
+   File "/checker.py", line 591, in accept
+     stmt.accept(self)
+   File "/nodes.py", line 1351, in accept
+     return visitor.visit_assignment_stmt(self)
+   File "/checker.py", line 2931, in visit_assignment_stmt
+     self.check_assignment(s.lvalues[-1], s.rvalue, s.type is None, s.new_syntax)
+   File "/checker.py", line 3140, in check_assignment
+     rvalue_type = self.expr_checker.accept(rvalue, type_context=type_context)
+   File "/checkexpr.py", line 5834, in accept
+     typ = node.accept(self)
+   File "/nodes.py", line 2833, in accept
+     return visitor.visit_await_expr(self)
+   File "/checkexpr.py", line 5967, in visit_await_expr
+     actual_type = get_proper_type(self.accept(e.expr, expected_type))
+   File "/checkexpr.py", line 5834, in accept
+     typ = node.accept(self)
+           ^^^^^^^^^^^^^^^^^
+   File "/nodes.py", line 1969, in accept
+     return visitor.visit_call_expr(self)
+            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/checkexpr.py", line 480, in visit_call_expr
+     return self.visit_call_expr_inner(e, allow_none_return=allow_none_return)
+            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/checkexpr.py", line 614, in visit_call_expr_inner
+     ret_type = self.check_call_expr_with_callee_type(
+                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/checkexpr.py", line 1467, in check_call_expr_with_callee_type
+     ret_type, callee_type = self.check_call(
+                             ^^^^^^^^^^^^^^^^
+   File "/checkexpr.py", line 1561, in check_call
+     return self.check_callable_call(
+            ^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/checkexpr.py", line 1746, in check_callable_call
+     callee = self.infer_function_type_arguments(
+              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/checkexpr.py", line 2085, in infer_function_type_arguments
+     (callee_type, inferred_args) = self.infer_function_type_arguments_pass2(
+                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/checkexpr.py", line 2220, in infer_function_type_arguments_pass2
+     inferred_args, _ = infer_function_type_arguments(
+                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/infer.py", line 56, in infer_function_type_arguments
+     constraints = infer_constraints_for_callable(
+                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/constraints.py", line 249, in infer_constraints_for_callable
+     c = infer_constraints(callee.arg_types[i], actual_type, SUPERTYPE_OF)
+         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/constraints.py", line 317, in infer_constraints
+     return _infer_constraints(template, actual, direction, skip_neg_op)
+            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/constraints.py", line 410, in _infer_constraints
+     return template.accept(ConstraintBuilderVisitor(actual, direction, skip_neg_op))
+            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/types.py", line 1971, in accept
+     return visitor.visit_callable_type(self)
+            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/constraints.py", line 1184, in visit_callable_type
+     res = self.infer_against_any(template.arg_types, self.actual)
+           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/constraints.py", line 1357, in infer_against_any
+     res.extend(infer_constraints(t, any_type, self.direction))
+                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/constraints.py", line 317, in infer_constraints
+     return _infer_constraints(template, actual, direction, skip_neg_op)
+            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/constraints.py", line 398, in _infer_constraints
+     infer_constraints_if_possible(t_item, actual, direction)
+   File "/constraints.py", line 435, in infer_constraints_if_possible
+     return infer_constraints(template, actual, direction)
+            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/constraints.py", line 317, in infer_constraints
+     return _infer_constraints(template, actual, direction, skip_neg_op)
+            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/constraints.py", line 410, in _infer_constraints
+     return template.accept(ConstraintBuilderVisitor(actual, direction, skip_neg_op))
+            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/types.py", line 1057, in accept
+     return visitor.visit_unpack_type(self)
+            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/constraints.py", line 690, in visit_unpack_type
+     raise RuntimeError("Mypy bug: unpack should be handled at a higher level.")
+ RuntimeError: Mypy bug: unpack should be handled at a higher level.
- homeassistant/components/notion/sensor.py:90: error: Returning Any from function declared to return "str | None"  [no-any-return]
- homeassistant/components/notion/sensor.py:91: error: Returning Any from function declared to return "str | None"  [no-any-return]
- homeassistant/components/notion/binary_sensor.py:144: error: Returning Any from function declared to return "bool | None"  [no-any-return]
- homeassistant/components/netatmo/entity.py:109: error: Returning Any from function declared to return "tuple[str, str]"  [no-any-return]
- homeassistant/components/myuplink/update.py:61: error: Returning Any from function declared to return "str | None"  [no-any-return]
- homeassistant/components/myuplink/update.py:66: error: Returning Any from function declared to return "str | None"  [no-any-return]
- homeassistant/components/myuplink/binary_sensor.py:166: error: Returning Any from function declared to return "bool"  [no-any-return]
- homeassistant/components/madvr/remote.py:51: error: Returning Any from function declared to return "bool"  [no-any-return]
- homeassistant/components/litterrobot/update.py:56: error: Returning Any from function declared to return "str"  [no-any-return]
- homeassistant/components/litterrobot/update.py:61: error: Returning Any from function declared to return "bool"  [no-any-return]
- homeassistant/components/litterrobot/sensor.py:68: error: Unused "type: ignore" comment  [unused-ignore]
- homeassistant/components/litterrobot/select.py:51: error: Unused "type: ignore" comment  [unused-ignore]
- homeassistant/components/litterrobot/binary_sensor.py:50: error: Unused "type: ignore" comment  [unused-ignore]
- homeassistant/components/litterrobot/binary_sensor.py:66: error: Unused "type: ignore" comment  [unused-ignore]
- homeassistant/components/lamarzocco/update.py:75: error: Returning Any from function declared to return "str | None"  [no-any-return]
- homeassistant/components/lamarzocco/update.py:82: error: Returning Any from function declared to return "str"  [no-any-return]
- homeassistant/components/lamarzocco/switch.py:131: error: Returning Any from function declared to return "bool"  [no-any-return]

... (truncated 399 lines) ...

mitmproxy (https://github.com/mitmproxy/mitmproxy)
+ ./mitmproxy/tools/main.py:113: error: INTERNAL ERROR -- Please try using mypy master on GitHub:
+ https://mypy.readthedocs.io/en/stable/common_issues.html#using-a-development-mypy-build
+ Please report a bug at https://github.com/python/mypy/issues
+ version: 1.12.0+dev.9181063bdb7ddad7a116daddae341e60ab92623b
+ ./mitmproxy/tools/main.py:113: : note: use --pdb to drop into pdb
+ Traceback (most recent call last):
+   File "", line 8, in <module>
+     sys.exit(console_entry())
+   File "/__main__.py", line 15, in console_entry
+     main()
+   File "/main.py", line 103, in main
+     res, messages, blockers = run_build(sources, options, fscache, t0, stdout, stderr)
+   File "/main.py", line 187, in run_build
+     res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
+   File "/build.py", line 193, in build
+     result = _build(
+   File "/build.py", line 268, in _build
+     graph = dispatch(sources, manager, stdout)
+   File "/build.py", line 2950, in dispatch
+     process_graph(graph, manager)
+   File "/build.py", line 3348, in process_graph
+     process_stale_scc(graph, scc, manager)
+   File "/build.py", line 3449, in process_stale_scc
+     graph[id].type_check_first_pass()
+   File "/build.py", line 2314, in type_check_first_pass
+     self.type_checker().check_first_pass()
+   File "/checker.py", line 483, in check_first_pass
+     self.accept(d)
+   File "/checker.py", line 591, in accept
+     stmt.accept(self)
+   File "/nodes.py", line 819, in accept
+     return visitor.visit_func_def(self)
+   File "/checker.py", line 1043, in visit_func_def
+     self._visit_func_def(defn)
+   File "/checker.py", line 1047, in _visit_func_def
+     self.check_func_item(defn, name=defn.name)
+   File "/checker.py", line 1120, in check_func_item
+     self.check_func_def(defn, typ, name, allow_empty)
+   File "/checker.py", line 1352, in check_func_def
+     self.accept(item.body)
+   File "/checker.py", line 591, in accept
+     stmt.accept(self)
+   File "/nodes.py", line 1264, in accept
+     return visitor.visit_block(self)
+   File "/checker.py", line 2883, in visit_block
+     self.accept(s)
+   File "/checker.py", line 591, in accept
+     stmt.accept(self)
+   File "/nodes.py", line 819, in accept
+     return visitor.visit_func_def(self)
+   File "/checker.py", line 1043, in visit_func_def
+     self._visit_func_def(defn)
+   File "/checker.py", line 1047, in _visit_func_def
+     self.check_func_item(defn, name=defn.name)
+   File "/checker.py", line 1120, in check_func_item
+     self.check_func_def(defn, typ, name, allow_empty)
+   File "/checker.py", line 1352, in check_func_def
+     self.accept(item.body)
+   File "/checker.py", line 591, in accept
+     stmt.accept(self)
+   File "/nodes.py", line 1264, in accept
+     return visitor.visit_block(self)
+   File "/checker.py", line 2883, in visit_block
+     self.accept(s)
+   File "/checker.py", line 591, in accept
+     stmt.accept(self)
+   File "/nodes.py", line 819, in accept
+     return visitor.visit_func_def(self)
+   File "/checker.py", line 1043, in visit_func_def
+     self._visit_func_def(defn)
+   File "/checker.py", line 1047, in _visit_func_def
+     self.check_func_item(defn, name=defn.name)
+   File "/checker.py", line 1120, in check_func_item
+     self.check_func_def(defn, typ, name, allow_empty)
+   File "/checker.py", line 1352, in check_func_def
+     self.accept(item.body)
+   File "/checker.py", line 591, in accept
+     stmt.accept(self)
+   File "/nodes.py", line 1264, in accept
+     return visitor.visit_block(self)
+   File "/checker.py", line 2883, in visit_block
+     self.accept(s)
+   File "/checker.py", line 591, in accept
+     stmt.accept(self)
+   File "/nodes.py", line 1284, in accept
+     return visitor.visit_expression_stmt(self)
+   File "/checker.py", line 4515, in visit_expression_stmt
+     expr_type = self.expr_checker.accept(s.expr, allow_none_return=True, always_allow_any=True)
+   File "/checkexpr.py", line 5826, in accept
+     typ = self.visit_call_expr(node, allow_none_return=True)
+   File "/checkexpr.py", line 480, in visit_call_expr
+     return self.visit_call_expr_inner(e, allow_none_return=allow_none_return)
+   File "/checkexpr.py", line 614, in visit_call_expr_inner
+     ret_type = self.check_call_expr_with_callee_type(
+   File "/checkexpr.py", line 1467, in check_call_expr_with_callee_type
+     ret_type, callee_type = self.check_call(
+   File "/checkexpr.py", line 1561, in check_call
+     return self.check_callable_call(
+   File "/checkexpr.py", line 1746, in check_callable_call
+     callee = self.infer_function_type_arguments(
+   File "/checkexpr.py", line 2058, in infer_function_type_arguments
+     arg_types = self.infer_arg_types_in_context(
+   File "/checkexpr.py", line 1945, in infer_arg_types_in_context
+     res[ai] = self.accept(args[ai], arg_type)
+   File "/checkexpr.py", line 5834, in accept
+     typ = node.accept(self)
+           ^^^^^^^^^^^^^^^^^
+   File "/nodes.py", line 1969, in accept
+     return visitor.visit_call_expr(self)
+            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/checkexpr.py", line 480, in visit_call_expr
+     return self.visit_call_expr_inner(e, allow_none_return=allow_none_return)
+            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/checkexpr.py", line 614, in visit_call_expr_inner
+     ret_type = self.check_call_expr_with_callee_type(
+                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/checkexpr.py", line 1467, in check_call_expr_with_callee_type
+     ret_type, callee_type = self.check_call(
+                             ^^^^^^^^^^^^^^^^
+   File "/checkexpr.py", line 1572, in check_call
+     return self.check_overload_call(
+            ^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/checkexpr.py", line 2686, in check_overload_call
+     inferred_result = self.infer_overload_return_type(
+                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/checkexpr.py", line 2841, in infer_overload_return_type
+     ret_type, infer_type = self.check_call(
+                            ^^^^^^^^^^^^^^^^
+   File "/checkexpr.py", line 1561, in check_call
+     return self.check_callable_call(
+            ^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/checkexpr.py", line 1746, in check_callable_call
+     callee = self.infer_function_type_arguments(
+              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/checkexpr.py", line 2073, in infer_function_type_arguments
+     inferred_args, _ = infer_function_type_arguments(
+                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/infer.py", line 56, in infer_function_type_arguments
+     constraints = infer_constraints_for_callable(
+                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/constraints.py", line 249, in infer_constraints_for_callable
+     c = infer_constraints(callee.arg_types[i], actual_type, SUPERTYPE_OF)
+         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/constraints.py", line 317, in infer_constraints
+     return _infer_constraints(template, actual, direction, skip_neg_op)
+            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/constraints.py", line 410, in _infer_constraints
+     return template.accept(ConstraintBuilderVisitor(actual, direction, skip_neg_op))
+            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/types.py", line 1971, in accept
+     return visitor.visit_callable_type(self)
+            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/constraints.py", line 1115, in visit_callable_type
+     template_types = repack_callable_args(template, tuple_type)
+                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/constraints.py", line 1473, in repack_callable_args
+     assert isinstance(tp.items[0], UnpackType)
+                       ~~~~~~~~^^^
+ IndexError: list index out of range

github-actions[bot] avatar Jul 10 '24 13:07 github-actions[bot]

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

github-actions[bot] avatar Aug 27 '24 22:08 github-actions[bot]

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

github-actions[bot] avatar Aug 28 '24 07:08 github-actions[bot]

With the simplification from removing Any-tuple this looks pretty damn clean. With no diff from mypy_primer I think we only need new tests and then it's pretty much ready to merge :tada:

jakkdl avatar Sep 17 '24 13:09 jakkdl

~~I split off https://github.com/python/mypy/pull/17843 for the part of this PR I am certain is correct. I have some ideas on how to fix kwargs's presence with TypeVarTuple in the general case that I want to try out.~~

Turns out I can't split anything off because the two fixes need each other for any visible effect.

A5rocks avatar Sep 27 '24 15:09 A5rocks

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

github-actions[bot] avatar Sep 27 '24 16:09 github-actions[bot]

Would be lovely to get this merged, but it appears we've gotten merge conflicts that need resolved @A5rocks

jakkdl avatar Mar 31 '25 08:03 jakkdl

I've made a better version of this at https://github.com/python/mypy/pull/18958

A5rocks avatar Apr 23 '25 17:04 A5rocks