Skip to content

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.

@github-actions
Copy link
Contributor

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


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
@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.

4 participants