Skip to content

Use more precise context for invalid type argument errors #18290

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

Merged
merged 2 commits into from
Dec 14, 2024

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]
                ^

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
19 checks passed
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