ducktools-classbuilder 0.7.1__py3-none-any.whl → 0.7.3__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 ducktools-classbuilder might be problematic. Click here for more details.
- ducktools/classbuilder/__init__.py +14 -10
- ducktools/classbuilder/__init__.pyi +7 -7
- ducktools/classbuilder/_version.py +2 -2
- ducktools/classbuilder/annotations.py +39 -2
- {ducktools_classbuilder-0.7.1.dist-info → ducktools_classbuilder-0.7.3.dist-info}/METADATA +3 -2
- ducktools_classbuilder-0.7.3.dist-info/RECORD +13 -0
- {ducktools_classbuilder-0.7.1.dist-info → ducktools_classbuilder-0.7.3.dist-info}/WHEEL +1 -1
- ducktools_classbuilder-0.7.1.dist-info/RECORD +0 -13
- {ducktools_classbuilder-0.7.1.dist-info → ducktools_classbuilder-0.7.3.dist-info}/LICENSE.md +0 -0
- {ducktools_classbuilder-0.7.1.dist-info → ducktools_classbuilder-0.7.3.dist-info}/top_level.txt +0 -0
|
@@ -363,15 +363,17 @@ def eq_generator(cls, funcname="__eq__"):
|
|
|
363
363
|
]
|
|
364
364
|
|
|
365
365
|
if field_names:
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
366
|
+
instance_comparison = "\n and ".join(
|
|
367
|
+
f"self.{name} == other.{name}" for name in field_names
|
|
368
|
+
)
|
|
369
369
|
else:
|
|
370
370
|
instance_comparison = "True"
|
|
371
371
|
|
|
372
372
|
code = (
|
|
373
373
|
f"def {funcname}(self, other):\n"
|
|
374
|
-
f" return
|
|
374
|
+
f" return (\n"
|
|
375
|
+
f" {instance_comparison}\n"
|
|
376
|
+
f" ) if {class_comparison} else NotImplemented\n"
|
|
375
377
|
)
|
|
376
378
|
globs = {}
|
|
377
379
|
|
|
@@ -390,11 +392,13 @@ def frozen_setattr_generator(cls, funcname="__setattr__"):
|
|
|
390
392
|
if flags.get("slotted", True):
|
|
391
393
|
globs["__setattr_func"] = object.__setattr__
|
|
392
394
|
setattr_method = "__setattr_func(self, name, value)"
|
|
395
|
+
hasattr_check = "hasattr(self, name)"
|
|
393
396
|
else:
|
|
394
397
|
setattr_method = "self.__dict__[name] = value"
|
|
398
|
+
hasattr_check = "name in self.__dict__"
|
|
395
399
|
|
|
396
400
|
body = (
|
|
397
|
-
f" if
|
|
401
|
+
f" if {hasattr_check} or name not in __field_names:\n"
|
|
398
402
|
f' raise TypeError(\n'
|
|
399
403
|
f' f"{{type(self).__name__!r}} object does not support "'
|
|
400
404
|
f' f"attribute assignment"\n'
|
|
@@ -741,7 +745,7 @@ def make_slot_gatherer(field_type=Field):
|
|
|
741
745
|
|
|
742
746
|
def make_annotation_gatherer(
|
|
743
747
|
field_type=Field,
|
|
744
|
-
leave_default_values=
|
|
748
|
+
leave_default_values=False,
|
|
745
749
|
):
|
|
746
750
|
"""
|
|
747
751
|
Create a new annotation gatherer that will work with `Field` instances
|
|
@@ -807,7 +811,7 @@ def make_annotation_gatherer(
|
|
|
807
811
|
|
|
808
812
|
def make_field_gatherer(
|
|
809
813
|
field_type=Field,
|
|
810
|
-
leave_default_values=
|
|
814
|
+
leave_default_values=False,
|
|
811
815
|
):
|
|
812
816
|
def field_attribute_gatherer(cls_or_ns):
|
|
813
817
|
if isinstance(cls_or_ns, (_MappingProxyType, dict)):
|
|
@@ -840,7 +844,7 @@ def make_field_gatherer(
|
|
|
840
844
|
|
|
841
845
|
def make_unified_gatherer(
|
|
842
846
|
field_type=Field,
|
|
843
|
-
leave_default_values=
|
|
847
|
+
leave_default_values=False,
|
|
844
848
|
):
|
|
845
849
|
"""
|
|
846
850
|
Create a gatherer that will work via first slots, then
|
|
@@ -890,7 +894,7 @@ annotation_gatherer = make_annotation_gatherer()
|
|
|
890
894
|
|
|
891
895
|
# The unified gatherer used for slot classes must remove default
|
|
892
896
|
# values for slots to work correctly.
|
|
893
|
-
unified_gatherer = make_unified_gatherer(
|
|
897
|
+
unified_gatherer = make_unified_gatherer()
|
|
894
898
|
|
|
895
899
|
|
|
896
900
|
# Now the gatherers have been defined, add __repr__ and __eq__ to Field.
|
|
@@ -956,7 +960,7 @@ class AnnotationClass(metaclass=SlotMakerMeta):
|
|
|
956
960
|
def __init_subclass__(
|
|
957
961
|
cls,
|
|
958
962
|
methods=default_methods,
|
|
959
|
-
gatherer=
|
|
963
|
+
gatherer=unified_gatherer,
|
|
960
964
|
**kwargs
|
|
961
965
|
):
|
|
962
966
|
# Check class dict otherwise this will always be True as this base
|
|
@@ -178,37 +178,37 @@ def make_slot_gatherer(
|
|
|
178
178
|
@typing.overload
|
|
179
179
|
def make_annotation_gatherer(
|
|
180
180
|
field_type: type[_FieldType],
|
|
181
|
-
leave_default_values: bool =
|
|
181
|
+
leave_default_values: bool = False,
|
|
182
182
|
) -> Callable[[type | _CopiableMappings], tuple[dict[str, _FieldType], dict[str, typing.Any]]]: ...
|
|
183
183
|
|
|
184
184
|
@typing.overload
|
|
185
185
|
def make_annotation_gatherer(
|
|
186
186
|
field_type: _ReturnsField = Field,
|
|
187
|
-
leave_default_values: bool =
|
|
187
|
+
leave_default_values: bool = False,
|
|
188
188
|
) -> Callable[[type | _CopiableMappings], tuple[dict[str, Field], dict[str, typing.Any]]]: ...
|
|
189
189
|
|
|
190
190
|
@typing.overload
|
|
191
191
|
def make_field_gatherer(
|
|
192
192
|
field_type: type[_FieldType],
|
|
193
|
-
leave_default_values: bool =
|
|
193
|
+
leave_default_values: bool = False,
|
|
194
194
|
) -> Callable[[type | _CopiableMappings], tuple[dict[str, _FieldType], dict[str, typing.Any]]]: ...
|
|
195
195
|
|
|
196
196
|
@typing.overload
|
|
197
197
|
def make_field_gatherer(
|
|
198
198
|
field_type: _ReturnsField = Field,
|
|
199
|
-
leave_default_values: bool =
|
|
199
|
+
leave_default_values: bool = False,
|
|
200
200
|
) -> Callable[[type | _CopiableMappings], tuple[dict[str, Field], dict[str, typing.Any]]]: ...
|
|
201
201
|
|
|
202
202
|
@typing.overload
|
|
203
203
|
def make_unified_gatherer(
|
|
204
204
|
field_type: type[_FieldType],
|
|
205
|
-
leave_default_values: bool =
|
|
205
|
+
leave_default_values: bool = False,
|
|
206
206
|
) -> Callable[[type | _CopiableMappings], tuple[dict[str, _FieldType], dict[str, typing.Any]]]: ...
|
|
207
207
|
|
|
208
208
|
@typing.overload
|
|
209
209
|
def make_unified_gatherer(
|
|
210
210
|
field_type: _ReturnsField = Field,
|
|
211
|
-
leave_default_values: bool =
|
|
211
|
+
leave_default_values: bool = False,
|
|
212
212
|
) -> Callable[[type | _CopiableMappings], tuple[dict[str, Field], dict[str, typing.Any]]]: ...
|
|
213
213
|
|
|
214
214
|
|
|
@@ -249,7 +249,7 @@ class AnnotationClass(metaclass=SlotMakerMeta):
|
|
|
249
249
|
def __init_subclass__(
|
|
250
250
|
cls,
|
|
251
251
|
methods: frozenset[MethodMaker] | set[MethodMaker] = default_methods,
|
|
252
|
-
gatherer: _gatherer_type =
|
|
252
|
+
gatherer: _gatherer_type = unified_gatherer,
|
|
253
253
|
**kwargs,
|
|
254
254
|
) -> None: ...
|
|
255
255
|
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
__version__ = "0.7.
|
|
2
|
-
__version_tuple__ = (0, 7,
|
|
1
|
+
__version__ = "0.7.3"
|
|
2
|
+
__version_tuple__ = (0, 7, 3)
|
|
@@ -37,6 +37,36 @@ del _cell_factory
|
|
|
37
37
|
# End evil stuff from types.py
|
|
38
38
|
|
|
39
39
|
|
|
40
|
+
class _Stringlike(str):
|
|
41
|
+
# There are typing operators that are not supported by strings
|
|
42
|
+
# This adds the 'or' operator '|'
|
|
43
|
+
|
|
44
|
+
def __or__(self, other):
|
|
45
|
+
if isinstance(other, str):
|
|
46
|
+
other_r = other
|
|
47
|
+
elif name := getattr(other, "__name__", None):
|
|
48
|
+
other_r = name
|
|
49
|
+
else:
|
|
50
|
+
other_r = str(other)
|
|
51
|
+
|
|
52
|
+
return type(self)(f"{self} | {other_r}")
|
|
53
|
+
|
|
54
|
+
def __ror__(self, other):
|
|
55
|
+
if isinstance(other, str):
|
|
56
|
+
other_r = other
|
|
57
|
+
elif name := getattr(other, "__name__", None):
|
|
58
|
+
other_r = name
|
|
59
|
+
else:
|
|
60
|
+
other_r = str(other)
|
|
61
|
+
|
|
62
|
+
return type(self)(f"{other_r} | {self}")
|
|
63
|
+
|
|
64
|
+
def __repr__(self):
|
|
65
|
+
base = super().__repr__()
|
|
66
|
+
clsname = type(self).__name__
|
|
67
|
+
return f"{clsname}({base})"
|
|
68
|
+
|
|
69
|
+
|
|
40
70
|
class _StringGlobs(dict):
|
|
41
71
|
"""
|
|
42
72
|
Based on the fake globals dictionary used for annotations
|
|
@@ -47,7 +77,7 @@ class _StringGlobs(dict):
|
|
|
47
77
|
is not found.
|
|
48
78
|
"""
|
|
49
79
|
def __missing__(self, key):
|
|
50
|
-
return key
|
|
80
|
+
return _Stringlike(key)
|
|
51
81
|
|
|
52
82
|
def __repr__(self):
|
|
53
83
|
cls_name = self.__class__.__name__
|
|
@@ -165,7 +195,14 @@ def call_annotate_func(annotate):
|
|
|
165
195
|
closure = None
|
|
166
196
|
|
|
167
197
|
new_annotate = _FunctionType(annotate.__code__, globs, closure=closure)
|
|
168
|
-
|
|
198
|
+
|
|
199
|
+
# Convert _Stringlike back to str
|
|
200
|
+
annos = {
|
|
201
|
+
k: str(v) if isinstance(v, _Stringlike) else v
|
|
202
|
+
for k, v in new_annotate(1).items()
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
return annos
|
|
169
206
|
|
|
170
207
|
|
|
171
208
|
def get_ns_annotations(ns, eval_str=True):
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: ducktools-classbuilder
|
|
3
|
-
Version: 0.7.
|
|
3
|
+
Version: 0.7.3
|
|
4
4
|
Summary: Toolkit for creating class boilerplate generators
|
|
5
5
|
Author: David C Ellis
|
|
6
6
|
License: MIT License
|
|
@@ -48,8 +48,9 @@ Requires-Dist: pydantic ; extra == 'performance_tests'
|
|
|
48
48
|
Provides-Extra: testing
|
|
49
49
|
Requires-Dist: pytest >=8.2 ; extra == 'testing'
|
|
50
50
|
Requires-Dist: pytest-cov ; extra == 'testing'
|
|
51
|
-
Requires-Dist: mypy ; extra == 'testing'
|
|
52
51
|
Requires-Dist: typing-extensions ; extra == 'testing'
|
|
52
|
+
Provides-Extra: type_checking
|
|
53
|
+
Requires-Dist: mypy ; extra == 'type_checking'
|
|
53
54
|
|
|
54
55
|
# Ducktools: Class Builder #
|
|
55
56
|
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
ducktools/classbuilder/__init__.py,sha256=sHgrsySQDxcvnkL0GsQu9Q4Um2-9gRFyGeYGgNAEjag,32521
|
|
2
|
+
ducktools/classbuilder/__init__.pyi,sha256=t2KrEsEhKFbLpl0QeX0CiCy_VTRFRZO_2ABdfndRfZY,7939
|
|
3
|
+
ducktools/classbuilder/_version.py,sha256=SIkfjhjtpB8h4zuKinR8f9uXIG2btFt5dWqwqdWWTLQ,52
|
|
4
|
+
ducktools/classbuilder/annotations.py,sha256=cgFlMmEXIhBUZ3DWbPQgFVqPx56s1vR3KROaiypDroo,9174
|
|
5
|
+
ducktools/classbuilder/annotations.pyi,sha256=vW3YQIiKYYQJll9_B4oTkBwIh4nOy1AnU9Ny8_a0dRY,686
|
|
6
|
+
ducktools/classbuilder/prefab.py,sha256=6YOVVYYeuMF5gv9DnK-sCvNKxBaBoqDXNLUQ22-xINk,24097
|
|
7
|
+
ducktools/classbuilder/prefab.pyi,sha256=x2ioTpkhNjQXFeKABFOzE0xNeZ8f_W5vusmuAzE19mc,4491
|
|
8
|
+
ducktools/classbuilder/py.typed,sha256=la67KBlbjXN-_-DfGNcdOcjYumVpKG_Tkw-8n5dnGB4,8
|
|
9
|
+
ducktools_classbuilder-0.7.3.dist-info/LICENSE.md,sha256=6Thz9Dbw8R4fWInl6sGl8Rj3UnKnRbDwrc6jZerpugQ,1070
|
|
10
|
+
ducktools_classbuilder-0.7.3.dist-info/METADATA,sha256=bPvyPBu8p23LSFZ4Acnc13eQ4RGZzIrgjgn0FJ0dgC0,11004
|
|
11
|
+
ducktools_classbuilder-0.7.3.dist-info/WHEEL,sha256=OVMc5UfuAQiSplgO0_WdW7vXVGAt9Hdd6qtN4HotdyA,91
|
|
12
|
+
ducktools_classbuilder-0.7.3.dist-info/top_level.txt,sha256=uSDLtio3ZFqdwcsMJ2O5yhjB4Q3ytbBWbA8rJREganc,10
|
|
13
|
+
ducktools_classbuilder-0.7.3.dist-info/RECORD,,
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
ducktools/classbuilder/__init__.py,sha256=oT-U127MZ2xVXTaaCmH02Mxh1JhnQ65pkydcd2otqhc,32517
|
|
2
|
-
ducktools/classbuilder/__init__.pyi,sha256=NCLMWT3G0Z5lJky8EV_N6XcW8smScti6y2p163nZ8rM,7965
|
|
3
|
-
ducktools/classbuilder/_version.py,sha256=GkzZtP41uShUoMdcKAWBkfQEBwmWhBFNXQ0WU1xWj5c,52
|
|
4
|
-
ducktools/classbuilder/annotations.py,sha256=x-3936HcJzv04rga8k0fFTbu1656yDglVN6kCan4hiw,8203
|
|
5
|
-
ducktools/classbuilder/annotations.pyi,sha256=vW3YQIiKYYQJll9_B4oTkBwIh4nOy1AnU9Ny8_a0dRY,686
|
|
6
|
-
ducktools/classbuilder/prefab.py,sha256=6YOVVYYeuMF5gv9DnK-sCvNKxBaBoqDXNLUQ22-xINk,24097
|
|
7
|
-
ducktools/classbuilder/prefab.pyi,sha256=x2ioTpkhNjQXFeKABFOzE0xNeZ8f_W5vusmuAzE19mc,4491
|
|
8
|
-
ducktools/classbuilder/py.typed,sha256=la67KBlbjXN-_-DfGNcdOcjYumVpKG_Tkw-8n5dnGB4,8
|
|
9
|
-
ducktools_classbuilder-0.7.1.dist-info/LICENSE.md,sha256=6Thz9Dbw8R4fWInl6sGl8Rj3UnKnRbDwrc6jZerpugQ,1070
|
|
10
|
-
ducktools_classbuilder-0.7.1.dist-info/METADATA,sha256=Jo1LiPtmH3i5Z5N4QpjZkqtXAf59jYGbs1uVzMSCmLQ,10968
|
|
11
|
-
ducktools_classbuilder-0.7.1.dist-info/WHEEL,sha256=R0nc6qTxuoLk7ShA2_Y-UWkN8ZdfDBG2B6Eqpz2WXbs,91
|
|
12
|
-
ducktools_classbuilder-0.7.1.dist-info/top_level.txt,sha256=uSDLtio3ZFqdwcsMJ2O5yhjB4Q3ytbBWbA8rJREganc,10
|
|
13
|
-
ducktools_classbuilder-0.7.1.dist-info/RECORD,,
|
{ducktools_classbuilder-0.7.1.dist-info → ducktools_classbuilder-0.7.3.dist-info}/LICENSE.md
RENAMED
|
File without changes
|
{ducktools_classbuilder-0.7.1.dist-info → ducktools_classbuilder-0.7.3.dist-info}/top_level.txt
RENAMED
|
File without changes
|