check_type is no longer narrowing types (regression from 0.27.0 -> 0.27.1)
Describe the Bug
Test code:
from typeguard import check_type
from typing import reveal_type
x: dict[str, int] | float = {}
reveal_type(x)
x = check_type(x, dict[str, int])
reveal_type(x)
In pyrefly 0.27.0 (correct output):
INFO revealed type: dict[str, int] | float [reveal-type]
|
7 | reveal_type(x)
| ---
|
INFO revealed type: dict[str, int] [reveal-type]
|
9 | reveal_type(x)
| ---
|
INFO 0 errors
In pyrefly 0.27.1 (wrong output):
INFO revealed type: dict[str, int] | float [reveal-type]
|
7 | reveal_type(x)
| ---
|
INFO revealed type: dict[str, int] | float [reveal-type]
|
9 | reveal_type(x)
| ---
|
INFO 0 errors
It should have narrowed the type down to the dict with x = check_type(x, dict[str, int])
BTW: I would have appended a sandbox link but the sandbox fails with "Pyrefly encountered an internal error: {}." - even with the demo code.
Sandbox Link
No response
(Only applicable for extension issues) IDE Information
No response
kindly assign me this work , i'll do needfull
I caused this regression in a206d0075d1be9977e883d0158065bb0c8186b4c. When we see x = check_type(...) we use the expected type of x, which is dict[str, int] | float to instantiate the type parameter T. This is what we want for pushing down hints, but we want to actually instantiate T using the argument.
@vedant1022 appreciate your willingness to help, but I think this is not a great issue. I'll take this one on.
This issue has someone assigned, but has not had recent activity for more than 2 weeks.
If you are still working on this issue, please add a comment so everyone knows. Otherwise, please unassign yourself and allow someone else to take over.
Thank you for your contributions!
This issue has someone assigned, but has not had recent activity for more than 2 weeks.
If you are still working on this issue, please add a comment so everyone knows. Otherwise, please unassign yourself and allow someone else to take over.
Thank you for your contributions!
#1635 (closed in favor of this issue) another example of the same problem
This issue has someone assigned, but has not had recent activity for more than 2 weeks.
If you are still working on this issue, please add a comment so everyone knows. Otherwise, please unassign yourself and allow someone else to take over.
Thank you for your contributions!