Skip to content

Commit b78abad

Browse files
committed
docs: add glossary entries for field & attribute
1 parent a365cdc commit b78abad

3 files changed

Lines changed: 24 additions & 6 deletions

File tree

docs/glossary.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@ dunder methods
1010

1111
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.
1212

13+
1314
dict classes
1415
A regular class whose attributes are stored in the {attr}`object.__dict__` attribute of every single instance.
1516
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.
1617

1718
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)).
1819

20+
1921
slotted classes
2022
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.
2123
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
101103
- Pickling of slotted classes will fail if you define a class with missing attributes.
102104
103105
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`.
104122
:::
105123
106124
[^pypy]: On PyPy, there is no memory advantage in using slotted classes.

src/attr/_funcs.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -454,9 +454,9 @@ def resolve_types(
454454
"""
455455
Resolve any strings and forward annotations in type annotations.
456456
457-
This is only required if you need concrete types in `Attribute`'s *type*
458-
field. In other words, you don't need to resolve your types if you only use
459-
them for static type checking.
457+
This is only required if you need concrete types in :class:`Attribute`'s
458+
*type* field. In other words, you don't need to resolve your types if you
459+
only use them for static type checking.
460460
461461
With no arguments, names will be looked up in the module in which the class
462462
was created. If this is not what you want, for example, if the name only

src/attr/_make.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2784,7 +2784,7 @@ def evolve(self, **changes):
27842784
Copy *self* and apply *changes*.
27852785
27862786
This works similarly to `attrs.evolve` but that function does not work
2787-
with `Attribute`.
2787+
with {class}`Attribute`.
27882788
27892789
It is mainly meant to be used for `transform-fields`.
27902790
@@ -3078,8 +3078,8 @@ class Converter:
30783078
as a positional argument. (default: `False`)
30793079
30803080
takes_field (bool):
3081-
Pass the field definition (an `Attribute`) into the converter as a
3082-
positional argument. (default: `False`)
3081+
Pass the field definition (an :class:`Attribute`) into the
3082+
converter as a positional argument. (default: `False`)
30833083
30843084
.. versionadded:: 24.1.0
30853085
"""

0 commit comments

Comments
 (0)