Extend other classes to give them type checking via annotations
Project description
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)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
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 TypedClass-0.0.5-py3-none-any.whl.
File metadata
- Download URL: TypedClass-0.0.5-py3-none-any.whl
- Upload date:
- Size: 18.3 kB
- Tags: Python 3
- Uploaded using 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
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c1ce6a97d86b5adf1f9a7a291f67464b0f173829989e27e905cb28e4d044442a
|
|
| MD5 |
16b8572a9cc2bb260aca9858e77f27ae
|
|
| BLAKE2b-256 |
df6aaf4b7d39d6def458721749fa99cc2187f96e349934b2d8a09044f495893a
|