Skip to content

Commit a65996e

Browse files
committed
Fine-grained: Fix crash caused by unreachable class
Fixes #4596.
1 parent 63d6e7c commit a65996e

File tree

2 files changed

+59
-1
lines changed

2 files changed

+59
-1
lines changed

mypy/server/astmerge.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,9 @@ def fixup(self, node: SN) -> SN:
254254
def fixup_type(self, typ: Type) -> None:
255255
typ.accept(TypeReplaceVisitor(self.replacements))
256256

257-
def process_type_info(self, info: TypeInfo) -> None:
257+
def process_type_info(self, info: Optional[TypeInfo]) -> None:
258+
if info is None:
259+
return
258260
# TODO: Additional things:
259261
# - declared_metaclass
260262
# - metaclass_type

test-data/unit/fine-grained.test

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1861,3 +1861,59 @@ def f() -> None:
18611861
[out]
18621862
a.py:1: error: Need type annotation for 'y'
18631863
==
1864+
1865+
[case testSkippedClass1]
1866+
import a
1867+
[file a.py]
1868+
class A: pass
1869+
[file a.py.2]
1870+
import sys
1871+
if sys.platform == 'xyz':
1872+
class A: pass
1873+
[builtins fixtures/ops.pyi]
1874+
[out]
1875+
==
1876+
1877+
[case testSkippedClass2]
1878+
import a
1879+
[file a.py]
1880+
import sys
1881+
if sys.platform == 'xyz':
1882+
class A: pass
1883+
[file a.py.2]
1884+
import sys
1885+
if sys.platform == 'xyz':
1886+
class A: pass
1887+
[builtins fixtures/ops.pyi]
1888+
[out]
1889+
==
1890+
1891+
[case testSkippedClass3]
1892+
import a
1893+
[file a.py]
1894+
import sys
1895+
if sys.platform == 'xyz':
1896+
class A: pass
1897+
[file a.py.2]
1898+
class A: pass
1899+
[builtins fixtures/ops.pyi]
1900+
[out]
1901+
==
1902+
1903+
[case testSkippedClass4]
1904+
import a
1905+
[file a.py]
1906+
import sys
1907+
if sys.platform == 'xyz':
1908+
class A: pass
1909+
else:
1910+
class A: pass
1911+
[file a.py.2]
1912+
import sys
1913+
if sys.platform == 'xyz':
1914+
class A: pass
1915+
else:
1916+
class A: pass
1917+
[builtins fixtures/ops.pyi]
1918+
[out]
1919+
==

0 commit comments

Comments
 (0)