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

dmypy: Line number disappears when invoking multiple times #12498

Open
intgr opened this issue Mar 31, 2022 · 3 comments · May be fixed by #18161
Open

dmypy: Line number disappears when invoking multiple times #12498

intgr opened this issue Mar 31, 2022 · 3 comments · May be fixed by #18161
Labels
bug mypy got something wrong topic-daemon dmypy topic-error-reporting How we report errors

Comments

@intgr
Copy link
Contributor

intgr commented Mar 31, 2022

Bug Report

% dmypy restart
Daemon stopped
Daemon started
% dmypy run lib/testlib.py
lib/testlib.py:46: error: Unexpected attribute "xxxx" for model "Xxxx"
lib/testlib.py:142: error: The return type of a generator function should be "Generator" or one of its supertypes
Found 2 errors in 1 file (checked 945 source files)
% dmypy run lib/testlib.py
lib/testlib.py: error: The return type of a generator function should be "Generator" or one of its supertypes
lib/testlib.py:46: error: Unexpected attribute "xxxx" for model "Xxxx"
Found 2 errors in 1 file (checked 1 source file)

Note in the 2nd invocation lib/testlib.py: error: The return type of a generator function no longer has a line number.

To Reproduce

I tried reducing this to a smaller example, but failed to reproduce it that way. :(

Your Environment

  • Mypy version used: 0.942
  • Mypy command-line flags: (none)
  • Mypy configuration options from mypy.ini (and other config files): I can reproduce this when I delete mypy config of my project
  • Python version used: 3.10.2
  • Operating system and version: macOS
@intgr intgr added the bug mypy got something wrong label Mar 31, 2022
@AlexWaygood AlexWaygood added topic-daemon dmypy topic-error-reporting How we report errors labels Mar 31, 2022
@dubreuia
Copy link

I have the same issue

@ethanhs
Copy link
Collaborator

ethanhs commented Aug 5, 2022

Can one of you provide a project/example that reproduces this?

@bzoracler
Copy link
Contributor

bzoracler commented Nov 18, 2024

This issue seems to only occur with generator functions which are typed wrongly in the return type. Minimum reproducible example:

# generator_test.py

def gen() -> None:  # Deliberately wrong return type
    yield ""

With no daemon started, invoke dmypy run twice:

$ dmypy run .
Daemon started
generator_test.py:1: error: The return type of a generator function should be "Generator" or one of its supertypes  [misc]
$ dmypy run .
generator_test.py: error: The return type of a generator function should be "Generator" or one of its supertypes  [misc]

This doesn't happen when dmypy recheck is the second run, but as soon as dmypy run is run another time, the line number disappears:

$ dmypy run .
Daemon started
generator_test.py:1: error: The return type of a generator function should be "Generator" or one of its supertypes  [misc]
$ dmypy recheck
generator_test.py:1: error: The return type of a generator function should be "Generator" or one of its supertypes  [misc]
$ dmypy run .
generator_test.py: error: The return type of a generator function should be "Generator" or one of its supertypes  [misc]

If the return type is Generator or Iterator, this issue doesn't occur, even if the type argument isn't right:

# generator_test_2.py

from collections.abc import Iterator

def gen() -> Iterator[None]:  # Deliberately wrong return type
    yield ""
$ dmypy run .
Daemon started
generator_test_2.py:4: error: Incompatible types in "yield" (actual type "int", expected type "None")  [misc]
$ dmypy run .
generator_test_2.py:4: error: Incompatible types in "yield" (actual type "int", expected type "None")  [misc]

@bzoracler bzoracler linked a pull request Nov 18, 2024 that will close this issue
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 topic-error-reporting How we report errors
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants