pyrefly icon indicating copy to clipboard operation
pyrefly copied to clipboard

check_type is no longer narrowing types (regression from 0.27.0 -> 0.27.1)

Open kilroy42 opened this issue 5 months ago • 5 comments

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

kilroy42 avatar Aug 10 '25 20:08 kilroy42

kindly assign me this work , i'll do needfull

vedant1022 avatar Aug 12 '25 06:08 vedant1022

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.

samwgoldman avatar Aug 12 '25 18:08 samwgoldman

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!

github-actions[bot] avatar Sep 04 '25 00:09 github-actions[bot]

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!

github-actions[bot] avatar Oct 30 '25 00:10 github-actions[bot]

#1635 (closed in favor of this issue) another example of the same problem

stroxler avatar Nov 22 '25 00:11 stroxler

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!

github-actions[bot] avatar Dec 08 '25 00:12 github-actions[bot]