-
Notifications
You must be signed in to change notification settings - Fork 282
Closed
Labels
help wantedLarger than "good first issue", but still well-defined and ready for someone to pick upLarger than "good first issue", but still well-defined and ready for someone to pick uppytorch
Description
Describe the Bug
Currently the following code triggers a type error (pyrefly 0.16.1):
def verify_type(input: int):
pass
def foo(x: int | None) -> None:
assert type(x) is int
verify_type(x)Leads to
Argument `int | None` is not assignable to parameter `input` with type `int` in function `reveal_type`
Link to the pyright playground with the sample: https://pyright-play.net/?code=CYUwZgBGD20BQA8BcECWA7ALhAPhActOiAJQQC0AfAUSEgFARMQCGAzmyAE7aYCeABxCIyqNmiyNmXEADcQLADYB9fkJFMAxBAC2gvhEwALDAGtxxsWnEZMQA
Mypy also respects the assertion.
While assert isinstance(..) works just fine with pyrefly, these approaches are technically not the same, and some code uses specifically the pattern assert type(x) is y for type checking.
It would be great if pyrefly also supports this kind of type narrowing, although I'm not quite sure how popular the pattern is, hence usefulness should be decided my someone more experienced with python than me.
Thanks!
Sandbox Link
(Only applicable for extension issues) IDE Information
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
help wantedLarger than "good first issue", but still well-defined and ready for someone to pick upLarger than "good first issue", but still well-defined and ready for someone to pick uppytorch