Skip to content

Is int always a subclass of float in Pyright? #9208

Answered by erictraut
mmerlo asked this question in Q&A
Discussion options

You must be logged in to vote

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 though int is not a subclass of float at runtime, the type expression float is interpreted as float | int by static type checkers. Similarly, the type expression complex is interpreted as complex | float | int.

There is currently no way in the Python type system to specify a type that is "only a float but not an int". 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…

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@mmerlo
Comment options

@erictraut
Comment options

@mmerlo
Comment options

@erictraut
Comment options

@mmerlo
Comment options

Answer selected by mmerlo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants