Skip to content

Commit

Permalink
Use some more dogfooding (#7385)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ilevkivskyi authored Aug 24, 2019
1 parent b89e2fa commit eb5f4a4
Show file tree
Hide file tree
Showing 11 changed files with 19 additions and 15 deletions.
2 changes: 1 addition & 1 deletion mypy/config_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def parse_section(prefix: str, template: Options,
v = None # type: Any
try:
if ct is bool:
v = section.getboolean(key) # type: ignore # Until better stub
v = section.getboolean(key) # type: ignore[attr-defined] # Until better stub
if invert:
v = not v
elif callable(ct):
Expand Down
4 changes: 2 additions & 2 deletions mypy/fastparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def ast3_parse(source: Union[str, bytes], filename: str, mode: str,
Constant = Any
except ImportError:
try:
from typed_ast import ast35 # type: ignore # noqa: F401
from typed_ast import ast35 # type: ignore[attr-defined] # noqa: F401
except ImportError:
print('The typed_ast package is not installed.\n'
'You can install it with `python3 -m pip install typed-ast`.',
Expand Down Expand Up @@ -463,7 +463,7 @@ def translate_module_id(self, id: str) -> str:
return id

def visit_Module(self, mod: ast3.Module) -> MypyFile:
self.type_ignores = {ti.lineno: parse_type_ignore_tag(ti.tag) # type: ignore
self.type_ignores = {ti.lineno: parse_type_ignore_tag(ti.tag) # type: ignore[attr-defined]
for ti in mod.type_ignores}
body = self.fix_function_overloads(self.translate_stmt_list(mod.body, ismodule=True))
return MypyFile(body,
Expand Down
4 changes: 2 additions & 2 deletions mypy/fastparse2.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
from mypy.fastparse import ast3, ast3_parse
except ImportError:
try:
from typed_ast import ast35 # type: ignore # noqa: F401
from typed_ast import ast35 # type: ignore[attr-defined] # noqa: F401
except ImportError:
print('The typed_ast package is not installed.\n'
'You can install it with `python3 -m pip install typed-ast`.',
Expand Down Expand Up @@ -342,7 +342,7 @@ def translate_module_id(self, id: str) -> str:
return id

def visit_Module(self, mod: ast27.Module) -> MypyFile:
self.type_ignores = {ti.lineno: parse_type_ignore_tag(ti.tag) # type: ignore
self.type_ignores = {ti.lineno: parse_type_ignore_tag(ti.tag) # type: ignore[attr-defined]
for ti in mod.type_ignores}
body = self.fix_function_overloads(self.translate_stmt_list(mod.body))
return MypyFile(body,
Expand Down
2 changes: 1 addition & 1 deletion mypy/fscache.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def _fake_init(self, path: str) -> os.stat_result:
st = self.stat(dirname) # May raise OSError
# Get stat result as a sequence so we can modify it.
# (Alas, typeshed's os.stat_result is not a sequence yet.)
tpl = tuple(st) # type: ignore
tpl = tuple(st) # type: ignore[arg-type, var-annotated]
seq = list(tpl) # type: List[float]
seq[stat.ST_MODE] = stat.S_IFREG | 0o444
seq[stat.ST_INO] = 1
Expand Down
4 changes: 2 additions & 2 deletions mypy/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -1552,8 +1552,8 @@ def [T <: int] f(self, x: int, y: T) -> None
s += ' = ...'

# If we got a "special arg" (i.e: self, cls, etc...), prepend it to the arg list
if tp.definition is not None and tp.definition.name() is not None:
definition_args = tp.definition.arg_names # type: ignore
if isinstance(tp.definition, FuncDef) and tp.definition.name() is not None:
definition_args = tp.definition.arg_names
if definition_args and tp.arg_names != definition_args \
and len(definition_args) > 0:
if s:
Expand Down
2 changes: 1 addition & 1 deletion mypy/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
# mypyc doesn't properly handle import from of submodules that we
# don't have stubs for, hence the hacky double import
import lxml.etree # type: ignore # noqa: F401
from lxml import etree # type: ignore
from lxml import etree
LXML_INSTALLED = True
except ImportError:
LXML_INSTALLED = False
Expand Down
2 changes: 1 addition & 1 deletion mypy/server/aststrip.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def visit_class_def(self, node: ClassDef) -> None:
node.base_type_exprs.extend(node.removed_base_type_exprs)
node.removed_base_type_exprs = []
node.defs.body = [s for s in node.defs.body
if s not in to_delete]
if s not in to_delete] # type: ignore[comparison-overlap]
with self.enter_class(node.info):
super().visit_class_def(node)
TypeState.reset_subtype_caches_for(node.info)
Expand Down
6 changes: 3 additions & 3 deletions mypy/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,13 +196,13 @@ def expand_all_if_possible(self) -> Optional['ProperType']:

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

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

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

def accept(self, visitor: 'TypeVisitor[T]') -> T:
return visitor.visit_type_type(self)
Expand Down
3 changes: 3 additions & 0 deletions mypy_self_check.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ check_untyped_defs = True
disallow_subclassing_any = True
warn_no_return = True
strict_optional = True
strict_equality = True
no_implicit_optional = True
disallow_any_generics = True
disallow_any_unimported = True
warn_redundant_casts = True
warn_unused_ignores = True
warn_unused_configs = True
show_traceback = True
show_error_codes = True
always_false = MYPYC
plugins = misc/proper_plugin.py
3 changes: 2 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ exclude =
# B006: use of mutable defaults in function signatures
# B007: Loop control variable not used within the loop body.
# B011: Don't use assert False
extend-ignore = E128,W601,E701,E704,E402,B3,B006,B007,B011
# F821: Name not defined (generates false positives with error codes)
extend-ignore = E128,W601,E701,E704,E402,B3,B006,B007,B011,F821

This comment has been minimized.

Copy link
@blueyed

blueyed Jan 15, 2020

Contributor

Note that F821 can be removed with the next pyflakes release (PyCQA/pyflakes#455).

This comment has been minimized.

Copy link
@JukkaL

JukkaL Jan 15, 2020

Collaborator

Good! Thanks for the pointer.


[coverage:run]
branch = true
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ description = type check ourselves
basepython = python3.7
commands =
python -m mypy --config-file mypy_self_check.ini -p mypy -p mypyc
python -m mypy --config-file mypy_self_check.ini scripts/stubtest.py scripts/mypyc
python -m mypy --config-file mypy_self_check.ini misc/proper_plugin.py scripts/stubtest.py scripts/mypyc

[testenv:docs]
description = invoke sphinx-build to build the HTML docs
Expand Down

0 comments on commit eb5f4a4

Please sign in to comment.