'Type hinting on __aenter__ with generic inheritance is broken in PyCharm?

I have this simple example of a Generic class with a __aenter__:

from typing import TypeVar, Generic

T = TypeVar('T')


class A(Generic[T]):
    async def __aenter__(self):
        return self


class B(A[int]):
    def b(self): pass


async with B() as b:
    b.b

For some reasons PyCharm doesn't show b() as an available function With generics

But when I remove generics from classes:

from typing import TypeVar, Generic

T = TypeVar('T')


class A:
    async def __aenter__(self):
        return self


class B(A):
    def b(self): pass


async with B() as b:
    b.b()

I get b() available

Without generics

What's wrong? And is the only way to bypass it - overriding __aenter__ for every subclass?

PyCharm 2021.3



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source