@@ -751,7 +751,6 @@ def correct_rel_imp(imp: Union[ImportFrom, ImportAll]) -> str:
751751 res .append ((ancestor_pri , "." .join (ancestors ), imp .line ))
752752 elif isinstance (imp , ImportFrom ):
753753 cur_id = correct_rel_imp (imp )
754- pos = len (res )
755754 all_are_submodules = True
756755 # Also add any imported names that are submodules.
757756 pri = import_priority (imp , PRI_MED )
@@ -768,7 +767,10 @@ def correct_rel_imp(imp: Union[ImportFrom, ImportAll]) -> str:
768767 # if all of the imports are submodules, do the import at a lower
769768 # priority.
770769 pri = import_priority (imp , PRI_HIGH if not all_are_submodules else PRI_LOW )
771- res .insert (pos , ((pri , cur_id , imp .line )))
770+ # The imported module goes in after the
771+ # submodules, for the same namespace related
772+ # reasons discussed in the Import case.
773+ res .append ((pri , cur_id , imp .line ))
772774 elif isinstance (imp , ImportAll ):
773775 pri = import_priority (imp , PRI_HIGH )
774776 res .append ((pri , correct_rel_imp (imp ), imp .line ))
@@ -1317,7 +1319,7 @@ def validate_meta(meta: Optional[CacheMeta], id: str, path: Optional[str],
13171319 st = manager .get_stat (path )
13181320 except OSError :
13191321 return None
1320- if not stat .S_ISREG (st .st_mode ):
1322+ if not ( stat .S_ISREG (st .st_mode ) or stat . S_ISDIR ( st . st_mode ) ):
13211323 manager .log ('Metadata abandoned for {}: file {} does not exist' .format (id , path ))
13221324 return None
13231325
@@ -1360,7 +1362,11 @@ def validate_meta(meta: Optional[CacheMeta], id: str, path: Optional[str],
13601362
13611363 t0 = time .time ()
13621364 try :
1363- source_hash = manager .fscache .hash_digest (path )
1365+ # dir means it is a namespace package
1366+ if stat .S_ISDIR (st .st_mode ):
1367+ source_hash = ''
1368+ else :
1369+ source_hash = manager .fscache .hash_digest (path )
13641370 except (OSError , UnicodeDecodeError , DecodeError ):
13651371 return None
13661372 manager .add_stats (validate_hash_time = time .time () - t0 )
@@ -1838,7 +1844,7 @@ def __init__(self,
18381844 if path and source is None and self .manager .fscache .isdir (path ):
18391845 source = ''
18401846 self .source = source
1841- if path and source is None and self .manager .cache_enabled :
1847+ if path and self .manager .cache_enabled :
18421848 self .meta = find_cache_meta (self .id , path , manager )
18431849 # TODO: Get mtime if not cached.
18441850 if self .meta is not None :
@@ -2038,6 +2044,9 @@ def parse_file(self) -> None:
20382044 else :
20392045 err = "mypy: can't decode file '{}': {}" .format (self .path , str (decodeerr ))
20402046 raise CompileError ([err ], module_with_blocker = self .id ) from decodeerr
2047+ elif self .path and self .manager .fscache .isdir (self .path ):
2048+ source = ''
2049+ self .source_hash = ''
20412050 else :
20422051 assert source is not None
20432052 self .source_hash = compute_hash (source )
0 commit comments