Skip to content

Commit 09b8b55

Browse files
authored
selfcheck: enable the ignore-without-code error code (#13534)
1 parent 3efbc5c commit 09b8b55

19 files changed

+31
-26
lines changed

misc/proper_plugin.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from typing import Callable
44

5+
from mypy.checker import TypeChecker
56
from mypy.nodes import TypeInfo
67
from mypy.plugin import FunctionContext, Plugin
78
from mypy.subtypes import is_proper_subtype
@@ -153,7 +154,9 @@ def proper_types_hook(ctx: FunctionContext) -> Type:
153154

154155

155156
def get_proper_type_instance(ctx: FunctionContext) -> Instance:
156-
types = ctx.api.modules["mypy.types"] # type: ignore
157+
checker = ctx.api
158+
assert isinstance(checker, TypeChecker)
159+
types = checker.modules["mypy.types"]
157160
proper_type_info = types.names["ProperType"]
158161
assert isinstance(proper_type_info.node, TypeInfo)
159162
return Instance(proper_type_info.node, [])

mypy/checker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5715,7 +5715,7 @@ def named_type(self, name: str) -> Instance:
57155715
sym = self.lookup_qualified(name)
57165716
node = sym.node
57175717
if isinstance(node, TypeAlias):
5718-
assert isinstance(node.target, Instance) # type: ignore
5718+
assert isinstance(node.target, Instance) # type: ignore[misc]
57195719
node = node.target.type
57205720
assert isinstance(node, TypeInfo)
57215721
any_type = AnyType(TypeOfAny.from_omitted_generics)

mypy/checkexpr.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ def analyze_ref_expr(self, e: RefExpr, lvalue: bool = False) -> Type:
320320
result = self.typeddict_callable(node)
321321
else:
322322
result = type_object_type(node, self.named_type)
323-
if isinstance(result, CallableType) and isinstance( # type: ignore
323+
if isinstance(result, CallableType) and isinstance( # type: ignore[misc]
324324
result.ret_type, Instance
325325
):
326326
# We need to set correct line and column
@@ -3823,7 +3823,7 @@ class LongName(Generic[T]): ...
38233823
x = A()
38243824
y = cast(A, ...)
38253825
"""
3826-
if isinstance(alias.target, Instance) and alias.target.invalid: # type: ignore
3826+
if isinstance(alias.target, Instance) and alias.target.invalid: # type: ignore[misc]
38273827
# An invalid alias, error already has been reported
38283828
return AnyType(TypeOfAny.from_error)
38293829
# If this is a generic alias, we set all variables to `Any`.

mypy/constraints.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ def visit_instance(self, template: Instance) -> list[Constraint]:
577577
if isinstance(actual, Instance):
578578
instance = actual
579579
erased = erase_typevars(template)
580-
assert isinstance(erased, Instance) # type: ignore
580+
assert isinstance(erased, Instance) # type: ignore[misc]
581581
# We always try nominal inference if possible,
582582
# it is much faster than the structural one.
583583
if self.direction == SUBTYPE_OF and template.type.has_base(instance.type.fullname):

mypy/fastparse.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1990,9 +1990,10 @@ def visit_Subscript(self, n: ast3.Subscript) -> Type:
19901990
for s in dims:
19911991
if getattr(s, "col_offset", None) is None:
19921992
if isinstance(s, ast3.Index):
1993-
s.col_offset = s.value.col_offset # type: ignore
1993+
s.col_offset = s.value.col_offset # type: ignore[attr-defined]
19941994
elif isinstance(s, ast3.Slice):
1995-
s.col_offset = s.lower.col_offset # type: ignore
1995+
assert s.lower is not None
1996+
s.col_offset = s.lower.col_offset # type: ignore[attr-defined]
19961997
sliceval = ast3.Tuple(dims, n.ctx)
19971998

19981999
empty_tuple_index = False

mypy/memprofile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def collect_memory_stats() -> tuple[dict[str, int], dict[str, int]]:
3535
if hasattr(obj, "__dict__"):
3636
# Keep track of which class a particular __dict__ is associated with.
3737
inferred[id(obj.__dict__)] = f"{n} (__dict__)"
38-
if isinstance(obj, (Node, Type)): # type: ignore
38+
if isinstance(obj, (Node, Type)): # type: ignore[misc]
3939
if hasattr(obj, "__dict__"):
4040
for x in obj.__dict__.values():
4141
if isinstance(x, list):

mypy/nodes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1113,7 +1113,7 @@ def __init__(
11131113
) -> None:
11141114
super().__init__()
11151115
self.name = name
1116-
self.fullname = None # type: ignore
1116+
self.fullname = None # type: ignore[assignment]
11171117
self.defs = defs
11181118
self.type_vars = type_vars or []
11191119
self.base_type_exprs = base_type_exprs or []

mypy/plugins/singledispatch.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class RegisterCallableInfo(NamedTuple):
4040

4141
def get_singledispatch_info(typ: Instance) -> SingledispatchTypeVars | None:
4242
if len(typ.args) == 2:
43-
return SingledispatchTypeVars(*typ.args) # type: ignore
43+
return SingledispatchTypeVars(*typ.args) # type: ignore[arg-type]
4444
return None
4545

4646

@@ -200,7 +200,7 @@ def call_singledispatch_function_after_register_argument(ctx: MethodContext) ->
200200
"""Called on the function after passing a type to register"""
201201
register_callable = ctx.type
202202
if isinstance(register_callable, Instance):
203-
type_args = RegisterCallableInfo(*register_callable.args) # type: ignore
203+
type_args = RegisterCallableInfo(*register_callable.args) # type: ignore[arg-type]
204204
func = get_first_arg(ctx.arg_types)
205205
if func is not None:
206206
register_function(ctx, type_args.singledispatch_obj, func, type_args.register_type)

mypy/report.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from mypy.version import __version__
2626

2727
try:
28-
from lxml import etree # type: ignore
28+
from lxml import etree # type: ignore[import]
2929

3030
LXML_INSTALLED = True
3131
except ImportError:

mypy/semanal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5291,7 +5291,7 @@ def named_type_or_none(self, fullname: str, args: list[Type] | None = None) -> I
52915291
return None
52925292
node = sym.node
52935293
if isinstance(node, TypeAlias):
5294-
assert isinstance(node.target, Instance) # type: ignore
5294+
assert isinstance(node.target, Instance) # type: ignore[misc]
52955295
node = node.target.type
52965296
assert isinstance(node, TypeInfo), node
52975297
if args is not None:

mypy/server/objgraph.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ def get_edges(o: object) -> Iterator[tuple[object, object]]:
6464
# in closures and self pointers to other objects
6565

6666
if hasattr(e, "__closure__"):
67-
yield (s, "__closure__"), e.__closure__ # type: ignore
67+
yield (s, "__closure__"), e.__closure__ # type: ignore[union-attr]
6868
if hasattr(e, "__self__"):
69-
se = e.__self__ # type: ignore
69+
se = e.__self__ # type: ignore[union-attr]
7070
if se is not o and se is not type(o) and hasattr(s, "__self__"):
71-
yield s.__self__, se # type: ignore
71+
yield s.__self__, se # type: ignore[attr-defined]
7272
else:
7373
if not type(e) in TYPE_BLACKLIST:
7474
yield s, e

mypy/stubgen.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -985,7 +985,7 @@ def visit_assignment_stmt(self, o: AssignmentStmt) -> None:
985985
continue
986986
if isinstance(lvalue, TupleExpr) or isinstance(lvalue, ListExpr):
987987
items = lvalue.items
988-
if isinstance(o.unanalyzed_type, TupleType): # type: ignore
988+
if isinstance(o.unanalyzed_type, TupleType): # type: ignore[misc]
989989
annotations: Iterable[Type | None] = o.unanalyzed_type.items
990990
else:
991991
annotations = [None] * len(items)

mypy/stubtest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ def _verify_final(
354354
) -> Iterator[Error]:
355355
try:
356356

357-
class SubClass(runtime): # type: ignore
357+
class SubClass(runtime): # type: ignore[misc,valid-type]
358358
pass
359359

360360
except TypeError:

mypy/test/testcheck.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
)
2727

2828
try:
29-
import lxml # type: ignore
29+
import lxml # type: ignore[import]
3030
except ImportError:
3131
lxml = None
3232

mypy/test/testcmdline.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
)
2121

2222
try:
23-
import lxml # type: ignore
23+
import lxml # type: ignore[import]
2424
except ImportError:
2525
lxml = None
2626

mypy/test/testreports.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from mypy.test.helpers import Suite, assert_equal
88

99
try:
10-
import lxml # type: ignore
10+
import lxml # type: ignore[import]
1111
except ImportError:
1212
lxml = None
1313

@@ -22,7 +22,7 @@ def test_get_line_rate(self) -> None:
2222

2323
@pytest.mark.skipif(lxml is None, reason="Cannot import lxml. Is it installed?")
2424
def test_as_xml(self) -> None:
25-
import lxml.etree as etree # type: ignore
25+
import lxml.etree as etree # type: ignore[import]
2626

2727
cobertura_package = CoberturaPackage("foobar")
2828
cobertura_package.covered_lines = 21

mypy/type_visitor.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ def visit_instance(self, t: Instance) -> Type:
209209
last_known_value: LiteralType | None = None
210210
if t.last_known_value is not None:
211211
raw_last_known_value = t.last_known_value.accept(self)
212-
assert isinstance(raw_last_known_value, LiteralType) # type: ignore
212+
assert isinstance(raw_last_known_value, LiteralType) # type: ignore[misc]
213213
last_known_value = raw_last_known_value
214214
return Instance(
215215
typ=t.type,
@@ -266,7 +266,7 @@ def visit_typeddict_type(self, t: TypedDictType) -> Type:
266266

267267
def visit_literal_type(self, t: LiteralType) -> Type:
268268
fallback = t.fallback.accept(self)
269-
assert isinstance(fallback, Instance) # type: ignore
269+
assert isinstance(fallback, Instance) # type: ignore[misc]
270270
return LiteralType(value=t.value, fallback=fallback, line=t.line, column=t.column)
271271

272272
def visit_union_type(self, t: UnionType) -> Type:
@@ -284,7 +284,7 @@ def visit_overloaded(self, t: Overloaded) -> Type:
284284
items: list[CallableType] = []
285285
for item in t.items:
286286
new = item.accept(self)
287-
assert isinstance(new, CallableType) # type: ignore
287+
assert isinstance(new, CallableType) # type: ignore[misc]
288288
items.append(new)
289289
return Overloaded(items=items)
290290

mypy/typeanal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1550,7 +1550,7 @@ def expand_type_alias(
15501550
assert typ.alias is not None
15511551
# HACK: Implement FlexibleAlias[T, typ] by expanding it to typ here.
15521552
if (
1553-
isinstance(typ.alias.target, Instance) # type: ignore
1553+
isinstance(typ.alias.target, Instance) # type: ignore[misc]
15541554
and typ.alias.target.type.fullname == "mypy_extensions.FlexibleAlias"
15551555
):
15561556
exp = get_proper_type(typ)

mypy_self_check.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ always_false = MYPYC
1111
plugins = misc/proper_plugin.py
1212
python_version = 3.7
1313
exclude = mypy/typeshed/|mypyc/test-data/|mypyc/lib-rt/
14+
enable_error_code = ignore-without-code

0 commit comments

Comments
 (0)