@@ -857,6 +857,8 @@ def verify_module(id: str, path: str) -> bool:
857
857
"""Check that all packages containing id have a __init__ file."""
858
858
if path .endswith (('__init__.py' , '__init__.pyi' )):
859
859
path = dirname (path )
860
+ return True
861
+
860
862
for i in range (id .count ('.' )):
861
863
path = dirname (path )
862
864
if not any (os .path .isfile (os .path .join (path , '__init__{}' .format (extension )))
@@ -1457,13 +1459,15 @@ def __init__(self,
1457
1459
self .order = State .order_counter
1458
1460
self .caller_state = caller_state
1459
1461
self .caller_line = caller_line
1462
+ self .namespace = False
1460
1463
if caller_state :
1461
1464
self .import_context = caller_state .import_context [:]
1462
1465
self .import_context .append ((caller_state .xpath , caller_line ))
1463
1466
else :
1464
1467
self .import_context = []
1465
1468
self .id = id or '__main__'
1466
1469
self .options = manager .options .clone_for_module (self .id )
1470
+
1467
1471
if not path and source is None :
1468
1472
assert id is not None
1469
1473
file_id = id
@@ -1516,6 +1520,13 @@ def __init__(self,
1516
1520
manager .missing_modules .add (id )
1517
1521
raise ModuleNotFound
1518
1522
else :
1523
+ if ancestor_for :
1524
+ self .child_modules = set ()
1525
+ self .ancestors = []
1526
+ self .dependencies = []
1527
+ self .suppressed = []
1528
+ self .namespace = True
1529
+ return
1519
1530
# If we can't find a root source it's always fatal.
1520
1531
# TODO: This might hide non-fatal errors from
1521
1532
# root sources processed earlier.
@@ -1725,6 +1736,9 @@ def parse_file(self) -> None:
1725
1736
# The file was already parsed (in __init__()).
1726
1737
return
1727
1738
1739
+ if self .namespace :
1740
+ return
1741
+
1728
1742
manager = self .manager
1729
1743
modules = manager .modules
1730
1744
manager .log ("Parsing %s (%s)" % (self .xpath , self .id ))
@@ -1743,9 +1757,13 @@ def parse_file(self) -> None:
1743
1757
except (UnicodeDecodeError , DecodeError ) as decodeerr :
1744
1758
raise CompileError ([
1745
1759
"mypy: can't decode file '{}': {}" .format (self .path , str (decodeerr ))])
1746
- assert source is not None
1747
- self .tree = manager .parse_file (self .id , self .xpath , source ,
1748
- self .ignore_all or self .options .ignore_errors )
1760
+
1761
+ if not self .namespace :
1762
+ assert source is not None
1763
+ self .tree = manager .parse_file (self .id , self .xpath , source ,
1764
+ self .ignore_all or self .options .ignore_errors )
1765
+ else :
1766
+ self .tree = MypyFile ([], [])
1749
1767
1750
1768
modules [self .id ] = self .tree
1751
1769
@@ -1807,13 +1825,20 @@ def parse_file(self) -> None:
1807
1825
self .check_blockers ()
1808
1826
1809
1827
def semantic_analysis (self ) -> None :
1828
+ if self .namespace :
1829
+ return
1830
+
1810
1831
assert self .tree is not None , "Internal error: method must be called on parsed file only"
1811
1832
patches = [] # type: List[Callable[[], None]]
1812
1833
with self .wrap_context ():
1813
1834
self .manager .semantic_analyzer .visit_file (self .tree , self .xpath , self .options , patches )
1814
1835
self .patches = patches
1815
1836
1816
1837
def semantic_analysis_pass_three (self ) -> None :
1838
+ if self .namespace :
1839
+ self .patches = []
1840
+ return
1841
+
1817
1842
assert self .tree is not None , "Internal error: method must be called on parsed file only"
1818
1843
patches = [] # type: List[Callable[[], None]]
1819
1844
with self .wrap_context ():
@@ -1828,6 +1853,9 @@ def semantic_analysis_apply_patches(self) -> None:
1828
1853
patch_func ()
1829
1854
1830
1855
def type_check_first_pass (self ) -> None :
1856
+ if self .namespace :
1857
+ return
1858
+
1831
1859
assert self .tree is not None , "Internal error: method must be called on parsed file only"
1832
1860
manager = self .manager
1833
1861
if self .options .semantic_analysis_only :
@@ -1838,12 +1866,18 @@ def type_check_first_pass(self) -> None:
1838
1866
self .type_checker .check_first_pass ()
1839
1867
1840
1868
def type_check_second_pass (self ) -> bool :
1869
+ if self .namespace :
1870
+ return False
1871
+
1841
1872
if self .options .semantic_analysis_only :
1842
1873
return False
1843
1874
with self .wrap_context ():
1844
1875
return self .type_checker .check_second_pass ()
1845
1876
1846
1877
def finish_passes (self ) -> None :
1878
+ if self .namespace :
1879
+ return
1880
+
1847
1881
assert self .tree is not None , "Internal error: method must be called on parsed file only"
1848
1882
manager = self .manager
1849
1883
if self .options .semantic_analysis_only :
@@ -1892,6 +1926,9 @@ def valid_references(self) -> Set[str]:
1892
1926
return valid_refs
1893
1927
1894
1928
def write_cache (self ) -> None :
1929
+ if self .namespace :
1930
+ return
1931
+
1895
1932
assert self .tree is not None , "Internal error: method must be called on parsed file only"
1896
1933
if not self .path or self .options .cache_dir == os .devnull :
1897
1934
return
0 commit comments