10000 Show error codes for some notes by ilevkivskyi · Pull Request #13880 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

Show error codes for some notes #13880

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 1 commit into from
Oct 13, 2022
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
8000
Diff view
9 changes: 8 additions & 1 deletion mypy/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

T = TypeVar("T")

# Show error codes for some note-level messages (these usually appear alone
# and not as a comment for a previous error-level message).
SHOW_NOTE_CODES: Final = {codes.ANNOTATION_UNCHECKED}
allowed_duplicates: Final = ["@overload", "Got:", "Expected:"]

# Keep track of the original error code when the error code of a message is changed.
Expand Down Expand Up @@ -782,7 +785,11 @@ def format_messages(
s = f"{srcloc}: {severity}: {message}"
else:
s = message
if not self.hide_error_codes and code and severity != "note":
if (
not self.hide_error_codes
and code
and (severity != "note" or code in SHOW_NOTE_CODES)
):
# If note has an error code, it is related to a previous error. Avoid
# displaying duplicate error codes.
s = f"{s} [{code.code}]"
Expand Down
4 changes: 4 additions & 0 deletions test-data/unit/check-errorcodes.test
Original file line number Diff line number Diff line change
Expand Up @@ -966,6 +966,10 @@ T = TypeVar("T")
def test(tp: Type[T]) -> T: ...
test(C) # E: Only concrete class can be given where "Type[C]" is expected [type-abstract]

[case testUncheckedAnnotationCodeShown]
def f():
x: int = "no" # N: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs [annotation-unchecked]

[case testUncheckedAnnotationSuppressed]
# flags: --disable-error-code=annotation-unchecked
def f():
Expand Down
0