-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
ay0503
wants to merge
3
commits into
python:master
Choose a base branch
from
ay0503:bug/force-list-comp-union
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+34
−0
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This comment has been minimized.
This comment has been minimized.
ay0503
force-pushed
the
bug/force-list-comp-union
branch
from
November 28, 2024 06:14
4eb09ac
to
fe3322a
Compare
for more information, see https://pre-commit.ci
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/re.pyi:44: 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.4c9fecfbb901a6cf2d1e778cce31558600c32c47
+ 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 1545, in accept
+ return visitor.visit_if_stmt(self)
+ File "/checker.py", line 4729, 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 1385, in accept
+ return visitor.visit_operator_assignment_stmt(self)
+ File "/checker.py", line 4756, in visit_operator_assignment_stmt
+ rvalue_type, method_type = self.expr_checker.check_op(method, lvalue_type, s.rvalue, s)
+ File "/checkexpr.py", line 4186, in check_op
+ return self.check_method_call_by_name(
+ File "/checkexpr.py", line 3827, in check_method_call_by_name
+ return self.check_method_call(method, base_type, method_type, args, arg_kinds, context)
+ File "/checkexpr.py", line 3878, in check_method_call
+ return self.check_call(
+ File "/checkexpr.py", line 1572, in check_call
+ return self.check_callable_call(
+ File "/checkexpr.py", line 1786, in check_callable_call
+ arg_types = self.infer_arg_types_in_context(callee, args, arg_kinds, formal_to_actual)
+ File "/checkexpr.py", line 1960, in infer_arg_types_in_context
+ res[ai] = self.accept(args[ai], arg_type)
+ File "/checkexpr.py", line 5916, in accept
+ typ = node.accept(self)
+ ^^^^^^^^^^^^^^^^^
+ File "/nodes.py", line 2313, in accept
+ return visitor.visit_list_expr(self)
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ File "/checkexpr.py", line 4980, in visit_list_expr
+ return self.check_lst_expr(e, "builtins.list", "<list>")
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ File "/checkexpr.py", line 5049, in check_lst_expr
+ item_type = self.infer_item_type(item_types)
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ File "/checkexpr.py", line 5021, in infer_item_type
+ joined_type = self.chk.join_types(*item_types)
+ ^^^^^^^^^^^^^^^^^^^
+ AttributeError: 'TypeChecker' object has no attribute 'join_types'
janus (https://github.com/aio-libs/janus)
+ /tmp/mypy_primer/new_mypy/venv/lib/python3.12/site-packages/mypy/typeshed/stdlib/typing.pyi:106: 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.4c9fecfbb901a6cf2d1e778cce31558600c32c47
+ 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 1545, in accept
+ return visitor.visit_if_stmt(self)
+ File "/checker.py", line 4729, 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 1385, in accept
+ return visitor.visit_operator_assignment_stmt(self)
+ File "/checker.py", line 4756, in visit_operator_assignment_stmt
+ rvalue_type, method_type = self.expr_checker.check_op(method, lvalue_type, s.rvalue, s)
+ File "/checkexpr.py", line 4186, in check_op
+ return self.check_method_call_by_name(
+ File "/checkexpr.py", line 3827, in check_method_call_by_name
+ return self.check_method_call(method, base_type, method_type, args, arg_kinds, context)
+ File "/checkexpr.py", line 3878, in check_method_call
+ return self.check_call(
+ File "/checkexpr.py", line 1572, in check_call
+ return self.check_callable_call(
+ File "/checkexpr.py", line 1786, in check_callable_call
+ arg_types = self.infer_arg_types_in_context(callee, args, arg_kinds, formal_to_actual)
+ File "/checkexpr.py", line 1960, in infer_arg_types_in_context
+ res[ai] = self.accept(args[ai], arg_type)
+ File "/checkexpr.py", line 5916, in accept
+ typ = node.accept(self)
+ ^^^^^^^^^^^^^^^^^
+ File "/nodes.py", line 2313, in accept
+ return visitor.visit_list_expr(self)
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ File "/checkexpr.py", line 4980, in visit_list_expr
+ return self.check_lst_expr(e, "builtins.list", "<list>")
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ File "/checkexpr.py", line 5049, in check_lst_expr
+ item_type = self.infer_item_type(item_types)
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ File "/checkexpr.py", line 5021, in infer_item_type
+ joined_type = self.chk.join_types(*item_types)
+ ^^^^^^^^^^^^^^^^^^^
+ AttributeError: 'TypeChecker' object has no attribute 'join_types'
dacite (https://github.com/konradhalas/dacite)
- dacite/config.py:8: error: Unused "type: ignore" comment [unused-ignore]
- dacite/types.py:52: error: Unused "type: ignore" comment [unused-ignore]
- dacite/types.py:67: error: Unused "type: ignore" comment [unused-ignore]
- dacite/types.py:161: error: Unused "type: ignore" comment [unused-ignore]
- dacite/dataclasses.py:17: error: Unused "type: ignore" comment [unused-ignore]
- dacite/dataclasses.py:18: error: Unused "type: ignore" comment [unused-ignore]
+ /tmp/mypy_primer/new_mypy/venv/lib/python3.12/site-packages/mypy/typeshed/stdlib/typing.pyi:106: 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.4c9fecfbb901a6cf2d1e778cce31558600c32c47
+ 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 1545, in accept
+ return visitor.visit_if_stmt(self)
+ File "/checker.py", line 4729, 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 1385, in accept
+ return visitor.visit_operator_assignment_stmt(self)
+ File "/checker.py", line 4756, in visit_operator_assignment_stmt
+ rvalue_type, method_type = self.expr_checker.check_op(method, lvalue_type, s.rvalue, s)
+ File "/checkexpr.py", line 4186, in check_op
+ return self.check_method_call_by_name(
+ File "/checkexpr.py", line 3827, in check_method_call_by_name
+ return self.check_method_call(method, base_type, method_type, args, arg_kinds, context)
+ File "/checkexpr.py", line 3878, in check_method_call
+ return self.check_call(
+ File "/checkexpr.py", line 1572, in check_call
+ return self.check_callable_call(
+ File "/checkexpr.py", line 1786, in check_callable_call
+ arg_types = self.infer_arg_types_in_context(callee, args, arg_kinds, formal_to_actual)
+ File "/checkexpr.py", line 1960, in infer_arg_types_in_context
+ res[ai] = self.accept(args[ai], arg_type)
+ File "/checkexpr.py", line 5916, in accept
+ typ = node.accept(self)
+ ^^^^^^^^^^^^^^^^^
+ File "/nodes.py", line 2313, in accept
+ return visitor.visit_list_expr(self)
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ File "/checkexpr.py", line 4980, in visit_list_expr
+ return self.check_lst_expr(e, "builtins.list", "<list>")
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ File "/checkexpr.py", line 5049, in check_lst_expr
+ item_type = self.infer_item_type(item_types)
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ File "/checkexpr.py", line 5021, in infer_item_type
+ joined_type = self.chk.join_types(*item_types)
+ ^^^^^^^^^^^^^^^^^^^
+ AttributeError: 'TypeChecker' object has no attribute 'join_types'
zipp (https://github.com/jaraco/zipp)
+ /tmp/mypy_primer/new_mypy/venv/lib/python3.12/site-packages/mypy/typeshed/stdlib/typing.pyi:106: 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.4c9fecfbb901a6cf2d1e778cce31558600c32c47
+ 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 1545, in accept
+ return visitor.visit_if_stmt(self)
+ File "/checker.py", line 4729, 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 1385, in accept
+ return visitor.visit_operator_assignment_stmt(self)
+ File "/checker.py", line 4756, in visit_operator_assignment_stmt
+ rvalue_type, method_type = self.expr_checker.check_op(method, lvalue_type, s.rvalue, s)
+ File "/checkexpr.py", line 4186, in check_op
+ return self.check_method_call_by_name(
+ File "/checkexpr.py", line 3827, in check_method_call_by_name
+ return self.check_method_call(method, base_type, method_type, args, arg_kinds, context)
+ File "/checkexpr.py", line 3878, in check_method_call
+ return self.check_call(
+ File "/checkexpr.py", line 1572, in check_call
+ return self.check_callable_call(
+ File "/checkexpr.py", line 1786, in check_callable_call
+ arg_types = self.infer_arg_types_in_context(callee, args, arg_kinds, formal_to_actual)
+ File "/checkexpr.py", line 1960, in infer_arg_types_in_context
+ res[ai] = self.accept(args[ai], arg_type)
+ File "/checkexpr.py", line 5916, in accept
+ typ = node.accept(self)
+ ^^^^^^^^^^^^^^^^^
+ File "/nodes.py", line 2313, in accept
+ return visitor.visit_list_expr(self)
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ File "/checkexpr.py", line 4980, in visit_list_expr
+ return self.check_lst_expr(e, "builtins.list", "<list>")
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ File "/checkexpr.py", line 5049, in check_lst_expr
+ item_type = self.infer_item_type(item_types)
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ File "/checkexpr.py", line 5021, in infer_item_type
+ joined_type = self.chk.join_types(*item_types)
+ ^^^^^^^^^^^^^^^^^^^
+ AttributeError: 'TypeChecker' object has no attribute 'join_types'
websockets (https://github.com/aaugustin/websockets): 2.69x faster (16.0s -> 5.9s in a single noisy sample)
+ /tmp/mypy_primer/new_mypy/venv/lib/python3.12/site-packages/mypy/typeshed/stdlib/typing.pyi:106: 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.4c9fecfbb901a6cf2d1e778cce31558600c32c47
+ 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 1545, in accept
+ return visitor.visit_if_stmt(self)
+ File "/checker.py", line 4729, 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 1385, in accept
+ return visitor.visit_operator_assignment_stmt(self)
+ File "/checker.py", line 4756, in visit_operator_assignment_stmt
+ rvalue_type, method_type = self.expr_checker.check_op(method, lvalue_type, s.rvalue, s)
+ File "/checkexpr.py", line 4186, in check_op
+ return self.check_method_call_by_name(
+ File "/checkexpr.py", line 3827, in check_method_call_by_name
+ return self.check_method_call(method, base_type, method_type, args, arg_kinds, context)
+ File "/checkexpr.py", line 3878, in check_method_call
+ return self.check_call(
+ File "/checkexpr.py", line 1572, in check_call
+ return self.check_callable_call(
+ File "/checkexpr.py", line 1786, in check_callable_call
+ arg_types = self.infer_arg_types_in_context(callee, args, arg_kinds, formal_to_actual)
+ File "/checkexpr.py", line 1960, in infer_arg_types_in_context
+ res[ai] = self.accept(args[ai], arg_type)
+ File "/checkexpr.py", line 5916, in accept
+ typ = node.accept(self)
+ ^^^^^^^^^^^^^^^^^
+ File "/nodes.py", line 2313, in accept
+ return visitor.visit_list_expr(self)
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ File "/checkexpr.py", line 4980, in visit_list_expr
+ return self.check_lst_expr(e, "builtins.list", "<list>")
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ File "/checkexpr.py", line 5049, in check_lst_expr
+ item_type = self.infer_item_type(item_types)
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ File "/checkexpr.py", line 5021, in infer_item_type
+ joined_type = self.chk.join_types(*item_types)
+ ^^^^^^^^^^^^^^^^^^^
+ AttributeError: 'TypeChecker' object has no attribute 'join_types'
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/typing.pyi:106: 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.4c9fecfbb901a6cf2d1e778cce31558600c32c47
+ 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 1545, in accept
+ return visitor.visit_if_stmt(self)
+ File "/checker.py", line 4729, 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 1385, in accept
+ return visitor.visit_operator_assignment_stmt(self)
+ File "/checker.py", line 4756, in visit_operator_assignment_stmt
+ rvalue_type, method_type = self.expr_checker.check_op(method, lvalue_type, s.rvalue, s)
+ File "/checkexpr.py", line 4186, in check_op
+ return self.check_method_call_by_name(
+ File "/checkexpr.py", line 3827, in check_method_call_by_name
+ return self.check_method_call(method, base_type, method_type, args, arg_kinds, context)
+ File "/checkexpr.py", line 3878, in check_method_call
+ return self.check_call(
+ File "/checkexpr.py", line 1572, in check_call
+ return self.check_callable_call(
+ File "/checkexpr.py", line 1786, in check_callable_call
+ arg_types = self.infer_arg_types_in_context(callee, args, arg_kinds, formal_to_actual)
+ File "/checkexpr.py", line 1960, in infer_arg_types_in_context
+ res[ai] = self.accept(args[ai], arg_type)
+ File "/checkexpr.py", line 5916, in accept
+ typ = node.accept(self)
+ ^^^^^^^^^^^^^^^^^
+ File "/nodes.py", line 2313, in accept
+ return visitor.visit_list_expr(self)
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ File "/checkexpr.py", line 4980, in visit_list_expr
+ return self.check_lst_expr(e, "builtins.list", "<list>")
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ File "/checkexpr.py", line 5049, in check_lst_expr
+ item_type = self.infer_item_type(item_types)
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ File "/checkexpr.py", line 5021, in infer_item_type
+ joined_type = self.chk.join_types(*item_types)
+ ^^^^^^^^^^^^^^^^^^^
+ AttributeError: 'TypeChecker' object has no attribute 'join_types'
parso (https://github.com/davidhalter/parso)
- parso/tree.py:1: note: class abc.abstractproperty is deprecated: Use 'property' with 'abstractmethod' instead [deprecated]
- 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]
+ /tmp/mypy_primer/new_mypy/venv/lib/python3.12/site-packages/mypy/typeshed/stdlib/typing.pyi:106: 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.4c9fecfbb901a6cf2d1e778cce31558600c32c47
+ 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 1545, in accept
+ return visitor.visit_if_stmt(self)
+ File "/checker.py", line 4729, 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 1385, in accept
+ return visitor.visit_operator_assignment_stmt(self)
+ File "/checker.py", line 4756, in visit_operator_assignment_stmt
+ rvalue_type, method_type = self.expr_checker.check_op(method, lvalue_type, s.rvalue, s)
+ File "/checkexpr.py", line 4186, in check_op
+ return self.check_method_call_by_name(
+ File "/checkexpr.py", line 3827, in check_method_call_by_name
+ return self.check_method_call(method, base_type, method_type, args, arg_kinds, context)
+ File "/checkexpr.py", line 3878, in check_method_call
+ return self.check_call(
+ File "/checkexpr.py", line 1572, in check_call
+ return self.check_callable_call(
+ File "/checkexpr.py", line 1786, in check_callable_call
+ arg_types = self.infer_arg_types_in_context(callee, args, arg_kinds, formal_to_actual)
+ File "/checkexpr.py", line 1960, in infer_arg_types_in_context
+ res[ai] = self.accept(args[ai], arg_type)
+ File "/checkexpr.py", line 5916, in accept
+ typ = node.accept(self)
+ ^^^^^^^^^^^^^^^^^
+ File "/nodes.py", line 2313, in accept
+ return visitor.visit_list_expr(self)
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ File "/checkexpr.py", line 4980, in visit_list_expr
+ return self.check_lst_expr(e, "builtins.list", "<list>")
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ File "/checkexpr.py", line 5049, in check_lst_expr
+ item_type = self.infer_item_type(item_types)
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ File "/checkexpr.py", line 5021, in infer_item_type
+ joined_type = self.chk.join_types(*item_types)
+ ^^^^^^^^^^^^^^^^^^^
+ AttributeError: 'TypeChecker' object has no attribute 'join_types'
pycryptodome (https://github.com/Legrandin/pycryptodome): 2.79x faster (18.0s -> 6.5s in a single noisy sample)
- lib/Crypto/SelfTest/Hash/test_BLAKE2.py:421: error: Unused "type: ignore" comment [unused-ignore]
+ /tmp/mypy_primer/new_mypy/venv/lib/python3.12/site-packages/mypy/typeshed/stdlib/typing.pyi:106: 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.4c9fecfbb901a6cf2d1e778cce31558600c32c47
+ 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 1545, in accept
+ return visitor.visit_if_stmt(self)
+ File "/checker.py", line 4729, 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 1385, in accept
+ return visitor.visit_operator_assignment_stmt(self)
+ File "/checker.py", line 4756, in visit_operator_assignment_stmt
... (truncated 12312 lines) ...``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 thanobject
. 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:
However, while this fixes this issue, it also generalizes the entire list expression inference to be forced as well.