Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Mypy hangs on recursive type keyword in combination with an unresolved type name #18505

Description

@NiklasRosenstein

Bug Report

From as far as I could boil it down, it seems that when you use the type keyword in one place referencing a type name that is undefined, and then using a another type keyword to re-assign the same global name on a class member, Mypy freezes.

To Reproduce

from typing import TypedDict

type Resource = dict[str, Any]

class CustomizeRequest: ...

class DecoratorController:
    type CustomizeRequest = CustomizeRequest

https://mypy-play.net/?mypy=latest&python=3.12&gist=f69f8d424122ed4c7d0778b37e34021f

It begins working as soon as you do any one of these things:

  • from typing import Any (passes)
  • type SomeOtherName = CustomizeRequest (fails, Any undefined)
  • remove type Resource = dict[str, Any] (passes)

Expected Behavior

Mypy should not freeze, but error and report that Any is undefined.

Actual Behavior

As explained above.

Your Environment

  • Mypy version used: 1.14.1 (compiled: yes)
  • Mypy command-line flags: n/a
  • Mypy configuration options from mypy.ini (and other config files): strict = true
  • Python version used: CPython 3.13.1

Activity

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