omlish 0.0.0.dev284__py3-none-any.whl → 0.0.0.dev285__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.
Files changed (103) hide show
  1. omlish/__about__.py +2 -2
  2. omlish/dataclasses/__init__.py +58 -60
  3. omlish/dataclasses/api/__init__.py +25 -0
  4. omlish/dataclasses/api/classes/__init__.py +0 -0
  5. omlish/dataclasses/api/classes/conversion.py +30 -0
  6. omlish/dataclasses/api/classes/decorator.py +145 -0
  7. omlish/dataclasses/api/classes/make.py +109 -0
  8. omlish/dataclasses/api/classes/metadata.py +133 -0
  9. omlish/dataclasses/api/classes/params.py +78 -0
  10. omlish/dataclasses/api/fields/__init__.py +0 -0
  11. omlish/dataclasses/api/fields/building.py +120 -0
  12. omlish/dataclasses/api/fields/constructor.py +56 -0
  13. omlish/dataclasses/api/fields/conversion.py +191 -0
  14. omlish/dataclasses/api/fields/metadata.py +94 -0
  15. omlish/dataclasses/concerns/__init__.py +17 -0
  16. omlish/dataclasses/concerns/abc.py +15 -0
  17. omlish/dataclasses/concerns/copy.py +63 -0
  18. omlish/dataclasses/concerns/doc.py +53 -0
  19. omlish/dataclasses/concerns/eq.py +60 -0
  20. omlish/dataclasses/concerns/fields.py +119 -0
  21. omlish/dataclasses/concerns/frozen.py +133 -0
  22. omlish/dataclasses/concerns/hash.py +165 -0
  23. omlish/dataclasses/concerns/init.py +453 -0
  24. omlish/dataclasses/concerns/matchargs.py +27 -0
  25. omlish/dataclasses/concerns/mro.py +16 -0
  26. omlish/dataclasses/concerns/order.py +87 -0
  27. omlish/dataclasses/concerns/override.py +98 -0
  28. omlish/dataclasses/concerns/params.py +14 -0
  29. omlish/dataclasses/concerns/replace.py +48 -0
  30. omlish/dataclasses/concerns/repr.py +95 -0
  31. omlish/dataclasses/{impl → concerns}/slots.py +25 -1
  32. omlish/dataclasses/debug.py +2 -0
  33. omlish/dataclasses/errors.py +115 -0
  34. omlish/dataclasses/generation/__init__.py +0 -0
  35. omlish/dataclasses/generation/base.py +38 -0
  36. omlish/dataclasses/generation/compilation.py +258 -0
  37. omlish/dataclasses/generation/execution.py +195 -0
  38. omlish/dataclasses/generation/globals.py +83 -0
  39. omlish/dataclasses/generation/idents.py +6 -0
  40. omlish/dataclasses/generation/mangling.py +18 -0
  41. omlish/dataclasses/generation/manifests.py +20 -0
  42. omlish/dataclasses/generation/ops.py +97 -0
  43. omlish/dataclasses/generation/plans.py +35 -0
  44. omlish/dataclasses/generation/processor.py +174 -0
  45. omlish/dataclasses/generation/registry.py +42 -0
  46. omlish/dataclasses/generation/utils.py +83 -0
  47. omlish/dataclasses/{impl/reflect.py → inspect.py} +53 -90
  48. omlish/dataclasses/{impl/internals.py → internals.py} +26 -32
  49. omlish/dataclasses/metaclass/__init__.py +0 -0
  50. omlish/dataclasses/metaclass/bases.py +69 -0
  51. omlish/dataclasses/metaclass/confer.py +65 -0
  52. omlish/dataclasses/metaclass/meta.py +115 -0
  53. omlish/dataclasses/metaclass/specs.py +38 -0
  54. omlish/dataclasses/processing/__init__.py +0 -0
  55. omlish/dataclasses/processing/base.py +83 -0
  56. omlish/dataclasses/processing/driving.py +45 -0
  57. omlish/dataclasses/processing/priority.py +13 -0
  58. omlish/dataclasses/processing/registry.py +81 -0
  59. omlish/dataclasses/reflection.py +81 -0
  60. omlish/dataclasses/specs.py +224 -0
  61. omlish/dataclasses/tools/__init__.py +0 -0
  62. omlish/dataclasses/{impl → tools}/as_.py +23 -8
  63. omlish/dataclasses/tools/iter.py +27 -0
  64. omlish/dataclasses/tools/modifiers.py +52 -0
  65. omlish/dataclasses/tools/replace.py +17 -0
  66. omlish/dataclasses/tools/repr.py +12 -0
  67. omlish/dataclasses/{static.py → tools/static.py} +25 -4
  68. omlish/dataclasses/utils.py +54 -109
  69. omlish/diag/__init__.py +4 -4
  70. omlish/inject/impl/origins.py +1 -1
  71. omlish/lang/cached/function.py +4 -2
  72. omlish/marshal/objects/dataclasses.py +3 -7
  73. omlish/marshal/objects/helpers.py +3 -3
  74. omlish/secrets/marshal.py +1 -1
  75. omlish/secrets/secrets.py +1 -1
  76. omlish/sql/queries/base.py +1 -1
  77. omlish/typedvalues/marshal.py +2 -2
  78. {omlish-0.0.0.dev284.dist-info → omlish-0.0.0.dev285.dist-info}/METADATA +1 -1
  79. {omlish-0.0.0.dev284.dist-info → omlish-0.0.0.dev285.dist-info}/RECORD +83 -43
  80. omlish/dataclasses/impl/LICENSE +0 -279
  81. omlish/dataclasses/impl/__init__.py +0 -33
  82. omlish/dataclasses/impl/api.py +0 -278
  83. omlish/dataclasses/impl/copy.py +0 -30
  84. omlish/dataclasses/impl/errors.py +0 -53
  85. omlish/dataclasses/impl/fields.py +0 -245
  86. omlish/dataclasses/impl/frozen.py +0 -93
  87. omlish/dataclasses/impl/hashing.py +0 -86
  88. omlish/dataclasses/impl/init.py +0 -199
  89. omlish/dataclasses/impl/main.py +0 -93
  90. omlish/dataclasses/impl/metaclass.py +0 -235
  91. omlish/dataclasses/impl/metadata.py +0 -75
  92. omlish/dataclasses/impl/order.py +0 -57
  93. omlish/dataclasses/impl/overrides.py +0 -53
  94. omlish/dataclasses/impl/params.py +0 -128
  95. omlish/dataclasses/impl/processing.py +0 -24
  96. omlish/dataclasses/impl/replace.py +0 -40
  97. omlish/dataclasses/impl/repr.py +0 -66
  98. omlish/dataclasses/impl/simple.py +0 -50
  99. omlish/dataclasses/impl/utils.py +0 -167
  100. {omlish-0.0.0.dev284.dist-info → omlish-0.0.0.dev285.dist-info}/WHEEL +0 -0
  101. {omlish-0.0.0.dev284.dist-info → omlish-0.0.0.dev285.dist-info}/entry_points.txt +0 -0
  102. {omlish-0.0.0.dev284.dist-info → omlish-0.0.0.dev285.dist-info}/licenses/LICENSE +0 -0
  103. {omlish-0.0.0.dev284.dist-info → omlish-0.0.0.dev285.dist-info}/top_level.txt +0 -0
@@ -1,279 +0,0 @@
1
- A. HISTORY OF THE SOFTWARE
2
- ==========================
3
-
4
- Python was created in the early 1990s by Guido van Rossum at Stichting
5
- Mathematisch Centrum (CWI, see https://www.cwi.nl) in the Netherlands
6
- as a successor of a language called ABC. Guido remains Python's
7
- principal author, although it includes many contributions from others.
8
-
9
- In 1995, Guido continued his work on Python at the Corporation for
10
- National Research Initiatives (CNRI, see https://www.cnri.reston.va.us)
11
- in Reston, Virginia where he released several versions of the
12
- software.
13
-
14
- In May 2000, Guido and the Python core development team moved to
15
- BeOpen.com to form the BeOpen PythonLabs team. In October of the same
16
- year, the PythonLabs team moved to Digital Creations, which became
17
- Zope Corporation. In 2001, the Python Software Foundation (PSF, see
18
- https://www.python.org/psf/) was formed, a non-profit organization
19
- created specifically to own Python-related Intellectual Property.
20
- Zope Corporation was a sponsoring member of the PSF.
21
-
22
- All Python releases are Open Source (see https://opensource.org for
23
- the Open Source Definition). Historically, most, but not all, Python
24
- releases have also been GPL-compatible; the table below summarizes
25
- the various releases.
26
-
27
- Release Derived Year Owner GPL-
28
- from compatible? (1)
29
-
30
- 0.9.0 thru 1.2 1991-1995 CWI yes
31
- 1.3 thru 1.5.2 1.2 1995-1999 CNRI yes
32
- 1.6 1.5.2 2000 CNRI no
33
- 2.0 1.6 2000 BeOpen.com no
34
- 1.6.1 1.6 2001 CNRI yes (2)
35
- 2.1 2.0+1.6.1 2001 PSF no
36
- 2.0.1 2.0+1.6.1 2001 PSF yes
37
- 2.1.1 2.1+2.0.1 2001 PSF yes
38
- 2.1.2 2.1.1 2002 PSF yes
39
- 2.1.3 2.1.2 2002 PSF yes
40
- 2.2 and above 2.1.1 2001-now PSF yes
41
-
42
- Footnotes:
43
-
44
- (1) GPL-compatible doesn't mean that we're distributing Python under
45
- the GPL. All Python licenses, unlike the GPL, let you distribute
46
- a modified version without making your changes open source. The
47
- GPL-compatible licenses make it possible to combine Python with
48
- other software that is released under the GPL; the others don't.
49
-
50
- (2) According to Richard Stallman, 1.6.1 is not GPL-compatible,
51
- because its license has a choice of law clause. According to
52
- CNRI, however, Stallman's lawyer has told CNRI's lawyer that 1.6.1
53
- is "not incompatible" with the GPL.
54
-
55
- Thanks to the many outside volunteers who have worked under Guido's
56
- direction to make these releases possible.
57
-
58
-
59
- B. TERMS AND CONDITIONS FOR ACCESSING OR OTHERWISE USING PYTHON
60
- ===============================================================
61
-
62
- Python software and documentation are licensed under the
63
- Python Software Foundation License Version 2.
64
-
65
- Starting with Python 3.8.6, examples, recipes, and other code in
66
- the documentation are dual licensed under the PSF License Version 2
67
- and the Zero-Clause BSD license.
68
-
69
- Some software incorporated into Python is under different licenses.
70
- The licenses are listed with code falling under that license.
71
-
72
-
73
- PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
74
- --------------------------------------------
75
-
76
- 1. This LICENSE AGREEMENT is between the Python Software Foundation
77
- ("PSF"), and the Individual or Organization ("Licensee") accessing and
78
- otherwise using this software ("Python") in source or binary form and
79
- its associated documentation.
80
-
81
- 2. Subject to the terms and conditions of this License Agreement, PSF hereby
82
- grants Licensee a nonexclusive, royalty-free, world-wide license to reproduce,
83
- analyze, test, perform and/or display publicly, prepare derivative works,
84
- distribute, and otherwise use Python alone or in any derivative version,
85
- provided, however, that PSF's License Agreement and PSF's notice of copyright,
86
- i.e., "Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
87
- 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023 Python Software Foundation;
88
- All Rights Reserved" are retained in Python alone or in any derivative version
89
- prepared by Licensee.
90
-
91
- 3. In the event Licensee prepares a derivative work that is based on
92
- or incorporates Python or any part thereof, and wants to make
93
- the derivative work available to others as provided herein, then
94
- Licensee hereby agrees to include in any such work a brief summary of
95
- the changes made to Python.
96
-
97
- 4. PSF is making Python available to Licensee on an "AS IS"
98
- basis. PSF MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR
99
- IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, PSF MAKES NO AND
100
- DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS
101
- FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF PYTHON WILL NOT
102
- INFRINGE ANY THIRD PARTY RIGHTS.
103
-
104
- 5. PSF SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON
105
- FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS
106
- A RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON,
107
- OR ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF.
108
-
109
- 6. This License Agreement will automatically terminate upon a material
110
- breach of its terms and conditions.
111
-
112
- 7. Nothing in this License Agreement shall be deemed to create any
113
- relationship of agency, partnership, or joint venture between PSF and
114
- Licensee. This License Agreement does not grant permission to use PSF
115
- trademarks or trade name in a trademark sense to endorse or promote
116
- products or services of Licensee, or any third party.
117
-
118
- 8. By copying, installing or otherwise using Python, Licensee
119
- agrees to be bound by the terms and conditions of this License
120
- Agreement.
121
-
122
-
123
- BEOPEN.COM LICENSE AGREEMENT FOR PYTHON 2.0
124
- -------------------------------------------
125
-
126
- BEOPEN PYTHON OPEN SOURCE LICENSE AGREEMENT VERSION 1
127
-
128
- 1. This LICENSE AGREEMENT is between BeOpen.com ("BeOpen"), having an
129
- office at 160 Saratoga Avenue, Santa Clara, CA 95051, and the
130
- Individual or Organization ("Licensee") accessing and otherwise using
131
- this software in source or binary form and its associated
132
- documentation ("the Software").
133
-
134
- 2. Subject to the terms and conditions of this BeOpen Python License
135
- Agreement, BeOpen hereby grants Licensee a non-exclusive,
136
- royalty-free, world-wide license to reproduce, analyze, test, perform
137
- and/or display publicly, prepare derivative works, distribute, and
138
- otherwise use the Software alone or in any derivative version,
139
- provided, however, that the BeOpen Python License is retained in the
140
- Software, alone or in any derivative version prepared by Licensee.
141
-
142
- 3. BeOpen is making the Software available to Licensee on an "AS IS"
143
- basis. BEOPEN MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR
144
- IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, BEOPEN MAKES NO AND
145
- DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS
146
- FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF THE SOFTWARE WILL NOT
147
- INFRINGE ANY THIRD PARTY RIGHTS.
148
-
149
- 4. BEOPEN SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF THE
150
- SOFTWARE FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS
151
- AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THE SOFTWARE, OR ANY
152
- DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF.
153
-
154
- 5. This License Agreement will automatically terminate upon a material
155
- breach of its terms and conditions.
156
-
157
- 6. This License Agreement shall be governed by and interpreted in all
158
- respects by the law of the State of California, excluding conflict of
159
- law provisions. Nothing in this License Agreement shall be deemed to
160
- create any relationship of agency, partnership, or joint venture
161
- between BeOpen and Licensee. This License Agreement does not grant
162
- permission to use BeOpen trademarks or trade names in a trademark
163
- sense to endorse or promote products or services of Licensee, or any
164
- third party. As an exception, the "BeOpen Python" logos available at
165
- http://www.pythonlabs.com/logos.html may be used according to the
166
- permissions granted on that web page.
167
-
168
- 7. By copying, installing or otherwise using the software, Licensee
169
- agrees to be bound by the terms and conditions of this License
170
- Agreement.
171
-
172
-
173
- CNRI LICENSE AGREEMENT FOR PYTHON 1.6.1
174
- ---------------------------------------
175
-
176
- 1. This LICENSE AGREEMENT is between the Corporation for National
177
- Research Initiatives, having an office at 1895 Preston White Drive,
178
- Reston, VA 20191 ("CNRI"), and the Individual or Organization
179
- ("Licensee") accessing and otherwise using Python 1.6.1 software in
180
- source or binary form and its associated documentation.
181
-
182
- 2. Subject to the terms and conditions of this License Agreement, CNRI
183
- hereby grants Licensee a nonexclusive, royalty-free, world-wide
184
- license to reproduce, analyze, test, perform and/or display publicly,
185
- prepare derivative works, distribute, and otherwise use Python 1.6.1
186
- alone or in any derivative version, provided, however, that CNRI's
187
- License Agreement and CNRI's notice of copyright, i.e., "Copyright (c)
188
- 1995-2001 Corporation for National Research Initiatives; All Rights
189
- Reserved" are retained in Python 1.6.1 alone or in any derivative
190
- version prepared by Licensee. Alternately, in lieu of CNRI's License
191
- Agreement, Licensee may substitute the following text (omitting the
192
- quotes): "Python 1.6.1 is made available subject to the terms and
193
- conditions in CNRI's License Agreement. This Agreement together with
194
- Python 1.6.1 may be located on the internet using the following
195
- unique, persistent identifier (known as a handle): 1895.22/1013. This
196
- Agreement may also be obtained from a proxy server on the internet
197
- using the following URL: http://hdl.handle.net/1895.22/1013".
198
-
199
- 3. In the event Licensee prepares a derivative work that is based on
200
- or incorporates Python 1.6.1 or any part thereof, and wants to make
201
- the derivative work available to others as provided herein, then
202
- Licensee hereby agrees to include in any such work a brief summary of
203
- the changes made to Python 1.6.1.
204
-
205
- 4. CNRI is making Python 1.6.1 available to Licensee on an "AS IS"
206
- basis. CNRI MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR
207
- IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, CNRI MAKES NO AND
208
- DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS
209
- FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF PYTHON 1.6.1 WILL NOT
210
- INFRINGE ANY THIRD PARTY RIGHTS.
211
-
212
- 5. CNRI SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON
213
- 1.6.1 FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS
214
- A RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON 1.6.1,
215
- OR ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF.
216
-
217
- 6. This License Agreement will automatically terminate upon a material
218
- breach of its terms and conditions.
219
-
220
- 7. This License Agreement shall be governed by the federal
221
- intellectual property law of the United States, including without
222
- limitation the federal copyright law, and, to the extent such
223
- U.S. federal law does not apply, by the law of the Commonwealth of
224
- Virginia, excluding Virginia's conflict of law provisions.
225
- Notwithstanding the foregoing, with regard to derivative works based
226
- on Python 1.6.1 that incorporate non-separable material that was
227
- previously distributed under the GNU General Public License (GPL), the
228
- law of the Commonwealth of Virginia shall govern this License
229
- Agreement only as to issues arising under or with respect to
230
- Paragraphs 4, 5, and 7 of this License Agreement. Nothing in this
231
- License Agreement shall be deemed to create any relationship of
232
- agency, partnership, or joint venture between CNRI and Licensee. This
233
- License Agreement does not grant permission to use CNRI trademarks or
234
- trade name in a trademark sense to endorse or promote products or
235
- services of Licensee, or any third party.
236
-
237
- 8. By clicking on the "ACCEPT" button where indicated, or by copying,
238
- installing or otherwise using Python 1.6.1, Licensee agrees to be
239
- bound by the terms and conditions of this License Agreement.
240
-
241
- ACCEPT
242
-
243
-
244
- CWI LICENSE AGREEMENT FOR PYTHON 0.9.0 THROUGH 1.2
245
- --------------------------------------------------
246
-
247
- Copyright (c) 1991 - 1995, Stichting Mathematisch Centrum Amsterdam,
248
- The Netherlands. All rights reserved.
249
-
250
- Permission to use, copy, modify, and distribute this software and its
251
- documentation for any purpose and without fee is hereby granted,
252
- provided that the above copyright notice appear in all copies and that
253
- both that copyright notice and this permission notice appear in
254
- supporting documentation, and that the name of Stichting Mathematisch
255
- Centrum or CWI not be used in advertising or publicity pertaining to
256
- distribution of the software without specific, written prior
257
- permission.
258
-
259
- STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
260
- THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
261
- FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
262
- FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
263
- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
264
- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
265
- OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
266
-
267
- ZERO-CLAUSE BSD LICENSE FOR CODE IN THE PYTHON DOCUMENTATION
268
- ----------------------------------------------------------------------
269
-
270
- Permission to use, copy, modify, and/or distribute this software for any
271
- purpose with or without fee is hereby granted.
272
-
273
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
274
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
275
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
276
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
277
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
278
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
279
- PERFORMANCE OF THIS SOFTWARE.
@@ -1,33 +0,0 @@
1
- """
2
- TODO:
3
- - metaclass:
4
- - cleanup confer
5
- - descriptors - check_type/validators don't handle setters lol
6
- - deep_frozen?
7
- - field:
8
- - frozen
9
- - pickle/transient
10
- - mangled
11
- - doc
12
- - derive
13
- - check_type
14
- - class
15
- - strict_eq
16
- - allow_setattr
17
- - mangler
18
- - observable
19
- - c/py gen
20
- - iterable
21
- - proto/jsonschema gen
22
- - enums
23
- - nodal
24
- - embedding? forward kwargs in general? or only for replace?
25
-
26
- TODO refs:
27
- - batch up exec calls
28
- - https://github.com/python/cpython/commit/8945b7ff55b87d11c747af2dad0e3e4d631e62d6
29
- - add doc parameter to dataclasses.field
30
- - https://github.com/python/cpython/commit/9c7657f09914254724683d91177aed7947637be5
31
- - add decorator argument to make_dataclass
32
- - https://github.com/python/cpython/commit/3e3a4d231518f91ff2f3c5a085b3849e32f1d548
33
- """
@@ -1,278 +0,0 @@
1
- """
2
- TODO:
3
- - fix code redundancy
4
- """
5
- import collections.abc
6
- import contextlib
7
- import dataclasses as dc
8
- import keyword
9
- import sys
10
- import types
11
- import typing as ta
12
-
13
- from ... import check as check_
14
- from ... import lang
15
- from .internals import PARAMS_ATTR
16
- from .internals import Params
17
- from .main import process_class
18
- from .metadata import METADATA_ATTR
19
- from .metadata import Metadata
20
- from .params import FieldExtras
21
- from .params import ParamsExtras
22
-
23
-
24
- MISSING = dc.MISSING
25
-
26
-
27
- def field( # noqa
28
- default=MISSING,
29
- *,
30
- default_factory=MISSING,
31
- init=True,
32
- repr=True, # noqa
33
- hash=None, # noqa
34
- compare=True,
35
- metadata=None,
36
- kw_only=MISSING,
37
-
38
- derive: ta.Callable[..., ta.Any] | None = None,
39
- coerce: bool | ta.Callable[[ta.Any], ta.Any] | None = None,
40
- validate: ta.Callable[[ta.Any], bool] | None = None,
41
- check_type: bool | type | tuple[type | None, ...] | None = None,
42
- override: bool = False,
43
- repr_fn: ta.Callable[[ta.Any], str | None] | None = None,
44
- repr_priority: int | None = None,
45
- frozen: bool | None = None,
46
- ): # -> dc.Field
47
- if default is not MISSING and default_factory is not MISSING:
48
- raise ValueError('cannot specify both default and default_factory')
49
-
50
- fx = FieldExtras()
51
- if metadata is not None:
52
- fx = metadata.get(FieldExtras, fx)
53
-
54
- fx = dc.replace(fx, **lang.opt_kw(
55
- derive=derive,
56
- coerce=coerce,
57
- validate=validate,
58
- check_type=check_type,
59
- override=override,
60
- repr_fn=repr_fn,
61
- repr_priority=repr_priority,
62
- frozen=frozen,
63
- ))
64
-
65
- md: ta.Mapping = {FieldExtras: fx}
66
- if metadata is not None:
67
- md = collections.ChainMap(md, check_.isinstance(metadata, collections.abc.Mapping)) # type: ignore
68
-
69
- return dc.Field(
70
- default,
71
- default_factory, # noqa
72
- init,
73
- repr,
74
- hash,
75
- compare,
76
- types.MappingProxyType(md),
77
- kw_only, # noqa
78
- )
79
-
80
-
81
- def _strip_missing_values(d):
82
- return {k: v for k, v in d.items() if v is not MISSING}
83
-
84
-
85
- def dataclass( # noqa
86
- cls=None,
87
- /,
88
- *,
89
- init=True,
90
- repr=True, # noqa
91
- eq=True,
92
- order=False,
93
- unsafe_hash=False,
94
- frozen=False,
95
- match_args=True,
96
- kw_only=False,
97
- slots=False,
98
- weakref_slot=False,
99
-
100
- metadata=None,
101
-
102
- reorder=MISSING,
103
- cache_hash=MISSING,
104
- generic_init=MISSING,
105
- override=MISSING,
106
- repr_id=MISSING,
107
- ):
108
- def wrap(cls):
109
- pkw = dict(
110
- init=init,
111
- repr=repr,
112
- eq=eq,
113
- order=order,
114
- unsafe_hash=unsafe_hash,
115
- frozen=frozen,
116
- match_args=match_args,
117
- kw_only=kw_only,
118
- slots=slots,
119
- weakref_slot=weakref_slot,
120
- )
121
-
122
- dmd = cls.__dict__.get(METADATA_ATTR)
123
-
124
- epk = dict(dmd.get(_ExtraParamsKwargs, ()) if dmd is not None else ())
125
- epk.update(_strip_missing_values(dict(
126
- reorder=reorder,
127
- cache_hash=cache_hash,
128
- generic_init=generic_init,
129
- override=override,
130
- repr_id=repr_id,
131
- )))
132
- pex = ParamsExtras(**epk)
133
-
134
- mmd: dict = {
135
- ParamsExtras: pex,
136
- }
137
-
138
- md: Metadata = mmd
139
- cmds = []
140
- if metadata is not None:
141
- cmds.append(check_.isinstance(metadata, collections.abc.Mapping))
142
- if dmd is not None:
143
- cmds.append(dmd)
144
- if cmds:
145
- md = collections.ChainMap(md, *cmds) # type: ignore
146
-
147
- setattr(cls, PARAMS_ATTR, Params(**pkw))
148
- setattr(cls, METADATA_ATTR, types.MappingProxyType(md))
149
-
150
- return process_class(cls)
151
-
152
- if cls is None:
153
- return wrap
154
-
155
- return wrap(cls)
156
-
157
-
158
- def make_dataclass( # noqa
159
- cls_name,
160
- fields,
161
- *,
162
- bases=(),
163
- namespace=None,
164
- init=True,
165
- repr=True, # noqa
166
- eq=True,
167
- order=False,
168
- unsafe_hash=False,
169
- frozen=False,
170
- match_args=True,
171
- kw_only=False,
172
- slots=False,
173
- weakref_slot=False,
174
- module=None,
175
-
176
- reorder=MISSING,
177
- cache_hash=MISSING,
178
- generic_init=MISSING,
179
- override=MISSING,
180
- repr_id=MISSING,
181
- ):
182
- if namespace is None:
183
- namespace = {}
184
-
185
- seen = set()
186
- annotations = {}
187
- defaults = {}
188
- for item in fields:
189
- if isinstance(item, str):
190
- name = item
191
- tp = 'typing.Any'
192
- elif len(item) == 2:
193
- name, tp, = item
194
- elif len(item) == 3:
195
- name, tp, spec = item
196
- defaults[name] = spec
197
- else:
198
- raise TypeError(f'Invalid field: {item!r}')
199
- if not isinstance(name, str) or not name.isidentifier():
200
- raise TypeError(f'Field names must be valid identifiers: {name!r}')
201
- if keyword.iskeyword(name):
202
- raise TypeError(f'Field names must not be keywords: {name!r}')
203
- if name in seen:
204
- raise TypeError(f'Field name duplicated: {name!r}')
205
-
206
- seen.add(name)
207
- annotations[name] = tp
208
-
209
- def exec_body_callback(ns):
210
- ns.update(namespace)
211
- ns.update(defaults)
212
- ns['__annotations__'] = annotations
213
-
214
- cls = types.new_class(cls_name, bases, {}, exec_body_callback)
215
-
216
- if module is None:
217
- try:
218
- module = sys._getframemodulename(1) or '__main__' # type: ignore # noqa
219
- except AttributeError:
220
- with contextlib.suppress(AttributeError, ValueError):
221
- module = sys._getframe(1).f_globals.get('__name__', '__main__') # noqa
222
- if module is not None:
223
- cls.__module__ = module
224
-
225
- return dataclass(
226
- cls,
227
- init=init,
228
- repr=repr,
229
- eq=eq,
230
- order=order,
231
- unsafe_hash=unsafe_hash,
232
- frozen=frozen,
233
- match_args=match_args,
234
- kw_only=kw_only,
235
- slots=slots,
236
- weakref_slot=weakref_slot,
237
-
238
- reorder=reorder,
239
- cache_hash=cache_hash,
240
- generic_init=generic_init,
241
- override=override,
242
- repr_id=repr_id,
243
- )
244
-
245
-
246
- class _ExtraParamsKwargs:
247
- pass
248
-
249
-
250
- def extra_class_params( # noqa
251
- *,
252
- reorder=MISSING,
253
- cache_hash=MISSING,
254
- generic_init=MISSING,
255
- override=MISSING,
256
- repr_id=MISSING,
257
- ):
258
- def inner(cls):
259
- if PARAMS_ATTR in cls.__dict__:
260
- raise TypeError(cls)
261
- try:
262
- md = cls.__dict__[METADATA_ATTR]
263
- except KeyError:
264
- md = {}
265
- setattr(cls, METADATA_ATTR, md)
266
- if _ExtraParamsKwargs in md:
267
- raise TypeError(cls)
268
-
269
- md[_ExtraParamsKwargs] = _strip_missing_values(dict(
270
- reorder=reorder,
271
- cache_hash=cache_hash,
272
- generic_init=generic_init,
273
- override=override,
274
- repr_id=repr_id,
275
- ))
276
-
277
- return cls
278
- return inner
@@ -1,30 +0,0 @@
1
- """
2
- TODO:
3
- - __deepcopy__
4
- """
5
- import dataclasses as dc
6
-
7
- from .fields import field_type
8
- from .internals import FIELDS_ATTR
9
- from .internals import FieldType
10
- from .processing import Processor
11
- from .utils import set_new_attribute
12
-
13
-
14
- MISSING = dc.MISSING
15
-
16
-
17
- def _copy(obj):
18
- kw = {}
19
-
20
- for f in getattr(obj, FIELDS_ATTR).values():
21
- if field_type(f) is FieldType.CLASS:
22
- continue
23
- kw[f.name] = getattr(obj, f.name)
24
-
25
- return obj.__class__(**kw)
26
-
27
-
28
- class CopyProcessor(Processor):
29
- def _process(self) -> None:
30
- set_new_attribute(self._cls, '__copy__', _copy)
@@ -1,53 +0,0 @@
1
- import types
2
- import typing as ta
3
-
4
-
5
- ##
6
-
7
-
8
- class ValidationError(Exception):
9
- pass
10
-
11
-
12
- def _hands_off_repr(obj: ta.Any) -> str:
13
- return f'{obj.__class__.__qualname__}@{hex(id(obj))[2:]}'
14
-
15
-
16
- def _fn_repr(fn: ta.Callable) -> str:
17
- if (co := getattr(fn, '__code__', None)) is None or not isinstance(co, types.CodeType):
18
- return repr(fn)
19
-
20
- if not (co_filename := co.co_filename):
21
- return repr(fn)
22
-
23
- return f'{fn!r} ({co_filename}:{co.co_firstlineno})'
24
-
25
-
26
- class FieldValidationError(ValidationError):
27
- def __init__(
28
- self,
29
- obj: ta.Any,
30
- field: str,
31
- fn: ta.Callable,
32
- value: ta.Any,
33
- ) -> None:
34
- super().__init__(
35
- f'{self.__class__.__name__} '
36
- f'for field {field!r} '
37
- f'on object {_hands_off_repr(obj)} '
38
- f'in validator {_fn_repr(fn)} '
39
- f'with value {value!r}',
40
- )
41
-
42
- self.obj = obj
43
- self.field = field
44
- self.fn = fn
45
- self.value = value
46
-
47
- def __repr__(self) -> str:
48
- return f'{self.__class__.__name__}({", ".join([
49
- f"obj={_hands_off_repr(self.obj)}",
50
- f"field={self.field!r}",
51
- f"fn={_fn_repr(self.fn)}",
52
- f"value={self.value!r}",
53
- ])})'