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

Fix bug where Y019 was not emitted on methods that use PEP-695 TypeVars #402

Merged
merged 1 commit into from
Jun 19, 2023

Conversation

AlexWaygood
Copy link
Collaborator

And add a lot more tests that use PEP-695 syntax. Closes #391.

Comment on lines +43 to +44
def __new__[S](cls: type[S], *args: Any, **kwargs: Any) -> S: ... # Y019 Use "typing_extensions.Self" instead of "S", e.g. "def __new__(cls, *args: Any, **kwargs: Any) -> Self: ..."
def generic_instance_method[S](self: S) -> S: ... # Y019 Use "typing_extensions.Self" instead of "S", e.g. "def generic_instance_method(self) -> Self: ..."
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Y019 is not emitted on these two methods on main

@github-actions
Copy link

This change has no effect on typeshed. 🤖🎉

@AlexWaygood AlexWaygood merged commit e52d86d into main Jun 19, 2023
@AlexWaygood AlexWaygood deleted the 695 branch June 19, 2023 15:12
charliermarsh pushed a commit to astral-sh/ruff that referenced this pull request Aug 3, 2023
)

## Summary

Implements `Y019` from
[flake8-pyi](https://github.com/PyCQA/flake8-pyi).

The rule checks if

-  instance methods that return `self` 
-  class methods that return an instance of `cls`
- `__new__` methods

Return a custom `TypeVar` instead of `typing.Self` and raises a
violation if this is the case. The rule also covers
[PEP-695](https://peps.python.org/pep-0695/) syntax as introduced in
upstream in PyCQA/flake8-pyi#402

## Test Plan

Added fixtures with test cases from upstream implementation (plus
additional one for an excluded edge case, mentioned in upstream
implementation)
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.

Add tests for stubs that use PEP-695 syntax
2 participants