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

fix crash issue when using shadowfile with pretty #17853#17894

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
JukkaL merged 4 commits intopython:masterfromchanghoetyng:test-#17853
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes fromall 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
18 changes: 17 additions & 1 deletionmypy/errors.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -922,9 +922,25 @@ def file_messages(self, path: str, formatter: ErrorFormatter | None = None) -> l
self.flushed_files.add(path)
source_lines = None
if self.options.pretty and self.read_source:
source_lines = self.read_source(path)
# Find shadow file mapping and read source lines if a shadow file exists for the given path.
# If shadow file mapping is not found, read source lines
mapped_path = self.find_shadow_file_mapping(path)
if mapped_path:
source_lines = self.read_source(mapped_path)
else:
source_lines = self.read_source(path)
return self.format_messages(error_tuples, source_lines)

def find_shadow_file_mapping(self, path: str) -> str | None:
"""Return the shadow file path for a given source file path or None."""
if self.options.shadow_file is None:
return None

for i in self.options.shadow_file:
if i[0] == path:
return i[1]
return None

def new_messages(self) -> list[str]:
"""Return a string list of new error messages.

Expand Down
17 changes: 17 additions & 0 deletionstest-data/unit/cmdline.test
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -914,6 +914,23 @@ s4.py:2: error: Incompatible return value type (got "int", expected "str")
s3.py:2: error: Incompatible return value type (got "List[int]", expected "int")
s1.py:2: error: Incompatible return value type (got "int", expected "str")

[case testShadowFileWithPretty]
# cmd: mypy a.py --pretty --shadow-file a.py b.py
[file a.py]
b: bytes
[file b.py]
a: int = ""
b: bytes = 1
[out]
a.py:1: error: Incompatible types in assignment (expression has type "str",
variable has type "int")
a: int = ""
^~
a.py:2: error: Incompatible types in assignment (expression has type "int",
variable has type "bytes")
b: bytes = 1
^

[case testConfigWarnUnusedSection1]
# cmd: mypy foo.py quux.py spam/eggs.py
[file mypy.ini]
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp