Skip to content

Commit 43d306b

Browse files
committed
Update type.md
1 parent 4432532 commit 43d306b

File tree

1 file changed

+5
-9
lines changed
  • crates/ty_python_semantic/resources/mdtest/narrow

1 file changed

+5
-9
lines changed

crates/ty_python_semantic/resources/mdtest/narrow/type.md

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -146,23 +146,19 @@ def _(x: A | B):
146146

147147
## No special narrowing for custom `type` callable
148148

149-
`stub.pyi`:
150-
151-
```pyi
152-
from ty_extensions import TypeOf
153-
154-
def type(x: object) -> TypeOf[int]: ...
155-
```
156-
157149
```py
158-
from stub import type
150+
def type(x: object):
151+
return int
159152

160153
class A: ...
161154
class B: ...
162155

163156
def _(x: A | B):
157+
# The custom `type` function always returns `int`,
158+
# so any branch other than `type(...) is int` is unreachable.
164159
if type(x) is A:
165160
reveal_type(x) # revealed: Never
161+
# And the condition here is always `True` and has no effect on the narrowing of `x`.
166162
elif type(x) is int:
167163
reveal_type(x) # revealed: A | B
168164
else:

0 commit comments

Comments
 (0)