@@ -751,7 +751,6 @@ def correct_rel_imp(imp: Union[ImportFrom, ImportAll]) -> str:
751
751
res .append ((ancestor_pri , "." .join (ancestors ), imp .line ))
752
752
elif isinstance (imp , ImportFrom ):
753
753
cur_id = correct_rel_imp (imp )
754
- pos = len (res )
755
754
all_are_submodules = True
756
755
# Also add any imported names that are submodules.
757
756
pri = import_priority (imp , PRI_MED )
@@ -768,7 +767,10 @@ def correct_rel_imp(imp: Union[ImportFrom, ImportAll]) -> str:
768
767
# if all of the imports are submodules, do the import at a lower
769
768
# priority.
770
769
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 ))
772
774
elif isinstance (imp , ImportAll ):
773
775
pri = import_priority (imp , PRI_HIGH )
774
776
res .append ((pri , correct_rel_imp (imp ), imp .line ))
@@ -1317,7 +1319,7 @@ def validate_meta(meta: Optional[CacheMeta], id: str, path: Optional[str],
1317
1319
st = manager .get_stat (path )
1318
1320
except OSError :
1319
1321
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 ) ):
1321
1323
manager .log ('Metadata abandoned for {}: file {} does not exist' .format (id , path ))
1322
1324
return None
1323
1325
@@ -1360,7 +1362,11 @@ def validate_meta(meta: Optional[CacheMeta], id: str, path: Optional[str],
1360
1362
1361
1363
t0 = time .time ()
1362
1364
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 )
1364
1370
except (OSError , UnicodeDecodeError , DecodeError ):
1365
1371
return None
1366
1372
manager .add_stats (validate_hash_time = time .time () - t0 )
@@ -1838,7 +1844,7 @@ def __init__(self,
1838
1844
if path and source is None and self .manager .fscache .isdir (path ):
1839
1845
source = ''
1840
1846
self .source = source
1841
- if path and source is None and self .manager .cache_enabled :
1847
+ if path and self .manager .cache_enabled :
1842
1848
self .meta = find_cache_meta (self .id , path , manager )
1843
1849
# TODO: Get mtime if not cached.
1844
1850
if self .meta is not None :
@@ -2038,6 +2044,9 @@ def parse_file(self) -> None:
2038
2044
else :
2039
2045
err = "mypy: can't decode file '{}': {}" .format (self .path , str (decodeerr ))
2040
2046
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 = ''
2041
2050
else :
2042
2051
assert source is not None
2043
2052
self .source_hash = compute_hash (source )
0 commit comments