Skip to content
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

[PEP 695] Detect errors related to mixing old and new style features #17269

Merged
merged 2 commits into from
May 30, 2024

Conversation

JukkaL
Copy link
Collaborator

@JukkaL JukkaL commented May 20, 2024

Generic[...] or Protocol[...] shouldn't be used with new-style syntax.

Generic functions and classes using the new syntax shouldn't mix new-style and
old-style type parameters.

Work on #15238.

Copy link
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

@@ -2421,6 +2421,10 @@ def annotation_in_unchecked_function(self, context: Context) -> None:
code=codes.ANNOTATION_UNCHECKED,
)

def type_parameters_should_be_declared(self, undeclared: list[str], context: Context) -> None:
names = ", ".join('"' + n + '"' for n in undeclared)
self.fail(f"All type parameters should be declared ({names} not declared)", context)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this error message more explicitly refer to "mixing" PEP 695 type variables vs legacy type variables?

I'm sure users would figure it out, but the legacy type variables are "declared" in some sense so it may confuse folks.

(Also I realize fine tuning the error messages can be done later, I just was briefly confused when skimming)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is fine for now; I couldn't think of a better wording immediately.

@JukkaL JukkaL merged commit 7032f8c into master May 30, 2024
18 checks passed
@JukkaL JukkaL deleted the type-var-syntax-4-old-and-new branch May 30, 2024 14:22
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.

3 participants