-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Mypy hangs on recursive type
keyword in combination with an unresolved type name
#18505
Comments
Hold on, it seems to also happen not necessarily because of an undefined type name. In my original file, the one from which I started stripping down to a smaller reproducible version, I don't actually have an undefined type name. Simply lifting the recursive referencing of the Maybe the way I want to use the Full example: https://mypy-play.net/?mypy=latest&python=3.12&gist=cb3570afdf70f2a8117c3b680b275f04 Diff to make it pass instead of freeze: diff --git a/applicationmapper/metacontroller_api.py b/applicationmapper/metacontroller_api.py
index d52185d..7b1f931 100644
--- a/applicationmapper/metacontroller_api.py
+++ b/applicationmapper/metacontroller_api.py
@@ -223,8 +223,8 @@ class ResourceRule(TypedDict):
class DecoratorController:
- type CustomizeRequest = CustomizeRequest
- type CustomizeResponse = CustomizeResponse
+ type CustomizeRequestFoo = CustomizeRequest
+ type CustomizeResponseFoo = CustomizeResponse
type SyncRequest = DecoratorSyncRequest.Type
type SyncResponse = DecoratorSyncResponse.Type
type FinalizeRequest = DecoratorFinalizeRequest.Type
@@ -244,8 +244,8 @@ class DecoratorController:
class CompositeController:
- type CustomizeRequest = CustomizeRequest
- type CustomizeResponse = CustomizeResponse
+ type CustomizeRequestFoo = CustomizeRequest
+ type CustomizeResponseFoo = CustomizeResponse
type SyncRequest = CompositeSyncRequest.Type
type SyncResponse = CompositeSyncResponse.Type
type FinalizeRequest = CompositeFinalizeRequest.Type Also using Edit: What's also interesting is that I actually want to use type: CustomizeRequest = CustomizeRequest.Type in which case Mypy will not freeze, but it will complain that the name is not defined (in either case, using the class CustomizeRequest:
class Type(TypedDict): ...
type: _CustomizeRequest = CustomizeRequest.Type
class CompositeController:
type CustomizeRequest = _CustomizeRequest |
The most minimal repro I managed to construct (without typeddict and other class CustomizeResponse:
relatedResources: "ResourceRule"
class ResourceRule: pass
class DecoratorController:
type CustomizeResponse = CustomizeResponse A few random interruptions explain where
I'm not really deep into PEP695, what does it say about scoping here? My quick runtime checking says that alias' (marking as crash since freezing is no better than traceback, it's a hard failure) |
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 anothertype
keyword to re-assign the same global name on a class member, Mypy freezes.To Reproduce
It begins working as soon as you do any one of these things:
from typing import Any
(passes)type SomeOtherName = CustomizeRequest
(fails,Any
undefined)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.ini
(and other config files):strict = true
The text was updated successfully, but these errors were encountered: