@@ -48,10 +48,8 @@ def is_attribute_visible(
48
48
) -> bool :
49
49
return (
50
50
bool ( description )
51
- or not name .startswith ( '_' )
52
- or ( name .startswith ( '__' )
53
- and name .endswith ( '__' )
54
- and len ( name ) > 4 ) ) # noqa: PLR2004
51
+ or ( name .startswith ( '__' ) and name .endswith ( '__' ) )
52
+ or not name .startswith ( '_' ) )
55
53
56
54
57
55
def reduce_annotation (
@@ -81,7 +79,11 @@ def _introspect_class(
81
79
context : _interfaces .Context ,
82
80
cache : _interfaces .AnnotationsCache ,
83
81
) -> __ .cabc .Sequence [ _interfaces .InformationBase ]:
84
- annotations = _access_annotations ( possessor , context )
82
+ annotations : dict [ str , __ .typx .Any ] = { }
83
+ # Descendant annotations override ancestor annotations.
84
+ for class_ in reversed ( possessor .__mro__ ):
85
+ annotations_b = _access_annotations ( class_ , context )
86
+ annotations .update ( annotations_b )
85
87
if not annotations : return ( )
86
88
informations : list [ _interfaces .InformationBase ] = [ ]
87
89
for name , annotation in annotations .items ( ):
@@ -134,16 +136,7 @@ def _introspect_module(
134
136
context : _interfaces .Context ,
135
137
cache : _interfaces .AnnotationsCache ,
136
138
) -> __ .cabc .Sequence [ _interfaces .InformationBase ]:
137
- nomargs : _nomina .Variables = dict ( eval_str = True )
138
- nomargs [ 'globals' ] = context .resolver_globals
139
- nomargs [ 'locals' ] = context .resolver_locals
140
- try :
141
- annotations = __ .types .MappingProxyType (
142
- __ .inspect .get_annotations ( possessor , ** nomargs ) )
143
- except TypeError as exc :
144
- emessage = f"Cannot access annotations for { possessor !r} : { exc } "
145
- context .notifier ( 'error' , emessage )
146
- annotations = ( )
139
+ annotations = _access_annotations ( possessor , context )
147
140
if not annotations : return ( )
148
141
informations : list [ _interfaces .InformationBase ] = [ ]
149
142
for name , annotation in annotations .items ( ):
@@ -211,27 +204,18 @@ def _introspect_function_valences(
211
204
212
205
213
206
def _access_annotations (
214
- possessor : _nomina .Decoratable , context : _interfaces .Context
207
+ possessor : _nomina .Documentable , context : _interfaces .Context
215
208
) -> __ .cabc .Mapping [ str , __ .typx .Any ]:
216
- nomargs : _nomina .Variables = dict ( include_extras = True )
217
- nomargs [ 'globalns ' ] = context .resolver_globals
218
- nomargs [ 'localns ' ] = context .resolver_locals
209
+ nomargs : _nomina .Variables = dict ( eval_str = True )
210
+ nomargs [ 'globals ' ] = context .resolver_globals
211
+ nomargs [ 'locals ' ] = context .resolver_locals
219
212
try :
220
213
return __ .types .MappingProxyType (
221
- __ .typx .get_type_hints ( possessor , ** nomargs ) )
222
- except TypeError :
223
- # Fallback to lower-level resolution which sometimes works better.
224
- # Note: No inheritance merges for classes.
225
- nomargs = dict ( eval_str = True )
226
- nomargs [ 'globals' ] = context .resolver_globals
227
- nomargs [ 'locals' ] = context .resolver_locals
228
- try :
229
- return __ .types .MappingProxyType (
230
- __ .inspect .get_annotations ( possessor , ** nomargs ) )
231
- except TypeError as exc :
232
- emessage = f"Cannot access annotations for { possessor !r} : { exc } "
233
- context .notifier ( 'error' , emessage )
234
- return __ .dictproxy_empty
214
+ __ .inspect .get_annotations ( possessor , ** nomargs ) )
215
+ except TypeError as exc :
216
+ emessage = f"Cannot access annotations for { possessor !r} : { exc } "
217
+ context .notifier ( 'error' , emessage )
218
+ return __ .dictproxy_empty
235
219
236
220
237
221
def _classes_sequence_to_union (
0 commit comments