benoit-dubreuil / template-repo-cpp-ecosystem

Template repository for projects using C++ and its ecosystem
MIT License
0 stars 0 forks source link

Test `meta_prog/encapsulation` Package #180

Open benoit-dubreuil opened 3 years ago

benoit-dubreuil commented 3 years ago

Specifications

Tips

Use the following scratch code as a starting point.

from typing import Generic, TypeVar

from ext.meta_prog.generics.cls_proxy_injector import GenericClassProxyInjectorMixin

T_A = TypeVar('T_A')
T_B = TypeVar('T_B')
T_Cls = TypeVar('T_Cls', bound='TestGeneric')
T_Cls2 = TypeVar('T_Cls2', bound='TestGeneric2')
T_Cls3 = TypeVar('T_Cls3', bound='TestGeneric3')

class TestGeneric(GenericClassProxyInjectorMixin, Generic[T_A, T_B]):

    def __init__(self: T_Cls, *args, **kwargs) -> None:
        super().__init__(*args, **kwargs)

        print(self.has_generics())
        print(self.generics_by_type_vars)

        print()

class TestGeneric2(GenericClassProxyInjectorMixin, list[str]):

    def __init__(self: T_Cls2, *args, **kwargs) -> None:
        super().__init__(*args, **kwargs)

        print(self.has_generics())
        print(self.generics_by_type_vars)

        print()

class TestGeneric3(GenericClassProxyInjectorMixin, Generic[T_A], list[T_A]):

    def __init__(self: T_Cls3, *args, **kwargs) -> None:
        super().__init__(*args, **kwargs)

        print(self.has_generics())
        print(self.generics_by_type_vars)

        print()

tmp = TestGeneric[str, int]
tmp.__class__
test_obj = tmp()
test_obj = TestGeneric()

test_obj2 = TestGeneric2()
TestGeneric2.__class_getitem__(item=None).__class__

test_obj3 = TestGeneric3[str]()
test_obj3 = TestGeneric3()