File tree Expand file tree Collapse file tree 2 files changed +10
-2
lines changed
Expand file tree Collapse file tree 2 files changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -88,7 +88,9 @@ def __hash__(self) -> int:
8888
8989 def __subclasscheck__ (self , subclass ):
9090 args = get_args (subclass )
91- match origin := get_origin (subclass ) or subclass :
91+ match origin := get_origin (subclass ):
92+ case None :
93+ origin = subclass
9294 case typing .Literal :
9395 return all (isinstance (arg , self ) for arg in args )
9496 case typing .Union | types .UnionType :
Original file line number Diff line number Diff line change @@ -39,6 +39,7 @@ def test_union():
3939 assert issubclass (int , subtype (int | float ))
4040 assert issubclass (subtype (int | float ), subtype (int | float | None ))
4141 assert subtype (Iterable | Mapping | Sequence ) is Iterable
42+ assert not issubclass (Union , subtype (type [int ]))
4243
4344 # Test nested subtype with UnionType base
4445 tp = subtype (int | float )
@@ -77,10 +78,15 @@ def func(_: cls[int]): ...
7778
7879 @func .register
7980 def _ (_ : type [cls [int ]]):
81+ return int
82+
83+ @func .register
84+ def _ (_ : type [cls ]):
8085 return type
8186
8287 assert func (cls [int ]()) is None
83- assert func (cls [int ]) is type
88+ assert func (cls [int ]) is int
89+ assert func (cls ) is type
8490
8591
8692def test_tuple ():
You can’t perform that action at this time.
0 commit comments