TypedClass
A python class made for extended other classes giving them type checking on annotated attributes and other nice things like required attributes, immutable attributes, validation functions for attributes, choices for attributes.
Example Usage
TypedClass
from TypedClass import TypedClass, TypeDef
class ExampleTypedClass(TypedClass):
simple: int
using_type_def: TypeDef(typeof=int)
simple_with_default: float = 1.01
type_hint_with_default: TypeDef(
typeof=int
) = 22
all_options: TypeDef(
typeof=int,
required=True,
immutable=True,
choices=[21, 22, 23],
validate_fn=lambda x: x > 20
) = 23
def __init__(
self,
simple: int,
using_type_def: int,
simple_with_default: float = 1.01,
type_hint_with_default: int = 22,
all_options: int = 23,
):
super().__init__(
simple=simple,
using_type_def=using_type_def,
simple_with_default=simple_with_default,
type_hint_with_default=type_hint_with_default,
all_options=all_options
)
TypedClassStrict
Same as above, only everything is set to required and immutable by default.
TypedClassJson
from TypedClass import TypedClassJson
class ExampleJSONValidationUsageObj(TypedClassJson):
name: str
value: str
valid: bool
class ExampleJSONValidationUsageWithHelperClass(TypedClassJson):
_id: int
sender: str
kind: str
nested_obj: ExampleJSONValidationUsageObj
nested_obj_with_help: ExampleJSONValidationUsageObj
example_json = {
'_id': 1,
'sender': 'nic',
'kind': 'message',
'nested_obj': {
'name': 'nested_obj',
'value': 'cool',
'valid': True
},
'nested_obj_with_help': {
'name': 'nested_obj_with_help',
'value': 'very cool',
'valid': True
}
}
# ...
import unittest
json_output_example = ExampleJSONValidationUsageWithHelperClass(example_json)
tc = unittest.TestCase('__init__')
tc.assertEqual(example_json, json_output_example.dict)
Metadata
Release files for TypedClass 0.0.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| TypedClass-0.0.5-py3-none-any.whl | Python 3 | none | any | Details |
Release files / TypedClass-0.0.5-py3-none-any.whl
| Download URL | TypedClass-0.0.5-py3-none-any.whl |
|---|---|
| Size | 18.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c1ce6a97d86b5adf1f9a7a291f67464b0f173829989e27e905cb28e4d044442a
|
|
BLAKE2b-256 checksum How to use checksums |
df6aaf4b7d39d6def458721749fa99cc2187f96e349934b2d8a09044f495893a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.7
|