pyderive3 0.0.1__tar.gz → 0.0.2__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.
- {pyderive3-0.0.1 → pyderive3-0.0.2}/PKG-INFO +8 -2
- {pyderive3-0.0.1 → pyderive3-0.0.2}/README.md +7 -1
- {pyderive3-0.0.1 → pyderive3-0.0.2}/pyderive/abc.py +5 -1
- {pyderive3-0.0.1 → pyderive3-0.0.2}/pyderive/compile.py +8 -6
- {pyderive3-0.0.1 → pyderive3-0.0.2}/pyderive/dataclass.py +15 -11
- {pyderive3-0.0.1 → pyderive3-0.0.2}/pyderive/parse.py +3 -1
- {pyderive3-0.0.1 → pyderive3-0.0.2}/pyderive3.egg-info/PKG-INFO +8 -2
- {pyderive3-0.0.1 → pyderive3-0.0.2}/setup.py +1 -1
- {pyderive3-0.0.1 → pyderive3-0.0.2}/pyderive/__init__.py +0 -0
- {pyderive3-0.0.1 → pyderive3-0.0.2}/pyderive3.egg-info/SOURCES.txt +0 -0
- {pyderive3-0.0.1 → pyderive3-0.0.2}/pyderive3.egg-info/dependency_links.txt +0 -0
- {pyderive3-0.0.1 → pyderive3-0.0.2}/pyderive3.egg-info/requires.txt +0 -0
- {pyderive3-0.0.1 → pyderive3-0.0.2}/pyderive3.egg-info/top_level.txt +0 -0
- {pyderive3-0.0.1 → pyderive3-0.0.2}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: pyderive3
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.2
|
|
4
4
|
Summary: Python3 Custom Data Class Helpers
|
|
5
5
|
Home-page: https://github.com/imgurbot12/pyderive
|
|
6
6
|
Author: Andrew Scott
|
|
@@ -13,10 +13,16 @@ Requires-Python: >=3.8
|
|
|
13
13
|
Description-Content-Type: text/markdown
|
|
14
14
|
|
|
15
15
|
pyderive
|
|
16
|
-
|
|
16
|
+
---------
|
|
17
17
|
|
|
18
18
|
Python3 Custom Dataclass Helpers
|
|
19
19
|
|
|
20
|
+
### Installation
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
pip install pyderive3
|
|
24
|
+
```
|
|
25
|
+
|
|
20
26
|
### Features
|
|
21
27
|
|
|
22
28
|
##### Expanded Reimplementation of Dataclasses
|
|
@@ -62,11 +62,15 @@ class FieldDef(Protocol):
|
|
|
62
62
|
kw_only: bool = False
|
|
63
63
|
frozen: bool = False
|
|
64
64
|
field_type: FieldType = FieldType.STANDARD
|
|
65
|
-
|
|
65
|
+
|
|
66
66
|
@abstractmethod
|
|
67
67
|
def __init__(self, name: str, anno: Type, default: Any = MISSING):
|
|
68
68
|
raise NotImplementedError
|
|
69
69
|
|
|
70
|
+
def finalize(self):
|
|
71
|
+
"""run finalize when field variables are finished compiling"""
|
|
72
|
+
pass
|
|
73
|
+
|
|
70
74
|
class Field(FieldDef):
|
|
71
75
|
|
|
72
76
|
def __init__(self,
|
|
@@ -191,17 +191,19 @@ def create_hash(fields: Fields) -> Callable:
|
|
|
191
191
|
names_t = _tuple_str(names, 'self')
|
|
192
192
|
return _create_fn('__hash__', ['self'], [f'return hash({names_t})'])
|
|
193
193
|
|
|
194
|
-
def assign_func(cls: Type, func: Callable,
|
|
194
|
+
def assign_func(cls: Type, func: Callable,
|
|
195
|
+
name: Optional[str] = None, overwrite: bool = False) -> bool:
|
|
195
196
|
"""
|
|
196
197
|
assign function to the object and modify qualname
|
|
197
198
|
|
|
198
|
-
:param cls:
|
|
199
|
-
:param func:
|
|
200
|
-
:param name:
|
|
201
|
-
:
|
|
199
|
+
:param cls: class object to assign to
|
|
200
|
+
:param func: function to assign to value
|
|
201
|
+
:param name: name of function to assign
|
|
202
|
+
:param overwrite: allow for overwrite if enabled
|
|
203
|
+
:return: true if object already exists else false
|
|
202
204
|
"""
|
|
203
205
|
name = name or func.__name__
|
|
204
|
-
if name in cls.__dict__:
|
|
206
|
+
if not overwrite and name in cls.__dict__:
|
|
205
207
|
return True
|
|
206
208
|
if isinstance(func, FunctionType):
|
|
207
209
|
func.__qualname__ = f'{cls.__qualname__}.{func.__name__}'
|
|
@@ -4,7 +4,7 @@ DataClass stdlib recreation using existing helpers
|
|
|
4
4
|
import abc
|
|
5
5
|
import copy
|
|
6
6
|
from typing import *
|
|
7
|
-
from typing_extensions import dataclass_transform
|
|
7
|
+
from typing_extensions import dataclass_transform, runtime_checkable
|
|
8
8
|
|
|
9
9
|
from .abc import *
|
|
10
10
|
from .parse import *
|
|
@@ -62,6 +62,7 @@ HASH_ACTIONS: Dict[Tuple[bool, bool, bool, bool], Any] = {
|
|
|
62
62
|
(True, True, True, True ): _hash_err,
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
+
@runtime_checkable
|
|
65
66
|
class DataClassLike(Generic[F], Protocol):
|
|
66
67
|
"""Protocol for DataClass-Like Objects"""
|
|
67
68
|
__datafields__: List[F]
|
|
@@ -143,8 +144,8 @@ def asdict(cls, *, recurse: int = 0, dict_factory: Type[dict] = dict) -> dict:
|
|
|
143
144
|
@dataclass_transform(field_specifiers=(FieldDef, Field, field))
|
|
144
145
|
def _process_class(
|
|
145
146
|
cls: TypeT,
|
|
146
|
-
init: bool =
|
|
147
|
-
repr: bool =
|
|
147
|
+
init: Optional[bool] = None,
|
|
148
|
+
repr: Optional[bool] = None,
|
|
148
149
|
eq: bool = True,
|
|
149
150
|
order: bool = False,
|
|
150
151
|
unsafe_hash: bool = False,
|
|
@@ -165,11 +166,14 @@ def _process_class(
|
|
|
165
166
|
# assign fields to dataclass
|
|
166
167
|
setattr(cls, FIELD_ATTR, fields)
|
|
167
168
|
# build functions
|
|
168
|
-
if init:
|
|
169
|
+
if init or init is None:
|
|
170
|
+
overwrite = init is True
|
|
169
171
|
post_init = hasattr(cls, POST_INIT)
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
172
|
+
initfunc = create_init(fields, kw_only, post_init, frozen)
|
|
173
|
+
assign_func(cls, initfunc, overwrite=overwrite)
|
|
174
|
+
if repr or repr is None:
|
|
175
|
+
overwrite = repr is True
|
|
176
|
+
assign_func(cls, create_repr(fields), overwrite=overwrite)
|
|
173
177
|
if eq:
|
|
174
178
|
assign_func(cls, create_compare(fields, '__eq__', '=='))
|
|
175
179
|
if order:
|
|
@@ -207,8 +211,8 @@ def _process_class(
|
|
|
207
211
|
@overload
|
|
208
212
|
@dataclass_transform(field_specifiers=(FieldDef, Field, field))
|
|
209
213
|
def dataclass(cls: Type[T],
|
|
210
|
-
init: bool =
|
|
211
|
-
repr: bool =
|
|
214
|
+
init: Optional[bool] = None,
|
|
215
|
+
repr: Optional[bool] = None,
|
|
212
216
|
eq: bool = True,
|
|
213
217
|
order: bool = False,
|
|
214
218
|
unsafe_hash: bool = False,
|
|
@@ -223,8 +227,8 @@ def dataclass(cls: Type[T],
|
|
|
223
227
|
|
|
224
228
|
@overload
|
|
225
229
|
def dataclass(*,
|
|
226
|
-
init: bool =
|
|
227
|
-
repr: bool =
|
|
230
|
+
init: Optional[bool] = None,
|
|
231
|
+
repr: Optional[bool] = None,
|
|
228
232
|
eq: bool = True,
|
|
229
233
|
order: bool = False,
|
|
230
234
|
unsafe_hash: bool = False,
|
|
@@ -95,6 +95,8 @@ def parse_fields(
|
|
|
95
95
|
if not isinstance(anno, type) and isinstance(anno, InitVar):
|
|
96
96
|
field.anno = anno.type
|
|
97
97
|
field.field_type = FieldType.INIT_VAR
|
|
98
|
+
# finalize field build and assign to struct
|
|
99
|
+
field.finalize()
|
|
98
100
|
fields.fields[name] = field
|
|
99
101
|
# apply fields to baseclass to allow for inheritance
|
|
100
102
|
if fields.fields:
|
|
@@ -132,7 +134,7 @@ def flatten_fields(
|
|
|
132
134
|
for name in fields.order:
|
|
133
135
|
field = fields.fields[name]
|
|
134
136
|
default = has_default(field)
|
|
135
|
-
kwargs = kwargs or default
|
|
137
|
+
kwargs = kwargs or (default and field.init and not field.kw_only)
|
|
136
138
|
missing = name not in struct.fields
|
|
137
139
|
# raise error if non-kwarg found after kwargs start
|
|
138
140
|
if order_kw and kwargs and missing and not default:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: pyderive3
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.2
|
|
4
4
|
Summary: Python3 Custom Data Class Helpers
|
|
5
5
|
Home-page: https://github.com/imgurbot12/pyderive
|
|
6
6
|
Author: Andrew Scott
|
|
@@ -13,10 +13,16 @@ Requires-Python: >=3.8
|
|
|
13
13
|
Description-Content-Type: text/markdown
|
|
14
14
|
|
|
15
15
|
pyderive
|
|
16
|
-
|
|
16
|
+
---------
|
|
17
17
|
|
|
18
18
|
Python3 Custom Dataclass Helpers
|
|
19
19
|
|
|
20
|
+
### Installation
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
pip install pyderive3
|
|
24
|
+
```
|
|
25
|
+
|
|
20
26
|
### Features
|
|
21
27
|
|
|
22
28
|
##### Expanded Reimplementation of Dataclasses
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|