@@ -32,10 +32,12 @@ These tools are available from the main `ducktools.classbuilder` module.
3232* ` @slotclass `
3333 * A decorator based implementation that uses a special dict subclass assigned
3434 to ` __slots__ ` to describe the fields for method generation.
35- * ` AnnotationClass `
36- * A subclass based implementation that works with ` __slots__ ` , type annotations
37- or ` Field(...) ` attributes to describe the fields for method generation.
38- * If ` __slots__ ` isn't used to declare fields, it will be generated by a metaclass.
35+ * ` SlotMakerMeta `
36+ * A metaclass for creating other implementations using annotations, fields or slots.
37+ * This metaclass will allow for creating ` __slots__ ` correctly in subclasses.
38+ * ` builder `
39+ * This is the main tool used for constructing decorators and base classes to provide
40+ generated methods.
3941
4042Each of these forms of class generation will result in the same methods being
4143attached to the class after the field information has been obtained.
@@ -65,8 +67,9 @@ This includes more customization including `__prefab_pre_init__` and `__prefab_p
6567functions for subclass customization.
6668
6769A ` @prefab ` decorator and ` Prefab ` base class are provided.
68- Similar to ` AnnotationClass ` , ` Prefab ` will generate ` __slots__ ` by default.
69- However decorated classes with ` @prefab ` that do not declare fields using ` __slots__ `
70+
71+ ` Prefab ` will generate ` __slots__ ` by default.
72+ decorated classes with ` @prefab ` that do not declare fields using ` __slots__ `
7073will ** not** be slotted and there is no ` slots ` argument to apply this.
7174
7275Here is an example of applying a conversion in ` __post_init__ ` :
@@ -110,7 +113,7 @@ the fields can be set *before* the class is constructed, so the class
110113will work correctly without needing to be rebuilt.
111114
112115For example these two classes would be roughly equivalent, except that
113- ` @dataclass ` has had to recreate the class from scratch while ` AnnotationClass `
116+ ` @dataclass ` has had to recreate the class from scratch while ` Prefab `
114117has created ` __slots__ ` and added the methods on to the original class.
115118This means that any references stored to the original class * before*
116119` @dataclass ` has rebuilt the class will not be pointing towards the
@@ -125,7 +128,7 @@ functions.
125128``` python
126129import json
127130from dataclasses import dataclass
128- from ducktools.classbuilder import AnnotationClass, Field
131+ from ducktools.classbuilder.prefab import Prefab, attribute
129132
130133
131134class _RegisterDescriptor :
@@ -168,10 +171,10 @@ class DataCoords:
168171 return {" x" : self .x, " y" : self .y}
169172
170173
171- # slots=True is the default for AnnotationClass
172- class BuilderCoords (AnnotationClass , slots = True ):
174+ # slots=True is the default for Prefab
175+ class BuilderCoords (Prefab ):
173176 x: float = 0.0
174- y: float = Field (default = 0.0 , doc = " y coordinate" )
177+ y: float = attribute (default = 0.0 , doc = " y coordinate" )
175178
176179 @register.register_method
177180 def to_json (self ):
@@ -235,9 +238,6 @@ It will copy values provided as the `type` to `Field` into the
235238Values provided to ` doc ` will be placed in the final ` __slots__ `
236239field so they are present on the class if ` help(...) ` is called.
237240
238- ` AnnotationClass ` offers the same features with additional methods of gathering
239- fields.
240-
241241If you want something with more features you can look at the ` prefab `
242242submodule which provides more specific features that differ further from the
243243behaviour of ` dataclasses ` .
0 commit comments