python / python/mypy

dmypy suggest generates syntax error in annotation in some cases

Open
#18,934 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug topic-daemon
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

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:

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with the shown dmypy suggest examples, then inspect mypy/suggestions.py around line 853 to trace how annotation names are formatted. Done means the List and Tuple outputs use consistent qualification and no annotation contains the erroneous colon; verify against all four examples.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
50/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.