Skip to content

Making a subclass of a non-generic subclass of ContextManager more specific #3839

@OddBloke

Description

@OddBloke

Given the following classes:

from typing import ContextManager

class SuperClass(ContextManager[SuperClass]): ...
class FirstSubClass(SuperClass): ...
class SecondSubClass(SuperClass, ContextManager[SecondSubClass]): ...

a reveal_type for each C.__enter__ gives:

cm.py:24: error: Revealed type is 'def () -> cm.SuperClass*'
cm.py:25: error: Revealed type is 'def () -> cm.SuperClass*'
cm.py:26: error: Revealed type is 'def () -> cm.SuperClass*'

What I'm trying to express is that the final one should be 'def () -> cm.SecondSubClass'. Is there a neat way of expressing what I want?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions