Skip to content

Use more precise context for invalid type argument errors#18290

Merged
hauntsaninja merged 2 commits intopython:masterfrom
brianschubert:gh-12274-typearg-col-number
Dec 14, 2024
Merged

Use more precise context for invalid type argument errors#18290
hauntsaninja merged 2 commits intopython:masterfrom
brianschubert:gh-12274-typearg-col-number

Conversation

@brianschubert
Copy link
Collaborator

Fixes #12274

Uses the actual invalid type argument as the error context when possible.

Given:

# flags: --pretty --show-column-number
class Foo[S, T: int]: 
    pass

x: Foo[str, str]

Before:

main.py:3:4: error: Type argument "str" of "Foo" must be a subtype of "int"  [type-var]
    x: Foo[str, str]
       ^

After:

main.py:3:13: error: Type argument "str" of "Foo" must be a subtype of "int"  [type-var]
    x: Foo[str, str]
                ^

@github-actions
Copy link
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

AutoSplit (https://github.com/Toufool/AutoSplit)
- typings/cv2/mat_wrapper/__init__.pyi:7:23: error: Type argument "float" of "ndarray" must be a subtype of "tuple[int, ...]"  [type-var]
+ typings/cv2/mat_wrapper/__init__.pyi:7:34: error: Type argument "float" of "ndarray" must be a subtype of "tuple[int, ...]"  [type-var]

@hauntsaninja hauntsaninja merged commit 9db2368 into python:master Dec 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

(🐞) Wrong column number for "Invalid location for ParamSpec"

2 participants