ducktools-classbuilder 0.8.3__py3-none-any.whl → 0.9.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.
Potentially problematic release.
This version of ducktools-classbuilder might be problematic. Click here for more details.
- ducktools/classbuilder/__init__.py +9 -25
- ducktools/classbuilder/__init__.pyi +0 -13
- ducktools/classbuilder/_version.py +2 -2
- ducktools/classbuilder/annotations.py +1 -1
- ducktools/classbuilder/prefab.py +3 -3
- ducktools/classbuilder/prefab.pyi +110 -38
- {ducktools_classbuilder-0.8.3.dist-info → ducktools_classbuilder-0.9.0.dist-info}/METADATA +1 -1
- ducktools_classbuilder-0.9.0.dist-info/RECORD +13 -0
- ducktools_classbuilder-0.8.3.dist-info/RECORD +0 -13
- {ducktools_classbuilder-0.8.3.dist-info → ducktools_classbuilder-0.9.0.dist-info}/LICENSE +0 -0
- {ducktools_classbuilder-0.8.3.dist-info → ducktools_classbuilder-0.9.0.dist-info}/WHEEL +0 -0
- {ducktools_classbuilder-0.8.3.dist-info → ducktools_classbuilder-0.9.0.dist-info}/top_level.txt +0 -0
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
import os
|
|
34
34
|
|
|
35
35
|
from .annotations import get_ns_annotations, is_classvar
|
|
36
|
-
from ._version import __version__, __version_tuple__
|
|
36
|
+
from ._version import __version__, __version_tuple__ # noqa: F401
|
|
37
37
|
|
|
38
38
|
# Change this name if you make heavy modifications
|
|
39
39
|
INTERNALS_DICT = "__classbuilder_internals__"
|
|
@@ -47,7 +47,7 @@ _UNDER_TESTING = os.environ.get("PYTEST_VERSION") is not None
|
|
|
47
47
|
# Obtain types the same way types.py does in pypy
|
|
48
48
|
# See: https://github.com/pypy/pypy/blob/19d9fa6be11165116dd0839b9144d969ab426ae7/lib-python/3/types.py#L61-L73
|
|
49
49
|
class _C: __slots__ = 's' # noqa
|
|
50
|
-
_MemberDescriptorType = type(_C.s) #
|
|
50
|
+
_MemberDescriptorType = type(_C.s) # type: ignore
|
|
51
51
|
_MappingProxyType = type(type.__dict__)
|
|
52
52
|
del _C
|
|
53
53
|
|
|
@@ -280,7 +280,7 @@ def get_init_generator(null=NOTHING, extra_code=None):
|
|
|
280
280
|
|
|
281
281
|
assigns = "\n ".join(assignments) if assignments else "pass\n"
|
|
282
282
|
code = (
|
|
283
|
-
f"def {funcname}(self, {args}):\n"
|
|
283
|
+
f"def {funcname}(self, {args}):\n"
|
|
284
284
|
f" {assigns}\n"
|
|
285
285
|
)
|
|
286
286
|
# Handle additional function calls
|
|
@@ -663,10 +663,10 @@ class Field(metaclass=SlotMakerMeta):
|
|
|
663
663
|
def from_field(cls, fld, /, **kwargs):
|
|
664
664
|
"""
|
|
665
665
|
Create an instance of field or subclass from another field.
|
|
666
|
-
|
|
667
|
-
This is intended to be used to convert a base
|
|
666
|
+
|
|
667
|
+
This is intended to be used to convert a base
|
|
668
668
|
Field into a subclass.
|
|
669
|
-
|
|
669
|
+
|
|
670
670
|
:param fld: field class to convert
|
|
671
671
|
:param kwargs: Additional keyword arguments for subclasses
|
|
672
672
|
:return: new field subclass instance
|
|
@@ -762,7 +762,9 @@ def make_annotation_gatherer(
|
|
|
762
762
|
else:
|
|
763
763
|
cls_dict = cls_or_ns.__dict__
|
|
764
764
|
|
|
765
|
-
|
|
765
|
+
# This should really be dict[str, field_type] but static analysis
|
|
766
|
+
# doesn't understand this.
|
|
767
|
+
cls_fields: dict[str, Field] = {}
|
|
766
768
|
modifications = {}
|
|
767
769
|
|
|
768
770
|
cls_annotations = get_ns_annotations(cls_dict)
|
|
@@ -959,24 +961,6 @@ def slotclass(cls=None, /, *, methods=default_methods, syntax_check=True):
|
|
|
959
961
|
return cls
|
|
960
962
|
|
|
961
963
|
|
|
962
|
-
class AnnotationClass(metaclass=SlotMakerMeta):
|
|
963
|
-
__slots__ = {}
|
|
964
|
-
|
|
965
|
-
def __init_subclass__(
|
|
966
|
-
cls,
|
|
967
|
-
methods=default_methods,
|
|
968
|
-
gatherer=unified_gatherer,
|
|
969
|
-
**kwargs
|
|
970
|
-
):
|
|
971
|
-
# Check class dict otherwise this will always be True as this base
|
|
972
|
-
# class uses slots.
|
|
973
|
-
slots = "__slots__" in cls.__dict__
|
|
974
|
-
|
|
975
|
-
builder(cls, gatherer=gatherer, methods=methods, flags={"slotted": slots})
|
|
976
|
-
check_argument_order(cls)
|
|
977
|
-
super().__init_subclass__(**kwargs)
|
|
978
|
-
|
|
979
|
-
|
|
980
964
|
@slotclass
|
|
981
965
|
class GatheredFields:
|
|
982
966
|
"""
|
|
@@ -5,7 +5,6 @@ import inspect
|
|
|
5
5
|
|
|
6
6
|
from collections.abc import Callable
|
|
7
7
|
from types import MappingProxyType
|
|
8
|
-
from typing_extensions import dataclass_transform
|
|
9
8
|
|
|
10
9
|
_py_type = type | str # Alias for type hint values
|
|
11
10
|
_CopiableMappings = dict[str, typing.Any] | MappingProxyType[str, typing.Any]
|
|
@@ -244,18 +243,6 @@ def slotclass(
|
|
|
244
243
|
|
|
245
244
|
_gatherer_type = Callable[[type | _CopiableMappings], tuple[dict[str, Field], dict[str, typing.Any]]]
|
|
246
245
|
|
|
247
|
-
|
|
248
|
-
@dataclass_transform(field_specifiers=(Field,))
|
|
249
|
-
class AnnotationClass(metaclass=SlotMakerMeta):
|
|
250
|
-
__slots__: dict
|
|
251
|
-
|
|
252
|
-
def __init_subclass__(
|
|
253
|
-
cls,
|
|
254
|
-
methods: frozenset[MethodMaker] | set[MethodMaker] = default_methods,
|
|
255
|
-
gatherer: _gatherer_type = unified_gatherer,
|
|
256
|
-
**kwargs,
|
|
257
|
-
) -> None: ...
|
|
258
|
-
|
|
259
246
|
class GatheredFields:
|
|
260
247
|
__slots__: dict[str, None]
|
|
261
248
|
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
__version__ = "0.
|
|
2
|
-
__version_tuple__ = (0,
|
|
1
|
+
__version__ = "0.9.0"
|
|
2
|
+
__version_tuple__ = (0, 9, 0)
|
ducktools/classbuilder/prefab.py
CHANGED
|
@@ -36,7 +36,7 @@ from . import (
|
|
|
36
36
|
|
|
37
37
|
# These aren't used but are re-exported for ease of use
|
|
38
38
|
# noinspection PyUnresolvedReferences
|
|
39
|
-
from . import SlotFields, KW_ONLY
|
|
39
|
+
from . import SlotFields, KW_ONLY # noqa: F401
|
|
40
40
|
|
|
41
41
|
PREFAB_FIELDS = "PREFAB_FIELDS"
|
|
42
42
|
PREFAB_INIT_FUNC = "__prefab_init__"
|
|
@@ -294,7 +294,7 @@ class Attribute(Field):
|
|
|
294
294
|
"""
|
|
295
295
|
iter: bool = True
|
|
296
296
|
serialize: bool = True
|
|
297
|
-
metadata: dict = Field(default=FIELD_NOTHING, default_factory=dict)
|
|
297
|
+
metadata: dict = Field(default=FIELD_NOTHING, default_factory=dict) # type: ignore
|
|
298
298
|
|
|
299
299
|
|
|
300
300
|
# noinspection PyShadowingBuiltins
|
|
@@ -551,7 +551,7 @@ def _make_prefab(
|
|
|
551
551
|
|
|
552
552
|
class Prefab(metaclass=SlotMakerMeta):
|
|
553
553
|
_meta_gatherer = prefab_gatherer
|
|
554
|
-
__slots__ = {}
|
|
554
|
+
__slots__ = {} # type: ignore
|
|
555
555
|
|
|
556
556
|
# noinspection PyShadowingBuiltins
|
|
557
557
|
def __init_subclass__(
|
|
@@ -4,7 +4,8 @@ from typing_extensions import dataclass_transform
|
|
|
4
4
|
|
|
5
5
|
import inspect
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
# Suppress weird pylance error
|
|
8
|
+
from collections.abc import Callable # type: ignore
|
|
8
9
|
|
|
9
10
|
from . import (
|
|
10
11
|
NOTHING,
|
|
@@ -58,36 +59,73 @@ class Attribute(Field):
|
|
|
58
59
|
default: typing.Any | _NothingType = NOTHING,
|
|
59
60
|
default_factory: typing.Any | _NothingType = NOTHING,
|
|
60
61
|
type: type | _NothingType = NOTHING,
|
|
61
|
-
doc: str | None =
|
|
62
|
-
init: bool =
|
|
63
|
-
repr: bool =
|
|
64
|
-
compare: bool =
|
|
65
|
-
iter: bool =
|
|
66
|
-
kw_only: bool =
|
|
67
|
-
serialize: bool =
|
|
68
|
-
metadata: dict | None =
|
|
62
|
+
doc: str | None = ...,
|
|
63
|
+
init: bool = ...,
|
|
64
|
+
repr: bool = ...,
|
|
65
|
+
compare: bool = ...,
|
|
66
|
+
iter: bool = ...,
|
|
67
|
+
kw_only: bool = ...,
|
|
68
|
+
serialize: bool = ...,
|
|
69
|
+
metadata: dict | None = ...,
|
|
69
70
|
) -> None: ...
|
|
70
71
|
|
|
71
72
|
def __repr__(self) -> str: ...
|
|
72
73
|
def __eq__(self, other: Attribute | object) -> bool: ...
|
|
73
74
|
def validate_field(self) -> None: ...
|
|
74
75
|
|
|
76
|
+
@typing.overload
|
|
75
77
|
def attribute(
|
|
76
78
|
*,
|
|
77
|
-
default:
|
|
78
|
-
default_factory:
|
|
79
|
-
init: bool =
|
|
80
|
-
repr: bool =
|
|
81
|
-
compare: bool =
|
|
82
|
-
iter: bool =
|
|
83
|
-
kw_only: bool =
|
|
84
|
-
serialize: bool =
|
|
85
|
-
exclude_field: bool =
|
|
86
|
-
private: bool =
|
|
87
|
-
doc: str | None =
|
|
88
|
-
metadata: dict | None =
|
|
89
|
-
type: type | _NothingType =
|
|
90
|
-
) ->
|
|
79
|
+
default: _T,
|
|
80
|
+
default_factory: _NothingType = NOTHING,
|
|
81
|
+
init: bool = ...,
|
|
82
|
+
repr: bool = ...,
|
|
83
|
+
compare: bool = ...,
|
|
84
|
+
iter: bool = ...,
|
|
85
|
+
kw_only: bool = ...,
|
|
86
|
+
serialize: bool = ...,
|
|
87
|
+
exclude_field: bool = ...,
|
|
88
|
+
private: bool = ...,
|
|
89
|
+
doc: str | None = ...,
|
|
90
|
+
metadata: dict | None = ...,
|
|
91
|
+
type: type | _NothingType = ...,
|
|
92
|
+
) -> _T: ...
|
|
93
|
+
|
|
94
|
+
@typing.overload
|
|
95
|
+
def attribute(
|
|
96
|
+
*,
|
|
97
|
+
default: _NothingType = NOTHING,
|
|
98
|
+
default_factory: Callable[[], _T],
|
|
99
|
+
init: bool = ...,
|
|
100
|
+
repr: bool = ...,
|
|
101
|
+
compare: bool = ...,
|
|
102
|
+
iter: bool = ...,
|
|
103
|
+
kw_only: bool = ...,
|
|
104
|
+
serialize: bool = ...,
|
|
105
|
+
exclude_field: bool = ...,
|
|
106
|
+
private: bool = ...,
|
|
107
|
+
doc: str | None = ...,
|
|
108
|
+
metadata: dict | None = ...,
|
|
109
|
+
type: type | _NothingType = ...,
|
|
110
|
+
) -> _T: ...
|
|
111
|
+
|
|
112
|
+
@typing.overload
|
|
113
|
+
def attribute(
|
|
114
|
+
*,
|
|
115
|
+
default: _NothingType = NOTHING,
|
|
116
|
+
default_factory: _NothingType = NOTHING,
|
|
117
|
+
init: bool = ...,
|
|
118
|
+
repr: bool = ...,
|
|
119
|
+
compare: bool = ...,
|
|
120
|
+
iter: bool = ...,
|
|
121
|
+
kw_only: bool = ...,
|
|
122
|
+
serialize: bool = ...,
|
|
123
|
+
exclude_field: bool = ...,
|
|
124
|
+
private: bool = ...,
|
|
125
|
+
doc: str | None = ...,
|
|
126
|
+
metadata: dict | None = ...,
|
|
127
|
+
type: type | _NothingType = ...,
|
|
128
|
+
) -> typing.Any: ...
|
|
91
129
|
|
|
92
130
|
def prefab_gatherer(cls_or_ns: type | MappingProxyType) -> tuple[dict[str, Attribute], dict[str, typing.Any]]: ...
|
|
93
131
|
|
|
@@ -111,7 +149,8 @@ _T = typing.TypeVar("_T")
|
|
|
111
149
|
# noinspection PyUnresolvedReferences
|
|
112
150
|
@dataclass_transform(field_specifiers=(Attribute, attribute))
|
|
113
151
|
class Prefab(metaclass=SlotMakerMeta):
|
|
114
|
-
_meta_gatherer: Callable[[type | _CopiableMappings], tuple[dict[str, Field], dict[str, typing.Any]]]
|
|
152
|
+
_meta_gatherer: Callable[[type | _CopiableMappings], tuple[dict[str, Field], dict[str, typing.Any]]] = ...
|
|
153
|
+
__slots__: dict[str, typing.Any] = ...
|
|
115
154
|
def __init_subclass__(
|
|
116
155
|
cls,
|
|
117
156
|
init: bool = True,
|
|
@@ -125,23 +164,56 @@ class Prefab(metaclass=SlotMakerMeta):
|
|
|
125
164
|
recursive_repr: bool = False,
|
|
126
165
|
) -> None: ...
|
|
127
166
|
|
|
128
|
-
|
|
129
|
-
#
|
|
130
|
-
#
|
|
167
|
+
# As far as I can tell these are the correct types
|
|
168
|
+
# But mypy.stubtest crashes trying to analyse them
|
|
169
|
+
# Due to the combination of overload and dataclass_transform
|
|
170
|
+
# @typing.overload
|
|
171
|
+
# def prefab(
|
|
172
|
+
# cls: None = None,
|
|
173
|
+
# *,
|
|
174
|
+
# init: bool = ...,
|
|
175
|
+
# repr: bool = ...,
|
|
176
|
+
# eq: bool = ...,
|
|
177
|
+
# iter: bool = ...,
|
|
178
|
+
# match_args: bool = ...,
|
|
179
|
+
# kw_only: bool = ...,
|
|
180
|
+
# frozen: bool = ...,
|
|
181
|
+
# dict_method: bool = ...,
|
|
182
|
+
# recursive_repr: bool = ...,
|
|
183
|
+
# ) -> Callable[[type[_T]], type[_T]]: ...
|
|
184
|
+
|
|
185
|
+
# @dataclass_transform(field_specifiers=(Attribute, attribute))
|
|
186
|
+
# @typing.overload
|
|
187
|
+
# def prefab(
|
|
188
|
+
# cls: type[_T],
|
|
189
|
+
# *,
|
|
190
|
+
# init: bool = ...,
|
|
191
|
+
# repr: bool = ...,
|
|
192
|
+
# eq: bool = ...,
|
|
193
|
+
# iter: bool = ...,
|
|
194
|
+
# match_args: bool = ...,
|
|
195
|
+
# kw_only: bool = ...,
|
|
196
|
+
# frozen: bool = ...,
|
|
197
|
+
# dict_method: bool = ...,
|
|
198
|
+
# recursive_repr: bool = ...,
|
|
199
|
+
# ) -> type[_T]: ...
|
|
200
|
+
|
|
201
|
+
# As mypy crashes, and the only difference is the return type
|
|
202
|
+
# just return `Any` for now to avoid the overload.
|
|
131
203
|
@dataclass_transform(field_specifiers=(Attribute, attribute))
|
|
132
204
|
def prefab(
|
|
133
|
-
cls: type[_T] | None =
|
|
205
|
+
cls: type[_T] | None = ...,
|
|
134
206
|
*,
|
|
135
|
-
init: bool =
|
|
136
|
-
repr: bool =
|
|
137
|
-
eq: bool =
|
|
138
|
-
iter: bool =
|
|
139
|
-
match_args: bool =
|
|
140
|
-
kw_only: bool =
|
|
141
|
-
frozen: bool =
|
|
142
|
-
dict_method: bool =
|
|
143
|
-
recursive_repr: bool =
|
|
144
|
-
) ->
|
|
207
|
+
init: bool = ...,
|
|
208
|
+
repr: bool = ...,
|
|
209
|
+
eq: bool = ...,
|
|
210
|
+
iter: bool = ...,
|
|
211
|
+
match_args: bool = ...,
|
|
212
|
+
kw_only: bool = ...,
|
|
213
|
+
frozen: bool = ...,
|
|
214
|
+
dict_method: bool = ...,
|
|
215
|
+
recursive_repr: bool = ...,
|
|
216
|
+
) -> typing.Any: ...
|
|
145
217
|
|
|
146
218
|
def build_prefab(
|
|
147
219
|
class_name: str,
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
ducktools/classbuilder/__init__.py,sha256=IfMN45iuJJ0BadtmjwjoYhXCLw6WOSQTMk9s_cxGT0M,32312
|
|
2
|
+
ducktools/classbuilder/__init__.pyi,sha256=66VOHYndP7z83Bl7QzTOyoF8j2nLFRRFfaQ6-mTdnmo,7683
|
|
3
|
+
ducktools/classbuilder/_version.py,sha256=RJaQx44-8b_pifglxqeP0c25pHPZ-Zu98duqjj_ZSOg,52
|
|
4
|
+
ducktools/classbuilder/annotations.py,sha256=VEZsCM8lwfhaWrQi8dUOAkicYHxUHaSAyM-FzL34wXI,3583
|
|
5
|
+
ducktools/classbuilder/annotations.pyi,sha256=c5vYtULdDgMYWtkzeYMsHIbmnEuT2Ru-nNZieWvYuQ4,247
|
|
6
|
+
ducktools/classbuilder/prefab.py,sha256=I1FRb1avVp6u1TPJgEs5QB1pnRH0xh8PQoI3oF8su5Q,24415
|
|
7
|
+
ducktools/classbuilder/prefab.pyi,sha256=sd800Hx2jf3CIaIfcurzanKGV-7-Km6_dY8JrM2FRHw,6363
|
|
8
|
+
ducktools/classbuilder/py.typed,sha256=la67KBlbjXN-_-DfGNcdOcjYumVpKG_Tkw-8n5dnGB4,8
|
|
9
|
+
ducktools_classbuilder-0.9.0.dist-info/LICENSE,sha256=6Thz9Dbw8R4fWInl6sGl8Rj3UnKnRbDwrc6jZerpugQ,1070
|
|
10
|
+
ducktools_classbuilder-0.9.0.dist-info/METADATA,sha256=l6eUeDAEMjJKTInGL2Q7oXGSfj0ur0sKy8UWdbtB15c,9636
|
|
11
|
+
ducktools_classbuilder-0.9.0.dist-info/WHEEL,sha256=iAkIy5fosb7FzIOwONchHf19Qu7_1wCWyFNR5gu9nU0,91
|
|
12
|
+
ducktools_classbuilder-0.9.0.dist-info/top_level.txt,sha256=uSDLtio3ZFqdwcsMJ2O5yhjB4Q3ytbBWbA8rJREganc,10
|
|
13
|
+
ducktools_classbuilder-0.9.0.dist-info/RECORD,,
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
ducktools/classbuilder/__init__.py,sha256=6rU3erZbq2eNJ8P1zr948J7aHDFqyS8w5b2mKUEKrj8,32731
|
|
2
|
-
ducktools/classbuilder/__init__.pyi,sha256=47rT22Copd8gKiw26sTdAkA99NjMMwX6WsYsN0EEEtY,8060
|
|
3
|
-
ducktools/classbuilder/_version.py,sha256=WeYjLPgnZeDbw78yAtmbCWqzpBXhNlopfXe1KzTtm_c,52
|
|
4
|
-
ducktools/classbuilder/annotations.py,sha256=tFCuVSjnD8VleA7ytQnHo7PrMdlO1EzuTs-zK6tCQyo,3567
|
|
5
|
-
ducktools/classbuilder/annotations.pyi,sha256=c5vYtULdDgMYWtkzeYMsHIbmnEuT2Ru-nNZieWvYuQ4,247
|
|
6
|
-
ducktools/classbuilder/prefab.py,sha256=Lg3gBn3-09036vn5PNvbXt4m8srEo0JP3tf7rxdqk1I,24369
|
|
7
|
-
ducktools/classbuilder/prefab.pyi,sha256=qHK6KvV4C5fky4KCqskpoTUHKD4wCVxTdyGaydrATOE,4582
|
|
8
|
-
ducktools/classbuilder/py.typed,sha256=la67KBlbjXN-_-DfGNcdOcjYumVpKG_Tkw-8n5dnGB4,8
|
|
9
|
-
ducktools_classbuilder-0.8.3.dist-info/LICENSE,sha256=6Thz9Dbw8R4fWInl6sGl8Rj3UnKnRbDwrc6jZerpugQ,1070
|
|
10
|
-
ducktools_classbuilder-0.8.3.dist-info/METADATA,sha256=4Srcr862qbqjoIY5MpWJoxIK70STNtqqlUVNv0gtp6o,9636
|
|
11
|
-
ducktools_classbuilder-0.8.3.dist-info/WHEEL,sha256=iAkIy5fosb7FzIOwONchHf19Qu7_1wCWyFNR5gu9nU0,91
|
|
12
|
-
ducktools_classbuilder-0.8.3.dist-info/top_level.txt,sha256=uSDLtio3ZFqdwcsMJ2O5yhjB4Q3ytbBWbA8rJREganc,10
|
|
13
|
-
ducktools_classbuilder-0.8.3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
{ducktools_classbuilder-0.8.3.dist-info → ducktools_classbuilder-0.9.0.dist-info}/top_level.txt
RENAMED
|
File without changes
|