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
* Add default_role for Sphinx.
Fix a bunch of broken refs along the way, which become
errors now via -W if you have default_role set.
In theory you can catch those via sphinx-build -n (i.e.
nitpick mode), which IMHO is a decent idea anyhow, but it's
a longer diff to enable that because it'd involve fixing a
bunch of the places that try to reference types that don't
exist (e.g. :type foo: Any value). But obviously can be done.
Also didn't actually use this anywhere yet (the any role),
but will do so in a follow-up if this is acceptable.
* Remove the roles from builtin objects to demo any.
* Style.
* Add z.i to intersphinx.
Enables the link to z.i.Interface.
* Enable nitpick mode.
Fix the remaining broken links or whitelist them via nitpick_ignore.
* Kill all :func:s.
* Kill all :class:es.
* Kill all :doc:s.
* Kill all :ref:s.
Except one, that probably meant :func:, and which
is a duplicate ref.
* Kill :exc: and :data:.
* Kill :mod:s.
* Kill new explicit refs from the merge.
Copy file name to clipboardExpand all lines: docs/backward-compatibility.rst
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,14 +6,14 @@ Backward Compatibility
6
6
``attrs`` has a very strong backward compatibility policy that is inspired by the policy of the `Twisted framework <https://twistedmatrix.com/trac/wiki/CompatibilityPolicy>`_.
7
7
8
8
Put simply, you shouldn't ever be afraid to upgrade ``attrs`` if you're only using its public APIs.
9
-
If there will ever be a need to break compatibility, it will be announced in the :doc:`changelog` and raise a ``DeprecationWarning`` for a year (if possible) before it's finally really broken.
9
+
If there will ever be a need to break compatibility, it will be announced in the `changelog` and raise a ``DeprecationWarning`` for a year (if possible) before it's finally really broken.
10
10
11
11
12
12
.. _exemption:
13
13
14
14
.. warning::
15
15
16
-
The structure of the :class:`attr.Attribute` class is exempt from this rule.
16
+
The structure of the `attr.Attribute` class is exempt from this rule.
17
17
It *will* change in the future, but since it should be considered read-only, that shouldn't matter.
18
18
19
19
However if you intend to build extensions on top of ``attrs`` you have to anticipate that.
Copy file name to clipboardExpand all lines: docs/examples.rst
+13-15Lines changed: 13 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,3 @@
1
-
.. _examples:
2
-
3
1
``attrs`` by Example
4
2
====================
5
3
@@ -217,15 +215,15 @@ If you don't set ``kw_only=True``, then there's is no valid attribute ordering a
217
215
Converting to Collections Types
218
216
-------------------------------
219
217
220
-
When you have a class with data, it often is very convenient to transform that class into a :class:`dict` (for example if you want to serialize it to JSON):
218
+
When you have a class with data, it often is very convenient to transform that class into a `dict` (for example if you want to serialize it to JSON):
221
219
222
220
.. doctest::
223
221
224
222
>>> attr.asdict(Coordinates(x=1, y=2))
225
223
{'x': 1, 'y': 2}
226
224
227
225
Some fields cannot or should not be transformed.
228
-
For that, :func:`attr.asdict` offers a callback that decides whether an attribute should be included:
226
+
For that, `attr.asdict` offers a callback that decides whether an attribute should be included:
229
227
230
228
.. doctest::
231
229
@@ -241,7 +239,7 @@ For that, :func:`attr.asdict` offers a callback that decides whether an attribut
For the common case where you want to :func:`include <attr.filters.include>` or :func:`exclude <attr.filters.exclude>` certain types or attributes, ``attrs`` ships with a few helpers:
242
+
For the common case where you want to `include <attr.filters.include>` or `exclude <attr.filters.exclude>` certain types or attributes, ``attrs`` ships with a few helpers:
245
243
246
244
.. doctest::
247
245
@@ -426,7 +424,7 @@ You can use a decorator:
426
424
ValueError: value out of bounds
427
425
428
426
429
-
``attrs`` ships with a bunch of validators, make sure to :ref:`check them out <api_validators>` before writing your own:
427
+
``attrs`` ships with a bunch of validators, make sure to `check them out <api_validators>` before writing your own:
430
428
431
429
.. doctest::
432
430
@@ -440,7 +438,7 @@ You can use a decorator:
440
438
...
441
439
TypeError: ("'x' must be <type 'int'> (got '42' that is a <type 'str'>).", Attribute(name='x', default=NOTHING, factory=NOTHING, validator=<instance_of validator for type <type 'int'>>, type=None, kw_only=False), <type 'int'>, '42')
442
440
443
-
Check out :ref:`validators` for more details.
441
+
Check out `validators` for more details.
444
442
445
443
446
444
Conversion
@@ -458,7 +456,7 @@ This can be useful for doing type-conversions on values that you don't want to f
458
456
>>> o.x
459
457
1
460
458
461
-
Check out :ref:`converters` for more details.
459
+
Check out `converters` for more details.
462
460
463
461
464
462
.. _metadata:
@@ -481,13 +479,13 @@ All ``attrs`` attributes may include arbitrary metadata in the form of a read-on
481
479
Metadata is not used by ``attrs``, and is meant to enable rich functionality in third-party libraries.
482
480
The metadata dictionary follows the normal dictionary rules: keys need to be hashable, and both keys and values are recommended to be immutable.
483
481
484
-
If you're the author of a third-party library with ``attrs`` integration, please see :ref:`Extending Metadata <extending_metadata>`.
482
+
If you're the author of a third-party library with ``attrs`` integration, please see `Extending Metadata <extending_metadata>`.
485
483
486
484
487
485
Types
488
486
-----
489
487
490
-
``attrs`` also allows you to associate a type with an attribute using either the *type* argument to :func:`attr.ib` or -- as of Python 3.6 -- using `PEP 526 <https://www.python.org/dev/peps/pep-0526/>`_-annotations:
488
+
``attrs`` also allows you to associate a type with an attribute using either the *type* argument to `attr.ib` or -- as of Python 3.6 -- using `PEP 526 <https://www.python.org/dev/peps/pep-0526/>`_-annotations:
491
489
492
490
493
491
.. doctest::
@@ -501,7 +499,7 @@ Types
501
499
>>> attr.fields(C).y.type
502
500
<class 'int'>
503
501
504
-
If you don't mind annotating *all* attributes, you can even drop the :func:`attr.ib` and assign default values instead:
502
+
If you don't mind annotating *all* attributes, you can even drop the `attr.ib` and assign default values instead:
505
503
506
504
.. doctest::
507
505
@@ -572,11 +570,11 @@ If you'd like to enforce it, ``attrs`` will try to help:
572
570
>>> i.x
573
571
1
574
572
575
-
Please note that true immutability is impossible in Python but it will :ref:`get <how-frozen>` you 99% there.
573
+
Please note that true immutability is impossible in Python but it will `get <how-frozen>` you 99% there.
576
574
By themselves, immutable classes are useful for long-lived objects that should never change; like configurations for example.
577
575
578
576
In order to use them in regular program flow, you'll need a way to easily create new instances with changed attributes.
579
-
In Clojure that function is called `assoc <https://clojuredocs.org/clojure.core/assoc>`_ and ``attrs`` shamelessly imitates it: :func:`attr.evolve`:
577
+
In Clojure that function is called `assoc <https://clojuredocs.org/clojure.core/assoc>`_ and ``attrs`` shamelessly imitates it: `attr.evolve`:
580
578
581
579
.. doctest::
582
580
@@ -598,7 +596,7 @@ Other Goodies
598
596
-------------
599
597
600
598
Sometimes you may want to create a class programmatically.
601
-
``attrs`` won't let you down and gives you :func:`attr.make_class` :
599
+
``attrs`` won't let you down and gives you `attr.make_class` :
602
600
603
601
.. doctest::
604
602
@@ -625,7 +623,7 @@ You can still have power over the attributes if you pass a dictionary of name: `
625
623
>>> i.y
626
624
[]
627
625
628
-
If you need to dynamically make a class with :func:`attr.make_class` and it needs to be a subclass of something else than ``object``, use the ``bases`` argument:
626
+
If you need to dynamically make a class with `attr.make_class` and it needs to be a subclass of something else than ``object``, use the ``bases`` argument:
Copy file name to clipboardExpand all lines: docs/glossary.rst
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -36,14 +36,14 @@ Glossary
36
36
- Slotted classes can inherit from other classes just like non-slotted classes, but some of the benefits of slotted classes are lost if you do that.
37
37
If you must inherit from other classes, try to inherit only from other slotted classes.
38
38
39
-
- Slotted classes must implement :meth:`__getstate__ <object.__getstate__>` and :meth:`__setstate__ <object.__setstate__>` to be serializable with :mod:`pickle` protocol 0 and 1.
39
+
- Slotted classes must implement :meth:`__getstate__ <object.__getstate__>` and :meth:`__setstate__ <object.__setstate__>` to be serializable with `pickle` protocol 0 and 1.
40
40
Therefore, ``attrs`` creates these methods automatically for ``slots=True`` classes (Python 2 uses protocol 0 by default).
41
41
42
42
.. note::
43
43
44
44
If the ``@attr.s(slots=True)`` decorated class already implements the :meth:`__getstate__ <object.__getstate__>` and :meth:`__setstate__ <object.__setstate__>` methods, they will be *overridden* by ``attrs`` autogenerated implementation.
45
45
46
-
Also, `think twice <https://www.youtube.com/watch?v=7KnfGDajDQw>`_ before using :mod:`pickle`.
46
+
Also, `think twice <https://www.youtube.com/watch?v=7KnfGDajDQw>`_ before using `pickle`.
47
47
48
48
- Slotted classes are weak-referenceable by default.
49
49
This can be disabled in CPython by passing ``weakref_slot=False`` to ``@attr.s`` [#pypyweakref]_.
Copy file name to clipboardExpand all lines: docs/hashing.rst
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,18 +15,18 @@ Hash Method Generation
15
15
Setting ``hash`` yourself can have unexpected consequences so we recommend to tinker with it only if you know exactly what you're doing.
16
16
17
17
Under certain circumstances, it's necessary for objects to be *hashable*.
18
-
For example if you want to put them into a :class:`set` or if you want to use them as keys in a :class:`dict`.
18
+
For example if you want to put them into a `set` or if you want to use them as keys in a `dict`.
19
19
20
20
The *hash* of an object is an integer that represents the contents of an object.
21
-
It can be obtained by calling :func:`hash` on an object and is implemented by writing a ``__hash__`` method for your class.
21
+
It can be obtained by calling `hash` on an object and is implemented by writing a ``__hash__`` method for your class.
22
22
23
23
``attrs`` will happily write a ``__hash__`` method for you [#fn1]_, however it will *not* do so by default.
24
24
Because according to the definition_ from the official Python docs, the returned hash has to fulfill certain constraints:
25
25
26
26
#. Two objects that are equal, **must** have the same hash.
27
27
This means that if ``x == y``, it *must* follow that ``hash(x) == hash(y)``.
28
28
29
-
By default, Python classes are compared *and* hashed by their :func:`id`.
29
+
By default, Python classes are compared *and* hashed by their `id`.
30
30
That means that every instance of a class has a different hash, no matter what attributes it carries.
31
31
32
32
It follows that the moment you (or ``attrs``) change the way equality is handled by implementing ``__eq__`` which is based on attribute values, this constraint is broken.
@@ -65,7 +65,7 @@ For a more thorough explanation of this topic, please refer to this blog post: `
65
65
66
66
Hashing and Mutability
67
67
----------------------
68
-
Changing any field involved in hash code computation after the first call to `__hash__` (typically this would be after its insertion into a hash-based collection) can result in silent bugs.
68
+
Changing any field involved in hash code computation after the first call to ``__hash__`` (typically this would be after its insertion into a hash-based collection) can result in silent bugs.
69
69
Therefore, it is strongly recommended that hashable classes be ``frozen.``
70
70
Beware, however, that this is not a complete guarantee of safety:
71
71
if a field points to an object and that object is mutated, the hash code may change, but ``frozen`` will not protect you.
Copy file name to clipboardExpand all lines: docs/how-does-it-work.rst
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -39,7 +39,7 @@ No magic, no meta programming, no expensive introspection at runtime.
39
39
40
40
Everything until this point happens exactly *once* when the class is defined.
41
41
As soon as a class is done, it's done.
42
-
And it's just a regular Python class like any other, except for a single ``__attrs_attrs__`` attribute that can be used for introspection or for writing your own tools and decorators on top of ``attrs`` (like :func:`attr.asdict`).
42
+
And it's just a regular Python class like any other, except for a single ``__attrs_attrs__`` attribute that can be used for introspection or for writing your own tools and decorators on top of ``attrs`` (like `attr.asdict`).
43
43
44
44
And once you start instantiating your classes, ``attrs`` is out of your way completely.
45
45
@@ -51,7 +51,7 @@ This **static** approach was very much a design goal of ``attrs`` and what I str
51
51
Immutability
52
52
------------
53
53
54
-
In order to give you immutability, ``attrs`` will attach a ``__setattr__`` method to your class that raises a :exc:`attr.exceptions.FrozenInstanceError` whenever anyone tries to set an attribute.
54
+
In order to give you immutability, ``attrs`` will attach a ``__setattr__`` method to your class that raises a `attr.exceptions.FrozenInstanceError` whenever anyone tries to set an attribute.
55
55
56
56
Depending on whether a class is a dict class or a slotted class, ``attrs`` uses a different technique to circumvent that limitation in the ``__init__`` method.
0 commit comments