Skip to content

Commit

Permalink
cached type hints
Browse files Browse the repository at this point in the history
  • Loading branch information
abyesilyurt committed Jun 25, 2024
1 parent 9e71b68 commit 3ac23c0
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/syft/src/syft/types/syft_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from collections.abc import Mapping
from collections.abc import Sequence
from collections.abc import Set
from functools import cache
from hashlib import sha256
import inspect
from inspect import Signature
Expand Down Expand Up @@ -229,6 +230,11 @@ def get_transform(
)


@cache
def cached_get_type_hints(cls: type) -> dict[str, Any]:
return typing.get_type_hints(cls)


class SyftMigrationRegistry:
__migration_version_registry__: dict[str, dict[int, str]] = {}
__migration_transform_registry__: dict[str, dict[str, Callable]] = {}
Expand Down Expand Up @@ -578,7 +584,7 @@ def _syft_set_validate_private_attrs_(self, **kwargs: Any) -> None:
return
# Validate and set private attributes
# https://github.com/pydantic/pydantic/issues/2105
annotations = typing.get_type_hints(self.__class__)
annotations = cached_get_type_hints(self.__class__)
for attr, decl in self.__private_attributes__.items():
value = kwargs.get(attr, decl.get_default())
var_annotation = annotations.get(attr)
Expand Down

0 comments on commit 3ac23c0

Please sign in to comment.