forked from Github-Mirrors/canaille
perf: cache the class attributes
This commit is contained in:
parent
2cab4bfa66
commit
6251455a1d
1 changed files with 16 additions and 12 deletions
|
@ -44,8 +44,11 @@ class Model:
|
|||
the value MUST be the same as the value of :attr:`~canaille.backends.models.Model.created`.
|
||||
"""
|
||||
|
||||
_attributes = None
|
||||
|
||||
@classproperty
|
||||
def attributes(cls):
|
||||
if not cls._attributes:
|
||||
annotations = ChainMap(
|
||||
*(
|
||||
typing.get_type_hints(klass)
|
||||
|
@ -54,11 +57,12 @@ class Model:
|
|||
)
|
||||
)
|
||||
# only keep types that are not typing.ClassVar
|
||||
return {
|
||||
cls._attributes = {
|
||||
key: value
|
||||
for key, value in annotations.items()
|
||||
if typing.get_origin(value) is not typing.ClassVar
|
||||
}
|
||||
return cls._attributes
|
||||
|
||||
|
||||
class BackendModel:
|
||||
|
|
Loading…
Reference in a new issue