evilutils 0.1.2__tar.gz → 0.2.0__tar.gz

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.
Files changed (57) hide show
  1. {evilutils-0.1.2/src/evilutils.egg-info → evilutils-0.2.0}/PKG-INFO +3 -2
  2. {evilutils-0.1.2 → evilutils-0.2.0}/pyproject.toml +11 -6
  3. evilutils-0.2.0/src/evilconverters/__init__.py +4 -0
  4. evilutils-0.2.0/src/evilconverters/error.py +1 -0
  5. evilutils-0.2.0/src/evilconverters/intflag.py +63 -0
  6. evilutils-0.2.0/src/evildatetime/__init__.py +8 -0
  7. evilutils-0.2.0/src/evilmonads/__init__.py +3 -0
  8. evilutils-0.2.0/src/evilmonads/py.typed +0 -0
  9. evilutils-0.2.0/src/evilmonads/result/__init__.py +32 -0
  10. evilutils-0.2.0/src/evilmonads/result/error.py +16 -0
  11. evilutils-0.2.0/src/evilmonads/result/result.py +19 -0
  12. evilutils-0.2.0/src/evilmonads/result/variants/__init__.py +6 -0
  13. evilutils-0.2.0/src/evilmonads/result/variants/err.py +20 -0
  14. evilutils-0.2.0/src/evilmonads/result/variants/null.py +18 -0
  15. evilutils-0.2.0/src/evilmonads/result/variants/ok.py +28 -0
  16. evilutils-0.2.0/src/evilpath/py.typed +0 -0
  17. evilutils-0.2.0/src/evilrng/__init__.py +78 -0
  18. evilutils-0.2.0/src/evilrng/py.typed +0 -0
  19. evilutils-0.2.0/src/evilstructs/__init__.py +5 -0
  20. evilutils-0.2.0/src/evilstructs/frozendict.py +68 -0
  21. evilutils-0.2.0/src/evilstructs/py.typed +0 -0
  22. evilutils-0.2.0/src/eviltyping/__init__.py +19 -0
  23. evilutils-0.2.0/src/eviltyping/aliases.py +8 -0
  24. evilutils-0.2.0/src/eviltyping/descriptors.py +51 -0
  25. evilutils-0.2.0/src/eviltyping/dunders.py +15 -0
  26. evilutils-0.2.0/src/eviltyping/guards.py +18 -0
  27. evilutils-0.2.0/src/eviltyping/name.py +28 -0
  28. evilutils-0.2.0/src/eviltyping/py.typed +0 -0
  29. {evilutils-0.1.2 → evilutils-0.2.0}/src/evilutils/info.py +1 -1
  30. evilutils-0.2.0/src/evilutils/py.typed +0 -0
  31. {evilutils-0.1.2 → evilutils-0.2.0/src/evilutils.egg-info}/PKG-INFO +3 -2
  32. evilutils-0.2.0/src/evilutils.egg-info/SOURCES.txt +52 -0
  33. evilutils-0.2.0/src/evilutils.egg-info/top_level.txt +9 -0
  34. evilutils-0.2.0/tests/test_converter.py +29 -0
  35. evilutils-0.2.0/tests/test_file_structure.py +24 -0
  36. evilutils-0.2.0/tests/test_structs.py +18 -0
  37. evilutils-0.2.0/tests/test_typing.py +26 -0
  38. evilutils-0.1.2/requirements.txt +0 -1
  39. evilutils-0.1.2/src/evilutils.egg-info/SOURCES.txt +0 -22
  40. evilutils-0.1.2/src/evilutils.egg-info/top_level.txt +0 -3
  41. {evilutils-0.1.2 → evilutils-0.2.0}/LICENSE +0 -0
  42. {evilutils-0.1.2 → evilutils-0.2.0}/MANIFEST.in +0 -0
  43. {evilutils-0.1.2 → evilutils-0.2.0}/README.md +0 -0
  44. {evilutils-0.1.2 → evilutils-0.2.0}/setup.cfg +0 -0
  45. {evilutils-0.1.2/src/evilfunctools → evilutils-0.2.0/src/evilconverters}/py.typed +0 -0
  46. {evilutils-0.1.2/src/evilpath → evilutils-0.2.0/src/evildatetime}/py.typed +0 -0
  47. {evilutils-0.1.2 → evilutils-0.2.0}/src/evilfunctools/__init__.py +3 -3
  48. {evilutils-0.1.2 → evilutils-0.2.0}/src/evilfunctools/compose.py +0 -0
  49. {evilutils-0.1.2 → evilutils-0.2.0}/src/evilfunctools/decorators.py +0 -0
  50. {evilutils-0.1.2/src/evilutils → evilutils-0.2.0/src/evilfunctools}/py.typed +0 -0
  51. {evilutils-0.1.2 → evilutils-0.2.0}/src/evilpath/__init__.py +0 -0
  52. {evilutils-0.1.2 → evilutils-0.2.0}/src/evilpath/path.py +0 -0
  53. {evilutils-0.1.2 → evilutils-0.2.0}/src/evilutils/__init__.py +0 -0
  54. {evilutils-0.1.2 → evilutils-0.2.0}/src/evilutils/__main__.py +0 -0
  55. {evilutils-0.1.2 → evilutils-0.2.0}/src/evilutils.egg-info/dependency_links.txt +0 -0
  56. {evilutils-0.1.2 → evilutils-0.2.0}/src/evilutils.egg-info/requires.txt +0 -0
  57. /evilutils-0.1.2/tests/test_evilpath.py → /evilutils-0.2.0/tests/test_path.py +0 -0
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.2
1
+ Metadata-Version: 2.4
2
2
  Name: evilutils
3
- Version: 0.1.2
3
+ Version: 0.2.0
4
4
  Summary: All of the utils I don't want to write twice.
5
5
  Author-email: Ernest Izdebski <44341687+ernieIzde8ski@users.noreply.github.com>
6
6
  License: Copyright 2025-present Ernest Izdebski
@@ -20,6 +20,7 @@ Requires-Python: >=3.12
20
20
  Description-Content-Type: text/markdown
21
21
  License-File: LICENSE
22
22
  Requires-Dist: typing_extensions>=4.12.2
23
+ Dynamic: license-file
23
24
 
24
25
  # evilutils
25
26
 
@@ -13,11 +13,6 @@ skip-magic-trailing-comma = true
13
13
  profile = "black"
14
14
  line_length = 90
15
15
 
16
- [tool.black]
17
- line-length = 90
18
- target-version = ["py312", "py313"]
19
- skip-magic-trailing-comma = true
20
-
21
16
  [tool.basedpyright]
22
17
  reportImplicitStringConcatenation = false
23
18
  pythonVersion = "3.12"
@@ -40,7 +35,8 @@ classifiers = [
40
35
  "License :: OSI Approved :: MIT License",
41
36
  "Operating System :: OS Independent",
42
37
  ]
43
- dynamic = ["dependencies", "version"]
38
+ dependencies = ["typing_extensions>=4.12.2"]
39
+ dynamic = ["version"]
44
40
  license = { file = "LICENSE" }
45
41
 
46
42
  [project.urls]
@@ -53,3 +49,12 @@ version = { attr = "evilutils.__version__" }
53
49
 
54
50
  [tool.setuptools.packages.find]
55
51
  where = ["src"]
52
+
53
+ [dependency-groups]
54
+ dev = [
55
+ "pip>=26.0.1",
56
+ "pre-commit>=4.5.1",
57
+ "pytest>=8.3.3,<9.0.0",
58
+ "pytest-case>=1.0.0",
59
+ "sphinx>=9.1.0",
60
+ ]
@@ -0,0 +1,4 @@
1
+ __all__ = ["ConversionError", "IntFlag", "IntFlagMeta", "auto"]
2
+
3
+ from .error import ConversionError
4
+ from .intflag import IntFlag, IntFlagMeta, auto
@@ -0,0 +1 @@
1
+ class ConversionError(RuntimeError): ...
@@ -0,0 +1,63 @@
1
+ import re
2
+ from collections.abc import Generator, Iterable
3
+ from enum import IntFlag, auto
4
+ from functools import reduce
5
+
6
+ __all__ = ["auto", "IntFlag", "IntFlagMeta"]
7
+
8
+ try:
9
+ from .error import ConversionError
10
+ except ImportError:
11
+ if __name__ == "__main__":
12
+ ConversionError = RuntimeError
13
+ else:
14
+ raise
15
+
16
+ _split_word_boundaries = re.compile(r"\b").split
17
+
18
+
19
+ def split_word_boundaries(__s: str):
20
+ for word in _split_word_boundaries(__s):
21
+ word = word.strip()
22
+ if word:
23
+ yield word
24
+
25
+
26
+ # todo: native Pydantic support when Pydantic is available
27
+ class IntFlagMeta(type(IntFlag)):
28
+ def loads(self, __s: str, /):
29
+ def iter_flags(args: Iterable[str]) -> Generator[IntFlagMeta]:
30
+ i = 0
31
+ last_yield = None
32
+
33
+ for i, arg in enumerate(args):
34
+ match (i % 2 == 0, arg):
35
+ case (True, "|"):
36
+ raise ConversionError(
37
+ f"Expected a flag, got a pipe at element #{i}"
38
+ )
39
+ case (False, "|"):
40
+ pass
41
+ case (True, flag):
42
+ last_yield = self[arg]
43
+ yield last_yield
44
+ case (False, flag):
45
+ raise ConversionError(
46
+ f"Expected a pipe, got a flag at element #{i} ({flag = })"
47
+ )
48
+
49
+ if last_yield is not None and i % 2 == 1:
50
+ raise ConversionError(
51
+ f"Expected word after pipe at element #{i} (after flag: {last_yield!r})"
52
+ )
53
+
54
+ try:
55
+ args = split_word_boundaries(__s)
56
+ flags = iter_flags(args)
57
+ flag = reduce(lambda f, g: f | g, flags)
58
+ return flag
59
+ except Exception as exc:
60
+ if isinstance(exc, ConversionError):
61
+ raise
62
+ else:
63
+ raise ConversionError("An internal exception occurred.") from exc
@@ -0,0 +1,8 @@
1
+ __all__ = ["Date", "DateTime", "Time", "TimeDelta", "TimeZone", "TzInfo"]
2
+
3
+ from datetime import date as Date
4
+ from datetime import datetime as DateTime
5
+ from datetime import time as Time
6
+ from datetime import timedelta as TimeDelta
7
+ from datetime import timezone as TimeZone
8
+ from datetime import tzinfo as TzInfo
@@ -0,0 +1,3 @@
1
+ __all__ = ["Err", "Null", "Ok", "Option", "Result", "UnwrapError", "catch_unwind"]
2
+
3
+ from .result import Err, Null, Ok, Option, Result, UnwrapError, catch_unwind
File without changes
@@ -0,0 +1,32 @@
1
+ """All the monads I don't want to write twice."""
2
+
3
+ __all__ = ["UnwrapError", "Err", "Null", "Ok", "Result", "Option", "catch_unwind"]
4
+
5
+
6
+ from collections.abc import Callable
7
+ from dataclasses import dataclass
8
+ from functools import wraps
9
+
10
+ from .error import UnwrapError
11
+ from .variants import Err, Null, Ok, Some
12
+
13
+ type Result[T, E: Exception] = Ok[T] | Err[E]
14
+ type Option[T] = Some[T] | Null
15
+
16
+
17
+ @dataclass
18
+ class catch_unwind[**P, T, E: Exception]:
19
+ """Wraps a function and prevents it from raising the given exception(s)."""
20
+
21
+ exc: type[E]
22
+
23
+ def __call__(self, func: Callable[P, T]) -> Callable[P, Result[T, E]]:
24
+ @wraps(func)
25
+ def wrapped(*args: P.args, **kwargs: P.kwargs) -> Result[T, E]:
26
+ try:
27
+ res = func(*args, **kwargs)
28
+ return Ok(res)
29
+ except self.exc as exc:
30
+ return Err(exc)
31
+
32
+ return wrapped
@@ -0,0 +1,16 @@
1
+ from eviltyping import name
2
+
3
+ INDENT = " " * 8
4
+ END = "\n"
5
+
6
+
7
+ class UnwrapError(Exception):
8
+ error: Exception | None = None
9
+
10
+ def __init__(self, received: object, expected: object) -> None:
11
+ message = [name(type(self)), "could not unwrap value:"]
12
+ if expected is None:
13
+ message += (" ", repr(received))
14
+ else:
15
+ message += (END, f"{INDENT}{expected = }{END}", f"{INDENT}{received = }")
16
+ super().__init__("".join(message))
@@ -0,0 +1,19 @@
1
+ from abc import ABC, abstractmethod
2
+ from typing import Never
3
+
4
+ from .error import UnwrapError
5
+
6
+ __all__ = ["Result"]
7
+
8
+
9
+ class Result[T, E: Exception | None](ABC):
10
+ """Base class for all `Result` types."""
11
+
12
+ def _bad_unwrap(self, expected: object = None) -> Never:
13
+ raise UnwrapError(self, expected)
14
+
15
+ @abstractmethod
16
+ def unwrap(self, expected: object = None) -> T: ...
17
+
18
+ @abstractmethod
19
+ def unwrap_err(self, expected: object = None) -> E: ...
@@ -0,0 +1,6 @@
1
+ __all__ = ["Err", "Null", "Ok", "Some"]
2
+
3
+
4
+ from .err import Err
5
+ from .null import Null
6
+ from .ok import Ok, Some
@@ -0,0 +1,20 @@
1
+ from dataclasses import dataclass
2
+ from typing import Never, final, override
3
+
4
+ from evilmonads.result.error import UnwrapError
5
+
6
+ from ..result import Result
7
+
8
+
9
+ @final
10
+ @dataclass(frozen=True)
11
+ class Err[E: Exception](Result[Never, E]):
12
+ exc: E
13
+
14
+ @override
15
+ def unwrap(self, expected: object = None) -> Never:
16
+ raise UnwrapError(self, expected)
17
+
18
+ @override
19
+ def unwrap_err(self, expected: object = None) -> E:
20
+ return self.exc
@@ -0,0 +1,18 @@
1
+ from dataclasses import dataclass
2
+ from typing import Never, final, override
3
+
4
+ from evilmonads.result.error import UnwrapError
5
+
6
+ from ..result import Result
7
+
8
+
9
+ @final
10
+ @dataclass(frozen=True)
11
+ class Null(Result[Never, None]):
12
+ @override
13
+ def unwrap(self, expected: object = None) -> Never:
14
+ raise UnwrapError(self, expected)
15
+
16
+ @override
17
+ def unwrap_err(self, expected: object = None) -> None:
18
+ return None
@@ -0,0 +1,28 @@
1
+ from dataclasses import dataclass
2
+ from typing import Never, final, override
3
+
4
+ from ..error import UnwrapError
5
+ from ..result import Result
6
+
7
+
8
+ @dataclass(frozen=True)
9
+ class _Ok[T](Result[T, Never]):
10
+ val: T
11
+
12
+ @override
13
+ def unwrap(self, expected: object = None) -> T:
14
+ return self.val
15
+
16
+ @override
17
+ def unwrap_err(self, expected: object = None) -> Never:
18
+ raise UnwrapError(self, expected)
19
+
20
+
21
+ @final
22
+ class Ok[T](_Ok[T]):
23
+ val: T
24
+
25
+
26
+ @final
27
+ class Some[T](_Ok[T]):
28
+ val: T
File without changes
@@ -0,0 +1,78 @@
1
+ from collections.abc import Callable, Sequence
2
+ from functools import partial
3
+ from random import Random
4
+ from typing import TYPE_CHECKING, final, overload
5
+
6
+ if TYPE_CHECKING:
7
+ from _typeshed import SupportsLenAndGetItem
8
+
9
+ __all__ = ["RNG"]
10
+
11
+
12
+ @final
13
+ class RNG:
14
+ """An alternative API to `random.Random`.
15
+
16
+ For now, this class cannot be subclassed. Pass a subclass of `Random` as
17
+ the first parameter instead.
18
+ """
19
+
20
+ @overload
21
+ def __init__(self, wrapped: Random, /) -> None: ...
22
+
23
+ @overload
24
+ def __init__(
25
+ self, seed: int | float | str | bytes | bytearray | None = None
26
+ ) -> None: ...
27
+
28
+ def __init__(
29
+ self, seed: Random | int | float | str | bytes | bytearray | None = None
30
+ ) -> None:
31
+ self.__inst = seed if isinstance(seed, Random) else Random(seed)
32
+
33
+ @property
34
+ def unit(self) -> Callable[[], float]:
35
+ return self.__inst.random
36
+
37
+ @overload
38
+ def choice[T](
39
+ self,
40
+ population: "SupportsLenAndGetItem[T]",
41
+ /,
42
+ k: None = None,
43
+ weights: Sequence[float] | None = None,
44
+ cumulative: bool = False,
45
+ ) -> T: ...
46
+
47
+ @overload
48
+ def choice[T](
49
+ self,
50
+ population: "SupportsLenAndGetItem[T]",
51
+ /,
52
+ k: int,
53
+ weights: Sequence[float] | None = None,
54
+ cumulative: bool = False,
55
+ ) -> Sequence[T]: ...
56
+
57
+ def choice[T](
58
+ self,
59
+ population: "SupportsLenAndGetItem[T]",
60
+ /,
61
+ k: int | None = None,
62
+ weights: Sequence[float] | None = None,
63
+ cumulative: bool = False,
64
+ ) -> T | Sequence[T]:
65
+ if weights is None and k is None:
66
+ return self.__inst.choice(population)
67
+ choices = self.__inst.choices
68
+ with_weights = (
69
+ partial(choices, cum_weights=weights)
70
+ if cumulative
71
+ else partial(choices, weights=weights)
72
+ )
73
+
74
+ result = with_weights(population, k=1 if k is None else k)
75
+ return result[0] if k is None else result
76
+
77
+
78
+ _inst = RNG()
File without changes
@@ -0,0 +1,5 @@
1
+ """All the data structures I don't want to write twice."""
2
+
3
+ from .frozendict import frozendict
4
+
5
+ __all__ = ["frozendict"]
@@ -0,0 +1,68 @@
1
+ __all__ = ["frozendict"]
2
+
3
+
4
+ from collections.abc import Hashable, Iterable, Iterator, Mapping
5
+ from typing import TYPE_CHECKING, override
6
+
7
+ from eviltyping import name
8
+
9
+ if TYPE_CHECKING:
10
+ from _typeshed import SupportsKeysAndGetItem
11
+
12
+
13
+ class ToDo(NotImplementedError):
14
+ pass
15
+
16
+
17
+ class frozendict[KT, VT](Mapping[KT, VT]):
18
+ """An immutable implementation of Mapping."""
19
+
20
+ # TODO: support Pydantic, pprint
21
+ __store: dict[KT, VT]
22
+ __as_str: str | None = None
23
+ __as_repr: str | None = None
24
+ __as_hash: int | None = None
25
+
26
+ def __init__(
27
+ self,
28
+ obj: "SupportsKeysAndGetItem[KT, VT] | Iterable[tuple[KT, VT]] | None" = None,
29
+ /,
30
+ ) -> None:
31
+ if obj is None:
32
+ self.__store = {}
33
+ else:
34
+ self.__store = dict(obj)
35
+
36
+ @override
37
+ def __iter__(self) -> Iterator[KT]:
38
+ yield from self.__store
39
+
40
+ @override
41
+ def __len__(self) -> int:
42
+ return len(self.__store)
43
+
44
+ @override
45
+ def __getitem__(self, key: KT, /) -> VT:
46
+ return self.__store[key]
47
+
48
+ @override
49
+ def __str__(self) -> str:
50
+ if self.__as_str is None:
51
+ self.__as_str = str(self.__store)
52
+ return self.__as_str
53
+
54
+ @override
55
+ def __repr__(self) -> str:
56
+ if self.__as_repr is None:
57
+ self.__as_repr = name(type(self)) + " " + repr(self.__store)
58
+ return self.__as_repr
59
+
60
+ @override
61
+ def __hash__(self: "frozendict[Hashable, Hashable]") -> int:
62
+ if self.__as_hash is None:
63
+ self.__as_hash = hash(tuple(self.items()))
64
+ return self.__as_hash
65
+
66
+ @override
67
+ def __contains__(self, key: object) -> bool:
68
+ return key in self.__store
File without changes
@@ -0,0 +1,19 @@
1
+ """All the types I don't want to write twice."""
2
+
3
+ __all__ = [
4
+ "StrPath",
5
+ "Destructor",
6
+ "Getter",
7
+ "Setter",
8
+ "Callable",
9
+ "Newable",
10
+ "strong_cast",
11
+ "HasName",
12
+ "name",
13
+ ]
14
+
15
+ from .aliases import StrPath
16
+ from .descriptors import Destructor, Getter, Setter
17
+ from .dunders import Callable, Newable
18
+ from .guards import strong_cast
19
+ from .name import HasName, name
@@ -0,0 +1,8 @@
1
+ """Useful type aliases."""
2
+
3
+ __all__ = ["StrPath"]
4
+
5
+ from os import PathLike
6
+
7
+ type StrPath = str | PathLike[str]
8
+ """Like StrPath from typeshed."""
@@ -0,0 +1,51 @@
1
+ """
2
+ Descriptor protocol, as a set of Protocols. See:
3
+
4
+ https://docs.python.org/3/howto/descriptor.html#descriptor-protocol
5
+ """
6
+
7
+ import sys
8
+ from typing import Generic, Protocol, TypeVar, overload
9
+
10
+ __all__ = ["Getter", "Setter", "Destructor"]
11
+
12
+ if sys.version_info < (3, 13):
13
+ # TODO: deprecate support for python 3.12 in late 2027
14
+ _Owner = TypeVar("_Owner", contravariant=True)
15
+ _RT_g = TypeVar("_RT_g", covariant=True)
16
+ _IT = TypeVar("_IT", contravariant=True)
17
+ _RT_d = TypeVar("_RT_d", covariant=True)
18
+ else:
19
+ _Owner = TypeVar("_Owner", default=object, contravariant=True)
20
+ # pyright: ignore[reportUnreachable]
21
+ _RT_g = TypeVar("_RT_g", covariant=True)
22
+ _IT = TypeVar("_IT", contravariant=True)
23
+ _RT_d = TypeVar("_RT_d", default=None, covariant=True)
24
+
25
+ ### Methods ###
26
+
27
+
28
+ class Getter(Protocol, Generic[_RT_g, _Owner]):
29
+ @overload
30
+ def __get__(self, instance: _Owner, /) -> _RT_g: ...
31
+
32
+ @overload
33
+ def __get__(self, instance: _Owner | None, owner: type[_Owner], /) -> _RT_g: ...
34
+
35
+ def __get__(
36
+ self, instance: _Owner | None, owner: type[_Owner] | None = None, /
37
+ ) -> _RT_g:
38
+ """
39
+ Implementation of a non-data descriptor. See:
40
+
41
+ https://docs.python.org/3/reference/datamodel.html#object.__get
42
+ """
43
+ ...
44
+
45
+
46
+ class Setter(Protocol, Generic[_IT, _RT_d, _Owner]):
47
+ def __set__(self, instance: _Owner, value: _IT, /) -> _RT_d: ...
48
+
49
+
50
+ class Destructor(Protocol, Generic[_RT_d, _Owner]):
51
+ def __delete__(self, instance: _Owner, /) -> _RT_d: ...
@@ -0,0 +1,15 @@
1
+ """Miscellaneous double-underscore protocols."""
2
+
3
+ from typing import Protocol
4
+
5
+ __all__ = ["Callable", "Newable"]
6
+
7
+
8
+ class Callable[**P, RT](Protocol):
9
+ """Like typing.Protocol but it doesn't scream at me for being wrong."""
10
+
11
+ def __call__(self, *args: P.args, **kwds: P.kwargs) -> RT: ...
12
+
13
+
14
+ class Newable[**P, RT](Protocol):
15
+ def __new__(cls, *args: P.args, **kwargs: P.kwargs) -> RT: ...
@@ -0,0 +1,18 @@
1
+ """Type guards and such."""
2
+
3
+ __all__ = ["strong_cast"]
4
+
5
+ from typing import TYPE_CHECKING, Any, TypeVar
6
+
7
+ if TYPE_CHECKING:
8
+
9
+ def strong_cast[T](
10
+ _type: type[T] | TypeVar,
11
+ _value: Any, # pyright: ignore[reportAny, reportExplicitAny]
12
+ /,
13
+ ) -> T: ...
14
+
15
+ else:
16
+
17
+ def strong_cast[T](_type, _value):
18
+ return _value
@@ -0,0 +1,28 @@
1
+ from typing import Protocol, Self
2
+
3
+ from .descriptors import Getter
4
+
5
+ __all__ = ["HasName", "name"]
6
+
7
+
8
+ class _HasNameStr(Protocol):
9
+ __name__: str
10
+
11
+
12
+ class _HasNameGetter(Protocol):
13
+ __name__: Getter[str, Self]
14
+
15
+
16
+ type HasName = _HasNameStr | _HasNameGetter
17
+ """An object with a `__name__` string."""
18
+
19
+
20
+ def name(obj: HasName, /) -> str:
21
+ """Returns the name of an object.
22
+
23
+ For the name of an object's *type*, consider `name(type(obj))`.
24
+
25
+ >>> name(type(1))
26
+ 'int'
27
+ """
28
+ return obj.__name__
File without changes
@@ -2,5 +2,5 @@ __author__ = "Ernest Izdebski"
2
2
  __copyright__ = "Copyright 2025-present, Ernest Izdebski"
3
3
  __credits__ = ["Ernest Izdebski"]
4
4
  __license__ = "MIT"
5
- __version__ = "0.1.2"
5
+ __version__ = "0.2.0"
6
6
  __maintainer__ = "Ernest Izdebski"
File without changes
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.2
1
+ Metadata-Version: 2.4
2
2
  Name: evilutils
3
- Version: 0.1.2
3
+ Version: 0.2.0
4
4
  Summary: All of the utils I don't want to write twice.
5
5
  Author-email: Ernest Izdebski <44341687+ernieIzde8ski@users.noreply.github.com>
6
6
  License: Copyright 2025-present Ernest Izdebski
@@ -20,6 +20,7 @@ Requires-Python: >=3.12
20
20
  Description-Content-Type: text/markdown
21
21
  License-File: LICENSE
22
22
  Requires-Dist: typing_extensions>=4.12.2
23
+ Dynamic: license-file
23
24
 
24
25
  # evilutils
25
26
 
@@ -0,0 +1,52 @@
1
+ LICENSE
2
+ MANIFEST.in
3
+ README.md
4
+ pyproject.toml
5
+ src/evilconverters/__init__.py
6
+ src/evilconverters/error.py
7
+ src/evilconverters/intflag.py
8
+ src/evilconverters/py.typed
9
+ src/evildatetime/__init__.py
10
+ src/evildatetime/py.typed
11
+ src/evilfunctools/__init__.py
12
+ src/evilfunctools/compose.py
13
+ src/evilfunctools/decorators.py
14
+ src/evilfunctools/py.typed
15
+ src/evilmonads/__init__.py
16
+ src/evilmonads/py.typed
17
+ src/evilmonads/result/__init__.py
18
+ src/evilmonads/result/error.py
19
+ src/evilmonads/result/result.py
20
+ src/evilmonads/result/variants/__init__.py
21
+ src/evilmonads/result/variants/err.py
22
+ src/evilmonads/result/variants/null.py
23
+ src/evilmonads/result/variants/ok.py
24
+ src/evilpath/__init__.py
25
+ src/evilpath/path.py
26
+ src/evilpath/py.typed
27
+ src/evilrng/__init__.py
28
+ src/evilrng/py.typed
29
+ src/evilstructs/__init__.py
30
+ src/evilstructs/frozendict.py
31
+ src/evilstructs/py.typed
32
+ src/eviltyping/__init__.py
33
+ src/eviltyping/aliases.py
34
+ src/eviltyping/descriptors.py
35
+ src/eviltyping/dunders.py
36
+ src/eviltyping/guards.py
37
+ src/eviltyping/name.py
38
+ src/eviltyping/py.typed
39
+ src/evilutils/__init__.py
40
+ src/evilutils/__main__.py
41
+ src/evilutils/info.py
42
+ src/evilutils/py.typed
43
+ src/evilutils.egg-info/PKG-INFO
44
+ src/evilutils.egg-info/SOURCES.txt
45
+ src/evilutils.egg-info/dependency_links.txt
46
+ src/evilutils.egg-info/requires.txt
47
+ src/evilutils.egg-info/top_level.txt
48
+ tests/test_converter.py
49
+ tests/test_file_structure.py
50
+ tests/test_path.py
51
+ tests/test_structs.py
52
+ tests/test_typing.py
@@ -0,0 +1,9 @@
1
+ evilconverters
2
+ evildatetime
3
+ evilfunctools
4
+ evilmonads
5
+ evilpath
6
+ evilrng
7
+ evilstructs
8
+ eviltyping
9
+ evilutils
@@ -0,0 +1,29 @@
1
+ from . import _ensure as _ # noqa: F401
2
+
3
+ # isort: split
4
+
5
+ import pytest
6
+
7
+ from evilconverters import ConversionError, IntFlag, IntFlagMeta, auto
8
+
9
+
10
+ def test_intflagmeta_loads():
11
+ class FooBar(IntFlag, metaclass=IntFlagMeta):
12
+ foo = auto()
13
+ bar = auto()
14
+
15
+ assert FooBar.loads("foo") == FooBar.foo
16
+
17
+ assert FooBar.loads("foo | bar") == FooBar.foo | FooBar.bar
18
+
19
+ with pytest.raises(ConversionError):
20
+ _ = FooBar.loads("")
21
+
22
+ with pytest.raises(ConversionError):
23
+ _ = FooBar.loads("foo | ")
24
+
25
+ with pytest.raises(ConversionError):
26
+ _ = FooBar.loads(" | foo")
27
+
28
+ with pytest.raises(ConversionError):
29
+ _ = FooBar.loads("baz")
@@ -0,0 +1,24 @@
1
+ from ._ensure import SRC_DIR
2
+
3
+ # isort: split
4
+
5
+ from pathlib import Path
6
+
7
+ from pytest_case import case
8
+
9
+ MODULES = list(SRC_DIR.glob("*/"))
10
+
11
+
12
+ def is_python_module(path: Path):
13
+ return (path / "__init__.py").is_file()
14
+
15
+
16
+ def is_typed(py_mod: Path):
17
+ return (py_mod / "py.typed").is_file()
18
+
19
+
20
+ @case((module,) for module in MODULES)
21
+ def test_modules_are_typed(path: Path) -> None:
22
+ assert not is_python_module(path) or is_typed(path), (
23
+ f"Module {path.name!r} should contain `py.typed` file"
24
+ )
@@ -0,0 +1,18 @@
1
+ from collections.abc import Mapping
2
+
3
+ from . import _ensure as _ # noqa: F401
4
+
5
+ # isort: split
6
+
7
+ from evilstructs import frozendict
8
+
9
+
10
+ def test_frozendict_can_be_used_as_mapping():
11
+ # This is more of a test of Pyright and my types, if anything
12
+ def first_key(obj: Mapping[str, str]) -> str | None:
13
+ keys = obj.keys()
14
+ return next(iter(keys), None)
15
+
16
+ obj = {"abc": "def"}
17
+ assert first_key(obj) == "abc"
18
+ assert first_key(frozendict(obj)) == "abc"
@@ -0,0 +1,26 @@
1
+ from . import _ensure as _ # noqa: F401
2
+
3
+ # isort: split
4
+
5
+ import pytest
6
+
7
+ from eviltyping import name
8
+
9
+
10
+ def test_classes_have_names():
11
+ assert isinstance(name(str), str)
12
+
13
+
14
+ def test_instances_dont():
15
+ with pytest.raises(AttributeError):
16
+ assert isinstance(name(object()), str) # pyright: ignore[reportArgumentType]
17
+
18
+
19
+ def test_can_get_type_name():
20
+ """
21
+ Issue: https://github.com/ernieIzde8ski/evilutils/issues/1
22
+ """
23
+
24
+ class FooBar: ...
25
+
26
+ assert name(FooBar) == "FooBar"
@@ -1 +0,0 @@
1
- typing_extensions>=4.12.2
@@ -1,22 +0,0 @@
1
- LICENSE
2
- MANIFEST.in
3
- README.md
4
- pyproject.toml
5
- requirements.txt
6
- src/evilfunctools/__init__.py
7
- src/evilfunctools/compose.py
8
- src/evilfunctools/decorators.py
9
- src/evilfunctools/py.typed
10
- src/evilpath/__init__.py
11
- src/evilpath/path.py
12
- src/evilpath/py.typed
13
- src/evilutils/__init__.py
14
- src/evilutils/__main__.py
15
- src/evilutils/info.py
16
- src/evilutils/py.typed
17
- src/evilutils.egg-info/PKG-INFO
18
- src/evilutils.egg-info/SOURCES.txt
19
- src/evilutils.egg-info/dependency_links.txt
20
- src/evilutils.egg-info/requires.txt
21
- src/evilutils.egg-info/top_level.txt
22
- tests/test_evilpath.py
@@ -1,3 +0,0 @@
1
- evilfunctools
2
- evilpath
3
- evilutils
File without changes
File without changes
File without changes
File without changes
@@ -6,11 +6,11 @@ from .compose import compose
6
6
  from .decorators import immediate
7
7
 
8
8
  __all__ = [
9
- "partial",
10
- "partialmethod",
11
9
  "cache",
12
10
  "cached_property",
13
11
  "compose",
14
- "wraps",
15
12
  "immediate",
13
+ "partial",
14
+ "partialmethod",
15
+ "wraps",
16
16
  ]