Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add option to show links to error code docs (once per code)#15449

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
ilevkivskyi merged 6 commits intopython:masterfromilevkivskyi:add-error-links
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from1 commit
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
PrevPrevious commit
NextNext commit
Address CR; dogfood
  • Loading branch information
@ilevkivskyi
ilevkivskyi committedJun 16, 2023
commit179b553bbe8338ba5ff5d1a7b6c9e50756ddfd22
86 changes: 58 additions & 28 deletionsmypy/errors.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -108,6 +108,7 @@ def __init__(
allow_dups: bool,
origin: tuple[str, Iterable[int]] | None = None,
target: str | None = None,
priority: int = 0,
) -> None:
self.import_ctx = import_ctx
self.file = file
Expand All@@ -126,6 +127,7 @@ def __init__(
self.allow_dups = allow_dups
self.origin = origin or (file, [line])
self.target = target
self.priority = priority


# Type used internally to represent errors:
Expand DownExpand Up@@ -436,34 +438,6 @@ def report(
target=self.current_target(),
)
self.add_error_info(info)
if (
self.options.show_error_code_links
and not self.options.hide_error_codes
and code is not None
):
message = f"See {BASE_RTD_URL}-{code.code} for information about this error"
if offset:
message = " " * offset + message
info = ErrorInfo(
self.import_context(),
file,
self.current_module(),
type,
function,
line,
column,
end_line,
end_column,
"note",
message,
code,
blocker=False,
only_once=True,
allow_dups=False,
origin=(self.file, origin_span),
target=self.current_target(),
)
self.add_error_info(info)

def _add_error_info(self, file: str, info: ErrorInfo) -> None:
assert file not in self.flushed_files
Expand DownExpand Up@@ -558,6 +532,34 @@ def add_error_info(self, info: ErrorInfo) -> None:
allow_dups=False,
)
self._add_error_info(file, note)
if (
self.options.show_error_code_links
and not self.options.hide_error_codes
and info.code is not None
):
message = f"See {BASE_RTD_URL}-{info.code.code} for more info"
if message in self.only_once_messages:
return
self.only_once_messages.add(message)
info = ErrorInfo(
info.import_ctx,
info.file,
info.module,
info.type,
info.function_or_member,
info.line,
info.column,
info.end_line,
info.end_column,
"note",
message,
info.code,
blocker=False,
only_once=True,
allow_dups=False,
priority=20,
)
self._add_error_info(file, info)

def has_many_errors(self) -> bool:
if self.options.many_errors_threshold < 0:
Expand DownExpand Up@@ -1069,6 +1071,34 @@ def sort_messages(self, errors: list[ErrorInfo]) -> list[ErrorInfo]:

# Sort the errors specific to a file according to line number and column.
a = sorted(errors[i0:i], key=lambda x: (x.line, x.column))
a = self.sort_within_context(a)
result.extend(a)
return result

def sort_within_context(self, errors: list[ErrorInfo]) -> list[ErrorInfo]:
"""For the same location decide which messages to show first/last.

Currently, we only compare within the same error code, to decide the
order of various additional notes.
"""
result = []
i = 0
while i < len(errors):
i0 = i
# Find neighbouring errors with the same position and error code.
while (
i + 1 < len(errors)
and errors[i + 1].line == errors[i].line
and errors[i + 1].column == errors[i].column
and errors[i + 1].end_line == errors[i].end_line
and errors[i + 1].end_column == errors[i].end_column
and errors[i + 1].code == errors[i].code
):
i += 1
i += 1

# Sort the messages specific to a given error by priority.
a = sorted(errors[i0:i], key=lambda x: x.priority)
result.extend(a)
return result

Expand Down
1 change: 1 addition & 0 deletionsmypy_self_check.ini
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,6 +9,7 @@ plugins = misc/proper_plugin.py
python_version = 3.7
exclude = mypy/typeshed/|mypyc/test-data/|mypyc/lib-rt/
enable_error_code = ignore-without-code,redundant-expr
show_error_code_links = True

[mypy-mypy.visitor]
# See docstring for NodeVisitor for motivation.
Expand Down
8 changes: 7 additions & 1 deletiontest-data/unit/check-flags.test
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2200,5 +2200,11 @@ cb(fn)
# flags: --show-error-codes --show-error-code-links

x: int = "" # E: Incompatible types in assignment (expression has type "str", variable has type "int") [assignment] \
# N: See https://mypy.rtfd.io/en/stable/_refs.html#code-assignment forinformation about this error
# N: See https://mypy.rtfd.io/en/stable/_refs.html#code-assignment formore info
y: int = "" # E: Incompatible types in assignment (expression has type "str", variable has type "int") [assignment]
list(1) # E: No overload variant of "list" matches argument type "int" [call-overload] \
# N: Possible overload variants: \
# N: def [T] __init__(self) -> List[T] \
# N: def [T] __init__(self, x: Iterable[T]) -> List[T] \
# N: See https://mypy.rtfd.io/en/stable/_refs.html#code-call-overload for more info
[builtins fixtures/list.pyi]

[8]ページ先頭

©2009-2026 Movatter.jp