Skip to content

Commit e6ba756

Browse files
committed
Merge pull request #1305 from ddfisher/master
Allow semantic analyzer errors to be suppressed with # type: ignore
2 parents d8f5cbc + 9a14814 commit e6ba756

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

mypy/semanal.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2357,7 +2357,9 @@ def __init__(self, modules: Dict[str, MypyFile], errors: Errors) -> None:
23572357

23582358
def visit_file(self, file_node: MypyFile, fnam: str) -> None:
23592359
self.errors.set_file(fnam)
2360+
self.errors.set_ignored_lines(file_node.ignored_lines)
23602361
file_node.accept(self)
2362+
self.errors.set_ignored_lines(set())
23612363

23622364
def visit_func_def(self, fdef: FuncDef) -> None:
23632365
self.errors.push_function(fdef.name())

mypy/test/data/check-ignore.test

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,26 @@ if 1: # type: ignore
146146
# blah
147147
pass
148148
[out]
149+
150+
[case testIgnoreTooManyTypeArguments]
151+
from typing import TypeVar, Generic
152+
T = TypeVar('T')
153+
U = TypeVar('U')
154+
155+
class Base(Generic[T, U]):
156+
pass
157+
158+
class PartialBase(Base[T, int], Generic[T]):
159+
pass
160+
161+
class Child(PartialBase[str, int]): # type: ignore
162+
pass
163+
164+
165+
def foo(x: Base[str, int]) -> None: pass
166+
foo(Child())
167+
168+
def bar(x: Base[str, str]) -> None: pass
169+
bar(Child())
170+
[out]
171+
main:19: error: Argument 1 to "bar" has incompatible type "Child"; expected Base[str, str]

0 commit comments

Comments
 (0)