Skip to content

Commit 7062598

Browse files
committed
add a test
1 parent b7555c7 commit 7062598

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

test-data/unit/check-narrowing.test

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3261,3 +3261,21 @@ def bar(y: Any):
32613261
else:
32623262
reveal_type(y) # N: Revealed type is "Any"
32633263
[builtins fixtures/dict-full.pyi]
3264+
3265+
3266+
[case testNarrowingConstrainedTypeVarType]
3267+
from __future__ import annotations
3268+
from typing import TypeVar, Any, Type
3269+
3270+
TargetType = TypeVar("TargetType", int, float, str)
3271+
3272+
def convert_type(target_type: Type[TargetType]) -> TargetType:
3273+
if target_type == str:
3274+
return str()
3275+
if target_type == int:
3276+
return int()
3277+
if target_type == float:
3278+
return float()
3279+
raise
3280+
3281+
[builtins fixtures/primitives.pyi]

0 commit comments

Comments
 (0)