@@ -258,7 +258,8 @@ class MypyFile(SymbolNode):
258258
259259 __slots__ = ('_fullname' , 'path' , 'defs' , 'alias_deps' ,
260260 'is_bom' , 'names' , 'imports' , 'ignored_lines' , 'is_stub' ,
261- 'is_cache_skeleton' , 'is_partial_stub_package' , 'plugin_deps' )
261+ 'is_cache_skeleton' , 'is_partial_stub_package' , 'plugin_deps' ,
262+ 'future_import_flags' )
262263
263264 # Fully qualified module name
264265 _fullname : Bogus [str ]
@@ -287,6 +288,8 @@ class MypyFile(SymbolNode):
287288 is_partial_stub_package : bool
288289 # Plugin-created dependencies
289290 plugin_deps : Dict [str , Set [str ]]
291+ # Future imports defined in this file. Populated during semantic analysis.
292+ future_import_flags : Set [str ]
290293
291294 def __init__ (self ,
292295 defs : List [Statement ],
@@ -309,6 +312,7 @@ def __init__(self,
309312 self .is_stub = False
310313 self .is_cache_skeleton = False
311314 self .is_partial_stub_package = False
315+ self .future_import_flags = set ()
312316
313317 def local_definitions (self ) -> Iterator [Definition ]:
314318 """Return all definitions within the module (including nested).
@@ -331,13 +335,17 @@ def accept(self, visitor: NodeVisitor[T]) -> T:
331335 def is_package_init_file (self ) -> bool :
332336 return len (self .path ) != 0 and os .path .basename (self .path ).startswith ('__init__.' )
333337
338+ def is_future_flag_set (self , flag : str ) -> bool :
339+ return flag in self .future_import_flags
340+
334341 def serialize (self ) -> JsonDict :
335342 return {'.class' : 'MypyFile' ,
336343 '_fullname' : self ._fullname ,
337344 'names' : self .names .serialize (self ._fullname ),
338345 'is_stub' : self .is_stub ,
339346 'path' : self .path ,
340347 'is_partial_stub_package' : self .is_partial_stub_package ,
348+ 'future_import_flags' : list (self .future_import_flags ),
341349 }
342350
343351 @classmethod
@@ -350,6 +358,7 @@ def deserialize(cls, data: JsonDict) -> 'MypyFile':
350358 tree .path = data ['path' ]
351359 tree .is_partial_stub_package = data ['is_partial_stub_package' ]
352360 tree .is_cache_skeleton = True
361+ tree .future_import_flags = set (data ['future_import_flags' ])
353362 return tree
354363
355364
0 commit comments