Skip to main content

A simple fields descriptors tool

Project description

Installation

pip install py-desc

Usage

Simple built-in types

>>> from py_desc.built_in import *
>>>
>>> class YourClass:
...     bool_var = Boolean()
...     string_var = String()
...     positive_int_var = PositiveInteger()
>>>
>>> a = YourClass()
>>> a.positive_int_var = 5
>>> a.string_var = 'str'
>>> a.bool_var = True
>>>
>>> a.bool_var = 'string'
ValueError: Must be boolean
>>> a.string_var = 5
ValueError: Must be string
>>> a.positive_int_var = -10
ValueError: Cannot be negative

Custom Types

>>> from py_desc.built_in import *
>>>
>>> class YourCustomClass:
...     first = CustomInteger(left=5)
...     second = CustomInteger(right=10)
...     third = CustomInteger(left=1, right=10)
>>>
>>> a = YourClass()
>>> a.first = 2
ValueError: Cannot be smaller than 5
>>> a.second = 50
ValueError: Cannot be equal or bigger than 10
>>> a.third = 6  # OK. this value in range 1-10
>>> a.third = 12
ValueError: Cannot be not in range [1:10]
>>> from py_desc.built_in import *
>>>
>>> @dataclass
>>> class ExampleData:
...     name: str
...     age: int
>>>
>>>
>>> class YourCustomClass:
...     custom_list_int = CustomList(int)
...     custom_list_data = CustomList(ExampleData)
>>>
>>> a = YourCustomClass()
>>> a.custom_list_int = [5, 6, 3, 6]  # OK. The same type was given
>>> a.custom_list_int = [5.6, 2.1, 'str']
ValueError: Values in list must be int
>>> a.custom_list_data = [ExampleData(name='Carl', age=23), ExampleData(name='Daniel', age=21)]
>>> print(a.custom_list_data)
[ExampleData(name='Carl', age=23), ExampleData(name='Daniel', age=21)]
>>> a.custom_list_data = (ExampleData(name='Carl', age=23), ExampleData(name='Daniel', age=21))
ValueError: Must be list

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

py_desc-0.5.2.tar.gz (9.4 kB view details)

Uploaded Source

Built Distribution

py_desc-0.5.2-py3-none-any.whl (11.9 kB view details)

Uploaded Python 3

File details

Details for the file py_desc-0.5.2.tar.gz.

File metadata

  • Download URL: py_desc-0.5.2.tar.gz
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.10.2

File hashes

Hashes for py_desc-0.5.2.tar.gz
Algorithm Hash digest
SHA256 b18306264fbb2e0d7b18f19f5da45e92698f34da6a66a449347216c9fe37e95e
MD5 c9d118c2497c7bc52e65d6ec09254b6f
BLAKE2b-256 bba63de32a37a7c0c78c262d9bbc6efd2c018bdac2a7d1d92dc2ccb36c16096d

See more details on using hashes here.

File details

Details for the file py_desc-0.5.2-py3-none-any.whl.

File metadata

  • Download URL: py_desc-0.5.2-py3-none-any.whl
  • Upload date:
  • Size: 11.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.10.2

File hashes

Hashes for py_desc-0.5.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c314e492d253f2388fd79a8f25ed4db9fb6ec481f4516405dd1de284612864da
MD5 027930167d89a07bfe618c7f36883b91
BLAKE2b-256 86ee575290bad5cf1c8fb1f6d6119ce8e007ca1d7648335fc525290eaed10d06

See more details on using hashes here.

Supported by

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