-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Model exact narrowing with type(x) checks #20703
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
test-data/unit/check-narrowing.test
Outdated
|
|
||
| T_value = TypeVar("T_value", A, B) | ||
|
|
||
| def f2(self, obj: T_value) -> T_value: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the difference between f1 and f2? Both are generic in a type variable with values.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nvm, I see you just fixed it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh sorry, I fixed that already :-)
More generally, the behaviour here isn't yet perfect.
I opened this PR to fix the testTypeEqualsCheckUsingIsNonOverlappingChild-xfail case, discovered we had an open issue it affected sterliakov/mypy-issues#259 , so adding the test case for it.
The test case I added highlights two preexisting issues. Ideally a) the narrowing works in the unconstrained case, b) we issue an error in both branches in the bad constrained case
| [builtins fixtures/isinstance.pyi] | ||
|
|
||
| [case testTypeEqualsCheckUsingIsNonOverlappingChild-xfail] | ||
| [case testTypeEqualsCheckUsingIsNonOverlappingChild] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the test case I was targeting with this PR
This comment has been minimized.
This comment has been minimized.
|
static-frame primer has a wrong type annotation and they already have a type-ignore for it |
|
Diff from mypy_primer, showing the effect of this PR on open source code: static-frame (https://github.com/static-frame/static-frame)
+ static_frame/core/archive_npy.py:232: error: Statement is unreachable [unreachable]
|
I have some changes planned to improve final support, which will pair nicely with this
Fixes biggest thing in #10302 (original issue in there is not an issue; fixes this comment #10302 (comment) )