-
Pyright (strict mode) does not report any issues when returning an
This appears to be the intended behavior based on this statement on Static Typing: Advanced Topics:
Is there a way to turn off this assumption so that pyright gives a error when an |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
Your question isn't really a "pyright" question as much as a "Python type system" question. The Python typing spec dictates how type checkers must interpret a There is currently no way in the Python type system to specify a type that is "only a I don't think it would work to reinterpret |
Beta Was this translation helpful? Give feedback.
Your question isn't really a "pyright" question as much as a "Python type system" question. The Python typing spec dictates how type checkers must interpret a
float
type annotation, and pyright is conformant with the spec. Even thoughint
is not a subclass offloat
at runtime, the type expressionfloat
is interpreted asfloat | int
by static type checkers. Similarly, the type expressioncomplex
is interpreted ascomplex | float | int
.There is currently no way in the Python type system to specify a type that is "only a
float
but not anint
". There has been some discussion about this in the typing forum.I don't think it would work to reinterpret
float
to have this meaning, even as an conf…