Skip to content

INTERNAL ERROR in master branch related to recent support for setter types being different from getter types #18648

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

Closed
dlech opened this issue Feb 9, 2025 · 4 comments · Fixed by #18649
Labels
crash topic-descriptors Properties, class vs. instance attributes topic-inheritance Inheritance and incompatible overrides

Comments

@dlech
Copy link

dlech commented Feb 9, 2025

Crash Report

I was running mypy from the master branch because I wanted to try out the changes from #18510. It looks like there is a bug in the implementation with regard to inheritance (the type in question is overriding an abstract property from an abstract base class).

Traceback

C:\Users\extra\work\pywinrt\_install\release\winrt\_winrt_windows_ui_input_inking.pyi:335: 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.653fc9bb79a8e45dcd6bc89fa9f24c5d170deeca
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\Users\extra\pipx\.cache\b97425f42183061\Scripts\mypy.exe\__main__.py", line 7, in <module>
    sys.exit(console_entry())
  File "C:\Users\extra\pipx\.cache\b97425f42183061\Lib\site-packages\mypy\__main__.py", line 15, in console_entry
    main()
  File "C:\Users\extra\pipx\.cache\b97425f42183061\Lib\site-packages\mypy\main.py", line 119, in main
    res, messages, blockers = run_build(sources, options, fscache, t0, stdout, stderr)
  File "C:\Users\extra\pipx\.cache\b97425f42183061\Lib\site-packages\mypy\main.py", line 203, in run_build
    res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
  File "C:\Users\extra\pipx\.cache\b97425f42183061\Lib\site-packages\mypy\build.py", line 191, in build
    result = _build(
  File "C:\Users\extra\pipx\.cache\b97425f42183061\Lib\site-packages\mypy\build.py", line 267, in _build
    graph = dispatch(sources, manager, stdout)
  File "C:\Users\extra\pipx\.cache\b97425f42183061\Lib\site-packages\mypy\build.py", line 2937, in dispatch
    process_graph(graph, manager)
  File "C:\Users\extra\pipx\.cache\b97425f42183061\Lib\site-packages\mypy\build.py", line 3335, in process_graph
    process_stale_scc(graph, scc, manager)
  File "C:\Users\extra\pipx\.cache\b97425f42183061\Lib\site-packages\mypy\build.py", line 3436, in process_stale_scc
    graph[id].type_check_first_pass()
  File "C:\Users\extra\pipx\.cache\b97425f42183061\Lib\site-packages\mypy\build.py", line 2309, in type_check_first_pass
    self.type_checker().check_first_pass()
  File "C:\Users\extra\pipx\.cache\b97425f42183061\Lib\site-packages\mypy\checker.py", line 469, in check_first_pass
    self.accept(d)
  File "C:\Users\extra\pipx\.cache\b97425f42183061\Lib\site-packages\mypy\checker.py", line 578, in accept
    stmt.accept(self)
  File "C:\Users\extra\pipx\.cache\b97425f42183061\Lib\site-packages\mypy\nodes.py", line 1200, in accept
    return visitor.visit_class_def(self)
  File "C:\Users\extra\pipx\.cache\b97425f42183061\Lib\site-packages\mypy\checker.py", line 2549, in visit_class_def
    self.accept(defn.defs)
  File "C:\Users\extra\pipx\.cache\b97425f42183061\Lib\site-packages\mypy\checker.py", line 578, in accept
    stmt.accept(self)
  File "C:\Users\extra\pipx\.cache\b97425f42183061\Lib\site-packages\mypy\nodes.py", line 1281, in accept
    return visitor.visit_block(self)
  File "C:\Users\extra\pipx\.cache\b97425f42183061\Lib\site-packages\mypy\checker.py", line 3043, in visit_block
    self.accept(s)
  File "C:\Users\extra\pipx\.cache\b97425f42183061\Lib\site-packages\mypy\checker.py", line 578, in accept
    stmt.accept(self)
    ~~~~~~~~~~~^^^^^^
  File "C:\Users\extra\pipx\.cache\b97425f42183061\Lib\site-packages\mypy\nodes.py", line 583, in accept
    return visitor.visit_overloaded_func_def(self)
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
  File "C:\Users\extra\pipx\.cache\b97425f42183061\Lib\site-packages\mypy\checker.py", line 637, in visit_overloaded_func_def
    self._visit_overloaded_func_def(defn)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
  File "C:\Users\extra\pipx\.cache\b97425f42183061\Lib\site-packages\mypy\checker.py", line 693, in _visit_overloaded_func_def
    found_method_base_classes = self.check_method_override(defn)
  File "C:\Users\extra\pipx\.cache\b97425f42183061\Lib\site-packages\mypy\checker.py", line 2017, in check_method_override
    result = self.check_method_or_accessor_override_for_base(
        defn, base, check_override_compatibility
    )
  File "C:\Users\extra\pipx\.cache\b97425f42183061\Lib\site-packages\mypy\checker.py", line 2055, in check_method_or_accessor_override_for_base
    if self.check_method_override_for_base_with_name(defn, name, base):
       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^
  File "C:\Users\extra\pipx\.cache\b97425f42183061\Lib\site-packages\mypy\checker.py", line 2150, in check_method_override_for_base_with_name
    self.check_setter_type_override(defn, base_attr, base)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\extra\pipx\.cache\b97425f42183061\Lib\site-packages\mypy\checker.py", line 2079, in check_setter_type_override
    original_type, is_original_setter = get_raw_setter_type(base_node)
                                        ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^
  File "C:\Users\extra\pipx\.cache\b97425f42183061\Lib\site-packages\mypy\checker.py", line 8888, in get_raw_setter_type
    assert var.type is not None
           ^^^^^^^^^^^^^^^^^^^^
AssertionError:
C:\Users\extra\work\pywinrt\_install\release\winrt\_winrt_windows_ui_input_inking.pyi:335: : note: use --pdb to drop into pdb

To Reproduce

It will take me some time to make a minimal reproducible test case if the stack trace is not enough.

@dlech dlech added the crash label Feb 9, 2025
@ilevkivskyi
Copy link
Member

OK, yeah, I understand what is going on, the override was processed before the supertype definition (this may happen if there is e.g. an import cycle or a forward reference). I thought that I ordered the checks correctly so that it will be properly deferred until supertype is ready, but looking at it again I didn't.

A minimal repro will be definitely helpful, since it cases like this making a fix is easier than writing a good test.

@ilevkivskyi ilevkivskyi added topic-inheritance Inheritance and incompatible overrides topic-descriptors Properties, class vs. instance attributes labels Feb 10, 2025
@ilevkivskyi
Copy link
Member

In the meantime I found my own weird repro. You can try the fix on your codebase #18649

@hauntsaninja
Copy link
Collaborator

Thanks for testing it out pre-release!

@dlech
Copy link
Author

dlech commented Feb 10, 2025

You can try the fix on your codebase

Confirmed fixed, thanks!

> pipx run --no-cache --spec git+https://github.com/python/mypy.git@master mypy -p winrt -p test -p samples -p perf --show-traceback
Success: no issues found in 918 source file
> pipx run --spec git+https://github.com/python/mypy.git@master mypy --version           
mypy 1.16.0+dev.1edb1d24fc25d2e3c9630830d943881ab37e39b5 (compiled: no)

Thanks for testing it out pre-release!

It's the best way to get someone else to fix a bug for you. 😆

x612skm pushed a commit to x612skm/mypy-dev that referenced this issue Feb 24, 2025
Fixes python#18648

The fix is straightforward, but unlike for getter I decided to not
create any ad-hoc types during `last_pass`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crash topic-descriptors Properties, class vs. instance attributes topic-inheritance Inheritance and incompatible overrides
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants