Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force List Expression to Infer Union Type of Member Types. #18205

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

ay0503
Copy link

@ay0503 ay0503 commented Nov 28, 2024

Infer Union Types for List Expressions with Heterogeneous Elements

Description:

This PR forces the type inference for list expressions in mypy to correctly infer Union types when a list contains elements of different types that have no common supertype other than object. However, currently this forces this for all list expression type inferences and hence breaks everything else. A pretty quirky fix would be to track any list comprehension accesses since this only happens when a union type list is used in the generator portion of a list comprehension.

Background:

Before, when a list literal was constructed with elements of disparate types without a meaningful common superclass, mypy would default to inferring the list's type as List[object]. This behavior led to type-checking issues in scenarios where a more precise type was expected.

For example:

class A:
    pass

class B:
    pass

a = A()
b = B()

l3: list[A | B] = [x for x in [a, b]]  # This would cause a mypy error

However, while this fixes this issue, it also generalizes the entire list expression inference to be forced as well.

This comment has been minimized.

@ay0503 ay0503 force-pushed the bug/force-list-comp-union branch from 4eb09ac to fe3322a Compare November 28, 2024 06:14

This comment has been minimized.

@ay0503 ay0503 marked this pull request as ready for review December 1, 2024 21:58
@ay0503 ay0503 force-pushed the bug/force-list-comp-union branch from fd184cc to b03bedc Compare December 6, 2024 23:01

This comment has been minimized.

This comment has been minimized.

@ay0503 ay0503 force-pushed the bug/force-list-comp-union branch from f5cc357 to da03a38 Compare December 8, 2024 07:34

This comment has been minimized.

@ay0503 ay0503 force-pushed the bug/force-list-comp-union branch from da03a38 to f5cc357 Compare December 8, 2024 18:21
Copy link
Contributor

github-actions bot commented Dec 8, 2024

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

git-revise (https://github.com/mystor/git-revise)
- gitrevise/odb.py:60: error: Unused "type: ignore" comment  [unused-ignore]
- gitrevise/odb.py:498: error: Redundant cast to "GitObjT"  [redundant-cast]
+ /tmp/mypy_primer/new_mypy/venv/lib/python3.12/site-packages/mypy/typeshed/stdlib/argparse.pyi:159: 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.14.0+dev.710a21f501f829783a51f1e7818569679f5d4658
+ 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 109, in main
+     res, messages, blockers = run_build(sources, options, fscache, t0, stdout, stderr)
+   File "/main.py", line 193, in run_build
+     res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
+   File "/build.py", line 194, in build
+     result = _build(
+   File "/build.py", line 269, in _build
+     graph = dispatch(sources, manager, stdout)
+   File "/build.py", line 2940, in dispatch
+     process_graph(graph, manager)
+   File "/build.py", line 3338, in process_graph
+     process_stale_scc(graph, scc, manager)
+   File "/build.py", line 3439, in process_stale_scc
+     graph[id].type_check_first_pass()
+   File "/build.py", line 2309, 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 592, in accept
+     stmt.accept(self)
+   File "/nodes.py", line 1196, in accept
+     return visitor.visit_class_def(self)
+   File "/checker.py", line 2462, in visit_class_def
+     self.accept(defn.defs)
+   File "/checker.py", line 592, in accept
+     stmt.accept(self)
+   File "/nodes.py", line 1277, in accept
+     return visitor.visit_block(self)
+   File "/checker.py", line 2952, in visit_block
+     self.accept(s)
+   File "/checker.py", line 592, in accept
+     stmt.accept(self)
+   File "/nodes.py", line 1545, in accept
+     return visitor.visit_if_stmt(self)
+   File "/checker.py", line 4742, in visit_if_stmt
+     self.accept(s.else_body)
+   File "/checker.py", line 592, in accept
+     stmt.accept(self)
+   File "/nodes.py", line 1277, in accept
+     return visitor.visit_block(self)
+   File "/checker.py", line 2952, in visit_block
+     self.accept(s)
+   File "/checker.py", line 592, in accept
+     stmt.accept(self)
+   File "/nodes.py", line 827, in accept
+     return visitor.visit_func_def(self)
+            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/checker.py", line 1046, in visit_func_def
+     self._visit_func_def(defn)
+   File "/checker.py", line 1050, in _visit_func_def
+     self.check_func_item(defn, name=defn.name)
+   File "/checker.py", line 1084, in check_func_item
+     self.check_func_def(defn, typ, name, allow_empty)
+   File "/checker.py", line 1328, in check_func_def
+     self.check_default_args(item, body_is_trivial)
+   File "/checker.py", line 1518, in check_default_args
+     self.check_simple_assignment(
+   File "/checker.py", line 4347, in check_simple_assignment
+     rvalue_type = self.expr_checker.accept(
+                   ^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/checkexpr.py", line 5961, in accept
+     assert typ is not None
+            ^^^^^^^^^^^^^^^
+ AssertionError: 

janus (https://github.com/aio-libs/janus)
+ janus/__init__.py:603: 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.14.0+dev.710a21f501f829783a51f1e7818569679f5d4658
+ janus/__init__.py:603: : 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 109, in main
+     res, messages, blockers = run_build(sources, options, fscache, t0, stdout, stderr)
+   File "/main.py", line 193, in run_build
+     res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
+   File "/build.py", line 194, in build
+     result = _build(
+   File "/build.py", line 269, in _build
+     graph = dispatch(sources, manager, stdout)
+   File "/build.py", line 2940, in dispatch
+     process_graph(graph, manager)
+   File "/build.py", line 3338, in process_graph
+     process_stale_scc(graph, scc, manager)
+   File "/build.py", line 3439, in process_stale_scc
+     graph[id].type_check_first_pass()
+   File "/build.py", line 2309, 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 592, in accept
+     stmt.accept(self)
+   File "/nodes.py", line 1196, in accept
+     return visitor.visit_class_def(self)
+   File "/checker.py", line 2462, in visit_class_def
+     self.accept(defn.defs)
+   File "/checker.py", line 592, in accept
+     stmt.accept(self)
+   File "/nodes.py", line 1277, in accept
+     return visitor.visit_block(self)
+   File "/checker.py", line 2952, in visit_block
+     self.accept(s)
+   File "/checker.py", line 592, in accept
+     stmt.accept(self)
+   File "/nodes.py", line 827, in accept
+     return visitor.visit_func_def(self)
+   File "/checker.py", line 1046, in visit_func_def
+     self._visit_func_def(defn)
+   File "/checker.py", line 1050, in _visit_func_def
+     self.check_func_item(defn, name=defn.name)
+   File "/checker.py", line 1084, in check_func_item
+     self.check_func_def(defn, typ, name, allow_empty)
+   File "/checker.py", line 1360, in check_func_def
+     self.accept(item.body)
+   File "/checker.py", line 592, in accept
+     stmt.accept(self)
+   File "/nodes.py", line 1277, in accept
+     return visitor.visit_block(self)
+   File "/checker.py", line 2952, in visit_block
+     self.accept(s)
+   File "/checker.py", line 592, in accept
+     stmt.accept(self)
+   File "/nodes.py", line 1364, in accept
+     return visitor.visit_assignment_stmt(self)
+            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/checker.py", line 3001, in visit_assignment_stmt
+     self.check_assignment(s.lvalues[-1], s.rvalue, s.type is None, s.new_syntax)
+   File "/checker.py", line 3148, in check_assignment
+     rvalue_type, lvalue_type, infer_lvalue_type = self.check_member_assignment(
+                                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/checker.py", line 4435, in check_member_assignment
+     rvalue_type = self.check_simple_assignment(get_type, rvalue, context)
+                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/checker.py", line 4347, in check_simple_assignment
+     rvalue_type = self.expr_checker.accept(
+                   ^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/checkexpr.py", line 5961, in accept
+     assert typ is not None
+            ^^^^^^^^^^^^^^^
+ AssertionError: 

zipp (https://github.com/jaraco/zipp)
+ ./docs/conf.py:43: 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.14.0+dev.710a21f501f829783a51f1e7818569679f5d4658
+ ./docs/conf.py:43: : note: use --pdb to drop into pdb
- tests/test_path.py:646: error: Name "zipfile.ZipInfo" is not defined  [name-defined]
+ 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 109, in main
+     res, messages, blockers = run_build(sources, options, fscache, t0, stdout, stderr)
+   File "/main.py", line 193, in run_build
+     res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
+   File "/build.py", line 194, in build
+     result = _build(
+   File "/build.py", line 269, in _build
+     graph = dispatch(sources, manager, stdout)
+   File "/build.py", line 2940, in dispatch
+     process_graph(graph, manager)
+   File "/build.py", line 3338, in process_graph
+     process_stale_scc(graph, scc, manager)
+   File "/build.py", line 3439, in process_stale_scc
+     graph[id].type_check_first_pass()
+   File "/build.py", line 2309, 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 592, in accept
+     stmt.accept(self)
+   File "/nodes.py", line 1364, in accept
+     return visitor.visit_assignment_stmt(self)
+            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/checker.py", line 3001, in visit_assignment_stmt
+     self.check_assignment(s.lvalues[-1], s.rvalue, s.type is None, s.new_syntax)
+   File "/checker.py", line 3179, in check_assignment
+     rvalue_type = self.check_simple_assignment(lvalue_type, rvalue, context=rvalue)
+                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/checker.py", line 4347, in check_simple_assignment
+     rvalue_type = self.expr_checker.accept(
+                   ^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/checkexpr.py", line 5961, in accept
+     assert typ is not None
+            ^^^^^^^^^^^^^^^
+ AssertionError: 

websockets (https://github.com/aaugustin/websockets)
+ /tmp/mypy_primer/new_mypy/venv/lib/python3.12/site-packages/mypy/typeshed/stdlib/argparse.pyi:142: 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.14.0+dev.710a21f501f829783a51f1e7818569679f5d4658
+ 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 109, in main
+     res, messages, blockers = run_build(sources, options, fscache, t0, stdout, stderr)
+   File "/main.py", line 193, in run_build
+     res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
+   File "/build.py", line 194, in build
+     result = _build(
+   File "/build.py", line 269, in _build
+     graph = dispatch(sources, manager, stdout)
+   File "/build.py", line 2940, in dispatch
+     process_graph(graph, manager)
+   File "/build.py", line 3338, in process_graph
+     process_stale_scc(graph, scc, manager)
+   File "/build.py", line 3439, in process_stale_scc
+     graph[id].type_check_first_pass()
+   File "/build.py", line 2309, 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 592, in accept
+     stmt.accept(self)
+   File "/nodes.py", line 1196, in accept
+     return visitor.visit_class_def(self)
+   File "/checker.py", line 2462, in visit_class_def
+     self.accept(defn.defs)
+   File "/checker.py", line 592, in accept
+     stmt.accept(self)
+   File "/nodes.py", line 1277, in accept
+     return visitor.visit_block(self)
+   File "/checker.py", line 2952, in visit_block
+     self.accept(s)
+   File "/checker.py", line 592, in accept
+     stmt.accept(self)
+   File "/nodes.py", line 1545, in accept
+     return visitor.visit_if_stmt(self)
+   File "/checker.py", line 4735, in visit_if_stmt
+     self.accept(b)
+   File "/checker.py", line 592, in accept
+     stmt.accept(self)
+   File "/nodes.py", line 1277, in accept
+     return visitor.visit_block(self)
+   File "/checker.py", line 2952, in visit_block
+     self.accept(s)
+   File "/checker.py", line 592, in accept
+     stmt.accept(self)
+   File "/nodes.py", line 827, in accept
+     return visitor.visit_func_def(self)
+            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/checker.py", line 1046, in visit_func_def
+     self._visit_func_def(defn)
+   File "/checker.py", line 1050, in _visit_func_def
+     self.check_func_item(defn, name=defn.name)
+   File "/checker.py", line 1084, in check_func_item
+     self.check_func_def(defn, typ, name, allow_empty)
+   File "/checker.py", line 1328, in check_func_def
+     self.check_default_args(item, body_is_trivial)
+   File "/checker.py", line 1518, in check_default_args
+     self.check_simple_assignment(
+   File "/checker.py", line 4347, in check_simple_assignment
+     rvalue_type = self.expr_checker.accept(
+                   ^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/checkexpr.py", line 5961, in accept
+     assert typ is not None
+            ^^^^^^^^^^^^^^^
+ AssertionError: 

mypy_primer (https://github.com/hauntsaninja/mypy_primer)
- mypy_primer/utils.py:173: error: Unused "type: ignore" comment  [unused-ignore]
+ /tmp/mypy_primer/new_mypy/venv/lib/python3.12/site-packages/mypy/typeshed/stdlib/argparse.pyi:142: 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.14.0+dev.710a21f501f829783a51f1e7818569679f5d4658
+ 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 109, in main
+     res, messages, blockers = run_build(sources, options, fscache, t0, stdout, stderr)
+   File "/main.py", line 193, in run_build
+     res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
+   File "/build.py", line 194, in build
+     result = _build(
+   File "/build.py", line 269, in _build
+     graph = dispatch(sources, manager, stdout)
+   File "/build.py", line 2940, in dispatch
+     process_graph(graph, manager)
+   File "/build.py", line 3338, in process_graph
+     process_stale_scc(graph, scc, manager)
+   File "/build.py", line 3439, in process_stale_scc
+     graph[id].type_check_first_pass()
+   File "/build.py", line 2309, 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 592, in accept
+     stmt.accept(self)
+   File "/nodes.py", line 1196, in accept
+     return visitor.visit_class_def(self)
+   File "/checker.py", line 2462, in visit_class_def
+     self.accept(defn.defs)
+   File "/checker.py", line 592, in accept
+     stmt.accept(self)
+   File "/nodes.py", line 1277, in accept
+     return visitor.visit_block(self)
+   File "/checker.py", line 2952, in visit_block
+     self.accept(s)
+   File "/checker.py", line 592, in accept
+     stmt.accept(self)
+   File "/nodes.py", line 1545, in accept
+     return visitor.visit_if_stmt(self)
+   File "/checker.py", line 4735, in visit_if_stmt
+     self.accept(b)
+   File "/checker.py", line 592, in accept
+     stmt.accept(self)
+   File "/nodes.py", line 1277, in accept
+     return visitor.visit_block(self)
+   File "/checker.py", line 2952, in visit_block
+     self.accept(s)
+   File "/checker.py", line 592, in accept
+     stmt.accept(self)
+   File "/nodes.py", line 827, in accept
+     return visitor.visit_func_def(self)
+            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/checker.py", line 1046, in visit_func_def
+     self._visit_func_def(defn)
+   File "/checker.py", line 1050, in _visit_func_def
+     self.check_func_item(defn, name=defn.name)
+   File "/checker.py", line 1084, in check_func_item
+     self.check_func_def(defn, typ, name, allow_empty)
+   File "/checker.py", line 1328, in check_func_def
+     self.check_default_args(item, body_is_trivial)
+   File "/checker.py", line 1518, in check_default_args
+     self.check_simple_assignment(
+   File "/checker.py", line 4347, in check_simple_assignment
+     rvalue_type = self.expr_checker.accept(
+                   ^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/checkexpr.py", line 5961, in accept
+     assert typ is not None
+            ^^^^^^^^^^^^^^^
+ AssertionError: 

parso (https://github.com/davidhalter/parso)
- parso/python/prefix.py:17: note: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs  [annotation-unchecked]
- parso/python/tree.py:49: error: Module "collections" does not explicitly export attribute "Mapping"  [attr-defined]
+ parso/normalizer.py:20: 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.14.0+dev.710a21f501f829783a51f1e7818569679f5d4658
+ parso/normalizer.py:20: : 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 109, in main
+     res, messages, blockers = run_build(sources, options, fscache, t0, stdout, stderr)
+   File "/main.py", line 193, in run_build
+     res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
+   File "/build.py", line 194, in build
+     result = _build(
+   File "/build.py", line 269, in _build
+     graph = dispatch(sources, manager, stdout)
+   File "/build.py", line 2940, in dispatch
+     process_graph(graph, manager)
+   File "/build.py", line 3338, in process_graph
+     process_stale_scc(graph, scc, manager)
+   File "/build.py", line 3439, in process_stale_scc
+     graph[id].type_check_first_pass()
+   File "/build.py", line 2309, 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 592, in accept
+     stmt.accept(self)
+   File "/nodes.py", line 1196, in accept
+     return visitor.visit_class_def(self)
+   File "/checker.py", line 2462, in visit_class_def
+     self.accept(defn.defs)
+   File "/checker.py", line 592, in accept
+     stmt.accept(self)
+   File "/nodes.py", line 1277, in accept
+     return visitor.visit_block(self)
+   File "/checker.py", line 2952, in visit_block
+     self.accept(s)
+   File "/checker.py", line 592, in accept
+     stmt.accept(self)
+   File "/nodes.py", line 827, in accept
+     return visitor.visit_func_def(self)
+   File "/checker.py", line 1046, in visit_func_def
+     self._visit_func_def(defn)
+   File "/checker.py", line 1050, in _visit_func_def
+     self.check_func_item(defn, name=defn.name)
+   File "/checker.py", line 1084, in check_func_item
+     self.check_func_def(defn, typ, name, allow_empty)
+   File "/checker.py", line 1360, in check_func_def
+     self.accept(item.body)
+   File "/checker.py", line 592, in accept
+     stmt.accept(self)
+   File "/nodes.py", line 1277, in accept
+     return visitor.visit_block(self)
+   File "/checker.py", line 2952, in visit_block
+     self.accept(s)
+   File "/checker.py", line 592, in accept
+     stmt.accept(self)
+   File "/nodes.py", line 1364, in accept
+     return visitor.visit_assignment_stmt(self)
+            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/checker.py", line 3001, in visit_assignment_stmt
+     self.check_assignment(s.lvalues[-1], s.rvalue, s.type is None, s.new_syntax)
+   File "/checker.py", line 3218, in check_assignment
+     rvalue_type = self.expr_checker.accept(rvalue, type_context=type_context)
+                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/checkexpr.py", line 5961, in accept
+     assert typ is not None
+            ^^^^^^^^^^^^^^^
+ AssertionError: 

pycryptodome (https://github.com/Legrandin/pycryptodome)
- lib/Crypto/SelfTest/Hash/test_BLAKE2.py:421: error: Unused "type: ignore" comment  [unused-ignore]
+ lib/Crypto/SelfTest/loader.py:58: 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.14.0+dev.710a21f501f829783a51f1e7818569679f5d4658
+ lib/Crypto/SelfTest/loader.py:58: : 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 109, in main
+     res, messages, blockers = run_build(sources, options, fscache, t0, stdout, stderr)
+   File "/main.py", line 193, in run_build
+     res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
+   File "/build.py", line 194, in build
+     result = _build(
+   File "/build.py", line 269, in _build
+     graph = dispatch(sources, manager, stdout)
+   File "/build.py", line 2940, in dispatch
+     process_graph(graph, manager)
+   File "/build.py", line 3338, in process_graph
+     process_stale_scc(graph, scc, manager)
+   File "/build.py", line 3439, in process_stale_scc
+     graph[id].type_check_first_pass()
+   File "/build.py", line 2309, 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 592, in accept
+     stmt.accept(self)
+   File "/nodes.py", line 827, in accept
+     return visitor.visit_func_def(self)
+   File "/checker.py", line 1046, in visit_func_def
+     self._visit_func_def(defn)
+   File "/checker.py", line 1050, in _visit_func_def
+     self.check_func_item(defn, name=defn.name)
+   File "/checker.py", line 1084, in check_func_item
+     self.check_func_def(defn, typ, name, allow_empty)
+   File "/checker.py", line 1360, in check_func_def
+     self.accept(item.body)
+   File "/checker.py", line 592, in accept
+     stmt.accept(self)
+   File "/nodes.py", line 1277, in accept
+     return visitor.visit_block(self)
+   File "/checker.py", line 2952, in visit_block
+     self.accept(s)
+   File "/checker.py", line 592, in accept
+     stmt.accept(self)
+   File "/nodes.py", line 1364, in accept
+     return visitor.visit_assignment_stmt(self)
+            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/checker.py", line 3001, in visit_assignment_stmt
+     self.check_assignment(s.lvalues[-1], s.rvalue, s.type is None, s.new_syntax)
+   File "/checker.py", line 3218, in check_assignment
+     rvalue_type = self.expr_checker.accept(rvalue, type_context=type_context)
+                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/checkexpr.py", line 5961, in accept
+     assert typ is not None
+            ^^^^^^^^^^^^^^^
+ AssertionError: 

python-htmlgen (https://github.com/srittau/python-htmlgen)
+ test_htmlgen/generator.py:29: 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.14.0+dev.710a21f501f829783a51f1e7818569679f5d4658
+ test_htmlgen/generator.py:29: : 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 109, in main
+     res, messages, blockers = run_build(sources, options, fscache, t0, stdout, stderr)
+   File "/main.py", line 193, in run_build
+     res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
+   File "/build.py", line 194, in build
+     result = _build(
+   File "/build.py", line 269, in _build
+     graph = dispatch(sources, manager, stdout)
+   File "/build.py", line 2940, in dispatch
+     process_graph(graph, manager)
+   File "/build.py", line 3338, in process_graph
+     process_stale_scc(graph, scc, manager)
+   File "/build.py", line 3439, in process_stale_scc
+     graph[id].type_check_first_pass()
+   File "/build.py", line 2309, 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 592, in accept
+     stmt.accept(self)
+   File "/nodes.py", line 1196, in accept
+     return visitor.visit_class_def(self)
+   File "/checker.py", line 2462, in visit_class_def
+     self.accept(defn.defs)
+   File "/checker.py", line 592, in accept
+     stmt.accept(self)
+   File "/nodes.py", line 1277, in accept
+     return visitor.visit_block(self)
+   File "/checker.py", line 2952, in visit_block
+     self.accept(s)
+   File "/checker.py", line 592, in accept
+     stmt.accept(self)
+   File "/nodes.py", line 827, in accept
+     return visitor.visit_func_def(self)
+   File "/checker.py", line 1046, in visit_func_def
+     self._visit_func_def(defn)
+   File "/checker.py", line 1050, in _visit_func_def
+     self.check_func_item(defn, name=defn.name)
+   File "/checker.py", line 1084, in check_func_item
+     self.check_func_def(defn, typ, name, allow_empty)
+   File "/checker.py", line 1360, in check_func_def
+     self.accept(item.body)
+   File "/checker.py", line 592, in accept
+     stmt.accept(self)
+   File "/nodes.py", line 1277, in accept
+     return visitor.visit_block(self)
+   File "/checker.py", line 2952, in visit_block
+     self.accept(s)
+   File "/checker.py", line 592, in accept
+     stmt.accept(self)
+   File "/nodes.py", line 1364, in accept
+     return visitor.visit_assignment_stmt(self)
+   File "/checker.py", line 3001, in visit_assignment_stmt
+     self.check_assignment(s.lvalues[-1], s.rvalue, s.type is None, s.new_syntax)
+   File "/checker.py", line 3218, in check_assignment
+     rvalue_type = self.expr_checker.accept(rvalue, type_context=type_context)
+   File "/checkexpr.py", line 5954, in accept
+     typ = node.accept(self)
+           ^^^^^^^^^^^^^^^^^
+   File "/nodes.py", line 1984, in accept
+     return visitor.visit_call_expr(self)
+            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/checkexpr.py", line 484, in visit_call_expr
+     return self.visit_call_expr_inner(e, allow_none_return=allow_none_return)
+            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/checkexpr.py", line 618, in visit_call_expr_inner
+     ret_type = self.check_call_expr_with_callee_type(
+                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/checkexpr.py", line 1475, in check_call_expr_with_callee_type
+     ret_type, callee_type = self.check_call(
+                             ^^^^^^^^^^^^^^^^
+   File "/checkexpr.py", line 1571, in check_call
+     return self.check_callable_call(
+            ^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/checkexpr.py", line 1785, in check_callable_call
+     arg_types = self.infer_arg_types_in_context(callee, args, arg_kinds, formal_to_actual)
+                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/checkexpr.py", line 1959, in infer_arg_types_in_context
+     res[ai] = self.accept(args[ai], arg_type)
+               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   File "/checkexpr.py", line 5961, in accept
+     assert typ is not None
+            ^^^^^^^^^^^^^^^
+ AssertionError: 

operator (https://github.com/canonical/operator)
+ /tmp/mypy_primer/new_mypy/venv/lib/python3.12/site-packages/mypy/typeshed/stdlib/copy.pyi:18: 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.14.0+dev.710a21f501f829783a51f1e7818569679f5d4658
+ note: use --pdb to drop into pdb
- ops/jujuversion.py:63: error: Argument 1 of "__eq__" is incompatible with supertype "object"; supertype defines the argument type as "object"  [override]
- ops/jujuversion.py:63: note: This violates the Liskov substitution principle
- ops/jujuversion.py:63: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#incompatible-overrides
- ops/jujuversion.py:63: note: It is recommended for "__eq__" to work with arbitrary objects, for example:
- ops/jujuversion.py:63: note:     def __eq__(self, other: object) -> bool:
- ops/jujuversion.py:63: note:         if not isinstance(other, JujuVersion):
- ops/jujuversion.py:63: note:             return NotImplemented
- ops/jujuversion.py:63: note:         return <logic to compare two JujuVersion instances>
- ops/_private/timeconv.py:92: error: Incompatible types in assignment (expression has type "float", variable has type "int")  [assignment]
- ops/_private/timeconv.py:94: error: Incompatible types in assignment (expression has type "int | float", variable has type "int")  [assignment]
- ops/_private/timeconv.py:96: error: Incompatible types in assignment (expression has type "int | float", variable has type "int")  [assignment]
- ops/_private/timeconv.py:98: error: Incompatible types in assignment (expression has type "int | float", variable has type "int")  [assignment]
- ops/_private/timeconv.py:100: error: Incompatible types in assignment (expression has type "int | float", variable has type "int")  [assignment]
- ops/_private/timeconv.py:102: error: Incompatible types in assignment (expression has type "int | float", variable has type "int")  [assignment]
- ops/lib/__init__.py:86: error: "None" has no attribute "get"  [attr-defined]
- ops/lib/__init__.py:211: error: Need type annotation for "libinfo" (hint: "libinfo: dict[<type>, <type>] = ...")  [var-annotated]

... (truncated 11160 lines) ...```

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant