Skip to content
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

Unchecked annotation note causes dmypy to exit with code 1 on a successful run #14101

Closed
vtclose opened this issue Nov 15, 2022 · 4 comments · Fixed by #14102
Closed

Unchecked annotation note causes dmypy to exit with code 1 on a successful run #14101

vtclose opened this issue Nov 15, 2022 · 4 comments · Fixed by #14102
Labels
bug mypy got something wrong topic-daemon dmypy

Comments

@vtclose
Copy link

vtclose commented Nov 15, 2022

Bug Report

When the code triggers annotation-unchecked warnings, both mypy and dmypy print a green "success" line. However there's an unexpected difference between exit codes. Mypy exits with 0 as expected in a successful check, but dmypy exits with a 1. This prevents me from using dmypy in automated scenarios.

To Reproduce

# example.py
def example():
    a: int = 1
    print(a + "2")
$ mypy example.py; echo $?
example.py:2: note: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs  [annotation-unchecked]
Success: no issues found in 1 source file
0 # Good, expected

$ dmypy run example.py; echo $?
Daemon started
example.py:2: note: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs  [annotation-unchecked]
Success: no issues found in 44 source files
1 # Bad, unexpected

Expected Behavior

Successful runs should return zero exit code in both mypy and dmypy.

Environment

$ python -V
Python 3.10.8
$ mypy -V
mypy 0.991 (compiled: yes)

A fresh venv with latest mypy installed, no configuration files at all.

@vtclose vtclose added the bug mypy got something wrong label Nov 15, 2022
@neob91-close
Copy link
Contributor

I'm on top of this.

ilevkivskyi pushed a commit that referenced this issue Nov 15, 2022
Fixes: #14101

This prevents non-error messages (e.g. warnings) from causing dmypy to
return exit code 1.
@charlietsai
Copy link

Is there any way to make warnings fail if we wanted that? My team finds the annotation-unchecked useful but our CI builds continue to pass so we often miss the warnings and end up committing typed code that doesn't get checked.

@ilevkivskyi
Copy link
Member

Is there any way to make warnings fail if we wanted that?

I don't think there is a way, but I see how such a flag for mypy may be useful. I would suggest you open a separate issue for this. In the meantime I guess you can write a bash wrapper script that fails if mypy shows some notes.

@agerlic
Copy link

agerlic commented Apr 21, 2023

We've noticed a similar issue with MyPy 1.1.1, could it be a regression?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-daemon dmypy
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants