Skip to content

stubtest: understand override #18815

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

Merged
merged 3 commits into from
Mar 20, 2025
Merged

Conversation

hauntsaninja
Copy link
Collaborator

@hauntsaninja hauntsaninja commented Mar 19, 2025

Fixes #18814

@jorenham
Copy link
Contributor

jorenham commented Mar 19, 2025

In numtype/tool/stubtest.py I changed line 5 to

#     "mypy[faster-cache] @ git+https://github.com/hauntsaninja/mypy@stubtover",

then ran

uv lock --script tool/stubtest.py --upgrade 

, set show_traceback = true in pyproject.toml, and ran

uv run tool/stubtest.py

which resulted in

      Built numtype @ file:///home/joren/Workspace/numtype
Uninstalled 1 package in 2ms
Installed 1 package in 1ms
python 3.13.2 (main, Feb  7 2025, 04:13:54) [GCC 11.4.0]
numtype 2.2.4.0.dev0 (numpy 2.2.4)

stubtest --mypy-config-file pyproject.toml --allowlist tool/allowlists/common.txt --allowlist tool/allowlists/common-todo.txt --allowlist tool/allowlists/ge-py312.txt numpy
Traceback (most recent call last):
  File "/home/joren/.cache/uv/environments-v2/stubtest-a47cadb5a2d3aac3/bin/stubtest", line 10, in <module>
    sys.exit(main())
  File ".venv/lib/python3.13/site-packages/mypy/stubtest.py", line 2150, in main
    return test_stubs(parse_options(sys.argv[1:]))
  File ".venv/lib/python3.13/site-packages/mypy/stubtest.py", line 2008, in test_stubs
    modules = build_stubs(modules, options, find_submodules=not args.check_typeshed)
  File ".venv/lib/python3.13/site-packages/mypy/stubtest.py", line 1786, in build_stubs
    res = mypy.build.build(sources=sources, options=options)
  File ".venv/lib/python3.13/site-packages/mypy/build.py", line 191, in build
    result = _build(
  File ".venv/lib/python3.13/site-packages/mypy/build.py", line 267, in _build
    graph = dispatch(sources, manager, stdout)
  File ".venv/lib/python3.13/site-packages/mypy/build.py", line 2937, in dispatch
    process_graph(graph, manager)
  File ".venv/lib/python3.13/site-packages/mypy/build.py", line 3335, in process_graph
    process_stale_scc(graph, scc, manager)
  File ".venv/lib/python3.13/site-packages/mypy/build.py", line 3436, in process_stale_scc
    graph[id].type_check_first_pass()
  File ".venv/lib/python3.13/site-packages/mypy/build.py", line 2309, in type_check_first_pass
    self.type_checker().check_first_pass()
  File ".venv/lib/python3.13/site-packages/mypy/checker.py", line 470, in check_first_pass
    self.accept(d)
  File ".venv/lib/python3.13/site-packages/mypy/checker.py", line 576, in accept
    stmt.accept(self)
  File ".venv/lib/python3.13/site-packages/mypy/nodes.py", line 1199, in accept
    return visitor.visit_class_def(self)
  File ".venv/lib/python3.13/site-packages/mypy/checker.py", line 2569, in visit_class_def
    self.accept(defn.defs)
  File ".venv/lib/python3.13/site-packages/mypy/checker.py", line 576, in accept
    stmt.accept(self)
  File ".venv/lib/python3.13/site-packages/mypy/nodes.py", line 1280, in accept
    return visitor.visit_block(self)
  File ".venv/lib/python3.13/site-packages/mypy/checker.py", line 3063, in visit_block
    self.accept(s)
  File ".venv/lib/python3.13/site-packages/mypy/checker.py", line 576, in accept
    stmt.accept(self)
    ~~~~~~~~~~~^^^^^^
  File ".venv/lib/python3.13/site-packages/mypy/nodes.py", line 580, in accept
    return visitor.visit_overloaded_func_def(self)
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
  File ".venv/lib/python3.13/site-packages/mypy/checker.py", line 641, in visit_overloaded_func_def
    self._visit_overloaded_func_def(defn)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
  File ".venv/lib/python3.13/site-packages/mypy/checker.py", line 697, in _visit_overloaded_func_def
    found_method_base_classes = self.check_method_override(defn)
  File ".venv/lib/python3.13/site-packages/mypy/checker.py", line 2022, in check_method_override
    result = self.check_method_or_accessor_override_for_base(
        defn, base, check_override_compatibility
    )
  File ".venv/lib/python3.13/site-packages/mypy/checker.py", line 2060, in check_method_or_accessor_override_for_base
    if self.check_method_override_for_base_with_name(defn, name, base):
       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^
  File ".venv/lib/python3.13/site-packages/mypy/checker.py", line 2194, in check_method_override_for_base_with_name
    self.check_setter_type_override(defn, base_attr, base)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
  File ".venv/lib/python3.13/site-packages/mypy/checker.py", line 2084, in check_setter_type_override
    original_type, is_original_setter = get_raw_setter_type(base_node)
                                        ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^
  File ".venv/lib/python3.13/site-packages/mypy/checker.py", line 8919, in get_raw_setter_type
    assert var.type is not None
           ^^^^^^^^^^^^^^^^^^^^
AssertionError: 
src/numpy-stubs/ma/core.pyi:309: 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.16.0+dev.73e19e32d426f15bb97c4877c8bcc73c96c549ab
src/numpy-stubs/ma/core.pyi:309: : note: use --pdb to drop into pdb

This looks like the same crash from before that I thought was fixed. Maybe your branch isn't up to date with master or something?

@jorenham
Copy link
Contributor

jorenham commented Mar 19, 2025

I created https://github.com/numpy/numtype/tree/mypy-18814 with the repro of the issue and the modifications from #18815 (comment)

From there, you can uv run --reinstall --upgrade tool/stubtest.py (no need to worry about lockfiles)

@hauntsaninja
Copy link
Collaborator Author

hauntsaninja commented Mar 20, 2025

Okay cool, in the light of day, I have confirmed this fixes the crash. (I did need to move one or two type ignores around when rebased on top of latest). Thanks for the report/repro!

@hauntsaninja hauntsaninja merged commit 045a6d8 into python:master Mar 20, 2025
12 checks passed
@hauntsaninja hauntsaninja deleted the stubtover branch March 20, 2025 02:02
@jorenham
Copy link
Contributor

Thanks again for the quick fix @hauntsaninja 💪🏻

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.

stubtest crashes on @override + @overload
2 participants