Wrong column reported for errors in function sig type comments
Open
Nobody has claimed this yet.
bug
priority-2-low
topic-error-reporting
topic-usability
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
For the following code
def extract_commit_hash(line): # type: (str) -> Optional[str]
...
def extract_commit_hash2(line): # type: (str) -> Optional(str)
...
mypy reports wrong columns:

mypy output:
> mypy --pretty --follow-imports skip --show-column-numbers --show-error-codes wrong-col.py
wrong-col.py:3:10: error: Name 'Optional' is not defined [name-defined]
def extract_commit_hash(line): # type: (str) -> Optional[str]
^
wrong-col.py:3:10: note: Did you forget to import it from "typing"? (Suggestion: "from typing import Optional")
wrong-col.py:6:10: error: Invalid type comment or annotation [valid-type]
def extract_commit_hash2(line): # type: (str) -> Optional(str)
^
wrong-col.py:6:10: note: Suggestion: use Optional[...] instead of Optional(...)
Found 2 errors in 1 file (checked 1 source file)
From what I found the reported column is always 10 even if the code is more indented.

Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the report with the shown wrong-col.py example and the mypy command using --show-column-numbers. Trace how diagnostics for function signature type comments calculate their column, then verify that errors in differently indented functions point to the relevant source location rather than a fixed column.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100