Skip to content

Force pyright not to evaluate __init__ when __new__ returns an object that is not a subtype #9907

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

You must be logged in to vote

Yes, you're correct. Pyright isn't following the typing spec here. The spec conformance test tests for a union that contains Any but doesn't check for an Any by itself. (I wrote this conformance test, so the omission was my fault.) That explains why this bug wasn't caught earlier. I also didn't have this case covered in the pyright unit tests.

I've created a separate bug report to track the issue.

This issue will be fixed in the next release of pyright. I've also updated the unit tests to cover this case.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@maximlt
Comment options

Answer selected by maximlt
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