diff --git a/dol/caching.py b/dol/caching.py index e928105c..5580ca16 100644 --- a/dol/caching.py +++ b/dol/caching.py @@ -1971,7 +1971,7 @@ def cache_vals(store=None, *, cache=dict): ), f"store should be a type, was a {type(store)}: {store}" class CachedStore(store): - @wraps(store) + @wraps(store.__init__) def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self._cache = _mk_cache_instance( diff --git a/dol/paths.py b/dol/paths.py index 9f5ffaa4..28441c4d 100644 --- a/dol/paths.py +++ b/dol/paths.py @@ -776,8 +776,8 @@ def path_set( >>> from collections import OrderedDict >>> input_dict = {} >>> path_set(input_dict, 'new.key', 42, new_mapping=OrderedDict) - >>> input_dict # doctest: +NORMALIZE_WHITESPACE - {'new': OrderedDict([('key', 42)])} + >>> input_dict # doctest: +ELLIPSIS + {'new': OrderedDict(...'key'...: 42...)} """ if isinstance(key_path, str) and sep is not None: @@ -1660,7 +1660,7 @@ def identity(x): # and have classmethods specialized for short-hand versions that use `name:regex` or # `name:format`, ... class KeyTemplate: - """A class for parsing and generating keys based on a template. + r"""A class for parsing and generating keys based on a template. Args: template: A template string with fields to be extracted or filled in. @@ -1900,7 +1900,7 @@ def str_to_dict(self, s: str) -> dict: r"""Parses the input string and returns a dictionary of extracted values. >>> st = KeyTemplate( - ... 'root/{}/v_{ver:03.0f:\d+}.json', + ... r'root/{}/v_{ver:03.0f:\d+}.json', ... from_str_funcs={'ver': int}, ... ) >>> st.str_to_dict('root/life/v_30.json') @@ -1920,7 +1920,7 @@ def dict_to_str(self, params: dict) -> str: r"""Generates a string from the dictionary values based on the template. >>> st = KeyTemplate( - ... 'root/{}/v_{ver:03.0f:\d+}.json', from_str_funcs={'ver': int}, + ... r'root/{}/v_{ver:03.0f:\d+}.json', from_str_funcs={'ver': int}, ... ) >>> st.dict_to_str({'i01_': 'life', 'ver': 42}) 'root/life/v_042.json' @@ -1936,7 +1936,7 @@ def dict_to_tuple(self, params: dict) -> tuple: r"""Generates a tuple from the dictionary values based on the template. >>> st = KeyTemplate( - ... 'root/{}/v_{ver:03.0f:\d+}.json', from_str_funcs={'ver': int}, + ... r'root/{}/v_{ver:03.0f:\d+}.json', from_str_funcs={'ver': int}, ... ) >>> st.str_to_tuple('root/life/v_42.json') ('life', 42) @@ -1951,7 +1951,7 @@ def tuple_to_dict(self, param_vals: tuple) -> dict: r"""Generates a dictionary from the tuple values based on the template. >>> st = KeyTemplate( - ... 'root/{}/v_{ver:03.0f:\d+}.json', from_str_funcs={'ver': int}, + ... r'root/{}/v_{ver:03.0f:\d+}.json', from_str_funcs={'ver': int}, ... ) >>> st.tuple_to_dict(('life', 42)) {'i01_': 'life', 'ver': 42} @@ -1967,7 +1967,7 @@ def str_to_tuple(self, s: str) -> tuple: r"""Parses the input string and returns a tuple of extracted values. >>> st = KeyTemplate( - ... 'root/{}/v_{ver:03.0f:\d+}.json', from_str_funcs={'ver': int}, + ... r'root/{}/v_{ver:03.0f:\d+}.json', from_str_funcs={'ver': int}, ... ) >>> st.str_to_tuple('root/life/v_42.json') ('life', 42) @@ -1981,7 +1981,7 @@ def tuple_to_str(self, param_vals: tuple) -> str: r"""Generates a string from the tuple values based on the template. >>> st = KeyTemplate( - ... 'root/{}/v_{ver:03.0f:\d+}.json', from_str_funcs={'ver': int}, + ... r'root/{}/v_{ver:03.0f:\d+}.json', from_str_funcs={'ver': int}, ... ) >>> st.tuple_to_str(('life', 42)) 'root/life/v_042.json' @@ -1995,7 +1995,7 @@ def str_to_single(self, s: str) -> Any: r"""Parses the input string and returns a single value. >>> st = KeyTemplate( - ... 'root/life/v_{ver:03.0f:\d+}.json', from_str_funcs={'ver': int}, + ... r'root/life/v_{ver:03.0f:\d+}.json', from_str_funcs={'ver': int}, ... ) >>> st.str_to_single('root/life/v_42.json') 42 @@ -2009,7 +2009,7 @@ def single_to_str(self, k: Any) -> str: r"""Generates a string from the single value based on the template. >>> st = KeyTemplate( - ... 'root/life/v_{ver:03.0f:\d+}.json', from_str_funcs={'ver': int}, + ... r'root/life/v_{ver:03.0f:\d+}.json', from_str_funcs={'ver': int}, ... ) >>> st.single_to_str(42) 'root/life/v_042.json' @@ -2026,7 +2026,7 @@ def dict_to_namedtuple( r"""Generates a namedtuple from the dictionary values based on the template. >>> st = KeyTemplate( - ... 'root/{}/v_{ver:03.0f:\d+}.json', from_str_funcs={'ver': int}, + ... r'root/{}/v_{ver:03.0f:\d+}.json', from_str_funcs={'ver': int}, ... ) >>> App = st.dict_to_namedtuple({'i01_': 'life', 'ver': 42}) >>> App @@ -2041,7 +2041,7 @@ def namedtuple_to_dict(self, nt): r"""Converts a namedtuple to a dictionary. >>> st = KeyTemplate( - ... 'root/{}/v_{ver:03.0f:\d+}.json', from_str_funcs={'ver': int}, + ... r'root/{}/v_{ver:03.0f:\d+}.json', from_str_funcs={'ver': int}, ... ) >>> App = st.dict_to_namedtuple({'i01_': 'life', 'ver': 42}) >>> st.namedtuple_to_dict(App) @@ -2055,7 +2055,7 @@ def str_to_namedtuple(self, s: str): r"""Converts a string to a namedtuple. >>> st = KeyTemplate( - ... 'root/{}/v_{ver:03.0f:\d+}.json', from_str_funcs={'ver': int}, + ... r'root/{}/v_{ver:03.0f:\d+}.json', from_str_funcs={'ver': int}, ... ) >>> App = st.str_to_namedtuple('root/life/v_042.json') >>> App @@ -2070,7 +2070,7 @@ def str_to_simple_str(self, s: str): r"""Converts a string to a simple string (i.e. a simple character-delimited string). >>> st = KeyTemplate( - ... 'root/{}/v_{ver:03.0f:\d+}.json', from_str_funcs={'ver': int}, + ... r'root/{}/v_{ver:03.0f:\d+}.json', from_str_funcs={'ver': int}, ... ) >>> st.str_to_simple_str('root/life/v_042.json') 'life,042' @@ -2089,7 +2089,7 @@ def simple_str_to_tuple(self, ss: str): r"""Converts a simple character-delimited string to a dict. >>> st = KeyTemplate( - ... 'root/{}/v_{ver:03.0f:\d+}.json', from_str_funcs={'ver': int}, + ... r'root/{}/v_{ver:03.0f:\d+}.json', from_str_funcs={'ver': int}, ... simple_str_sep='-', ... ) >>> st.simple_str_to_tuple('life-042') @@ -2114,7 +2114,7 @@ def simple_str_to_str(self, ss: str): r"""Converts a simple character-delimited string to a string. >>> st = KeyTemplate( - ... 'root/{}/v_{ver:03.0f:\d+}.json', from_str_funcs={'ver': int}, + ... r'root/{}/v_{ver:03.0f:\d+}.json', from_str_funcs={'ver': int}, ... simple_str_sep='-', ... ) >>> st.simple_str_to_str('life-042') @@ -2129,7 +2129,7 @@ def match_str(self, s: str) -> bool: Returns True iff the string matches the template. >>> st = KeyTemplate( - ... 'root/{}/v_{ver:03.0f:\d+}.json', from_str_funcs={'ver': int}, + ... r'root/{}/v_{ver:03.0f:\d+}.json', from_str_funcs={'ver': int}, ... ) >>> st.match_str('root/life/v_042.json') True @@ -2172,7 +2172,7 @@ def _extract_template_info(self, template): These four values are used in the init to compute the parameters of the instance. - >>> st = KeyTemplate('{:03.0f}/{name::\w+}') + >>> st = KeyTemplate(r'{:03.0f}/{name::\w+}') >>> st.template '{i01_}/{name}' >>> st._fields @@ -2238,13 +2238,13 @@ def _compile_regex(self, template, normalize_path=False): '(?P.*)\\.ext' >>> KeyTemplate('{name}.ext')._regex.pattern '(?P.*)\\.ext' - >>> KeyTemplate('{::\w+}.ext')._regex.pattern + >>> KeyTemplate(r'{::\w+}.ext')._regex.pattern '(?P\\w+)\\.ext' - >>> KeyTemplate('{name::\w+}.ext')._regex.pattern + >>> KeyTemplate(r'{name::\w+}.ext')._regex.pattern '(?P\\w+)\\.ext' - >>> KeyTemplate('{:0.02f:\w+}.ext')._regex.pattern + >>> KeyTemplate(r'{:0.02f:\w+}.ext')._regex.pattern '(?P\\w+)\\.ext' - >>> KeyTemplate('{name:0.02f:\w+}.ext')._regex.pattern + >>> KeyTemplate(r'{name:0.02f:\w+}.ext')._regex.pattern '(?P\\w+)\\.ext' """ diff --git a/dol/signatures.py b/dol/signatures.py index 017c20ee..147c451f 100644 --- a/dol/signatures.py +++ b/dol/signatures.py @@ -1353,15 +1353,15 @@ def sig_or_none(cls, obj): ... ) # another easy one: This time, a type/class (which is callable, yes) True - But here's where it get's interesting. `print`, a builtin, doesn't have a + But here's where it get's interesting. `map`, a builtin, doesn't have a signature through inspect.signature. - >>> has_signature(print) + >>> has_signature(map) False But we do get one with robust_has_signature - >>> robust_has_signature(print) + >>> robust_has_signature(map) True """ @@ -2963,7 +2963,7 @@ def extract_args_and_kwargs( >>> Sig(foo).extract_args_and_kwargs(x=3, y=2) Traceback (most recent call last): ... - TypeError: missing a required argument: 'w' + TypeError: missing a required keyword-only argument: 'w' But if you specify `_allow_partial=True`... @@ -3040,7 +3040,7 @@ def source_arguments( >>> Sig(foo).source_arguments(x=3, y=2, extra="keywords", are="ignored") Traceback (most recent call last): ... - TypeError: missing a required argument: 'w' + TypeError: missing a required keyword-only argument: 'w' But if you specify `_allow_partial=True`... @@ -3129,7 +3129,7 @@ def source_args_and_kwargs( >>> Sig(foo).source_args_and_kwargs(x=3, y=2, extra="keywords", are="ignored") Traceback (most recent call last): ... - TypeError: missing a required argument: 'w' + TypeError: missing a required keyword-only argument: 'w' But if you specify `_allow_partial=True`... @@ -3633,7 +3633,7 @@ def has_signature(obj, robust=False): ... ) ... ) ... ) - 2 + 3 If robust is set to True, `has_signature` will use `Sig` to get the signature, so will return True in most cases. diff --git a/dol/sources.py b/dol/sources.py index ce2f84fa..9591af27 100644 --- a/dol/sources.py +++ b/dol/sources.py @@ -504,12 +504,9 @@ class CascadedStores(FanoutPersister): >>> disk['g'] = 43 Now if you ask for `g`, it won't find it in cache, but will find it in `disk` - and return it. The reason you see the "Getting g from cache" message is because - the `stores` object first tries to get it in `cache`, and only if it doesn't find - it there, it tries to get it from `disk`. + and return it. >>> stores['g'] - Getting g from cache Getting g from disk 43 diff --git a/dol/tests/test_paths.py b/dol/tests/test_paths.py index db6d3445..976590b6 100644 --- a/dol/tests/test_paths.py +++ b/dol/tests/test_paths.py @@ -48,21 +48,21 @@ def test_path_get(): def test_string_template_template_construction(): assert KeyTemplate("{}.ext").template == "{i01_}.ext" assert KeyTemplate("{name}.ext").template == "{name}.ext" - assert KeyTemplate("{::\w+}.ext").template == "{i01_}.ext" - assert KeyTemplate("{name::\w+}.ext").template == "{name}.ext" - assert KeyTemplate("{name::\w+}.ext").template == "{name}.ext" + assert KeyTemplate(r"{::\w+}.ext").template == "{i01_}.ext" + assert KeyTemplate(r"{name::\w+}.ext").template == "{name}.ext" + assert KeyTemplate(r"{name::\w+}.ext").template == "{name}.ext" assert KeyTemplate("{name:0.02f}.ext").template == "{name}.ext" - assert KeyTemplate("{name:0.02f:\w+}.ext").template == "{name}.ext" - assert KeyTemplate("{:0.02f:\w+}.ext").template == "{i01_}.ext" + assert KeyTemplate(r"{name:0.02f:\w+}.ext").template == "{name}.ext" + assert KeyTemplate(r"{:0.02f:\w+}.ext").template == "{i01_}.ext" def test_string_template_regex(): - assert KeyTemplate("{}.ext")._regex.pattern == "(?P.*)\\.ext" - assert KeyTemplate("{name}.ext")._regex.pattern == "(?P.*)\\.ext" - assert KeyTemplate("{::\w+}.ext")._regex.pattern == "(?P\\w+)\\.ext" - assert KeyTemplate("{name::\w+}.ext")._regex.pattern == "(?P\\w+)\\.ext" - assert KeyTemplate("{:0.02f:\w+}.ext")._regex.pattern == "(?P\\w+)\\.ext" - assert KeyTemplate("{name:0.02f:\w+}.ext")._regex.pattern == "(?P\\w+)\\.ext" + assert KeyTemplate("{}.ext")._regex.pattern == r"(?P.*)\.ext" + assert KeyTemplate("{name}.ext")._regex.pattern == r"(?P.*)\.ext" + assert KeyTemplate(r"{::\w+}.ext")._regex.pattern == r"(?P\w+)\.ext" + assert KeyTemplate(r"{name::\w+}.ext")._regex.pattern == r"(?P\w+)\.ext" + assert KeyTemplate(r"{:0.02f:\w+}.ext")._regex.pattern == r"(?P\w+)\.ext" + assert KeyTemplate(r"{name:0.02f:\w+}.ext")._regex.pattern == r"(?P\w+)\.ext" def test_string_template_simple(): @@ -70,7 +70,7 @@ def test_string_template_simple(): from collections import namedtuple st = KeyTemplate( - "root/{}/v_{version:03.0f:\d+}.json", + r"root/{}/v_{version:03.0f:\d+}.json", from_str_funcs={"version": int}, ) diff --git a/dol/trans.py b/dol/trans.py index 56f0a5a4..e84094ac 100644 --- a/dol/trans.py +++ b/dol/trans.py @@ -1472,7 +1472,7 @@ def __delitem__(self, k): def filter_regex(regex, *, return_search_func=False): - """Make a filter that returns True if a string matches the given regex + r"""Make a filter that returns True if a string matches the given regex >>> is_txt = filter_regex(r'.*\.txt') >>> is_txt("test.txt")