Provides utilities for creating components
Project description
Classic Components
Предоставляет утилиты для удобного описания классов.
Главное, что предоставляет пакет - это декоратор component для обертывания классов. Класс, обернутый таким декоратором, называется далее компонентом, и обладает рядом свойств:
- автоматически сгенерированный конструктор на базе аннотаций (dataclass).
- добавляет "дополнительные аннотации" к аннотациям класса (подробности далее)
- добавляет автоматическую регистрацию инстансов в указанных реестрах
Простой пример:
from classic.components import component
@component
class SomeService:
prop: int
def action(self):
print(self.prop)
service = SomeService(prop=1)
service.action() # prints 1
Генерацию конструктора можно отключить:
from classic.components import component
@component(init=False)
class SomeService:
prop: int
def action(self):
print(self.prop)
service = SomeService(prop=1) # TypeError: SomeService() takes no arguments
Реестры
Также пакет предоставляет интерфейс для создания реестров и базовую реализацию реестра со слабыми ссылками. Это нужно не столько для кода приложений, сколько для других библиотек в платформе.
from classic.components import component, Registry, WeakSetRegistry
@component(init=False)
class SomeService:
registry: Registry
def action(self):
print(self.prop)
registry = WeakSetRegistry()
service = SomeService(registry=registry)
print(registry.storage)
# {<weakref at 0x109390fe0; to 'SomeService' at 0x10933ec50>}
Алиасы для dataclasses.field
Также есть алиасы для часто используемых параметров field из dataclasses:
from dataclasses import field
from classic.components import component, no_init, factory, default
@component
class SomeLogic:
some_list: field(default_factory=list)
analog: factory(list) # то же самое
some_str: str = field(default='Hello')
analog_str: str = default('Hello')
_some_field: int = field(default=0, init=False)
_analog: int = no_init(0) # то же самое
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file classic_components-1.3.2.tar.gz.
File metadata
- Download URL: classic_components-1.3.2.tar.gz
- Upload date:
- Size: 9.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0e97d3c28fa6584cc4c5f0bd5ef3a534c96673a2daa120ed8d98eb0e06e190d9
|
|
| MD5 |
5ac82e1c415eb521f45b9072630c9a35
|
|
| BLAKE2b-256 |
d75906b546c6355e35dfae1ce90432c490e8aa171c07056e770a0e8e622143b3
|
Provenance
The following attestation bundles were made for classic_components-1.3.2.tar.gz:
Publisher:
publish.yml on variasov/classic-components
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
classic_components-1.3.2.tar.gz -
Subject digest:
0e97d3c28fa6584cc4c5f0bd5ef3a534c96673a2daa120ed8d98eb0e06e190d9 - Sigstore transparency entry: 499556274
- Sigstore integration time:
-
Permalink:
variasov/classic-components@41358b74f98074d73b5c1213208e8dbce074686c -
Branch / Tag:
refs/heads/main - Owner: https://github.com/variasov
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@41358b74f98074d73b5c1213208e8dbce074686c -
Trigger Event:
push
-
Statement type:
File details
Details for the file classic_components-1.3.2-py3-none-any.whl.
File metadata
- Download URL: classic_components-1.3.2-py3-none-any.whl
- Upload date:
- Size: 9.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4f18aecad07603a97bfa123baba18a45857e076fad5cfa73664dcecfeeed13cd
|
|
| MD5 |
2e24f9d16af4bacc115d69a7f45cc7fa
|
|
| BLAKE2b-256 |
8041f7025c9ce728ac6037c1ab8f9dbd81351cff6c695264b962096dc7752927
|
Provenance
The following attestation bundles were made for classic_components-1.3.2-py3-none-any.whl:
Publisher:
publish.yml on variasov/classic-components
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
classic_components-1.3.2-py3-none-any.whl -
Subject digest:
4f18aecad07603a97bfa123baba18a45857e076fad5cfa73664dcecfeeed13cd - Sigstore transparency entry: 499556301
- Sigstore integration time:
-
Permalink:
variasov/classic-components@41358b74f98074d73b5c1213208e8dbce074686c -
Branch / Tag:
refs/heads/main - Owner: https://github.com/variasov
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@41358b74f98074d73b5c1213208e8dbce074686c -
Trigger Event:
push
-
Statement type: