Skip to content

selfcheck: enable the ignore-without-code error code #13534

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
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
5 changes: 4 additions & 1 deletion misc/proper_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from typing import Callable

from mypy.checker import TypeChecker
from mypy.nodes import TypeInfo
from mypy.plugin import FunctionContext, Plugin
from mypy.subtypes import is_proper_subtype
Expand Down Expand Up @@ -155,7 +156,9 @@ def proper_types_hook(ctx: FunctionContext) -> Type:


def get_proper_type_instance(ctx: FunctionContext) -> Instance:
types = ctx.api.modules["mypy.types"] # type: ignore
checker = ctx.api
assert isinstance(checker, TypeChecker)
types = checker.modules["mypy.types"]
proper_type_info = types.names["ProperType"]
assert isinstance(proper_type_info.node, TypeInfo)
return Instance(proper_type_info.node, [])
Expand Down
2 changes: 1 addition & 1 deletion mypy/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -5704,7 +5704,7 @@ def named_type(self, name: str) -> Instance:
sym = self.lookup_qualified(name)
node = sym.node
if isinstance(node, TypeAlias):
assert isinstance(node.target, Instance) # type: ignore
assert isinstance(node.target, Instance) # type: ignore[misc]
node = node.target.type
assert isinstance(node, TypeInfo)
any_type = AnyType(TypeOfAny.from_omitted_generics)
Expand Down
4 changes: 2 additions & 2 deletions mypy/checkexpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ def analyze_ref_expr(self, e: RefExpr, lvalue: bool = False) -> Type:
result = self.typeddict_callable(node)
else:
result = type_object_type(node, self.named_type)
if isinstance(result, CallableType) and isinstance( # type: ignore
if isinstance(result, CallableType) and isinstance( # type: ignore[misc]
result.ret_type, Instance
):
# We need to set correct line and column
Expand Down Expand Up @@ -3805,7 +3805,7 @@ class LongName(Generic[T]): ...
x = A()
y = cast(A, ...)
"""
if isinstance(alias.target, Instance) and alias.target.invalid: # type: ignore
if isinstance(alias.target, Instance) and alias.target.invalid: # type: ignore[misc]
# An invalid alias, error already has been reported
return AnyType(TypeOfAny.from_error)
# If this is a generic alias, we set all variables to `Any`.
Expand Down
2 changes: 1 addition & 1 deletion mypy/constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ def visit_instance(self, template: Instance) -> list[Constraint]:
if isinstance(actual, Instance):
instance = actual
erased = erase_typevars(template)
assert isinstance(erased, Instance) # type: ignore
assert isinstance(erased, Instance) # type: ignore[misc]
# We always try nominal inference if possible,
# it is much faster than the structural one.
if self.direction == SUBTYPE_OF and template.type.has_base(instance.type.fullname):
Expand Down
5 changes: 3 additions & 2 deletions mypy/fastparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -1990,9 +1990,10 @@ def visit_Subscript(self, n: ast3.Subscript) -> Type:
for s in dims:
if getattr(s, "col_offset", None) is None:
if isinstance(s, ast3.Index):
s.col_offset = s.value.col_offset # type: ignore
s.col_offset = s.value.col_offset # type: ignore[attr-defined]
elif isinstance(s, ast3.Slice):
s.col_offset = s.lower.col_offset # type: ignore
assert s.lower is not None
s.col_offset = s.lower.col_offset # type: ignore[attr-defined]
sliceval = ast3.Tuple(dims, n.ctx)

empty_tuple_index = False
Expand Down
2 changes: 1 addition & 1 deletion mypy/memprofile.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def collect_memory_stats() -> tuple[dict[str, int], dict[str, int]]:
if hasattr(obj, "__dict__"):
# Keep track of which class a particular __dict__ is associated with.
inferred[id(obj.__dict__)] = f"{n} (__dict__)"
if isinstance(obj, (Node, Type)): # type: ignore
if isinstance(obj, (Node, Type)): # type: ignore[misc]
if hasattr(obj, "__dict__"):
for x in obj.__dict__.values():
if isinstance(x, list):
Expand Down
2 changes: 1 addition & 1 deletion mypy/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1113,7 +1113,7 @@ def __init__(
) -> None:
super().__init__()
self.name = name
self.fullname = None # type: ignore
self.fullname = None # type: ignore[assignment]
self.defs = defs
self.type_vars = type_vars or []
self.base_type_exprs = base_type_exprs or []
Expand Down
4 changes: 2 additions & 2 deletions mypy/plugins/singledispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class RegisterCallableInfo(NamedTuple):

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


Expand Down Expand Up @@ -200,7 +200,7 @@ def call_singledispatch_function_after_register_argument(ctx: MethodContext) ->
"""Called on the function after passing a type to register"""
register_callable = ctx.type
if isinstance(register_callable, Instance):
type_args = RegisterCallableInfo(*register_callable.args) # type: ignore
type_args = RegisterCallableInfo(*register_callable.args) # type: ignore[arg-type]
func = get_first_arg(ctx.arg_types)
if func is not None:
register_function(ctx, type_args.singledispatch_obj, func, type_args.register_type)
Expand Down
2 changes: 1 addition & 1 deletion mypy/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from mypy.version import __version__

try:
from lxml import etree # type: ignore
from lxml import etree # type: ignore[import]

LXML_INSTALLED = True
except ImportError:
Expand Down
2 changes: 1 addition & 1 deletion mypy/semanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -5291,7 +5291,7 @@ def named_type_or_none(self, fullname: str, args: list[Type] | None = None) -> I
return None
node = sym.node
if isinstance(node, TypeAlias):
assert isinstance(node.target, Instance) # type: ignore
assert isinstance(node.target, Instance) # type: ignore[misc]
node = node.target.type
assert isinstance(node, TypeInfo), node
if args is not None:
Expand Down
6 changes: 3 additions & 3 deletions mypy/server/objgraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ def get_edges(o: object) -> Iterator[tuple[object, object]]:
# in closures and self pointers to other objects

if hasattr(e, "__closure__"):
yield (s, "__closure__"), e.__closure__ # type: ignore
yield (s, "__closure__"), e.__closure__ # type: ignore[union-attr]
if hasattr(e, "__self__"):
se = e.__self__ # type: ignore
se = e.__self__ # type: ignore[union-attr]
if se is not o and se is not type(o) and hasattr(s, "__self__"):
yield s.__self__, se # type: ignore
yield s.__self__, se # type: ignore[attr-defined]
else:
if not type(e) in TYPE_BLACKLIST:
yield s, e
Expand Down
2 changes: 1 addition & 1 deletion mypy/stubgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -985,7 +985,7 @@ def visit_assignment_stmt(self, o: AssignmentStmt) -> None:
continue
if isinstance(lvalue, TupleExpr) or isinstance(lvalue, ListExpr):
items = lvalue.items
if isinstance(o.unanalyzed_type, TupleType): # type: ignore
if isinstance(o.unanalyzed_type, TupleType): # type: ignore[misc]
annotations: Iterable[Type | None] = o.unanalyzed_type.items
else:
annotations = [None] * len(items)
Expand Down
2 changes: 1 addition & 1 deletion mypy/stubtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ def _verify_final(
) -> Iterator[Error]:
try:

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

except TypeError:
Expand Down
2 changes: 1 addition & 1 deletion mypy/test/testcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
)

try:
import lxml # type: ignore
import lxml # type: ignore[import]
except ImportError:
lxml = None

Expand Down
2 changes: 1 addition & 1 deletion mypy/test/testcmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
)

try:
import lxml # type: ignore
import lxml # type: ignore[import]
except ImportError:
lxml = None

Expand Down
4 changes: 2 additions & 2 deletions mypy/test/testreports.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from mypy.test.helpers import Suite, assert_equal

try:
import lxml # type: ignore
import lxml # type: ignore[import]
except ImportError:
lxml = None

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

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

cobertura_package = CoberturaPackage("foobar")
cobertura_package.covered_lines = 21
Expand Down
6 changes: 3 additions & 3 deletions mypy/type_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def visit_instance(self, t: Instance) -> Type:
last_known_value: LiteralType | None = None
if t.last_known_value is not None:
raw_last_known_value = t.last_known_value.accept(self)
assert isinstance(raw_last_known_value, LiteralType) # type: ignore
assert isinstance(raw_last_known_value, LiteralType) # type: ignore[misc]
last_known_value = raw_last_known_value
return Instance(
typ=t.type,
Expand Down Expand Up @@ -266,7 +266,7 @@ def visit_typeddict_type(self, t: TypedDictType) -> Type:

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

def visit_union_type(self, t: UnionType) -> Type:
Expand All @@ -284,7 +284,7 @@ def visit_overloaded(self, t: Overloaded) -> Type:
items: list[CallableType] = []
for item in t.items:
new = item.accept(self)
assert isinstance(new, CallableType) # type: ignore
assert isinstance(new, CallableType) # type: ignore[misc]
items.append(new)
return Overloaded(items=items)

Expand Down
2 changes: 1 addition & 1 deletion mypy/typeanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -1550,7 +1550,7 @@ def expand_type_alias(
assert typ.alias is not None
# HACK: Implement FlexibleAlias[T, typ] by expanding it to typ here.
if (
isinstance(typ.alias.target, Instance) # type: ignore
isinstance(typ.alias.target, Instance) # type: ignore[misc]
and typ.alias.target.type.fullname == "mypy_extensions.FlexibleAlias"
):
exp = get_proper_type(typ)
Expand Down
1 change: 1 addition & 0 deletions mypy_self_check.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ always_false = MYPYC
plugins = misc/proper_plugin.py
python_version = 3.7
exclude = mypy/typeshed/|mypyc/test-data/|mypyc/lib-rt/
enable_error_code = ignore-without-code