Provides utilities for creating components
Project description
Classic Components
Этот пакет предоставляет функциональность компонентов. Является частью проекта "Classic".
Главное, что предоставляет пакет - это декоратор component для обертывания классов. Класс, обернутый таким декоратором, называется далее компонентом, и обладает рядом свойств:
- автоматически сгенерированный конструктор на базе аннотаций.
- добавляет "дополнительные аннотации" к аннотациям класса (подробности далее)
- добавляет автоматическую регистрацию инстансов в указанных реестрах
Простой пример:
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
Также есть алиасы для часто используемых параметров field из dataclasses:
from dataclasses import field
from classic.components import component, no_init, factory
@component
class SomeLogic:
some_list: field(default_factory=list)
analog: factory(list) # то же самое
_some_field: object = field(init=False)
_analog: object = no_init # то же самое
Реестры
Также пакет предоставляет интерфейс для создания реестров и базовую реализацию реестра со слабыми ссылками. Это нужно не столько для кода приложений, сколько для других библиотек в платформе.
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>}
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.0.tar.gz.
File metadata
- Download URL: classic_components-1.3.0.tar.gz
- Upload date:
- Size: 10.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
933309e1ea0d6643ace4e2281519bb4b248e85472149f49342894249790286f5
|
|
| MD5 |
095d576ea36b1f60465c1e1a08aa7884
|
|
| BLAKE2b-256 |
81ca08073610b504b5f789396e77ba9433a77a139e82843a2c985a86a53e07e5
|
File details
Details for the file classic_components-1.3.0-py3-none-any.whl.
File metadata
- Download URL: classic_components-1.3.0-py3-none-any.whl
- Upload date:
- Size: 11.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e8b091f84dc98a2abf67de5918b4b6bc3aea09279ac90ffd5939241e84d41592
|
|
| MD5 |
ed61990c77944b7b81617677bb0c5d3c
|
|
| BLAKE2b-256 |
94430b950277b67f6de0a9b64686e25875840bfd620f8b5e1365023c06a9f78e
|