Python type hinting of "subclass of class a and b" with typevar

Viewed 203

I am making a decorator to generate ctypes.Structure with different fields,
I use a decorator to implement this idea but i dont know how to make a type hint of telling the return type is a subclass of given class and "class A", is there any way to tell ide b is a subclass of A and B ?

from ctypes import *
from typing import TypeVar, Type

_t = TypeVar('_t')


class A(Structure):
    pass


def make_a(cls: Type[_t]) -> Type[_t]: # if Type[_t] is used, attribute in A cant be hint
    # do something
    return type(cls.__name__, (cls, A), {
        '_fields_': [...],
    })


@make_a
class B:
    pass


b = B() # the ide cant determine b is also a subclass of A but only B
0 Answers
Related