Skip to content

Commit 42c9548

Browse files
authored
Invert API docs to point from NG to OG (#1316)
* Add disclaimer to attr NS * Transplant API docs from attr.s to attrs.define * Transplant API docs from attr.ib to attrs.field * Remove stale references to attr.ib * Fix refs * Link to glossary * Explain why * Links from API docs, too * Link type annotations for good measure
1 parent c0ca14c commit 42c9548

7 files changed

Lines changed: 459 additions & 434 deletions

File tree

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@ If your pull request is a documentation fix or a trivial typo, feel free to dele
2525
- [ ] If they've been added to `attr/__init__.pyi`, they've *also* been re-imported in `attrs/__init__.pyi`.
2626
- [ ] Updated **documentation** for changed code.
2727
- [ ] New functions/classes have to be added to `docs/api.rst` by hand.
28-
- [ ] Changes to the signature of `@attr.s()` have to be added by hand too.
28+
- [ ] Changes to the signatures of `@attr.s()` and `@attrs.define()` have to be added by hand too.
2929
- [ ] Changed/added classes/methods/functions have appropriate `versionadded`, `versionchanged`, or `deprecated` [directives](http://www.sphinx-doc.org/en/stable/markup/para.html#directive-versionadded).
3030
The next version is the second number in the current release + 1.
3131
The first number represents the current year.
3232
So if the current version on PyPI is 22.2.0, the next version is gonna be 22.3.0.
3333
If the next version is the first in the new year, it'll be 23.1.0.
34+
- [ ] If something changed that affects both `attrs.define()` and `attr.s()`, you have to add version directives to both.
3435
- [ ] Documentation in `.rst` and `.md` files is written using [semantic newlines](https://rhodesmill.org/brandon/2012/one-sentence-per-line/).
3536
- [ ] Changes (and possible deprecations) have news fragments in [`changelog.d`](https://github.com/python-attrs/attrs/blob/main/changelog.d).
3637
- [ ] Consider granting [push permissions to the PR branch](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/allowing-changes-to-a-pull-request-branch-created-from-a-fork), so maintainers can fix minor issues themselves without pestering you.

docs/api-attr.rst

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
API Reference for the ``attr`` Namespace
22
========================================
33

4+
.. note::
5+
6+
These are the traditional APIs whose creation predates type annotations.
7+
They are **not** deprecated, but we suggest using the :mod:`attrs` namespace for new code, because they look nicer and have better defaults.
8+
9+
See also :doc:`names`.
10+
411
.. module:: attr
512

613

@@ -9,10 +16,6 @@ Core
916

1017
.. autofunction:: attr.s(these=None, repr_ns=None, repr=None, cmp=None, hash=None, init=None, slots=False, frozen=False, weakref_slot=True, str=False, auto_attribs=False, kw_only=False, cache_hash=False, auto_exc=False, eq=None, order=None, auto_detect=False, collect_by_mro=False, getstate_setstate=None, on_setattr=None, field_transformer=None, match_args=True, unsafe_hash=None)
1118

12-
.. note::
13-
14-
*attrs* also comes with a serious-business alias ``attr.attrs``.
15-
1619
For example:
1720

1821
.. doctest::
@@ -75,6 +78,9 @@ Core
7578
...
7679
ValueError: x must be positive
7780

81+
.. function:: attrs
82+
83+
Serious business alias for `attr.s`.
7884

7985
.. function:: define
8086

docs/api.rst

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,22 @@ API Reference
55

66
*attrs* works by decorating a class using `attrs.define` or `attr.s` and then defining attributes on the class using `attrs.field`, `attr.ib`, or type annotations.
77

8-
What follows is the API explanation, if you'd like a more hands-on tutorial, have a look at `examples`.
8+
What follows is the dry API explanation for people who understand how *attrs* works.
9+
If you'd like a hands-on tutorial, have a look at `examples`.
910

1011
If you're confused by the many names, please check out `names` for clarification, but the `TL;DR <https://en.wikipedia.org/wiki/TL;DR>`_ is that as of version 21.3.0, *attrs* consists of **two** top-level package names:
1112

1213
- The classic ``attr`` that powers the venerable `attr.s` and `attr.ib`.
1314
- The newer ``attrs`` that only contains most modern APIs and relies on `attrs.define` and `attrs.field` to define your classes.
14-
Additionally it offers some ``attr`` APIs with nicer defaults (for example, `attrs.asdict`).
15+
Additionally, some of the APIs that also exist in ``attr`` have nicer defaults (for example, `attrs.asdict`).
1516

1617
The ``attrs`` namespace is built *on top of* ``attr`` -- which will *never* go away -- and is just as stable, since it doesn't constitute a rewrite.
17-
To keep repetition low and this document at a reasonable size, the ``attr`` namespace is `documented on a separate page <api-attr>`, though.
18+
To keep repetition low and this document at a reasonable size, the ``attr`` namespace is `documented on a separate page <api-attr>`.
1819

1920

2021
Core
2122
----
2223

23-
.. autodata:: attrs.NOTHING
24-
:no-value:
25-
2624
.. autofunction:: attrs.define
2725

2826
.. function:: mutable(same_as_define)
@@ -94,6 +92,10 @@ Core
9492
C(x=[1, 2, 3], y={1, 2, 3})
9593

9694

95+
.. autodata:: attrs.NOTHING
96+
:no-value:
97+
98+
9799
Exceptions
98100
----------
99101

docs/examples.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ True
1717
False
1818
```
1919

20-
So in other words: *attrs* is useful even without actual attributes!
20+
So in other words: *attrs* is useful even without actual {term}`fields <field>`!
2121

2222
But you'll usually want some data on your classes, so let's add some:
2323

docs/names.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ We recommend our modern APIs for new code:
1919
- and {func}`attrs.field()` to define an attribute.
2020

2121
They have been added in *attrs* 20.1.0, they are expressive, and they have modern defaults like slots and type annotation awareness switched on by default.
22-
Sometimes they're referred to as *next-generation* or *NG* APIs.
22+
Sometimes, they're referred to as *next-generation* or *NG* APIs.
2323
As of *attrs* 21.3.0 you can also import them from the `attrs` package namespace.
2424

25-
The traditional APIs {func}`attr.s` / {func}`attr.ib`, their serious-business aliases `attr.attrs` / `attr.attrib`, and the never-documented, but popular `attr.dataclass` easter egg will stay **forever**.
25+
The traditional, or *OG*, APIs {func}`attr.s` / {func}`attr.ib`, their serious-business aliases `attr.attrs` / `attr.attrib`, and the never-documented, but popular `attr.dataclass` easter egg will stay **forever**.
2626

2727
*attrs* will **never** force you to use type annotations.
2828

0 commit comments

Comments
 (0)