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] Add more error checks and tests for error conditions #17339

Merged
merged 5 commits into from
Jun 14, 2024

Conversation

JukkaL
Copy link
Collaborator

@JukkaL JukkaL commented Jun 6, 2024

Detect invalid number of constrained types. At least two are required, according do PEP 695.

Add tests for other simple errors.

Work on #15238.

This comment has been minimized.

This comment has been minimized.

@@ -330,3 +330,6 @@ def with_additional_msg(self, info: str) -> ErrorMessage:
NARROWED_TYPE_NOT_SUBTYPE: Final = ErrorMessage(
"Narrowed type {} is not a subtype of input type {}", codes.NARROWED_TYPE_NOT_SUBTYPE
)
TYPE_VAR_TOO_FEW_CONSTRAINED_TYPES: Final = ErrorMessage(
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this message be reused in semanal.py where a TypeVar cannot have only a single constraint message is used inline? This should help with discoverability of two TypeVar syntax variants constraints, because they share some common argument validation logic.

Copy link
Member

Choose a reason for hiding this comment

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

I agree, if there are not too many tests to update, we should reuse the same message for both old and new style variables.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I made the error messages consistent.

Copy link
Member

@ilevkivskyi ilevkivskyi left a comment

Choose a reason for hiding this comment

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

LG, only minor things.

@@ -271,7 +271,7 @@ def __hash__(self) -> int:
del error_codes[FILE.code]

# This is a catch-all for remaining uncategorized errors.
MISC: Final = ErrorCode("misc", "Miscellaneous other checks", "General")
MISC: Final[ErrorCode] = ErrorCode("misc", "Miscellaneous other checks", "General")
Copy link
Member

Choose a reason for hiding this comment

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

Is this because we are not deferring top-levels, LOL?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Possibly, though I didn't look into this in any detail. This is not the first instance of this issue in this module.

@@ -330,3 +330,6 @@ def with_additional_msg(self, info: str) -> ErrorMessage:
NARROWED_TYPE_NOT_SUBTYPE: Final = ErrorMessage(
"Narrowed type {} is not a subtype of input type {}", codes.NARROWED_TYPE_NOT_SUBTYPE
)
TYPE_VAR_TOO_FEW_CONSTRAINED_TYPES: Final = ErrorMessage(
Copy link
Member

Choose a reason for hiding this comment

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

I agree, if there are not too many tests to update, we should reuse the same message for both old and new style variables.

Copy link
Contributor

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

@JukkaL JukkaL merged commit 740d39e into master Jun 14, 2024
19 checks passed
@JukkaL JukkaL deleted the type-var-syntax-error-checks branch June 14, 2024 15:43
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