axabc
Advanced tools
| from .type_cheat import TypeCheat | ||
| __all__ = [ | ||
| 'TypeCheat', | ||
| ] | ||
| from typing import Generic, TypeVar, TYPE_CHECKING | ||
| TPrimaryType = TypeVar('TPrimaryType') | ||
| class TypeCheat(Generic[TPrimaryType]): | ||
| PrimaryType: type[TPrimaryType] | ||
| __abstract__ = True | ||
| if TYPE_CHECKING: | ||
| from typing import Self | ||
| def __new__(cls, *args, **kwargs) -> 'Self': | ||
| is_abstract = getattr(cls.__dict__, '__abstract__', False) | ||
| print(f'{is_abstract=}; {cls.PrimaryType=}') | ||
| if getattr(cls.__dict__, '__abstract__', False): | ||
| return super().__new__(cls) | ||
| return cls.PrimaryType(*args, **kwargs) # type: ignore | ||
| def __init_subclass__(cls) -> None: | ||
| if getattr(cls.__dict__, '__abstract__', False): | ||
| return | ||
| cls_name = cls.__new__ | ||
| if ( | ||
| not (bases := getattr(cls, "__orig_bases__")) | ||
| or not (generics := getattr(bases[0], '__args__')) | ||
| ): | ||
| raise RuntimeError( | ||
| f"Can't create fake type for {cls.__name__}" | ||
| "because it doesn't have any generic parameters" | ||
| "Use Example:\n" | ||
| f"class Some{cls_name}({cls_name}[SomeType]):\n\tpass" | ||
| ) | ||
| cls.PrimaryType: type[TPrimaryType] = generics[-1] | ||
| Metadata-Version: 2.1 | ||
| Name: axabc | ||
| Version: 0.0.62 | ||
| Version: 0.0.63 | ||
| Summary: library that defines abstractions for some repeated essences | ||
@@ -5,0 +5,0 @@ Author: axdjuraev |
@@ -32,2 +32,4 @@ README.md | ||
| axabc/test/__init__.py | ||
| axabc/test/base_async_test.py | ||
| axabc/test/base_async_test.py | ||
| axabc/types/__init__.py | ||
| axabc/types/type_cheat.py |
+1
-1
| Metadata-Version: 2.1 | ||
| Name: axabc | ||
| Version: 0.0.62 | ||
| Version: 0.0.63 | ||
| Summary: library that defines abstractions for some repeated essences | ||
@@ -5,0 +5,0 @@ Author: axdjuraev |
Alert delta unavailable
Currently unable to show alert delta for PyPI packages.
27624
5.07%36
5.88%599
5.64%