DetachHead / basedpyright

pyright fork with various type checking improvements, improved vscode support and pylance features built into the language server
http://docs.basedpyright.com/
Other
613 stars 13 forks source link

support `@final` on inline `TypedDict`s #386

Open DetachHead opened 1 month ago

DetachHead commented 1 month ago

pyright's has experimental support for inline TypedDict syntax:

foo: dict[{"foo": int}]

(although it will probably be removed from pyright in the future, if that happens i will keep it in basedpyright.)

unfortunately the @final decorator doesn't work on it:

from typing import final

Foo = final(dict[{"foo": int}])

class Bar(Foo): # no error
    b: int

perhaps we could use typing.Final instead:

Foo = Final[dict[{"foo": int}]]

which is a convenient solution because it unintentionally also provides runtime protection against subtyping it too:

TypeError: Cannot subclass typing.Final[dict[{'foo': <class 'int'>}]]

(related: #385)