Use more precise context for invalid type argument errors by brianschubert · Pull Request #18290 · python/mypy (original) (raw)

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 andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation1 Commits2 Checks18 Files changed

Conversation

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters

[ Show hidden characters]({{ revealButtonHref }})

brianschubert

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

@brianschubert

@brianschubert

@github-actions GitHub Actions

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

AutoSplit (https://github.com/Toufool/AutoSplit)

hauntsaninja

2 participants

@brianschubert @hauntsaninja