evilutils 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,17 @@
1
+ """Extensions upon the `functools` library."""
2
+
3
+ from functools import cache, cached_property, partial, partialmethod, wraps
4
+
5
+ from .compose import compose
6
+ from .decorators import immediate, map_result
7
+
8
+ __all__ = [
9
+ "partial",
10
+ "partialmethod",
11
+ "cache",
12
+ "cached_property",
13
+ "compose",
14
+ "wraps",
15
+ "immediate",
16
+ "map_result",
17
+ ]
@@ -0,0 +1,58 @@
1
+ from collections.abc import Callable
2
+ from functools import partial, wraps
3
+ from typing import overload
4
+
5
+ __all__ = ["compose"]
6
+
7
+ type Fn[_AT, _RT] = Callable[[_AT], _RT]
8
+
9
+ type PartialComposition[**P, RT, MT] = Callable[[Callable[P, RT]], Callable[P, MT]]
10
+ type AnyComposition[**P, RT, MT] = Callable[P, MT] | PartialComposition[P, RT, MT]
11
+
12
+
13
+ @overload
14
+ def compose[**P, RT, MT](F: Fn[RT, MT]) -> PartialComposition[P, RT, MT]:
15
+ """
16
+ A partial composition of F. This overload can be used as a decorator.
17
+ """
18
+ ...
19
+
20
+
21
+ @overload
22
+ def compose[**P, RT, MT](F: Fn[RT, MT], G: Callable[P, RT]) -> Callable[P, MT]:
23
+ """
24
+ A composition `F o G`.
25
+
26
+ See also: `Function composition`_
27
+
28
+ .. Function composition: https://en.wikipedia.org/wiki/Function_composition_(computer_science)
29
+ """
30
+ ...
31
+
32
+
33
+ def compose[**P, RT, MT](
34
+ F: Fn[RT, MT], G: Callable[P, RT] | None = None
35
+ ) -> AnyComposition[P, RT, MT]:
36
+ """
37
+ >>> double = lambda n: n * 2
38
+ >>> @compose(double)
39
+ ... def two() -> int:
40
+ ... return 1
41
+ >>>
42
+ >>> two()
43
+ 2
44
+
45
+ >>> plus_one = lambda n: n + 1
46
+ >>> plus_two = compose(plus_one, plus_one)
47
+ >>> plus_two(2)
48
+ 4
49
+ """
50
+
51
+ if G is None:
52
+ return partial(compose, F)
53
+
54
+ @wraps(G)
55
+ def composition(*args: P.args, **kwargs: P.kwargs) -> MT:
56
+ return F(G(*args, **kwargs))
57
+
58
+ return composition
@@ -0,0 +1,44 @@
1
+ from collections.abc import Callable
2
+ from functools import partial
3
+ from typing import ParamSpec, TypeVar
4
+
5
+ from .compose import compose
6
+
7
+ __all__ = ["immediate", "map_result"]
8
+
9
+ P = ParamSpec("P")
10
+ RT = TypeVar("RT")
11
+ MT = TypeVar("MT")
12
+
13
+ TT = TypeVar("TT", bound=type)
14
+
15
+
16
+ def immediate(func: Callable[[], RT]) -> RT:
17
+ """Immediately evaluate the given function, returning its output.
18
+
19
+ >>> @immediate
20
+ ... def VALUES():
21
+ ... return (0, 1)
22
+ >>>
23
+ >>> VALUES
24
+ (0, 1)
25
+ """
26
+ return func()
27
+
28
+
29
+ def map_result(
30
+ mapper: Callable[[RT], MT],
31
+ ) -> Callable[[Callable[P, RT]], Callable[P, MT]]:
32
+ """Map the returned value of a function using another function.
33
+
34
+ This is especially designed with generators in mind, though one
35
+ could easily find other uses.
36
+
37
+ >>> @map_result(tuple)
38
+ ... def __generate_values(a: int):
39
+ ... yield from (a, 1)
40
+ >>>
41
+ >>> __generate_values(0)
42
+ (0, 1)
43
+ """
44
+ return partial(compose, mapper)
evilfunctools/py.typed ADDED
File without changes
evilutils/__init__.py ADDED
@@ -0,0 +1,23 @@
1
+ """
2
+ All of the utils I don't want to write twice.
3
+
4
+ Note that this package is a dummy package. Use the other packages.
5
+ """
6
+
7
+ from .info import (
8
+ __author__,
9
+ __copyright__,
10
+ __credits__,
11
+ __license__,
12
+ __maintainer__,
13
+ __version__,
14
+ )
15
+
16
+ __all__ = [
17
+ "__author__",
18
+ "__copyright__",
19
+ "__credits__",
20
+ "__license__",
21
+ "__version__",
22
+ "__maintainer__",
23
+ ]
evilutils/__main__.py ADDED
@@ -0,0 +1,4 @@
1
+ from .info import __copyright__, __version__
2
+
3
+ print(f"{__package__} v{__version__}")
4
+ print(__copyright__)
evilutils/info.py ADDED
@@ -0,0 +1,6 @@
1
+ __author__ = "Ernest Izdebski"
2
+ __copyright__ = "Copyright 2025-present, Ernest Izdebski"
3
+ __credits__ = ["Ernest Izdebski"]
4
+ __license__ = "MIT"
5
+ __version__ = "0.1.0"
6
+ __maintainer__ = "Ernest Izdebski"
evilutils/py.typed ADDED
File without changes
@@ -0,0 +1,7 @@
1
+ Copyright 2025-present Ernest Izdebski
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,31 @@
1
+ Metadata-Version: 2.2
2
+ Name: evilutils
3
+ Version: 0.1.0
4
+ Summary: All of the utils I don't want to write twice.
5
+ Author-email: Ernest Izdebski <44341687+ernieIzde8ski@users.noreply.github.com>
6
+ License: Copyright 2025-present Ernest Izdebski
7
+
8
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
11
+
12
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
13
+
14
+ Project-URL: Homepage, https://github.com/ernieIzde8ski/evilutils
15
+ Project-URL: Issues, https://github.com/ernieIzde8ski/evilutils/issues
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: License :: OSI Approved :: MIT License
18
+ Classifier: Operating System :: OS Independent
19
+ Requires-Python: >=3.12
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Requires-Dist: typing_extensions>=4.12.2
23
+
24
+ # evilutils
25
+
26
+ All of the utils I don't want to write twice.
27
+
28
+ ## Development
29
+
30
+ This project uses [`pre-commit`](https://pre-commit.com) for formatting purposes
31
+ and `make` for compilation purposes. See `Makefile` for available rules.
@@ -0,0 +1,13 @@
1
+ evilfunctools/__init__.py,sha256=Gzo7G543avTp54cmSLSez-ZCpIxK0UiE8YgJMzWh7Ro,350
2
+ evilfunctools/compose.py,sha256=P-IhuKmJoE7I_TgemqCZbhH53ggZxWCnsOHkpqB9og0,1363
3
+ evilfunctools/decorators.py,sha256=QZAi8tt1bRSxRgzz2WtiEediKOv1e3_FbQ26xXuoQpo,970
4
+ evilfunctools/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
+ evilutils/__init__.py,sha256=Rn1zTbSOPSfFB4pCk86iqwxEpm58e4Ib3VPnctPe9Nw,384
6
+ evilutils/__main__.py,sha256=-9zdAxtqLhsRX6u5cufs1rc_Ejh0RRVVt6Qexz2iVXk,106
7
+ evilutils/info.py,sha256=gdHqWKYr2GCdzifkMjMZL7J8o7vCA7uG3llGWCgH7yY,200
8
+ evilutils/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
+ evilutils-0.1.0.dist-info/LICENSE,sha256=irYlzJ7QeYbiMnnykg7UGiumD3kPW7plXoiELLdTMug,1071
10
+ evilutils-0.1.0.dist-info/METADATA,sha256=l4l7DjfM017KPpuPrMkvWibkLYB66VeuccMO3lEODjs,1966
11
+ evilutils-0.1.0.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
12
+ evilutils-0.1.0.dist-info/top_level.txt,sha256=AOGYKOcSww2qOaq6PME2-FdJjg_nJMde6nyuwX84NBE,24
13
+ evilutils-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (75.8.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ evilfunctools
2
+ evilutils