Skip to content

Allow semantic analyzer errors to be suppressed with # type: ignore #1305

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions mypy/semanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -2357,7 +2357,9 @@ def __init__(self, modules: Dict[str, MypyFile], errors: Errors) -> None:

def visit_file(self, file_node: MypyFile, fnam: str) -> None:
self.errors.set_file(fnam)
self.errors.set_ignored_lines(file_node.ignored_lines)
file_node.accept(self)
self.errors.set_ignored_lines(set())

def visit_func_def(self, fdef: FuncDef) -> None:
self.errors.push_function(fdef.name())
Expand Down
23 changes: 23 additions & 0 deletions mypy/test/data/check-ignore.test
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,26 @@ if 1: # type: ignore
# blah
pass
[out]

[case testIgnoreTooManyTypeArguments]
from typing import TypeVar, Generic
T = TypeVar('T')
U = TypeVar('U')

class Base(Generic[T, U]):
pass

class PartialBase(Base[T, int], Generic[T]):
pass

class Child(PartialBase[str, int]): # type: ignore
pass


def foo(x: Base[str, int]) -> None: pass
foo(Child())

def bar(x: Base[str, str]) -> None: pass
bar(Child())
[out]
main:19: error: Argument 1 to "bar" has incompatible type "Child"; expected Base[str, str]