You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Expected behavior
By doing a match with Test(a = int()), python will check test is of type Test AND test.a is of type int.
But pyright "only assert" that test if of type Test. It keep the type int | str for test.a.
Yes, this is as designed. The type of the expression test is narrowed to type Test, but the type of test.a is not narrowed in this case. Narrowing is applied only to one expression, not both. Not surprisingly, mypy works the same way.
Describe the bug
It seems that doing a "type checking" with the object UI in pattern matching seems to not work properly.
Code
Expected behavior
By doing a match with
Test(a = int())
, python will checktest
is of typeTest
ANDtest.a
is of typeint
.But pyright "only assert" that
test
if of typeTest
. It keep the typeint | str
fortest.a
.VS Code extension or command-line
Both, and in unofficial playground:
https://pyright-playground.decorator-factory.su/?gzip=H4sIAJKQEWQC_32NOwrDQAxEe51icLUiwY1xY8gt0i9is8YLjgmWyhw-EobgImQqoTefsooq7lVtIrgedUbObWuWc9K6zlfIhLYZ3lDb-XCFAvZnhhuEyLzKr2hMIxM9xcoC-w4U0XpQcZuHE59KX3t8wt0LLhj4R8an_mW6oeMP_NNLyNYAAAA%3D
The text was updated successfully, but these errors were encountered: