@@ -279,6 +279,12 @@ def generic_class(self):
279279 def unpacking_in_comprehension (self ):
280280 return self .__s .unpacking_in_comprehension
281281
282+ def lazy_imports (self ):
283+ return self .__s .lazy_imports
284+
285+ def lazy_modules (self ):
286+ return self .__s .lazy_modules
287+
282288 def __get_source_line (self , line , col = 0 ):
283289 if self .__s .source is None :
284290 return None # pragma: no cover
@@ -535,6 +541,15 @@ def minimum_versions(self):
535541 if self .unpacking_in_comprehension ():
536542 mins = self .__add_versions_entity (mins , (None , (3 , 15 )),
537543 "unpacking in comprehension (PEP 798)" )
544+
545+ if self .lazy_imports ():
546+ mins = self .__add_versions_entity (mins , (None , (3 , 15 )),
547+ "lazy imports (PEP 810)" )
548+
549+ if self .lazy_modules ():
550+ mins = self .__add_versions_entity (mins , (None , (3 , 15 )),
551+ "`__lazy_modules__`" )
552+
538553 for directive in self .strftime_directives ():
539554 if directive in STRFTIME_REQS :
540555 vers = STRFTIME_REQS [directive ]
@@ -1021,6 +1036,12 @@ def visit_Import(self, node):
10211036 if self .__is_no_line (node .lineno ):
10221037 return
10231038
1039+ # PEP 810: `lazy import` (3.15+).
1040+ if hasattr (node , "is_lazy" ) and node .is_lazy :
1041+ self .__s .lazy_imports = True
1042+ self .__vvprint ("lazy imports (PEP 810)" , line = node .lineno ,
1043+ versions = [None , (3 , 15 )])
1044+
10241045 for name in node .names :
10251046 line = node .lineno
10261047 col = node .col_offset + 7 # "import" = 6 + 1
@@ -1042,6 +1063,12 @@ def visit_ImportFrom(self, node):
10421063 if self .__is_no_line (node .lineno ):
10431064 return
10441065
1066+ # PEP 810: `lazy from ... import` (3.15+).
1067+ if hasattr (node , "is_lazy" ) and node .is_lazy :
1068+ self .__s .lazy_imports = True
1069+ self .__vvprint ("lazy imports (PEP 810)" , line = node .lineno ,
1070+ versions = [None , (3 , 15 )])
1071+
10451072 from_col = 5 # "from" = 4 + 1
10461073 self .__add_module (node .module , node .lineno , node .col_offset + from_col )
10471074
@@ -1075,6 +1102,10 @@ def visit_Name(self, node):
10751102 elif node .id in ("True" , "False" ):
10761103 self .__s .bool_const = True
10771104 self .__vvvprint ("True/False constant" , versions = [(2 , 3 ), (3 , 0 )])
1105+ elif node .id == "__lazy_modules__" :
1106+ self .__s .lazy_modules = True
1107+ self .__vvprint ("`__lazy_modules__`" , line = node .lineno ,
1108+ versions = [None , (3 , 15 )])
10781109
10791110 def visit_Print (self , node ): # pragma: no cover
10801111 self .__s .printv2 = True
0 commit comments