Skip to content

Commit bcecfe5

Browse files
ilevkivskyiMichael0x2a
authored andcommitted
Use some more dogfooding (#7385)
This PR enables `--strict-equality` and `--show-error-codes` for self-check, and adds error codes in some `# type: ignore`s. So far this revealed two issues: * Both PyCharm and flake8 get crazy about error codes, generating many false positives * Error codes in `# type: ignore`s don't always work, see #7384
1 parent 8e943f3 commit bcecfe5

11 files changed

+19
-15
lines changed

mypy/config_parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ def parse_section(prefix: str, template: Options,
214214
v = None # type: Any
215215
try:
216216
if ct is bool:
217-
v = section.getboolean(key) # type: ignore # Until better stub
217+
v = section.getboolean(key) # type: ignore[attr-defined] # Until better stub
218218
if invert:
219219
v = not v
220220
elif callable(ct):

mypy/fastparse.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def ast3_parse(source: Union[str, bytes], filename: str, mode: str,
103103
Constant = Any
104104
except ImportError:
105105
try:
106-
from typed_ast import ast35 # type: ignore # noqa: F401
106+
from typed_ast import ast35 # type: ignore[attr-defined] # noqa: F401
107107
except ImportError:
108108
print('The typed_ast package is not installed.\n'
109109
'You can install it with `python3 -m pip install typed-ast`.',
@@ -463,7 +463,7 @@ def translate_module_id(self, id: str) -> str:
463463
return id
464464

465465
def visit_Module(self, mod: ast3.Module) -> MypyFile:
466-
self.type_ignores = {ti.lineno: parse_type_ignore_tag(ti.tag) # type: ignore
466+
self.type_ignores = {ti.lineno: parse_type_ignore_tag(ti.tag) # type: ignore[attr-defined]
467467
for ti in mod.type_ignores}
468468
body = self.fix_function_overloads(self.translate_stmt_list(mod.body, ismodule=True))
469469
return MypyFile(body,

mypy/fastparse2.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
from mypy.fastparse import ast3, ast3_parse
6666
except ImportError:
6767
try:
68-
from typed_ast import ast35 # type: ignore # noqa: F401
68+
from typed_ast import ast35 # type: ignore[attr-defined] # noqa: F401
6969
except ImportError:
7070
print('The typed_ast package is not installed.\n'
7171
'You can install it with `python3 -m pip install typed-ast`.',
@@ -342,7 +342,7 @@ def translate_module_id(self, id: str) -> str:
342342
return id
343343

344344
def visit_Module(self, mod: ast27.Module) -> MypyFile:
345-
self.type_ignores = {ti.lineno: parse_type_ignore_tag(ti.tag) # type: ignore
345+
self.type_ignores = {ti.lineno: parse_type_ignore_tag(ti.tag) # type: ignore[attr-defined]
346346
for ti in mod.type_ignores}
347347
body = self.fix_function_overloads(self.translate_stmt_list(mod.body))
348348
return MypyFile(body,

mypy/fscache.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def _fake_init(self, path: str) -> os.stat_result:
137137
st = self.stat(dirname) # May raise OSError
138138
# Get stat result as a sequence so we can modify it.
139139
# (Alas, typeshed's os.stat_result is not a sequence yet.)
140-
tpl = tuple(st) # type: ignore
140+
tpl = tuple(st) # type: ignore[arg-type, var-annotated]
141141
seq = list(tpl) # type: List[float]
142142
seq[stat.ST_MODE] = stat.S_IFREG | 0o444
143143
seq[stat.ST_INO] = 1

mypy/messages.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1552,8 +1552,8 @@ def [T <: int] f(self, x: int, y: T) -> None
15521552
s += ' = ...'
15531553

15541554
# If we got a "special arg" (i.e: self, cls, etc...), prepend it to the arg list
1555-
if tp.definition is not None and tp.definition.name() is not None:
1556-
definition_args = tp.definition.arg_names # type: ignore
1555+
if isinstance(tp.definition, FuncDef) and tp.definition.name() is not None:
1556+
definition_args = tp.definition.arg_names
15571557
if definition_args and tp.arg_names != definition_args \
15581558
and len(definition_args) > 0:
15591559
if s:

mypy/report.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
# mypyc doesn't properly handle import from of submodules that we
2929
# don't have stubs for, hence the hacky double import
3030
import lxml.etree # type: ignore # noqa: F401
31-
from lxml import etree # type: ignore
31+
from lxml import etree
3232
LXML_INSTALLED = True
3333
except ImportError:
3434
LXML_INSTALLED = False

mypy/server/aststrip.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def visit_class_def(self, node: ClassDef) -> None:
115115
node.base_type_exprs.extend(node.removed_base_type_exprs)
116116
node.removed_base_type_exprs = []
117117
node.defs.body = [s for s in node.defs.body
118-
if s not in to_delete]
118+
if s not in to_delete] # type: ignore[comparison-overlap]
119119
with self.enter_class(node.info):
120120
super().visit_class_def(node)
121121
TypeState.reset_subtype_caches_for(node.info)

mypy/types.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,13 +196,13 @@ def expand_all_if_possible(self) -> Optional['ProperType']:
196196

197197
# TODO: remove ignore caused by https://github.com/python/mypy/issues/6759
198198
@property
199-
def can_be_true(self) -> bool: # type: ignore
199+
def can_be_true(self) -> bool: # type: ignore[override]
200200
assert self.alias is not None
201201
return self.alias.target.can_be_true
202202

203203
# TODO: remove ignore caused by https://github.com/python/mypy/issues/6759
204204
@property
205-
def can_be_false(self) -> bool: # type: ignore
205+
def can_be_false(self) -> bool: # type: ignore[override]
206206
assert self.alias is not None
207207
return self.alias.target.can_be_false
208208

@@ -1903,7 +1903,7 @@ def make_normalized(item: Type, *, line: int = -1, column: int = -1) -> ProperTy
19031903
[TypeType.make_normalized(union_item) for union_item in item.items],
19041904
line=line, column=column
19051905
)
1906-
return TypeType(item, line=line, column=column) # type: ignore
1906+
return TypeType(item, line=line, column=column) # type: ignore[arg-type]
19071907

19081908
def accept(self, visitor: 'TypeVisitor[T]') -> T:
19091909
return visitor.visit_type_type(self)

mypy_self_check.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@ check_untyped_defs = True
66
disallow_subclassing_any = True
77
warn_no_return = True
88
strict_optional = True
9+
strict_equality = True
910
no_implicit_optional = True
1011
disallow_any_generics = True
1112
disallow_any_unimported = True
1213
warn_redundant_casts = True
14+
warn_unused_ignores = True
1315
warn_unused_configs = True
1416
show_traceback = True
17+
show_error_codes = True
1518
always_false = MYPYC
1619
plugins = misc/proper_plugin.py

setup.cfg

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ exclude =
4141
# B006: use of mutable defaults in function signatures
4242
# B007: Loop control variable not used within the loop body.
4343
# B011: Don't use assert False
44-
extend-ignore = E128,W601,E701,E704,E402,B3,B006,B007,B011
44+
# F821: Name not defined (generates false positives with error codes)
45+
extend-ignore = E128,W601,E701,E704,E402,B3,B006,B007,B011,F821
4546

4647
[coverage:run]
4748
branch = true

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ description = type check ourselves
5151
basepython = python3.7
5252
commands =
5353
python -m mypy --config-file mypy_self_check.ini -p mypy -p mypyc
54-
python -m mypy --config-file mypy_self_check.ini scripts/stubtest.py scripts/mypyc
54+
python -m mypy --config-file mypy_self_check.ini misc/proper_plugin.py scripts/stubtest.py scripts/mypyc
5555

5656
[testenv:docs]
5757
description = invoke sphinx-build to build the HTML docs

0 commit comments

Comments
 (0)