Skip to content

Should PYI041 consider bool to be redundant with int? #9810

Closed
@tylerlaprade

Description

@tylerlaprade

Currently, this rule only flags int | float unions as redundant. Coming from other languages, I didn't even realize int was a subtype of float, but I learned about it because of this rule. However, I found a bug in my code where I was converting False to 0.0 - this was because in Python, bool is actually an int. I found that the tests for this rule very explicitly consider int | bool to not be a violation, however this would have prevented me from writing the bug as I did.

image

The bool to int relation is in some ways stronger than int to float since isinstance() only recognizes the former:
image

Metadata

Metadata

Assignees

Labels

questionAsking for support or clarification

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions