Skip to content

Check for int | float #221

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
srittau opened this issue May 20, 2022 · 4 comments
Closed

Check for int | float #221

srittau opened this issue May 20, 2022 · 4 comments

Comments

@srittau
Copy link
Member

srittau commented May 20, 2022

As float is a subtype of int (for type checking purposes), int is redundant. There might be other constellations that are worth checking.

@AlexWaygood
Copy link
Collaborator

For numeric types, the following are redundant (according to PEP 484):

  • float | int (int is an implicit subtype of float)
  • complex | float (float is an implicit subtype of complex)
  • complex | int (int is an implicit subtype of complex)

@Zeckie
Copy link

Zeckie commented May 25, 2022

But at runtime, they aren't subtypes (eg. using type, isinstance or mro), and they have some differences that would not be allowed if they were subtypes.

eg. float has is_integer() but int does not

python/mypy#11511 (comment)

@hauntsaninja
Copy link
Collaborator

Yes, that is true. But all static type checkers treat them this way and PEP 484 isn't going to change on this point. If anything, this makes even more of a case for linting here, since it alerts users to a mismatch between their expectations of how int float subtyping works and the reality of PEP 484.

@AlexWaygood
Copy link
Collaborator

This issue was fixed by #222, so I'm closing it now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants