Skip to content
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

Allow optionally preventing bool from being accepted as a subtype of int in MyPy. #16135

Closed
stdedos opened this issue Sep 18, 2023 · 1 comment
Labels

Comments

@stdedos
Copy link
Contributor

stdedos commented Sep 18, 2023

Feature

Allow optionally preventing bool from being accepted as a subtype of int in MyPy.

Might be related? #8363

Pitch

def increment(x: int) -> int:
    return x + 1

print(increment(True))  # Outputs 2, which can be confusing

Python treats bool as a subclass of int, causing potential bugs when a bool is used where an int is expected. Adding a MyPy flag to reject this would improve type safety and code reliability.

Disclaimer: I have read already https://mypy.readthedocs.io/en/stable/builtin_types.html?#simple-types

@hauntsaninja
Copy link
Collaborator

Yup, this is a duplicate of the feature request in #8363

@hauntsaninja hauntsaninja closed this as not planned Won't fix, can't repro, duplicate, stale Sep 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants