@@ -134,7 +134,7 @@ def _get_external(module_name: str, access_path: Sequence[str]):
134
134
for attr in access_path :
135
135
member_type = getattr (member_type , attr )
136
136
return member_type
137
- except KeyError :
137
+ except ( KeyError , AttributeError ) :
138
138
# handle modules in namespace packages
139
139
module_path = "." .join ([module_name , * access_path ])
140
140
if module_path in sys .modules :
@@ -215,7 +215,7 @@ class SelectivePolicy(EvaluationPolicy):
215
215
allowed_getitem_external : set [tuple [str , ...]] = field (default_factory = set )
216
216
217
217
allowed_getattr : set [MayHaveGetattr ] = field (default_factory = set )
218
- allowed_getattr_external : set [tuple [str , ...]] = field (default_factory = set )
218
+ allowed_getattr_external : set [tuple [str , ...] | str ] = field (default_factory = set )
219
219
220
220
allowed_operations : set = field (default_factory = set )
221
221
allowed_operations_external : set [tuple [str , ...]] = field (default_factory = set )
@@ -225,18 +225,23 @@ class SelectivePolicy(EvaluationPolicy):
225
225
)
226
226
227
227
def can_get_attr (self , value , attr ):
228
+ allowed_getattr_external : set [tuple [str , ...]] = {
229
+ path if isinstance (path , tuple ) else tuple (path .split ("." ))
230
+ for path in self .allowed_getattr_external
231
+ }
232
+
228
233
has_original_attribute = _has_original_dunder (
229
234
value ,
230
235
allowed_types = self .allowed_getattr ,
231
236
allowed_methods = self ._getattribute_methods ,
232
- allowed_external = self . allowed_getattr_external ,
237
+ allowed_external = allowed_getattr_external ,
233
238
method_name = "__getattribute__" ,
234
239
)
235
240
has_original_attr = _has_original_dunder (
236
241
value ,
237
242
allowed_types = self .allowed_getattr ,
238
243
allowed_methods = self ._getattr_methods ,
239
- allowed_external = self . allowed_getattr_external ,
244
+ allowed_external = allowed_getattr_external ,
240
245
method_name = "__getattr__" ,
241
246
)
242
247
@@ -268,7 +273,7 @@ def can_get_attr(self, value, attr):
268
273
return True # pragma: no cover
269
274
270
275
# Properties in subclasses of allowed types may be ok if not changed
271
- for module_name , * access_path in self . allowed_getattr_external :
276
+ for module_name , * access_path in allowed_getattr_external :
272
277
try :
273
278
external_class = _get_external (module_name , access_path )
274
279
external_class_attr_val = getattr (external_class , attr )
0 commit comments