annotate mercurial/thirdparty/attr/_next_gen.py @ 51017:edc44ab7437a

debug-revlog: keep the revlog open for the analysis duration This is more explicit. No performance differences were observed.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Mon, 25 Sep 2023 16:57:53 +0200
parents e1c586b9a43c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
49643
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
1 # SPDX-License-Identifier: MIT
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
2
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
3 """
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
4 These are Python 3.6+-only and keyword-only APIs that call `attr.s` and
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
5 `attr.ib` with different default values.
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
6 """
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
7
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
8
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
9 from functools import partial
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
10
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
11 from . import setters
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
12 from ._funcs import asdict as _asdict
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
13 from ._funcs import astuple as _astuple
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
14 from ._make import (
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
15 NOTHING,
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
16 _frozen_setattrs,
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
17 _ng_default_on_setattr,
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
18 attrib,
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
19 attrs,
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
20 )
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
21 from .exceptions import UnannotatedAttributeError
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
22
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
23
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
24 def define(
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
25 maybe_cls=None,
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
26 *,
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
27 these=None,
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
28 repr=None,
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
29 hash=None,
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
30 init=None,
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
31 slots=True,
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
32 frozen=False,
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
33 weakref_slot=True,
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
34 str=False,
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
35 auto_attribs=None,
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
36 kw_only=False,
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
37 cache_hash=False,
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
38 auto_exc=True,
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
39 eq=None,
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
40 order=False,
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
41 auto_detect=True,
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
42 getstate_setstate=None,
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
43 on_setattr=None,
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
44 field_transformer=None,
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
45 match_args=True,
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
46 ):
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
47 r"""
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
48 Define an ``attrs`` class.
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
49
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
50 Differences to the classic `attr.s` that it uses underneath:
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
51
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
52 - Automatically detect whether or not *auto_attribs* should be `True` (c.f.
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
53 *auto_attribs* parameter).
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
54 - If *frozen* is `False`, run converters and validators when setting an
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
55 attribute by default.
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
56 - *slots=True*
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
57
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
58 .. caution::
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
59
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
60 Usually this has only upsides and few visible effects in everyday
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
61 programming. But it *can* lead to some suprising behaviors, so please
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
62 make sure to read :term:`slotted classes`.
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
63 - *auto_exc=True*
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
64 - *auto_detect=True*
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
65 - *order=False*
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
66 - Some options that were only relevant on Python 2 or were kept around for
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
67 backwards-compatibility have been removed.
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
68
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
69 Please note that these are all defaults and you can change them as you
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
70 wish.
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
71
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
72 :param Optional[bool] auto_attribs: If set to `True` or `False`, it behaves
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
73 exactly like `attr.s`. If left `None`, `attr.s` will try to guess:
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
74
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
75 1. If any attributes are annotated and no unannotated `attrs.fields`\ s
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
76 are found, it assumes *auto_attribs=True*.
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
77 2. Otherwise it assumes *auto_attribs=False* and tries to collect
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
78 `attrs.fields`\ s.
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
79
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
80 For now, please refer to `attr.s` for the rest of the parameters.
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
81
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
82 .. versionadded:: 20.1.0
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
83 .. versionchanged:: 21.3.0 Converters are also run ``on_setattr``.
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
84 """
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
85
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
86 def do_it(cls, auto_attribs):
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
87 return attrs(
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
88 maybe_cls=cls,
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
89 these=these,
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
90 repr=repr,
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
91 hash=hash,
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
92 init=init,
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
93 slots=slots,
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
94 frozen=frozen,
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
95 weakref_slot=weakref_slot,
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
96 str=str,
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
97 auto_attribs=auto_attribs,
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
98 kw_only=kw_only,
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
99 cache_hash=cache_hash,
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
100 auto_exc=auto_exc,
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
101 eq=eq,
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
102 order=order,
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
103 auto_detect=auto_detect,
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
104 collect_by_mro=True,
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
105 getstate_setstate=getstate_setstate,
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
106 on_setattr=on_setattr,
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
107 field_transformer=field_transformer,
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
108 match_args=match_args,
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
109 )
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
110
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
111 def wrap(cls):
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
112 """
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
113 Making this a wrapper ensures this code runs during class creation.
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
114
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
115 We also ensure that frozen-ness of classes is inherited.
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
116 """
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
117 nonlocal frozen, on_setattr
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
118
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
119 had_on_setattr = on_setattr not in (None, setters.NO_OP)
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
120
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
121 # By default, mutable classes convert & validate on setattr.
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
122 if frozen is False and on_setattr is None:
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
123 on_setattr = _ng_default_on_setattr
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
124
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
125 # However, if we subclass a frozen class, we inherit the immutability
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
126 # and disable on_setattr.
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
127 for base_cls in cls.__bases__:
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
128 if base_cls.__setattr__ is _frozen_setattrs:
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
129 if had_on_setattr:
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
130 raise ValueError(
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
131 "Frozen classes can't use on_setattr "
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
132 "(frozen-ness was inherited)."
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
133 )
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
134
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
135 on_setattr = setters.NO_OP
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
136 break
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
137
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
138 if auto_attribs is not None:
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
139 return do_it(cls, auto_attribs)
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
140
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
141 try:
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
142 return do_it(cls, True)
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
143 except UnannotatedAttributeError:
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
144 return do_it(cls, False)
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
145
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
146 # maybe_cls's type depends on the usage of the decorator. It's a class
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
147 # if it's used as `@attrs` but ``None`` if used as `@attrs()`.
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
148 if maybe_cls is None:
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
149 return wrap
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
150 else:
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
151 return wrap(maybe_cls)
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
152
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
153
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
154 mutable = define
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
155 frozen = partial(define, frozen=True, on_setattr=None)
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
156
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
157
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
158 def field(
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
159 *,
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
160 default=NOTHING,
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
161 validator=None,
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
162 repr=True,
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
163 hash=None,
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
164 init=True,
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
165 metadata=None,
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
166 converter=None,
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
167 factory=None,
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
168 kw_only=False,
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
169 eq=None,
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
170 order=None,
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
171 on_setattr=None,
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
172 ):
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
173 """
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
174 Identical to `attr.ib`, except keyword-only and with some arguments
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
175 removed.
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
176
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
177 .. versionadded:: 20.1.0
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
178 """
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
179 return attrib(
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
180 default=default,
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
181 validator=validator,
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
182 repr=repr,
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
183 hash=hash,
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
184 init=init,
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
185 metadata=metadata,
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
186 converter=converter,
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
187 factory=factory,
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
188 kw_only=kw_only,
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
189 eq=eq,
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
190 order=order,
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
191 on_setattr=on_setattr,
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
192 )
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
193
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
194
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
195 def asdict(inst, *, recurse=True, filter=None, value_serializer=None):
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
196 """
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
197 Same as `attr.asdict`, except that collections types are always retained
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
198 and dict is always used as *dict_factory*.
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
199
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
200 .. versionadded:: 21.3.0
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
201 """
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
202 return _asdict(
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
203 inst=inst,
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
204 recurse=recurse,
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
205 filter=filter,
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
206 value_serializer=value_serializer,
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
207 retain_collection_types=True,
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
208 )
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
209
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
210
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
211 def astuple(inst, *, recurse=True, filter=None):
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
212 """
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
213 Same as `attr.astuple`, except that collections types are always retained
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
214 and `tuple` is always used as the *tuple_factory*.
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
215
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
216 .. versionadded:: 21.3.0
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
217 """
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
218 return _astuple(
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
219 inst=inst, recurse=recurse, filter=filter, retain_collection_types=True
e1c586b9a43c attr: vendor 22.1.0
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
220 )