8000 Return 0 if there are only notes and no errors by ilevkivskyi · Pull Request #13879 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

Return 0 if there are only notes and no errors #13879

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 2 commits into from
Oct 14, 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
Diff view
4 changes: 2 additions & 2 deletions mypy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,10 @@ def main(
print_memory_profile()

code = 0
if messages:
n_errors, n_notes, n_files = util.count_stats(messages)
if messages and n_notes < len(messages):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: from the impl, it looks like it's not super guaranteed that n_errors + n_notes == len(messages), maybe clearer to phrase as if messages and n_errors?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, this is intentional. This case is complementary to the check for format_success() below. So that if something weird happens we both:

  • Do not show Success message
  • Return non 0 code

code = 2 if blockers else 1
if options.error_summary:
n_errors, n_notes, n_files = util.count_stats(messages)
if n_errors:
summary = formatter.format_error(
n_errors, n_files, len(sources), blockers=blockers, use_color=options.color_output
Expand Down
2 changes: 1 addition & 1 deletion mypy/test/testpythoneval.py
< 8000 /tr>
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def test_python_evaluation(testcase: DataDrivenTestCase, cache_dir: str) -> None
# Normalize paths so that the output is the same on Windows and Linux/macOS.
line = line.replace(test_temp_dir + os.sep, test_temp_dir + "/")
output.append(line.rstrip("\r\n"))
if returncode == 0:
if returncode == 0 and not output:
# Execute the program.
proc = subprocess.run(
[interpreter, "-Wignore", program], cwd=test_temp_dir, capture_output=True
Expand Down
41 changes: 31 additions & 10 deletions test-data/unit/cmdline.test
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ follow_imports = skip
[out]
main.py:2: note: Revealed type is "Any"
main.py:4: note: Revealed type is "Any"
== Return code: 0

[case testConfigFollowImportsError]
# cmd: mypy main.py
Expand Down Expand Up @@ -517,7 +518,7 @@ reveal_type(missing.x) # Expect Any
ignore_missing_imports = True
[out]
main.py:2: note: Revealed type is "Any"

== Return code: 0

[case testFailedImportOnWrongCWD]
# cmd: mypy main.py
Expand Down Expand Up @@ -654,15 +655,26 @@ python_version = 3.6
[file int_pow.py]
a = 1
b = a + 2
reveal_type(a**0) # N: Revealed type is "Literal[1]"
reveal_type(a**1) # N: Revealed type is "builtins.int"
reveal_type(a**2) # N: Revealed type is "builtins.int"
reveal_type(a**-0) # N: Revealed type is "Literal[1]"
reveal_type(a**-1) # N: Revealed type is "builtins.float"
reveal_type(a**(-2)) # N: Revealed type is "builtins.float"
reveal_type(a**b) # N: Revealed type is "Any"
reveal_type(a.__pow__(2)) # N: Revealed type is "builtins.int"
reveal_type(a.__pow__(a)) # N: Revealed type is "Any"
reveal_type(a**0)
reveal_type(a**1)
reveal_type(a**2)
reveal_type(a**-0)
reveal_type(a**-1)
reveal_type(a**(-2))
reveal_type(a**b)
reveal_type(a.__pow__(2))
reveal_type(a.__pow__(a))
[out]
int_pow.py:3: note: Revealed type is "Literal[1]"
int_pow.py:4: note: Revealed type is "builtins.int"
int_pow.py:5: note: Revealed type is "builtins.int"
int_pow.py:6: note: Revealed type is "Literal[1]"
int_pow.py:7: note: Revealed type is "builtins.float"
int_pow.py:8: note: Revealed type is "builtins.float"
int_pow.py:9: note: Revealed type is "Any"
int_pow.py:10: note: Revealed type is "builtins.int"
int_pow.py:11: note: Revealed type is "Any"
== Return code: 0

[case testDisallowAnyGenericsBuiltinCollections]
# cmd: mypy m.py
Expand Down Expand Up @@ -1484,3 +1496,12 @@ pass
[out]
Warning: --enable-recursive-aliases is deprecated; recursive types are enabled by default
== Return code: 0

[case testNotesOnlyResultInExitSuccess]
# cmd: mypy a.py
[file a.py]
def f():
x: int = "no"
[out]
a.py:2: note: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs
== Return code: 0
0