Skip to content

Is this a type narrowing bug for callables? #8983

Answered by erictraut
robert-bn asked this question in Q&A
Discussion options

You must be logged in to vote

Pyright narrows the type in the first function, but not in the second function.

Pyright's narrowing logic for the x is y type guard pattern doesn't currently handle the case where y is a class object whose constructor matches the callable type of x. I don't consider this a bug, but it is a missing feature. I think this is a reasonable enhancement request if you'd like to file one.

For what it's worth, mypy doesn't handle type narrowing for either of the x is str code samples above.

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
2 replies
@Daraan
Comment options

@robert-bn
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by robert-bn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants