Skip to content

[2.0 regression] Crash with --allow-redefinition on partial type with global #21423

Closed

Description

@hauntsaninja
λ cat test250.py
x = []

def f() -> None:
    global x
    x
λ mypy --no-incremental --show-traceback --allow-redefinition test250.py
test250.py:5: 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: 2.1.0+dev.16823a17c10ce5a00b0bbdee5fa9959dccea8ccc
Traceback (most recent call last):
  File "/Users/shantanu/.virtualenvs/mypy-fexc/bin/mypy", line 10, in <module>
    sys.exit(console_entry())
  File "/Users/shantanu/dev/mypy/mypy/__main__.py", line 16, in console_entry
    main()
  File "/Users/shantanu/dev/mypy/mypy/main.py", line 154, in main
    res, messages, blockers = run_build(sources, options, fscache, t0, stdout, stderr)
  File "/Users/shantanu/dev/mypy/mypy/main.py", line 244, in run_build
    res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
  File "/Users/shantanu/dev/mypy/mypy/build.py", line 422, in build
    result = build_inner(
  File "/Users/shantanu/dev/mypy/mypy/build.py", line 537, in build_inner
    graph = dispatch(sources, manager, stdout, connect_threads)
  File "/Users/shantanu/dev/mypy/mypy/build.py", line 4150, in dispatch
    process_graph(graph, manager)
  File "/Users/shantanu/dev/mypy/mypy/build.py", line 4618, in process_graph
    done, still_working, results = manager.wait_for_done(graph)
  File "/Users/shantanu/dev/mypy/mypy/build.py", line 1492, in wait_for_done
    process_stale_scc(graph, next_scc, self)
  File "/Users/shantanu/dev/mypy/mypy/build.py", line 4792, in process_stale_scc
    graph[id].type_check_first_pass()
  File "/Users/shantanu/dev/mypy/mypy/build.py", line 3414, in type_check_first_pass
    self.type_checker().check_first_pass(recurse_into_functions=recurse_into_functions)
  File "/Users/shantanu/dev/mypy/mypy/checker.py", line 618, in check_first_pass
    self.accept(d)
  File "/Users/shantanu/dev/mypy/mypy/checker.py", line 765, in accept
    stmt.accept(self)
  File "/Users/shantanu/dev/mypy/mypy/nodes.py", line 1159, in accept
    return visitor.visit_func_def(self)
  File "/Users/shantanu/dev/mypy/mypy/checker.py", line 1332, in visit_func_def
    self.visit_func_def_impl(defn)
  File "/Users/shantanu/dev/mypy/mypy/checker.py", line 1336, in visit_func_def_impl
    self.check_func_item(defn, name=defn.name)
  File "/Users/shantanu/dev/mypy/mypy/checker.py", line 1369, in check_func_item
    self.check_func_def(defn, typ, name, allow_empty)
  File "/Users/shantanu/dev/mypy/mypy/checker.py", line 1551, in check_func_def
    self.accept(item.body)
  File "/Users/shantanu/dev/mypy/mypy/checker.py", line 765, in accept
    stmt.accept(self)
  File "/Users/shantanu/dev/mypy/mypy/nodes.py", line 1816, in accept
    return visitor.visit_block(self)
  File "/Users/shantanu/dev/mypy/mypy/checker.py", line 3275, in visit_block
    self.accept(s)
  File "/Users/shantanu/dev/mypy/mypy/checker.py", line 765, in accept
    stmt.accept(self)
  File "/Users/shantanu/dev/mypy/mypy/nodes.py", line 1836, in accept
    return visitor.visit_expression_stmt(self)
  File "/Users/shantanu/dev/mypy/mypy/checker.py", line 5139, in visit_expression_stmt
    expr_type = self.expr_checker.accept(s.expr, allow_none_return=True, always_allow_any=True)
  File "/Users/shantanu/dev/mypy/mypy/checkexpr.py", line 6177, in accept
    typ = node.accept(self)  # r-value type, when interpreted as a value expression
  File "/Users/shantanu/dev/mypy/mypy/nodes.py", line 2439, in accept
    return visitor.visit_name_expr(self)
           ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
  File "/Users/shantanu/dev/mypy/mypy/checkexpr.py", line 350, in visit_name_expr
    narrowed = self.narrow_type_from_binder(e, result)
  File "/Users/shantanu/dev/mypy/mypy/checkexpr.py", line 6486, in narrow_type_from_binder
    narrowed = narrow_declared_type(known_type, restriction)
  File "/Users/shantanu/dev/mypy/mypy/meet.py", line 185, in narrow_declared_type
    elif not is_overlapping_types(declared, narrowed):
             ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^
  File "/Users/shantanu/dev/mypy/mypy/meet.py", line 379, in is_overlapping_types
    assert False, "Unexpectedly encountered partial type"
           ^^^^^
AssertionError: Unexpectedly encountered partial type

Activity

  1. ilevkivskyi commented on May 7, 2026

    @ilevkivskyi
    Member

    Fun part is that the crash disappears in parallel checking. So the fix may be a s simple as switching to two-phase checking, see #21348 (which I was going to do soon).

  2. ilevkivskyi commented on May 7, 2026

    @ilevkivskyi
    Member

    Btw @hauntsaninja do you know if this is something new or it can be reproduced with --allow-redefintion-new in older versions?

  3. hauntsaninja commented on May 7, 2026

    @hauntsaninja
    CollaboratorAuthor

    Just checked, looks like it bisects to #21285 cc @JukkaL

  4. changed the title [-]Crash with --allow-redefinition on partial type with global[/-] [+][2.0 regression] Crash with --allow-redefinition on partial type with global[/+] on May 7, 2026
  5. added a commit that references this issue on May 7, 2026
    3f0c355
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions