Skip to content

Missing reportUnnecessaryComparison when comparing objects of different types #9349

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

You must be logged in to vote

There are some heuristics involved in pyright's check here. It assumes that if the types are both built-in types like int and list, then it's not possible to create a subclass of the two types. Indeed, if you try to create a class that subclasses from both int and list, you will see that the runtime doesn't allow this. Compare this to my example above where it is possible to create a subclass of both Foo and list.

All else equal, when we need to choose between a potential false positive and a potential false negative, we tend to opt for the false negative. That informs the heuristics in this check.

In any case, pyright is working as intended here.

Replies: 1 comment 5 replies

Comment options

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

@erictraut
Comment options

@tkukushkin
Comment options

@erictraut
Comment options

Answer selected by tkukushkin
@tkukushkin
Comment options

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