ducktools-classbuilder 0.8.3__tar.gz → 0.9.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.
Potentially problematic release.
This version of ducktools-classbuilder might be problematic. Click here for more details.
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/PKG-INFO +1 -1
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/src/ducktools/classbuilder/__init__.py +9 -25
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/src/ducktools/classbuilder/__init__.pyi +0 -13
- ducktools_classbuilder-0.9.0/src/ducktools/classbuilder/_version.py +2 -0
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/src/ducktools/classbuilder/annotations.py +1 -1
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/src/ducktools/classbuilder/prefab.py +3 -3
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/src/ducktools/classbuilder/prefab.pyi +110 -38
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/src/ducktools_classbuilder.egg-info/PKG-INFO +1 -1
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/tests/annotations/test_annotated.py +1 -42
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/tests/prefab/dynamic/test_subclass_implementation.py +47 -1
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/tests/test_core.py +0 -47
- ducktools_classbuilder-0.8.3/src/ducktools/classbuilder/_version.py +0 -2
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/.github/dependabot.yml +0 -0
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/.github/workflows/auto_test.yml +0 -0
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/.github/workflows/publish_to_pypi.yml +0 -0
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/.github/workflows/publish_to_testpypi.yml +0 -0
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/.gitignore +0 -0
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/.readthedocs.yaml +0 -0
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/LICENSE +0 -0
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/MANIFEST.in +0 -0
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/README.md +0 -0
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/docs/Makefile +0 -0
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/docs/api.md +0 -0
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/docs/approach_vs_tool.md +0 -0
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/docs/conf.py +0 -0
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/docs/extension_examples.md +0 -0
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/docs/generated_code.md +0 -0
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/docs/index.md +0 -0
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/docs/make.bat +0 -0
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/docs/perf/performance_tests.md +0 -0
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/docs/prefab/index.md +0 -0
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/docs/tutorial.md +0 -0
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/docs_code/docs_ex10_frozen_attributes.py +0 -0
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/docs_code/docs_ex1_basic.py +0 -0
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/docs_code/docs_ex2_register.py +0 -0
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/docs_code/docs_ex3_iterable.py +0 -0
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/docs_code/docs_ex5_frozen.py +0 -0
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/docs_code/docs_ex7_posonly.py +0 -0
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/docs_code/docs_ex8_converters.py +0 -0
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/docs_code/docs_ex9_annotated.py +0 -0
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/docs_code/index_example.py +0 -0
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/docs_code/tutorial_code.py +0 -0
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/pyproject.toml +0 -0
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/setup.cfg +0 -0
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/src/ducktools/classbuilder/annotations.pyi +0 -0
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/src/ducktools/classbuilder/py.typed +0 -0
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/src/ducktools_classbuilder.egg-info/SOURCES.txt +0 -0
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/src/ducktools_classbuilder.egg-info/dependency_links.txt +0 -0
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/src/ducktools_classbuilder.egg-info/requires.txt +0 -0
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/src/ducktools_classbuilder.egg-info/top_level.txt +0 -0
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/tests/annotations/test_annotations_module.py +0 -0
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/tests/annotations/test_future_annotations.py +0 -0
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/tests/conftest.py +0 -0
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/tests/prefab/dynamic/test_compare_attrib.py +0 -0
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/tests/prefab/dynamic/test_construction.py +0 -0
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/tests/prefab/dynamic/test_frozen.py +0 -0
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/tests/prefab/dynamic/test_internals.py +0 -0
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/tests/prefab/dynamic/test_pre_post_init.py +0 -0
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/tests/prefab/dynamic/test_private.py +0 -0
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/tests/prefab/dynamic/test_slots_novalues.py +0 -0
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/tests/prefab/dynamic/test_slotted_class.py +0 -0
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/tests/prefab/shared/conftest.py +0 -0
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/tests/prefab/shared/examples/creation.py +0 -0
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/tests/prefab/shared/examples/creation_empty.py +0 -0
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/tests/prefab/shared/examples/dunders.py +0 -0
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/tests/prefab/shared/examples/fails/creation_2.py +0 -0
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/tests/prefab/shared/examples/fails/creation_3.py +0 -0
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/tests/prefab/shared/examples/fails/creation_5.py +0 -0
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/tests/prefab/shared/examples/fails/inheritance_1.py +0 -0
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/tests/prefab/shared/examples/fails/inheritance_2.py +0 -0
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/tests/prefab/shared/examples/funcs_prefabs.py +0 -0
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/tests/prefab/shared/examples/hint_syntax.py +0 -0
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/tests/prefab/shared/examples/inheritance.py +0 -0
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/tests/prefab/shared/examples/init_ex.py +0 -0
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/tests/prefab/shared/examples/kw_only.py +0 -0
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/tests/prefab/shared/examples/repr_func.py +0 -0
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/tests/prefab/shared/test_creation.py +0 -0
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/tests/prefab/shared/test_dunders.py +0 -0
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/tests/prefab/shared/test_funcs.py +0 -0
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/tests/prefab/shared/test_hint_syntax.py +0 -0
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/tests/prefab/shared/test_inheritance.py +0 -0
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/tests/prefab/shared/test_init.py +0 -0
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/tests/prefab/shared/test_kw_only.py +0 -0
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/tests/prefab/shared/test_repr.py +0 -0
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/tests/py312_tests/test_generic_annotations.py +0 -0
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/tests/py314_tests/_test_support.py +0 -0
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/tests/py314_tests/test_forwardref_annotations.py +0 -0
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/tests/test_field_flags.py +0 -0
- {ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/tests/test_slotmakermeta.py +0 -0
{ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/src/ducktools/classbuilder/__init__.py
RENAMED
|
@@ -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
|
|
{ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/src/ducktools/classbuilder/prefab.py
RENAMED
|
@@ -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__(
|
{ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/src/ducktools/classbuilder/prefab.pyi
RENAMED
|
@@ -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,
|
{ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/tests/annotations/test_annotated.py
RENAMED
|
@@ -4,14 +4,13 @@ does not interfere when wrapping ClassVar
|
|
|
4
4
|
"""
|
|
5
5
|
|
|
6
6
|
import sys
|
|
7
|
-
import pytest
|
|
8
7
|
|
|
9
8
|
from typing import ClassVar
|
|
10
9
|
from typing_extensions import Annotated
|
|
11
10
|
|
|
12
11
|
from ducktools.classbuilder import (
|
|
13
12
|
Field, SlotFields, NOTHING,
|
|
14
|
-
|
|
13
|
+
annotation_gatherer, make_annotation_gatherer
|
|
15
14
|
)
|
|
16
15
|
|
|
17
16
|
from ducktools.classbuilder.annotations import (
|
|
@@ -102,43 +101,3 @@ def test_make_annotation_gatherer():
|
|
|
102
101
|
for key in "defgh":
|
|
103
102
|
assert key not in annos
|
|
104
103
|
assert key not in modifications
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
def test_annotationclass():
|
|
108
|
-
class ExampleAnnotated(AnnotationClass, slots=False):
|
|
109
|
-
a: str = "a"
|
|
110
|
-
b: "list[str]" = "b"
|
|
111
|
-
c: Annotated[str, ""] = Field(default="c")
|
|
112
|
-
|
|
113
|
-
d: ClassVar[str] = "d"
|
|
114
|
-
e: Annotated[ClassVar[str], ""] = "e"
|
|
115
|
-
f: "Annotated[ClassVar[str], '']" = "f"
|
|
116
|
-
g: Annotated[Annotated[ClassVar[str], ""], ""] = "g"
|
|
117
|
-
h: Annotated[CV[str], ''] = "h"
|
|
118
|
-
|
|
119
|
-
for key in "abc":
|
|
120
|
-
assert key not in ExampleAnnotated.__dict__
|
|
121
|
-
|
|
122
|
-
for key in "defgh":
|
|
123
|
-
assert key in ExampleAnnotated.__dict__
|
|
124
|
-
|
|
125
|
-
ex = ExampleAnnotated()
|
|
126
|
-
for char in "abcdefgh":
|
|
127
|
-
assert getattr(ex, char) == char
|
|
128
|
-
|
|
129
|
-
ex2 = ExampleAnnotated()
|
|
130
|
-
ex3 = ExampleAnnotated("i", "j", "k")
|
|
131
|
-
|
|
132
|
-
assert ex == ex2
|
|
133
|
-
assert ex != ex3
|
|
134
|
-
|
|
135
|
-
prefix = "test_annotationclass.<locals>."
|
|
136
|
-
assert repr(ex) == f"{prefix}ExampleAnnotated(a='a', b='b', c='c')"
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
def test_annotated_syntax_error():
|
|
140
|
-
with pytest.raises(SyntaxError):
|
|
141
|
-
class ExampleAnnotated(AnnotationClass):
|
|
142
|
-
a: str = "a" # noqa: the error being highlighted is the error we are testing.
|
|
143
|
-
b: "list[str]"
|
|
144
|
-
c: Annotated[str, ""] = Field(default="c")
|
|
@@ -2,7 +2,7 @@ import inspect
|
|
|
2
2
|
|
|
3
3
|
import pytest
|
|
4
4
|
|
|
5
|
-
from ducktools.classbuilder.prefab import Prefab, Attribute, SlotFields
|
|
5
|
+
from ducktools.classbuilder.prefab import Prefab, Attribute, SlotFields, get_attributes
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
class TestConstructionForms:
|
|
@@ -178,3 +178,49 @@ class TestClassArguments:
|
|
|
178
178
|
assert params['a'].kind == inspect.Parameter.KEYWORD_ONLY
|
|
179
179
|
assert params['b'].kind == inspect.Parameter.KEYWORD_ONLY
|
|
180
180
|
assert params['b'].default == 1
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
def test_slots_weakref():
|
|
184
|
+
import weakref
|
|
185
|
+
|
|
186
|
+
class WeakrefClass(Prefab):
|
|
187
|
+
a: int = 1
|
|
188
|
+
b: int = 2
|
|
189
|
+
__weakref__: dict
|
|
190
|
+
|
|
191
|
+
flds = get_attributes(WeakrefClass)
|
|
192
|
+
assert 'a' in flds
|
|
193
|
+
assert 'b' in flds
|
|
194
|
+
assert '__weakref__' not in flds
|
|
195
|
+
|
|
196
|
+
slots = WeakrefClass.__slots__
|
|
197
|
+
assert 'a' in slots
|
|
198
|
+
assert 'b' in slots
|
|
199
|
+
assert '__weakref__' in slots
|
|
200
|
+
|
|
201
|
+
# Test weakrefs can be created
|
|
202
|
+
inst = WeakrefClass()
|
|
203
|
+
ref = weakref.ref(inst)
|
|
204
|
+
assert ref == inst.__weakref__
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
def test_has_dict():
|
|
208
|
+
class DictClass(Prefab):
|
|
209
|
+
a: int = 1
|
|
210
|
+
b: int = 2
|
|
211
|
+
__dict__: dict
|
|
212
|
+
|
|
213
|
+
flds = get_attributes(DictClass)
|
|
214
|
+
assert 'a' in flds
|
|
215
|
+
assert 'b' in flds
|
|
216
|
+
assert '__dict__' not in flds
|
|
217
|
+
|
|
218
|
+
slots = DictClass.__slots__
|
|
219
|
+
assert 'a' in slots
|
|
220
|
+
assert 'b' in slots
|
|
221
|
+
assert '__dict__' in slots
|
|
222
|
+
|
|
223
|
+
# Test if __dict__ is included new values can be added
|
|
224
|
+
inst = DictClass()
|
|
225
|
+
inst.c = 42
|
|
226
|
+
assert inst.__dict__ == {"c": 42}
|
|
@@ -19,7 +19,6 @@ from ducktools.classbuilder import (
|
|
|
19
19
|
slot_gatherer,
|
|
20
20
|
slotclass,
|
|
21
21
|
|
|
22
|
-
AnnotationClass,
|
|
23
22
|
Field,
|
|
24
23
|
GatheredFields,
|
|
25
24
|
GeneratedCode,
|
|
@@ -371,30 +370,6 @@ def test_slotclass_weakref():
|
|
|
371
370
|
assert ref == inst.__weakref__
|
|
372
371
|
|
|
373
372
|
|
|
374
|
-
def test_annotationclass_weakref():
|
|
375
|
-
import weakref
|
|
376
|
-
|
|
377
|
-
class WeakrefClass(AnnotationClass):
|
|
378
|
-
a: int = 1
|
|
379
|
-
b: int = 2
|
|
380
|
-
__weakref__: dict
|
|
381
|
-
|
|
382
|
-
flds = get_fields(WeakrefClass)
|
|
383
|
-
assert 'a' in flds
|
|
384
|
-
assert 'b' in flds
|
|
385
|
-
assert '__weakref__' not in flds
|
|
386
|
-
|
|
387
|
-
slots = WeakrefClass.__slots__
|
|
388
|
-
assert 'a' in slots
|
|
389
|
-
assert 'b' in slots
|
|
390
|
-
assert '__weakref__' in slots
|
|
391
|
-
|
|
392
|
-
# Test weakrefs can be created
|
|
393
|
-
inst = WeakrefClass()
|
|
394
|
-
ref = weakref.ref(inst)
|
|
395
|
-
assert ref == inst.__weakref__
|
|
396
|
-
|
|
397
|
-
|
|
398
373
|
def test_slotclass_dict():
|
|
399
374
|
@slotclass
|
|
400
375
|
class DictClass:
|
|
@@ -420,28 +395,6 @@ def test_slotclass_dict():
|
|
|
420
395
|
assert inst.__dict__ == {"c": 42}
|
|
421
396
|
|
|
422
397
|
|
|
423
|
-
def test_annotationclass_dict():
|
|
424
|
-
class DictClass(AnnotationClass):
|
|
425
|
-
a: int = 1
|
|
426
|
-
b: int = 2
|
|
427
|
-
__dict__: dict
|
|
428
|
-
|
|
429
|
-
flds = get_fields(DictClass)
|
|
430
|
-
assert 'a' in flds
|
|
431
|
-
assert 'b' in flds
|
|
432
|
-
assert '__dict__' not in flds
|
|
433
|
-
|
|
434
|
-
slots = DictClass.__slots__
|
|
435
|
-
assert 'a' in slots
|
|
436
|
-
assert 'b' in slots
|
|
437
|
-
assert '__dict__' in slots
|
|
438
|
-
|
|
439
|
-
# Test if __dict__ is included new values can be added
|
|
440
|
-
inst = DictClass()
|
|
441
|
-
inst.c = 42
|
|
442
|
-
assert inst.__dict__ == {"c": 42}
|
|
443
|
-
|
|
444
|
-
|
|
445
398
|
def test_fieldclass():
|
|
446
399
|
class NewField(Field):
|
|
447
400
|
serialize: bool = True
|
|
File without changes
|
{ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/.github/workflows/auto_test.yml
RENAMED
|
File without changes
|
{ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/.github/workflows/publish_to_pypi.yml
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/docs/perf/performance_tests.md
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/docs_code/docs_ex2_register.py
RENAMED
|
File without changes
|
{ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/docs_code/docs_ex3_iterable.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/docs_code/docs_ex8_converters.py
RENAMED
|
File without changes
|
{ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/docs_code/docs_ex9_annotated.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/src/ducktools/classbuilder/py.typed
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/tests/prefab/dynamic/test_frozen.py
RENAMED
|
File without changes
|
{ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/tests/prefab/dynamic/test_internals.py
RENAMED
|
File without changes
|
|
File without changes
|
{ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/tests/prefab/dynamic/test_private.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/tests/prefab/shared/conftest.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/tests/prefab/shared/test_creation.py
RENAMED
|
File without changes
|
{ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/tests/prefab/shared/test_dunders.py
RENAMED
|
File without changes
|
{ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/tests/prefab/shared/test_funcs.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/tests/prefab/shared/test_init.py
RENAMED
|
File without changes
|
{ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/tests/prefab/shared/test_kw_only.py
RENAMED
|
File without changes
|
{ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/tests/prefab/shared/test_repr.py
RENAMED
|
File without changes
|
|
File without changes
|
{ducktools_classbuilder-0.8.3 → ducktools_classbuilder-0.9.0}/tests/py314_tests/_test_support.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|