GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - delfick/mypy-release-2.2-bug-demonstration

BranchesTags
Open more actions menu

Latest commit

 

History

2 Commits
2 Commits

Folders and files

NameName
Last commit message
Last commit date
example
example
 
 
example_plugin
example_plugin
 
 
.gitignore
.gitignore
 
 
README.rst
README.rst
 
 
mypy.ini
mypy.ini
 
 
pyproject.toml
pyproject.toml
 
 

Repository files navigation

Demonstration

This demonstrates a bug with the release branch of mypy 2.2

python/mypy#21640

The way that https://github.com/delfick/extended-mypy-django-plugin works means I resolve types at mypy plugin time by using the get_type_analyze_hook for our django project (millions of lines of code) to convert Concrete[MyModel] and DefaultQuerySet[MyModel] into appropriate unions of types (as discovered by introspecting a django environment).

This means I end up with files that specify what those unions are as what I call "virtual dependencies" that I set as dependencies of files that reference these models (so that when django settings change to include new models, mypy understands to re-analyse relevant files).

The problem becomes with mypy 2.2 this breaks because of a change that means mypy isn't deferring the same way when it comes across placeholder types.

I can't figure out how to make a test case in mypy that demonstrates this problem, but the code here implements the bare minimum to demonstrate the failure

Running the following:

uv venv
source .venv/bin/activate
uv pip install -e .
uv pip install -e /path/to/mypy/release-2.2/branch
python -m mypy . --show-traceback

Results in:

version: 2.2.0+dev.3179030edcee070153b29cf21e06a0966beb088c
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/Users/stephen.moore/Projects/external/mypy/mypy/__main__.py", line 52, in <module>
    console_entry()
  File "/Users/stephen.moore/Projects/external/mypy/mypy/__main__.py", line 16, in console_entry
    main()
  File "/Users/stephen.moore/Projects/external/mypy/mypy/main.py", line 154, in main
    res, messages, blockers = run_build(sources, options, fscache, t0, stdout, stderr)
  File "/Users/stephen.moore/Projects/external/mypy/mypy/main.py", line 244, in run_build
    res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
  File "/Users/stephen.moore/Projects/external/mypy/mypy/build.py", line 422, in build
    result = build_inner(
  File "/Users/stephen.moore/Projects/external/mypy/mypy/build.py", line 537, in build_inner
    graph = dispatch(sources, manager, stdout, connect_threads)
  File "/Users/stephen.moore/Projects/external/mypy/mypy/build.py", line 4146, in dispatch
    process_graph(graph, manager)
  File "/Users/stephen.moore/Projects/external/mypy/mypy/build.py", line 4614, in process_graph
    done, still_working, results = manager.wait_for_done(graph)
  File "/Users/stephen.moore/Projects/external/mypy/mypy/build.py", line 1484, in wait_for_done
    process_stale_scc(graph, next_scc, self)
  File "/Users/stephen.moore/Projects/external/mypy/mypy/build.py", line 4782, in process_stale_scc
    mypy.semanal_main.semantic_analysis_for_scc(graph, scc, manager.errors)
  File "/Users/stephen.moore/Projects/external/mypy/mypy/semanal_main.py", line 92, in semantic_analysis_for_scc
    process_functions(graph, scc, patches)
  File "/Users/stephen.moore/Projects/external/mypy/mypy/semanal_main.py", line 275, in process_functions
    process_top_level_function(
  File "/Users/stephen.moore/Projects/external/mypy/mypy/semanal_main.py", line 314, in process_top_level_function
    deferred, incomplete, progress = semantic_analyze_target(
  File "/Users/stephen.moore/Projects/external/mypy/mypy/semanal_main.py", line 380, in semantic_analyze_target
    analyzer.refresh_partial(
  File "/Users/stephen.moore/Projects/external/mypy/mypy/semanal.py", line 709, in refresh_partial
    self.accept(node)
  File "/Users/stephen.moore/Projects/external/mypy/mypy/semanal.py", line 7733, in accept
    node.accept(self)
    ~~~~~~~~~~~^^^^^^
  File "/Users/stephen.moore/Projects/external/mypy/mypy/nodes.py", line 1165, in accept
    return visitor.visit_func_def(self)
           ~~~~~~~~~~~~~~~~~~~~~~^^^^^^
  File "/Users/stephen.moore/Projects/external/mypy/mypy/semanal.py", line 991, in visit_func_def
    self.analyze_func_def(defn)
    ~~~~~~~~~~~~~~~~~~~~~^^^^^^
  File "/Users/stephen.moore/Projects/external/mypy/mypy/semanal.py", line 1036, in analyze_func_def
    self.defer(defn)
    ~~~~~~~~~~^^^^^^
  File "/Users/stephen.moore/Projects/external/mypy/mypy/semanal.py", line 7334, in defer
    assert not self.final_iteration, "Must not defer during final iteration"
           ^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: Must not defer during final iteration

./example/parent.py:7: note: use --pdb to drop into pdb

But if you change mypy/semanal.py::2012 from self.defer(force_progress=tvar_defs != defn.type_vars) to self.mark_incomplete(defn.name, defn) then it passes. (note you need to reset the mypy cache if you change it back to get the error again)

But when I change this in mypy the unit tests on mypy fail. Debugging this further seems a bit beyond me.

---

AI Disclosure: None: I actively avoid LLMs

About

No description, website, or topics provided.

Resources

Readme
Activity

Stars

0 stars

Watchers

0 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.