Skip to content

Crash for certain type alias definitions with parameter with parameter bounded by a forward type #19734

@janramon

Description

@janramon

Crash Report

Sometime we want to use a class in typing before the class itself is defined, in such cases we can use quotes (stringizing). Suppose we have a type alias B depending on class A and a class A which (in my code, not in this simplified example) uses B:

type B[T:"A"] = int

class A:
    pass

Traceback

/tmp$ mypy --version
mypy 1.17.1 (compiled: yes)
/tmp$ mypy --show-traceback test.py
Traceback (most recent call last):
  File "/home/jramon/local/anaconda3/envs/trumpet/bin/mypy", line 8, in <module>
    sys.exit(console_entry())
             ^^^^^^^^^^^^^^^
  File "/home/jramon/local/anaconda3/envs/trumpet/lib/python3.12/site-packages/mypy/__main__.py", line 15, in console_entry
    main()
  File "mypy/main.py", line 127, in main
  File "mypy/main.py", line 211, in run_build
  File "mypy/build.py", line 191, in build
  File "mypy/build.py", line 267, in _build
  File "mypy/build.py", line 2939, in dispatch
  File "mypy/build.py", line 3337, in process_graph
  File "mypy/build.py", line 3464, in process_stale_scc
  File "mypy/build.py", line 2501, in write_cache
  File "mypy/build.py", line 1562, in write_cache
  File "mypy/nodes.py", line 367, in serialize
  File "mypy/nodes.py", line 4138, in serialize
  File "mypy/nodes.py", line 4074, in serialize
  File "mypy/nodes.py", line 3806, in serialize
  File "mypy/types.py", line 696, in serialize
  File "mypy/types.py", line 3191, in serialize
AssertionError: Internal error: unresolved placeholder type None
/tmp$ 

To Reproduce

The small code above reproduces the error.
In contrast mypy processes correctly the (similar) code below, reporting there are no errors:

type B[T:"A"] = "C"

class A:
    pass

class C:
    pass
/tmp$ mypy --show-traceback test.py
Success: no issues found in 1 source file

However, when we put the definition of class C at the top, the same problem arises again.

Your Environment

  • Mypy version used: 1.17.1
  • Mypy command-line flags: none (except for reporting the backtrace)
  • Mypy configuration options from mypy.ini (and other config files): none as far as a I know (there is no mypy.ini)
  • Python version used: 3.12.5
  • Operating system and version: Ubuntu 22.04

Metadata

Metadata

Assignees

No one assigned

    Labels

    crashsemantic-analyzerProblems that happen during semantic analysistopic-pep-695Issues related to PEP 695 syntax

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions