Skip to content

Commit

Permalink
set
Browse files Browse the repository at this point in the history
  • Loading branch information
Borda committed Oct 16, 2024
1 parent 51e7365 commit ce19201
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
17 changes: 10 additions & 7 deletions src/cachier/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import hashlib
import os
import pickle
from collections.abc import Mapping
from dataclasses import dataclass, replace
from typing import Optional, Union

Expand Down Expand Up @@ -63,7 +64,7 @@ def _update_with_defaults(
return param


def set_default_params(**params):
def set_default_params(**params: Mapping) -> None:
"""Configure global parameters applicable to all memoized functions.
This function takes the same keyword parameters as the ones defined in the
Expand All @@ -78,15 +79,17 @@ def set_default_params(**params):
"""
import cachier

valid_params = (
p
for p in params.items()
if hasattr(cachier.config._default_params, p[0])
valid_params = {
k: v
for k, v in params.items()
if hasattr(cachier.config._default_params, k)
}
cachier.config._default_params = replace(
cachier.config._default_params, **valid_params
)
replace(_default_params, **valid_params)


def get_default_params():
def get_default_params() -> Params:
"""Get current set of default parameters."""
import cachier

Expand Down
6 changes: 3 additions & 3 deletions tests/test_defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
from tests.test_mongo_core import _test_mongetter

MONGO_DELTA = datetime.timedelta(seconds=3)
_default_params = replace(cachier.get_default_params())
_fresh_defaults = replace(cachier.get_default_params())


def setup_function():
cachier.set_default_params(**_default_params)
cachier.set_default_params(**vars(_fresh_defaults))


def teardown_function():
cachier.set_default_params(**_default_params)
cachier.set_default_params(**vars(_fresh_defaults))


def test_hash_func_default_param():
Expand Down

0 comments on commit ce19201

Please sign in to comment.