Skip to content

Conversation

@wookie184
Copy link
Contributor

Add some missing Self return annotations in redis

Source for Monitor.__aenter__:
https://github.com/redis/redis-py/blob/e39c7babdd80ecdd930bed9d201e8fb9187309ac/redis/asyncio/client.py#L571

Source for PubSub.__aenter__:
https://github.com/redis/redis-py/blob/e39c7babdd80ecdd930bed9d201e8fb9187309ac/redis/asyncio/client.py#L671

The non-async equivalents already seem to be correct (e.g.

def __enter__(self: Self) -> Self: ...
)

Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

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

Thanks! We're not yet able to use typing(_extensions).Self due to lack of mypy support, so we currently use _typeshed.Self instead. _typeshed.Self is just a normal TypeVar, so you have to annotate the parameter as well as the return type:

@AlexWaygood
Copy link
Member

(Mypy already has support for typing(_extensions).Self on the master branch; we're just waiting for version 1.0 to be released.)

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

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

Thank you!

@github-actions
Copy link
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@AlexWaygood AlexWaygood merged commit 0024dc4 into python:main Jan 28, 2023
Avasam pushed a commit to Avasam/typeshed that referenced this pull request Feb 1, 2023
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.

2 participants