11from dataclasses import dataclass
22from enum import Enum
33from graphlib import TopologicalSorter
4- from typing import Annotated , get_args , get_origin
4+ from typing import Annotated , Any , get_args , get_origin
55
66from .utils import UnionTypes , is_dependent
77
@@ -52,6 +52,10 @@ def typeorder(t1, t2):
5252 """
5353 if t1 == t2 :
5454 return Order .SAME
55+ if t1 is Any :
56+ return Order .MORE
57+ if t2 is Any :
58+ return Order .LESS
5559
5660 if (
5761 hasattr (t1 , "__type_order__" )
@@ -80,8 +84,12 @@ def typeorder(t1, t2):
8084 return typeorder (t1 , t2 )
8185
8286 if o1 is Annotated :
87+ if t2 is Annotated :
88+ return Order .LESS
8389 return typeorder (get_args (t1 )[0 ], t2 )
8490 if o2 is Annotated :
91+ if t1 is Annotated :
92+ return Order .MORE
8593 return typeorder (t1 , get_args (t2 )[0 ])
8694
8795 if o2 and not o1 :
@@ -90,8 +98,8 @@ def typeorder(t1, t2):
9098 if o1 :
9199 if not o2 :
92100 order = typeorder (o1 , t2 )
93- if order is order .SAME :
94- order = order .LESS
101+ if order is Order .SAME :
102+ order = Order .LESS
95103 return order
96104
97105 if (order := typeorder (o1 , o2 )) is not Order .SAME :
@@ -110,6 +118,9 @@ def typeorder(t1, t2):
110118 ords = [typeorder (a1 , a2 ) for a1 , a2 in zip (args1 , args2 )]
111119 return Order .merge (ords )
112120
121+ if not isinstance (t1 , type ) or not isinstance (t2 , type ): # pragma: no cover
122+ return Order .SAME
123+
113124 sx = issubclass (t1 , t2 )
114125 sy = issubclass (t2 , t1 )
115126 if sx and sy : # pragma: no cover
@@ -125,7 +136,7 @@ def typeorder(t1, t2):
125136
126137def subclasscheck (t1 , t2 ):
127138 """Check whether t1 is a "subclass" of t2."""
128- if t1 == t2 :
139+ if t1 == t2 or t2 is Any :
129140 return True
130141
131142 if (
0 commit comments