@@ -2237,6 +2237,60 @@ class B:
22372237 with self .assertRaisesRegex (ValueError , "always fails to import" ):
22382238 get_annotations (ns ["B" ], format = Format .VALUE )
22392239
2240+ def test_get_annotations_lazy_import (self ):
2241+ ns = {}
2242+ exec (
2243+ textwrap .dedent (
2244+ """
2245+ lazy from test.test_lazy_import.data.basic2 import x
2246+ lazy from test.test_lazy_import.data.broken_module import y
2247+
2248+ class A:
2249+ a: object.fail
2250+ b: x
2251+
2252+ class B:
2253+ a: object.fail
2254+ b: y
2255+ """
2256+ ),
2257+ ns ,
2258+ )
2259+ self .addCleanup (
2260+ import_helper .unload , "test.test_lazy_import.data.basic2"
2261+ )
2262+ self .addCleanup (
2263+ import_helper .unload , "test.test_lazy_import.data.broken_module"
2264+ )
2265+ self .assertIs (type (ns ["x" ]), types .LazyImportType )
2266+ self .assertIs (type (ns ["y" ]), types .LazyImportType )
2267+
2268+ annos = get_annotations (ns ["A" ], format = Format .FORWARDREF )
2269+ self .assertEqual (
2270+ annos ,
2271+ {
2272+ "a" : support .EqualToForwardRef (
2273+ "object.fail" , is_class = True , owner = ns ["A" ]
2274+ ),
2275+ "b" : 42 ,
2276+ },
2277+ )
2278+
2279+ annos = get_annotations (ns ["B" ], format = Format .FORWARDREF )
2280+ self .assertEqual (
2281+ annos ,
2282+ {
2283+ "a" : support .EqualToForwardRef (
2284+ "object.fail" , is_class = True , owner = ns ["B" ]
2285+ ),
2286+ "b" : support .EqualToForwardRef (
2287+ "y" , is_class = True , owner = ns ["B" ]
2288+ ),
2289+ },
2290+ )
2291+ with self .assertRaisesRegex (ValueError , "always fails to import" ):
2292+ annos ["b" ].evaluate (format = Format .VALUE )
2293+
22402294 def test_evaluate_notimplemented_format (self ):
22412295 class C :
22422296 x : alias
0 commit comments