@@ -11,6 +11,9 @@ def add(x: float = 2.0, y: float = 1) -> float:
1111 return x + y
1212
1313
14+ identity = lambda x : x # noqa: E731
15+
16+
1417class Outer :
1518 class Inner :
1619 @staticmethod
@@ -86,6 +89,37 @@ def test_sys_modules_fallback_when_getmodule_returns_none(self):
8689 finally :
8790 del sys .modules ["_test_fallback_mod" ]
8891
92+ def test_builtin_type (self ):
93+ """get_scope works for a builtin type such as ``int``."""
94+ scope = object_scope .get_scope (int )
95+ # The builtins module is always merged in, so int and len must be present.
96+ self .assertIs (scope .int , int )
97+ self .assertIs (scope .len , len )
98+
99+ def test_builtin_function (self ):
100+ """get_scope works for a builtin function such as ``len``."""
101+ scope = object_scope .get_scope (len )
102+ self .assertIs (scope .len , len )
103+ self .assertIs (scope .int , int )
104+
105+ def test_user_defined_class (self ):
106+ """get_scope works for a user-defined class object."""
107+ scope = object_scope .get_scope (Outer )
108+ # Module-level names from this test module should be visible.
109+ self .assertIs (scope .Outer , Outer )
110+ self .assertIs (scope .add , add )
111+
112+ def test_static_method (self ):
113+ """get_scope works for a static method."""
114+ scope = object_scope .get_scope (Outer .Inner .nested_func )
115+ self .assertIs (scope .Outer , Outer )
116+ self .assertIs (scope .add , add )
117+
118+ def test_lambda (self ):
119+ """get_scope works for a module-level lambda."""
120+ scope = object_scope .get_scope (identity )
121+ self .assertIs (scope .identity , identity )
122+
89123 def test_no_resolvable_module_raises_value_error (self ):
90124 """When neither inspect.getmodule nor __module__ resolves, raise ValueError."""
91125 func = types .FunctionType (
0 commit comments