You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If I have a lru_cache decorated classmethod, I noticed that I can get an error where the return type will be literally Self rather than the inferred class. I've seen a lot of discussion about lru_cache support, but it wasn't clear to me if this would be a dupe.
To Reproduce
fromtypingimportSelffromfunctoolsimportlru_cacheclassA:
@classmethod@lru_cachedefa(cls) ->Self:
returncls()
x=id(A)
ifx==1:
aa=A.a()
else:
aa=A() # Incompatible types in assignment (expression has type "A", variable has type "Self") [assignment]
Expected Behavior
I expected this code to have no type errors
Actual Behavior
main.py:17: error: Incompatible types in assignment (expression has type "A", variable has type "Self") [assignment]
Found 1 error in 1 file (checked 1 source file)
Your Environment
mypy 1.15, python 3.11, stock config
The text was updated successfully, but these errors were encountered:
https://mypy-play.net/?mypy=latest&python=3.11&gist=81326668cbc8056d8f3b44d3396ea0d0
If I have a lru_cache decorated classmethod, I noticed that I can get an error where the return type will be literally Self rather than the inferred class. I've seen a lot of discussion about lru_cache support, but it wasn't clear to me if this would be a dupe.
To Reproduce
Expected Behavior
I expected this code to have no type errors
Actual Behavior
main.py:17: error: Incompatible types in assignment (expression has type "A", variable has type "Self") [assignment]
Found 1 error in 1 file (checked 1 source file)
Your Environment
mypy 1.15, python 3.11, stock config
The text was updated successfully, but these errors were encountered: