Skip to content

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

@AetherBreaker

Description

@AetherBreaker

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```

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions