Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

classic_components-1.3.2.tar.gz (9.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

classic_components-1.3.2-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

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

Hashes for classic_components-1.3.2.tar.gz
Algorithm Hash digest
SHA256 0e97d3c28fa6584cc4c5f0bd5ef3a534c96673a2daa120ed8d98eb0e06e190d9
MD5 5ac82e1c415eb521f45b9072630c9a35
BLAKE2b-256 d75906b546c6355e35dfae1ce90432c490e8aa171c07056e770a0e8e622143b3

See more details on using hashes here.

Provenance

The following attestation bundles were made for classic_components-1.3.2.tar.gz:

Publisher: publish.yml on variasov/classic-components

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file classic_components-1.3.2-py3-none-any.whl.

File metadata

File hashes

Hashes for classic_components-1.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4f18aecad07603a97bfa123baba18a45857e076fad5cfa73664dcecfeeed13cd
MD5 2e24f9d16af4bacc115d69a7f45cc7fa
BLAKE2b-256 8041f7025c9ce728ac6037c1ab8f9dbd81351cff6c695264b962096dc7752927

See more details on using hashes here.

Provenance

The following attestation bundles were made for classic_components-1.3.2-py3-none-any.whl:

Publisher: publish.yml on variasov/classic-components

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page