Skip to content

dmypy suggest generates syntax error in annotation in some cases #18934

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

Open
asottile-sentry opened this issue Apr 17, 2025 · 0 comments
Open
Labels
bug mypy got something wrong topic-daemon dmypy

Comments

@asottile-sentry
Copy link

asottile-sentry commented Apr 17, 2025

Bug Report

sometimes dmypy puts a : for some annotations instead of a . and is inconsistent with some types from typing

To Reproduce

class C: pass

def f1():
    return [C()]

def f2():
    return [1]

def f3():
    return (C(),)

def f4():
    return (1,)
[mypy]
check_untyped_defs = true

Expected Behavior

$ dmypy run .
...
$ dmypy suggest t.f1
() -> List[t.C]
$ dmypy suggest t.f2
() -> List[int]
$ dmypy suggest t.f3
() -> Tuple[t.C]
$ dmypy suggest t.f4
() -> Tuple[int]

Actual Behavior

$ dmypy run .
...
$ dmypy suggest t.f1
() -> typing:List[t.C]
$ dmypy suggest t.f2
() -> typing.List[int]
$ dmypy suggest t.f3
() -> Tuple[t.C]
$ dmypy suggest t.f4
() -> Tuple[int]

two separate oddities here:

  • the first produces typing:List (with a colon) instead of typing.List (the colon appears to come from here --
    delim = "." if "." not in obj else ":"
    )
    • I guess the colon is supposed to help with differentiating mod.Class.NestedClass vs mod.submod.Class ? though it seems to make no sense for List here
  • typing.List and Tuple should either both be fully qualified or neither

Your Environment

  • Mypy version used: 1.15.0
  • Mypy command-line flags: see above
  • Mypy configuration options from mypy.ini (and other config files): see above
  • Python version used: 3.13.1
@asottile-sentry asottile-sentry added the bug mypy got something wrong label Apr 17, 2025
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

No branches or pull requests

2 participants