##// END OF EJS Templates
Backport PR #14029: Allow safe access to the `__getattribute__` method of modules
Matthias Bussonnier -
Show More
@@ -637,6 +637,7 b' set_non_mutating_methods = set(dir(set)) & set(dir(frozenset))'
637
637
638 dict_keys: Type[collections.abc.KeysView] = type({}.keys())
638 dict_keys: Type[collections.abc.KeysView] = type({}.keys())
639 method_descriptor: Any = type(list.copy)
639 method_descriptor: Any = type(list.copy)
640 module = type(builtins)
640
641
641 NUMERICS = {int, float, complex}
642 NUMERICS = {int, float, complex}
642
643
@@ -686,6 +687,7 b' BUILTIN_GETATTR: Set[MayHaveGetattr] = {'
686 *NUMERICS,
687 *NUMERICS,
687 dict_keys,
688 dict_keys,
688 method_descriptor,
689 method_descriptor,
690 module,
689 }
691 }
690
692
691
693
@@ -568,3 +568,15 b' def test_assumption_named_tuples_share_getitem():'
568 pass
568 pass
569
569
570 assert A.__getitem__ == B.__getitem__
570 assert A.__getitem__ == B.__getitem__
571
572
573 @dec.skip_without("numpy")
574 def test_module_access():
575 import numpy
576
577 context = limited(numpy=numpy)
578 assert guarded_eval("numpy.linalg.norm", context) == numpy.linalg.norm
579
580 context = minimal(numpy=numpy)
581 with pytest.raises(GuardRejection):
582 guarded_eval("np.linalg.norm", context)
General Comments 0
You need to be logged in to leave comments. Login now