@@ -97,7 +97,7 @@ def cached_box(cls, *, ctx):
9797 return box
9898
9999
100- def get_annotated_type_hints (cls , * , ctx , ** kwargs ):
100+ def get_annotated_type_hints (cls , * , ctx , attrs_only = False , ** kwargs ):
101101 """Get the type hints/quals for a cls annotated with definition site.
102102
103103 This traverses the mro and finds the definition site for each annotation.
@@ -127,6 +127,10 @@ def get_annotated_type_hints(cls, *, ctx, **kwargs):
127127 else :
128128 break
129129
130+ # Skip method-like ClassVars when only attributes are wanted
131+ if attrs_only and "ClassVar" in quals and _is_method_like (ty ):
132+ continue
133+
130134 if k in abox .cls .__dict__ :
131135 # Wrap in tuple when creating Literal in case it *is* a tuple
132136 init = _make_init_type (abox .cls .__dict__ [k ])
@@ -650,11 +654,7 @@ def _callable_type_to_method(name, typ, ctx):
650654 return head (func )
651655
652656
653- def _function_type (func , * , receiver_type ):
654- root = inspect .unwrap (func )
655- sig = inspect .signature (root )
656- # XXX: __type_params__!!!
657-
657+ def _function_type_from_sig (sig , func , * , receiver_type ):
658658 empty = inspect .Parameter .empty
659659
660660 def _ann (x ):
@@ -702,6 +702,15 @@ def _ann(x):
702702 f = classmethod [specified_receiver , tuple [* params [1 :]], ret ]
703703 else :
704704 f = typing .Callable [params , ret ]
705+
706+ return f
707+
708+
709+ def _function_type (func , * , receiver_type ):
710+ root = inspect .unwrap (func )
711+ sig = inspect .signature (root )
712+ f = _function_type_from_sig (sig , func , receiver_type = receiver_type )
713+
705714 if root .__type_params__ :
706715 # Must store a lambda that performs type variable substitution
707716 type_params = root .__type_params__
@@ -757,7 +766,9 @@ def _hints_to_members(hints, ctx):
757766@type_eval .register_evaluator (Attrs )
758767@_lift_over_unions
759768def _eval_Attrs (tp , * , ctx ):
760- hints = get_annotated_type_hints (tp , include_extras = True , ctx = ctx )
769+ hints = get_annotated_type_hints (
770+ tp , include_extras = True , attrs_only = True , ctx = ctx
771+ )
761772 return _hints_to_members (hints , ctx )
762773
763774
@@ -1185,7 +1196,10 @@ def _eval_NewProtocol(*etyps: Member, ctx):
11851196 if type_eval .issubtype (
11861197 typing .Literal ["ClassVar" ], tquals
11871198 ) and _is_method_like (typ ):
1188- dct [name ] = _callable_type_to_method (name , typ , ctx )
1199+ try :
1200+ dct [name ] = _callable_type_to_method (name , typ , ctx )
1201+ except type_eval .StuckException :
1202+ annos [name ] = _add_quals (typ , tquals )
11891203 else :
11901204 annos [name ] = _add_quals (typ , tquals )
11911205 _unpack_init (dct , name , init )
0 commit comments