You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/glossary.md
+18Lines changed: 18 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,12 +10,14 @@ dunder methods
10
10
11
11
Its first documented use is a [mailing list posting](https://mail.python.org/pipermail/python-list/2002-September/155836.html) by Mark Jackson from 2002.
12
12
13
+
13
14
dict classes
14
15
A regular class whose attributes are stored in the {attr}`object.__dict__` attribute of every single instance.
15
16
This is quite wasteful especially for objects with very few data attributes and the space consumption can become significant when creating large numbers of instances.
16
17
17
18
This is the type of class you get by default both with and without *attrs* (except with the next APIs {func}`attrs.define()`, [`attrs.mutable()`](attrs.mutable), and [`attrs.frozen()`](attrs.frozen)).
18
19
20
+
19
21
slotted classes
20
22
A class whose instances have no {attr}`object.__dict__` attribute and [define](https://docs.python.org/3/reference/datamodel.html#slots) their attributes in a `object.__slots__` attribute instead.
21
23
In *attrs*, they are created by passing `slots=True` to `@attr.s` (and are on by default in {func}`attrs.define()`, [`attrs.mutable()`](attrs.mutable), and [`attrs.frozen()`](attrs.frozen)).
@@ -101,6 +103,22 @@ slotted classes
101
103
- Pickling of slotted classes will fail if you define a class with missing attributes.
102
104
103
105
This situation can occur if you define an `attrs.field(init=False)` and don't set the attribute by hand before pickling.
106
+
107
+
108
+
field
109
+
As the project name suggests, *attrs* is all about attributes.
110
+
We especially tried to emphasize that we only care about attributes and not about the classes themselves -- because we believe the class belongs to the user.
111
+
112
+
This explains why the traditional API uses an {func}`attr.ib` (or ``attrib``) function to define attributes and we still use the term throughout the documentation.
113
+
114
+
However, with the emergence of {mod}`dataclasses`, [Pydantic](https://docs.pydantic.dev/latest/concepts/fields/), and other libraries, the term "field" has become a common term for a predefined attribute on a class in the Python ecosystem.
115
+
116
+
So with out new APIs, we've embraced it too by calling the function to create them {func}`attrs.field`, and use the term "field" throughout the documentation interchangeably.
117
+
118
+
See also {doc}`names`.
119
+
120
+
attribute
121
+
See {term}`field`.
104
122
:::
105
123
106
124
[^pypy]: On PyPy, there is no memory advantage in using slotted classes.
0 commit comments