Replies: 1 comment
-
This is not a supported type guard form. For a full list of supported type guards, refer to this documentation. We do occasionally add support for new forms, but each requires custom logic and can potentially have a measurable impact on code analysis performance, so the bar is high. I wouldn't consider supporting this pattern at this time because this is the first request I've ever received for it. I'm willing to reconsider in the future if there's a signal from enough other pyright users (e.g. in the form of upvotes on this discussion topic). |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi.
I've observed that type narrowing doesn't work in a situation where the type of an unknown variable is compared with the type of a known class instance.
For example (pyright 1.1.389):
Curiously, it works as expected when
var
isAny
but not when var isA | None
. I also tested withisinstance()
anda.__class__
without success.Is this a pattern you might consider supporting?
My specific use case involves situations where class
A
is not publicly accessible from a third-party library, even though instances of the class are.Beta Was this translation helpful? Give feedback.
All reactions