jetpytools 2.0.2__py3-none-any.whl → 2.1.1__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.

Potentially problematic release.


This version of jetpytools might be problematic. Click here for more details.

jetpytools/_metadata.py CHANGED
@@ -1,6 +1,6 @@
1
1
  """Collection of stuff that's useful in general python programming"""
2
2
 
3
- __version__ = "2.0.2"
3
+ __version__ = "2.1.1"
4
4
 
5
5
  __author_name__, __author_email__ = "Jaded Encoding Thaumaturgy", "jaded.encoding.thaumaturgy@gmail.com"
6
6
  __maintainer_name__, __maintainer_email__ = __author_name__, __author_email__
jetpytools/enums/base.py CHANGED
@@ -1,23 +1,44 @@
1
1
  from __future__ import annotations
2
2
 
3
- from enum import Enum
4
- from typing import Any, Self
3
+ from abc import ABCMeta
4
+ from enum import Enum, EnumMeta, ReprEnum
5
+ from enum import property as enum_property
6
+ from typing import TYPE_CHECKING, Any, Self
5
7
 
6
- from ..exceptions import CustomValueError, NotFoundEnumValue
7
- from ..types import FuncExcept
8
+ from ..exceptions import CustomTypeError, NotFoundEnumValueError
9
+ from ..types import FuncExcept, copy_signature
8
10
 
9
- __all__ = ["CustomEnum", "CustomIntEnum", "CustomStrEnum"]
11
+ __all__ = ["CustomEnum", "CustomIntEnum", "CustomStrEnum", "EnumABCMeta"]
12
+
13
+
14
+ class EnumABCMeta(EnumMeta, ABCMeta):
15
+ """Metaclass combining EnumMeta and ABCMeta to support abstract enumerations."""
16
+
17
+ @copy_signature(EnumMeta.__new__)
18
+ def __new__(mcls, *args: Any, **kwargs: Any) -> Any:
19
+ enum_cls = super().__new__(mcls, *args, **kwargs)
20
+
21
+ if len(enum_cls) == 0:
22
+ return enum_cls
23
+
24
+ if enum_cls.__abstractmethods__:
25
+ raise CustomTypeError(
26
+ "Can't instantiate abstract class {cls_name} without an implementation "
27
+ "for abstract method{plural} {methods}.",
28
+ enum_cls,
29
+ cls_name=enum_cls.__name__,
30
+ plural="s" if len(enum_cls.__abstractmethods__) > 1 else "",
31
+ methods=", ".join(f"'{n}'" for n in sorted(enum_cls.__abstractmethods__)),
32
+ )
33
+
34
+ return enum_cls
10
35
 
11
36
 
12
37
  class CustomEnum(Enum):
13
38
  """Base class for custom enums."""
14
39
 
15
40
  @classmethod
16
- def _missing_(cls, value: Any) -> Self | None:
17
- return cls.from_param(value)
18
-
19
- @classmethod
20
- def from_param(cls, value: Any, func_except: FuncExcept | None = None) -> Self | None:
41
+ def from_param(cls, value: Any, func_except: FuncExcept | None = None) -> Self:
21
42
  """
22
43
  Return the enum value from a parameter.
23
44
 
@@ -28,44 +49,45 @@ class CustomEnum(Enum):
28
49
 
29
50
  :raises NotFoundEnumValue: Variable not found in the given enum.
30
51
  """
31
-
32
- if value is None:
33
- return None
34
-
35
- if func_except is None:
36
- func_except = cls.from_param
37
-
38
- if isinstance(value, cls):
39
- return value
40
-
41
- if value is cls:
42
- raise CustomValueError("You must select a member, not pass the enum!", func_except)
52
+ func_except = func_except or cls.from_param
43
53
 
44
54
  try:
45
55
  return cls(value)
46
- except Exception:
56
+ except (ValueError, TypeError):
47
57
  pass
48
58
 
49
59
  if isinstance(func_except, tuple):
50
60
  func_name, var_name = func_except
51
61
  else:
52
- func_name, var_name = func_except, str(cls)
62
+ func_name, var_name = func_except, repr(cls)
53
63
 
54
- raise NotFoundEnumValue(
64
+ raise NotFoundEnumValueError(
55
65
  'The given value for "{var_name}" argument must be a valid {enum_name}, not "{value}"!\n'
56
66
  "Valid values are: [{readable_enum}].",
57
67
  func_name,
58
68
  var_name=var_name,
59
69
  enum_name=cls,
60
70
  value=value,
61
- readable_enum=iter([f"{x.name} ({x.value})" for x in cls]),
71
+ readable_enum=(f"{name} ({value!r})" for name, value in cls.__members__.items()),
62
72
  reason=value,
63
- )
73
+ ) from None
64
74
 
65
75
 
66
- class CustomIntEnum(int, CustomEnum):
76
+ class CustomIntEnum(int, CustomEnum, ReprEnum):
67
77
  """Base class for custom int enums."""
68
78
 
79
+ if TYPE_CHECKING:
80
+ _value_: int
69
81
 
70
- class CustomStrEnum(str, CustomEnum):
82
+ @enum_property
83
+ def value(self) -> int: ...
84
+
85
+
86
+ class CustomStrEnum(str, CustomEnum, ReprEnum):
71
87
  """Base class for custom str enums."""
88
+
89
+ if TYPE_CHECKING:
90
+ _value_: str
91
+
92
+ @enum_property
93
+ def value(self) -> str: ...
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: jetpytools
3
- Version: 2.0.2
3
+ Version: 2.1.1
4
4
  Summary: Collection of stuff that's useful in general python programming
5
5
  Project-URL: Source Code, https://github.com/Jaded-Encoding-Thaumaturgy/jetpytools
6
6
  Project-URL: Contact, https://discord.gg/XTpc6Fa9eB
@@ -1,8 +1,8 @@
1
1
  jetpytools/__init__.py,sha256=ha_pCOMqfeIbipDRrtqKOqH3NQEpX4KwN2SskpsCGb4,114
2
- jetpytools/_metadata.py,sha256=BTjwrbkWnb_tGrAfT27AXcCTiifys4nvvnRB6AJn6ns,414
2
+ jetpytools/_metadata.py,sha256=nZtBcZq3sazGefQvFPr5W5r0xlgs5gx_n6ON6xgLUnk,414
3
3
  jetpytools/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
4
  jetpytools/enums/__init__.py,sha256=TvEt3TWmnzf2TWS_Gd6llyyXAGDKxdhdJsDgSvT7xys,41
5
- jetpytools/enums/base.py,sha256=Vuzlv84jXUCje7-yoyjucPcgkmfVkLHuuLXcmx4z1Yw,1970
5
+ jetpytools/enums/base.py,sha256=XR5HfZa6mKzqdUvEG5_EG7SpVL2yegbsfLptJFGnjEU,2858
6
6
  jetpytools/enums/other.py,sha256=Fwf8J98cqFQbnDsOPV90RTOJ_Ltd72Y3qVbSDzOl5Eg,1346
7
7
  jetpytools/exceptions/__init__.py,sha256=0rNEfnOuoSRUyKsutGzHFWQkgiFaK7diOT4VbRVKt9c,105
8
8
  jetpytools/exceptions/base.py,sha256=cKvND21z0McwbhpOg9oVYyMvLVa8MDs9m1g4FUbEHvM,6949
@@ -27,7 +27,7 @@ jetpytools/utils/file.py,sha256=3fJxAHjIN5zdyzO0guc3jDspcs5HPG4t4cwB_ZrAhh4,1062
27
27
  jetpytools/utils/funcs.py,sha256=2jOOIUQpifQ_kTuVUSrCAi8hvCmmvieBpMTfF8XuM24,979
28
28
  jetpytools/utils/math.py,sha256=ZqsAyVNBT4LD-zqP7QxEkGwWdVfrR7YAkdv87NQTMV0,3460
29
29
  jetpytools/utils/ranges.py,sha256=RAknSZkTAYxAXdFn_CKY8xGASu7xS7Gu039DX89ugDc,1293
30
- jetpytools-2.0.2.dist-info/METADATA,sha256=hGJCLx_FZHmzdIoUMNRrs5Lohi5s544OtjzLoS6UUEI,1198
31
- jetpytools-2.0.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
32
- jetpytools-2.0.2.dist-info/licenses/LICENSE,sha256=l0PN-qDtXcgOB5aXP_nSUsvCK5V3o9pQCGsTzyZhKL0,1071
33
- jetpytools-2.0.2.dist-info/RECORD,,
30
+ jetpytools-2.1.1.dist-info/METADATA,sha256=CujBkiLvL5FmBSKCYuppxsokWxzKckz8gp8SLD1BWL4,1198
31
+ jetpytools-2.1.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
32
+ jetpytools-2.1.1.dist-info/licenses/LICENSE,sha256=l0PN-qDtXcgOB5aXP_nSUsvCK5V3o9pQCGsTzyZhKL0,1071
33
+ jetpytools-2.1.1.dist-info/RECORD,,