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
Python allows annotations to be any expression, but if you use MyPy on your project, you can't use annotations for anything other than types (MyPy will error "Invalid type ...").
This issue proposes the following solution:
provide class typing.Annot (name for the purposes of this discussion):
during typechecking, MyPy treats annotations that are instances of Annot as if they were their type property
Benefits/Use cases
MyPy/other tools (including runtime inspection) also have extra info in kwargs available, if they know how to use it. For example, dataclasses (and attrs, and this concept) store extra field information in the value of the attribute:
@dataclass
class C:
z: int = field(repr=False, default=10)
...which is a workaround. With general-purpose annotations, it could look like this:
@dataclass
class C:
z: Annot(int, repr=False, default=10)
But the main benefit is that with this in place, it will be possible to add annotations as well as, or instead of, plain type info, without foregoing MyPy, paving the way for more tooling.
The text was updated successfully, but these errors were encountered:
Python allows annotations to be any expression, but if you use MyPy on your project, you can't use annotations for anything other than types (MyPy will error "Invalid type ...").
This issue proposes the following solution:
typing.Annot
(name for the purposes of this discussion):Annot
as if they were theirtype
propertyBenefits/Use cases
MyPy/other tools (including runtime inspection) also have extra info in
kwargs
available, if they know how to use it. For example, dataclasses (and attrs, and this concept) store extra field information in the value of the attribute:...which is a workaround. With general-purpose annotations, it could look like this:
This could also subsume class attribute annotations and Final annotations:
But the main benefit is that with this in place, it will be possible to add annotations as well as, or instead of, plain type info, without foregoing MyPy, paving the way for more tooling.
The text was updated successfully, but these errors were encountered: