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
@final doesn't work as expected with TypedDicts, but mypy doesn't complain about it:
fromtyping_extensionsimportfinal, TypedDict@final# No error hereclassC(TypedDict):
x: floaty: intz: strclassD(C): # No error herepass
This is confusing, since users would expect that @final prevents structural subtyping, but that's not the case. The simplest fix would be to generate an error if @final is used in a TypedDict definition.
Hints: This should be a pretty simple thing to fix. Look at what happens in analyze_class in mypy/semanal.py.
Fixes#7849
This fix modifies function `analyze_class` in `mypy/semanal.py`, if the analyzer identifies a `TypedDict`, it then traverses all decorators and checks if `@final` exists, and if so, generates an error.
@final
doesn't work as expected with TypedDicts, but mypy doesn't complain about it:This is confusing, since users would expect that
@final
prevents structural subtyping, but that's not the case. The simplest fix would be to generate an error if@final
is used in a TypedDict definition.Hints: This should be a pretty simple thing to fix. Look at what happens in
analyze_class
inmypy/semanal.py
.Originally reported in #7845.
The text was updated successfully, but these errors were encountered: