Skip to content

Commit

Permalink
Revert "add caching, add tests (#175)"
Browse files Browse the repository at this point in the history
This reverts commit 2208d4f.
  • Loading branch information
lidatong committed Mar 13, 2020
1 parent 22a25d0 commit da09282
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 117 deletions.
28 changes: 6 additions & 22 deletions dataclasses_json/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@
from datetime import datetime, timezone
from decimal import Decimal
from enum import Enum
from typing import Any, Collection, Dict, Mapping, Union, get_type_hints
from typing import Any, Collection, Mapping, Union, get_type_hints
from uuid import UUID

from cachetools import cached
from cachetools.lru import LRUCache
from typing_inspect import is_union_type # type: ignore

from dataclasses_json import cfg
Expand All @@ -26,10 +24,6 @@
_issubclass_safe)

Json = Union[dict, list, str, int, float, bool, None]
_MAX_CACHE_SIZE = 128
_get_type_hints_cache = LRUCache(maxsize=_MAX_CACHE_SIZE)
_is_supported_generic_cache = LRUCache(maxsize=_MAX_CACHE_SIZE)
_user_overrides_cache = LRUCache(maxsize=_MAX_CACHE_SIZE)


class _ExtendedEncoder(json.JSONEncoder):
Expand All @@ -53,14 +47,10 @@ def default(self, o) -> Json:
return result


confs = ['encoder', 'decoder', 'mm_field', 'letter_case']
FieldOverride = namedtuple('FieldOverride', confs)
def _user_overrides_or_exts(cls):
confs = ['encoder', 'decoder', 'mm_field', 'letter_case']
FieldOverride = namedtuple('FieldOverride', confs)


@cached(cache=_user_overrides_cache, key=id)
def _user_overrides_or_exts(cls) -> Dict[str, FieldOverride]:
overrides = {}
# overrides at the class-level
global_metadata = defaultdict(dict)
encoders = cfg.global_config.encoders
decoders = cfg.global_config.decoders
Expand Down Expand Up @@ -99,7 +89,7 @@ def _encode_json_type(value, default=_ExtendedEncoder().default):
return default(value)


def _encode_overrides(kvs: Dict[str, Any], overrides, encode_json=False):
def _encode_overrides(kvs, overrides, encode_json=False):
override_kvs = {}
for k, v in kvs.items():
if k in overrides:
Expand Down Expand Up @@ -128,11 +118,6 @@ def _decode_letter_case_overrides(field_names, overrides):
return names


@cached(cache=_get_type_hints_cache, key=id)
def _get_type_hints_cached(cls):
return get_type_hints(cls)


def _decode_dataclass(cls, kvs, infer_missing):
if isinstance(kvs, cls):
return kvs
Expand All @@ -155,7 +140,7 @@ def _decode_dataclass(cls, kvs, infer_missing):
kvs = _handle_undefined_parameters_safe(cls, kvs, usage="from")

init_kwargs = {}
types = _get_type_hints_cached(cls)
types = get_type_hints(cls)
for field in fields(cls):
# The field should be skipped from being added
# to init_kwargs as it's not intended as a constructor argument.
Expand Down Expand Up @@ -237,7 +222,6 @@ def _support_extended_types(field_type, field_value):
return res


@cached(cache=_is_supported_generic_cache, key=id)
def _is_supported_generic(type_):
not_str = not _issubclass_safe(type_, str)
is_enum = _issubclass_safe(type_, Enum)
Expand Down
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
'marshmallow>=3.3.0,<4.0.0',
'marshmallow-enum>=1.5.1,<2.0.0',
'typing-inspect>=0.4.0',
'stringcase==1.2.0,<2.0.0',
'cachetools==4.0.0,<5.0.0'
'stringcase==1.2.0,<2.0.0'
],
python_requires='>=3.6',
extras_require={
Expand Down
3 changes: 0 additions & 3 deletions tests/conftest.py

This file was deleted.

10 changes: 0 additions & 10 deletions tests/fixtures.py

This file was deleted.

80 changes: 0 additions & 80 deletions tests/test_cache.py

This file was deleted.

0 comments on commit da09282

Please sign in to comment.