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

[BUG] [TYPING] Live class __enter__ method return type improperly annotated as "Live" instead of typing.Self #3644

Open
2 tasks done
AetherBreaker opened this issue Feb 28, 2025 · 1 comment

Comments

@AetherBreaker
Copy link

Describe the bug

The Live class's __enter__ method has an improperly annotated return type.

The method returns "Live", which causes improper type information when using context managers on subclasses of Live

In the example below, the live object returned by the context manager would be typed as an instance of Live instead of CustomLive by most type checkers.

from rich.live import Live


class CustomLive(Live):
    pass


with CustomLive() as live:
    ...

Suggested Fix
Replace the return type of the __enter__ method with typing.Self

from typing import Self

class Live(JupyterMixin, RenderHook):
    def __enter__(self) -> Self:
        self.start(refresh=self._renderable is not None)
        return self```
Copy link

Thank you for your issue. Give us a little time to review it.

PS. You might want to check the FAQ if you haven't done so already.

This is an automated reply, generated by FAQtory

@AetherBreaker AetherBreaker changed the title [BUG] [TYPING] Live class __enter__ method improperly returns "Live" instead of typing.Self [BUG] [TYPING] Live class __enter__ method return type improperly annotated as "Live" instead of typing.Self Feb 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant