Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
1382b7c
Update check-errorcodes.test: add xfail test case for https://github.…
wyattscarpenter Sep 17, 2025
dbbba52
Update check-errorcodes.test: add reveal_locals
wyattscarpenter Sep 17, 2025
5fc0ccd
Update errors.py: allow error codes to be None and not default to misc
wyattscarpenter Sep 17, 2025
a366c80
Update errors.py: try only defaulting to None for notes
wyattscarpenter Sep 18, 2025
3a4d7c6
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 18, 2025
ad715ec
remove xfails
wyattscarpenter Sep 18, 2025
756a5c1
restore
wyattscarpenter Sep 18, 2025
6cff29d
whoops
wyattscarpenter Sep 18, 2025
0cc5db3
Update errors.py: make Severity a type
wyattscarpenter Sep 18, 2025
af86853
Update errors.py: put the severity in the bag bro
wyattscarpenter Sep 18, 2025
14e165d
mop up remaining severities
wyattscarpenter Sep 18, 2025
fa2e72b
try out a fix for this common code, that i will probably remove later…
wyattscarpenter Sep 18, 2025
9be5dc3
Revert "try out a fix for this common code, that i will probably remo…
wyattscarpenter Sep 18, 2025
57b5081
allow notes to inherit codes
wyattscarpenter Sep 18, 2025
3874155
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 18, 2025
c42c817
add test case for misc silencing redefinition notes
wyattscarpenter Sep 18, 2025
27c8517
Revert "start making Severity a type instead of str"
wyattscarpenter Sep 18, 2025
1ba24c5
add an unsuppressed example as well
wyattscarpenter Sep 18, 2025
a64f74e
parent all redefinition notes correctly
wyattscarpenter Sep 20, 2025
b22e1d6
reparent proper_plugin note
wyattscarpenter Sep 20, 2025
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
8 changes: 4 additions & 4 deletions mypy/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -7734,7 +7734,7 @@ def fail(
) -> ErrorInfo:
"""Produce an error message."""
if isinstance(msg, ErrorMessage):
return self.msg.fail(msg.value, context, code=msg.code)
msg, code = msg.value, msg.code # type: ignore[attr-defined] #TODO: https://github.com/python/mypy/issues/19891
return self.msg.fail(msg, context, code=code)

def note(
Expand All @@ -7744,12 +7744,12 @@ def note(
offset: int = 0,
*,
code: ErrorCode | None = None,
parent_error: ErrorInfo | None = None,
) -> None:
"""Produce a note."""
if isinstance(msg, ErrorMessage):
self.msg.note(msg.value, context, code=msg.code)
return
self.msg.note(msg, context, offset=offset, code=code)
msg, code = msg.value, msg.code # type: ignore[attr-defined] #TODO: https://github.com/python/mypy/issues/19891
self.msg.note(msg, context, offset=offset, code=code, parent_error=parent_error)

def iterable_item_type(
self, it: Instance | CallableType | TypeType | Overloaded, context: Context
Expand Down
13 changes: 11 additions & 2 deletions mypy/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ def report(
line: line number of error
column: column number of error
message: message to report
code: error code (defaults to 'misc'; not shown for notes)
code: error code (defaults to misc; or None for notes), not shown for notes
blocker: if True, don't continue analysis after this error
severity: 'error' or 'note'
file: if non-None, override current file as context
Expand Down Expand Up @@ -548,7 +548,16 @@ def report(
end_line = line

code = code or (parent_error.code if parent_error else None)
code = code or (codes.MISC if not blocker else None)
if code is None:
if blocker:
code = None # do we even need to do this for blockers?
elif severity == "note":
if parent_error is not None:
code = parent_error.code # this might be None, btw
else:
code = None
else:
code = codes.MISC

info = ErrorInfo(
import_ctx=self.import_context(),
Expand Down
4 changes: 2 additions & 2 deletions mypy/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -1516,9 +1516,9 @@ def incompatible_conditional_function_def(
if isinstance(old_type, (CallableType, Overloaded)) and isinstance(
new_type, (CallableType, Overloaded)
):
self.note("Original:", defn)
self.note("Original:", defn, parent_error=error)
self.pretty_callable_or_overload(old_type, defn, offset=4, parent_error=error)
self.note("Redefinition:", defn)
self.note("Redefinition:", defn, parent_error=error)
self.pretty_callable_or_overload(new_type, defn, offset=4, parent_error=error)

def cannot_instantiate_abstract_class(
Expand Down
3 changes: 2 additions & 1 deletion mypy/plugins/proper_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def isinstance_proper_hook(ctx: FunctionContext) -> Type:
) and is_dangerous_target(right):
if is_special_target(right):
return ctx.default_return_type
ctx.api.fail(
parent_error = ctx.api.fail(
"Never apply isinstance() to unexpanded types;"
" use mypy.types.get_proper_type() first",
ctx.context,
Expand All @@ -72,6 +72,7 @@ def isinstance_proper_hook(ctx: FunctionContext) -> Type:
"If you pass on the original type"
" after the check, always use its unexpanded version",
ctx.context,
parent_error=parent_error,
)
return ctx.default_return_type

Expand Down
23 changes: 22 additions & 1 deletion test-data/unit/check-errorcodes.test
Original file line number Diff line number Diff line change
@@ -1,6 +1,27 @@
-- Tests for error codes and ignoring errors using error codes
--
-- These implicitly use --show-error-codes.
-- These implicitly use --show-error-codes. # TODO: isn't this statement redundant now that this flag defaults to true?

[case testErrorCodeMiscDoesntSuppressRevealType]
# Prevent regression on https://github.com/python/mypy/issues/19840
from typing import reveal_type
reveal_type(1) #type: ignore[misc] # N: Revealed type is "Literal[1]?"

[case testErrorCodeMiscDoesntSuppressRevealLocals]
reveal_locals() #type:ignore[misc] # N: There are no locals to reveal

[case testErrorCodeMiscSuppressesAccompanyingNotes]
# flags: --strict
if x: #type: ignore[name-defined]
def y() -> None: pass
else:
def y() -> bool: return True # type: ignore[misc]
def y() -> str: return "hmm" # All conditional function variants must have identical signatures [misc] # E: All conditional function variants must have identical signatures [misc] \
# N: Original: \
# N: def y() -> None \
# N: Redefinition: \
# N: def y() -> str


[case testErrorCodeNoAttribute]
import m
Expand Down
Loading