Skip to content

Commit 1f78764

Browse files
committed
bump
1 parent 355e1e3 commit 1f78764

File tree

7 files changed

+101
-32
lines changed

7 files changed

+101
-32
lines changed

.pre-commit-config.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
fail_fast: true
22
repos:
33
- repo: https://github.com/asottile/pyupgrade
4-
rev: v3.19.1
4+
rev: v3.20.0
55
hooks:
66
- id: pyupgrade
77
args:
88
- --py38-plus
99
- --keep-runtime-typing
1010

1111
- repo: https://github.com/ambv/black
12-
rev: 24.10.0
12+
rev: 25.1.0
1313
hooks:
1414
- id: black
1515
language_version: python3.10
1616

1717
- repo: https://github.com/abravalheri/validate-pyproject
18-
rev: v0.23
18+
rev: v0.24.1
1919
hooks:
2020
- id: validate-pyproject
2121

2222
- repo: https://github.com/pre-commit/mirrors-mypy
23-
rev: v1.14.1
23+
rev: v1.16.0
2424
hooks:
2525
- id: mypy
2626
verbose: true
@@ -29,7 +29,7 @@ repos:
2929
#args: [ --strict ]
3030

3131
- repo: https://github.com/pycqa/flake8
32-
rev: 7.1.1 # pick a git hash / tag to point to
32+
rev: 7.2.0 # pick a git hash / tag to point to
3333
hooks:
3434
- id: flake8 # stop the build if there are Python syntax errors or undefined names
3535
additional_dependencies: [flake8-docstrings]
@@ -93,7 +93,7 @@ repos:
9393
# - id: pydocstyle
9494

9595
- repo: https://github.com/executablebooks/mdformat
96-
rev: 0.7.21
96+
rev: 0.7.22
9797
hooks:
9898
- id: mdformat
9999
additional_dependencies:

warg/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
__project__ = "Warg"
55

66
__author__ = "Christian Heider Lindbjerg"
7-
__version__ = "1.4.8"
7+
__version__ = "1.4.9"
88
__doc__ = r"""
99
Created on 27/04/2019
1010

warg/data_structures/mappings.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11
#!/usr/bin/env python3
22
import logging
33
from typing import Callable, Dict, Hashable, Iterable, Mapping, MutableMapping
4+
from collections import defaultdict
5+
46

57
logger = logging.getLogger(__name__)
6-
__all__ = ["invert_mapping", "invert_dict", "AppendingDict", "pivot_dict_object", "pivot_dict", "to_dict"]
8+
__all__ = [
9+
"invert_mapping",
10+
"invert_dict",
11+
"AppendingDict",
12+
"pivot_dict_object",
13+
"pivot_dict",
14+
"to_dict",
15+
"nested_dict",
16+
]
717

818

919
def append_to_dict(d: Dict, key, value) -> Dict:
@@ -116,6 +126,8 @@ def to_dict(m: Mapping) -> dict:
116126
return o
117127

118128

129+
nested_dict = lambda: defaultdict(nested_dict)
130+
119131
if __name__ == "__main__":
120132
logger.info(invert_mapping({"a": 1, "b": 2}))
121133

warg/decorators/kw_passing.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ def passes_kws_to(
116116
a receiver function. No call graph checks if this actually enforces this yet. Also all receiver kwargs
117117
must be able to be received by receivers if multiple contracts are use
118118
119+
:param no_pass_filter:
119120
:param receiver_funcs:
120121
:param keep_from_var_kw:
121122
:return:"""

warg/map_itertools.py

Lines changed: 72 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,52 +9,105 @@
99
__all__ = [
1010
"map_value_product",
1111
"map_product",
12+
"map_sorted",
1213
"map_permutations",
1314
"map_combinations",
1415
"map_combinations_with_replacement",
1516
]
1617

1718
import itertools
1819
import logging
19-
from typing import Any, Mapping, Tuple
20+
from typing import Any, Generator, Mapping, Optional, Tuple
2021

2122
logger = logging.getLogger(__name__)
2223

2324

24-
def map_value_product(dicts: Mapping) -> Any:
25-
"""description"""
26-
return (dict(zip(dicts, x)) for x in itertools.product(*dicts.values()))
25+
def map_value_product(mappings: Optional[Mapping]) -> Optional[Generator[dict, None, None]]:
26+
"""
27+
28+
:param mappings:
29+
:return:
30+
"""
31+
if mappings is None:
32+
return None
33+
34+
return (dict(zip(mappings, x)) for x in itertools.product(*mappings.values()))
35+
36+
37+
def map_reversed(mapping: Optional[Mapping]) -> Optional[dict]:
38+
"""
39+
40+
:param mapping:
41+
:return:
42+
"""
43+
if mapping is None:
44+
return None
45+
46+
return dict(reversed(list(mapping.items())))
47+
48+
49+
def map_sorted(mapping: Optional[Mapping], **kwargs) -> Optional[dict]:
50+
"""
2751
52+
:param mapping:
53+
:param kwargs:
54+
:return:
55+
"""
56+
if mapping is None:
57+
return None
2858

29-
def map_product(dicts: Mapping, repeat: int = 2) -> Any:
59+
return dict(sorted(mapping.items(), **kwargs))
60+
61+
62+
def map_product(mapping: Mapping, repeat: int = 2) -> Any:
3063
"""description"""
3164
yield from zip(
32-
itertools.product(dicts.keys(), repeat=repeat),
33-
itertools.product(dicts.values(), repeat=repeat),
65+
itertools.product(mapping.keys(), repeat=repeat),
66+
itertools.product(mapping.values(), repeat=repeat),
3467
)
3568

3669

37-
def map_permutations(dicts: Mapping, repeat: int = 2) -> Tuple:
38-
"""description"""
70+
def map_permutations(mapping: Mapping, repeat: int = 2) -> Generator[Tuple[Any, ...], None, None]:
71+
"""
72+
73+
:param mapping:
74+
:param repeat:
75+
:return:
76+
"""
3977
yield from zip(
40-
itertools.permutations(dicts.keys(), repeat),
41-
itertools.permutations(dicts.values(), repeat),
78+
itertools.permutations(mapping.keys(), repeat),
79+
itertools.permutations(mapping.values(), repeat),
4280
)
4381

4482

45-
def map_combinations(dicts: Mapping, repeat: int = 2) -> Tuple:
46-
"""description"""
83+
def map_combinations(mapping: Mapping, repeat: int = 2) -> Generator[Tuple[Any, ...], None, None]:
84+
"""
85+
86+
:param mapping:
87+
:param repeat:
88+
:return:
89+
"""
4790
yield from zip(
48-
itertools.combinations(dicts.keys(), repeat),
49-
itertools.combinations(dicts.values(), repeat),
91+
itertools.combinations(mapping.keys(), repeat),
92+
itertools.combinations(mapping.values(), repeat),
5093
)
5194

5295

53-
def map_combinations_with_replacement(dicts: Mapping, repeat: int = 2) -> Tuple:
54-
"""description"""
96+
def map_combinations_with_replacement(
97+
mappings: Mapping, repeat: int = 2
98+
) -> Generator[Tuple[Any, ...], None, None]:
99+
"""
100+
101+
:param mappings:
102+
:param repeat:
103+
:return:
104+
"""
105+
if mappings is None:
106+
return None
107+
55108
yield from zip(
56-
itertools.combinations_with_replacement(dicts.keys(), repeat),
57-
itertools.combinations_with_replacement(dicts.values(), repeat),
109+
itertools.combinations_with_replacement(mappings.keys(), repeat),
110+
itertools.combinations_with_replacement(mappings.values(), repeat),
58111
)
59112

60113

warg/modules.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
import pkgutil
44
from pathlib import Path
55
from types import ModuleType
6-
from typing import Sequence
6+
from typing import Any, Generator, Sequence
77

88
logger = logging.getLogger(__name__)
99

1010

1111
__all__ = ["iter_import_module", "get_submodules", "get_submodules_by_path"]
1212

1313

14-
def iter_import_module(module_name: str, module_paths: Sequence[str]) -> ModuleType:
14+
def iter_import_module(module_name: str, module_paths: Sequence[str]) -> Generator[ModuleType, Any, None]:
1515
logger.info(f"Found {module_name} in {module_paths}")
1616

1717
yield from (
@@ -20,13 +20,13 @@ def iter_import_module(module_name: str, module_paths: Sequence[str]) -> ModuleT
2020
)
2121

2222

23-
def get_submodules(module: ModuleType) -> ModuleType:
23+
def get_submodules(module: ModuleType) -> Generator[ModuleType, Any, None]:
2424
logger.info(f"Found {module.__path__} {module.__name__}")
2525

2626
yield from iter_import_module(module.__name__, module.__path__)
2727

2828

29-
def get_submodules_by_path(module_path: Path) -> ModuleType:
29+
def get_submodules_by_path(module_path: Path) -> Generator[ModuleType, Any, None]:
3030
assert module_path.exists(), f"{module_path} does not exist"
3131

3232
yield from iter_import_module(module_path.stem, [str(module_path)])

warg/packages/versioning.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,10 @@ def get_version(version: str, append_time: bool = False, verbose: bool = False,
9090

9191
except:
9292
if append_time:
93-
now = datetime.datetime.utcnow()
93+
try:
94+
now = datetime.datetime.now(datetime.UTC)
95+
except:
96+
now = datetime.datetime.utcnow()
9497
date_version = now.strftime("%Y%m%d%H%M%S")
9598
# date_version = time.time()
9699

0 commit comments

Comments
 (0)