-
Notifications
You must be signed in to change notification settings - Fork 1
Core: TypedClass
Izhar Ahmad edited this page Feb 2, 2022
·
2 revisions
Represents a typed class that provides type validation at runtime.
class User(typedclass.TypedClass):
id: int
name: str
email: typing.Optional[str] = None # default value is set so this is optional.
>>> User(id=1, name='foo') # ok
>>> User(id='1', name='foo')
TypeError: Parameter 'id' in User() must be an instance of <class 'int'>, Not <class 'str'>
Following generic classes from typing
module are also supported and properly validated by this class:
- typing.Optional
- typing.Union
- typing.Type
- typing.Literal
Support for other generic types will also be added soon. If you want to suggest one, Consider opening an issue on our GitHub repository!
- ignore_internal: builtins.bool
- Whether to ignore the annotations starting with single underscore.
Defaults to
True
. - ignore_extra: builtins.bool
- Whether to ignore extra keyword parameters passed during initialization.
Defaults to
False
.