Skip to content

Commit 8472889

Browse files
authored
Merge branch 'main' into tin/mypy-fields
2 parents da8aeaa + 7804a68 commit 8472889

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+1377
-608
lines changed

.github/CONTRIBUTING.md

+8-5
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ The official tag is `python-attrs` and helping out in support frees us up to imp
3030
This is a hard rule; patches with missing tests or documentation can't be merged.
3131
- Make sure your changes pass our [CI].
3232
You won't get any feedback until it's green unless you ask for it.
33+
- For the CI to pass, the coverage must be 100%.
34+
If you have problems to test something, open anyway and ask for advice.
35+
In some situations, we may agree to add an `# pragma: no cover`.
3336
- Once you've addressed review feedback, make sure to bump the pull request with a short note, so we know you're done.
3437
- Don’t break backwards compatibility.
3538

@@ -120,27 +123,27 @@ You don't need to install *towncrier* yourself, you just have to abide by a few
120123
- Wrap arguments into asterisks like in docstrings:
121124
`Added new argument *an_argument*.`
122125
- If you mention functions or other callables, add parentheses at the end of their names:
123-
`attr.func()` or `attr.Class.method()`.
126+
`attrs.func()` or `attrs.Class.method()`.
124127
This makes the changelog a lot more readable.
125128
- Prefer simple past tense or constructions with "now".
126129
For example:
127130

128-
+ Added `attr.validators.func()`.
129-
+ `attr.func()` now doesn't crash the Large Hadron Collider anymore when passed the *foobar* argument.
131+
+ Added `attrs.validators.func()`.
132+
+ `attrs.func()` now doesn't crash the Large Hadron Collider anymore when passed the *foobar* argument.
130133
- If you want to reference multiple issues, copy the news fragment to another filename.
131134
*towncrier* will merge all news fragments with identical contents into one entry with multiple links to the respective pull requests.
132135

133136
Example entries:
134137

135138
```rst
136-
Added ``attr.validators.func()``.
139+
Added ``attrs.validators.func()``.
137140
The feature really *is* awesome.
138141
```
139142

140143
or:
141144

142145
```rst
143-
``attr.func()`` now doesn't crash the Large Hadron Collider anymore when passed the *foobar* argument.
146+
``attrs.func()`` now doesn't crash the Large Hadron Collider anymore when passed the *foobar* argument.
144147
The bug really *was* nasty.
145148
```
146149

.github/PULL_REQUEST_TEMPLATE.md

+2
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@ If your pull request is a documentation fix or a trivial typo, feel free to dele
1919
- [ ] New features have been added to our [Hypothesis testing strategy](https://github.com/python-attrs/attrs/blob/main/tests/strategies.py).
2020
- [ ] Changes or additions to public APIs are reflected in our type stubs (files ending in ``.pyi``).
2121
- [ ] ...and used in the stub test file `tests/typing_example.py`.
22+
- [ ] If they've been added to `attr/__init__.pyi`, they've *also* been re-imported in `attrs/__init__.pyi`.
2223
- [ ] Updated **documentation** for changed code.
2324
- [ ] New functions/classes have to be added to `docs/api.rst` by hand.
2425
- [ ] Changes to the signature of `@attr.s()` have to be added by hand too.
2526
- [ ] Changed/added classes/methods/functions have appropriate `versionadded`, `versionchanged`, or `deprecated` [directives](http://www.sphinx-doc.org/en/stable/markup/para.html#directive-versionadded).
2627
Find the appropriate next version in our [``__init__.py``](https://github.com/python-attrs/attrs/blob/main/src/attr/__init__.py) file.
2728
- [ ] Documentation in `.rst` files is written using [semantic newlines](https://rhodesmill.org/brandon/2012/one-sentence-per-line/).
2829
- [ ] Changes (and possible deprecations) have news fragments in [`changelog.d`](https://github.com/python-attrs/attrs/blob/main/changelog.d).
30+
- [ ] 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.
2931

3032
<!--
3133
If you have *any* questions to *any* of the points above, just **submit and ask**!

.github/workflows/main.yml

+29-31
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,32 @@ name: CI
44
on:
55
push:
66
branches: ["main"]
7+
tags: ["*"]
78
pull_request:
89
branches: ["main"]
910
workflow_dispatch:
1011

1112
env:
1213
FORCE_COLOR: "1" # Make tools pretty.
13-
TOX_TESTENV_PASSENV: "FORCE_COLOR"
14+
TOX_TESTENV_PASSENV: FORCE_COLOR
1415
PYTHON_LATEST: "3.10"
1516

1617

1718
jobs:
1819
tests:
19-
name: "tox on ${{ matrix.python-version }}"
20-
runs-on: "ubuntu-latest"
20+
name: tox on ${{ matrix.python-version }}
21+
runs-on: ubuntu-latest
2122

2223
strategy:
2324
fail-fast: false
2425
matrix:
25-
python-version: ["2.7", "3.5", "3.6", "3.7", "3.8", "3.9", "3.10", "pypy-2.7", "pypy-3.7"]
26+
python-version: ["2.7", "3.5", "3.6", "3.7", "3.8", "3.9", "3.10", "pypy-2.7", "pypy-3.7", "pypy-3.8"]
2627

2728
steps:
28-
- uses: "actions/checkout@v2"
29-
- uses: "actions/setup-python@v2"
29+
- uses: actions/checkout@v2
30+
- uses: actions/setup-python@v2
3031
with:
31-
python-version: "${{ matrix.python-version }}"
32+
python-version: ${{ matrix.python-version }}
3233

3334
- name: "Install dependencies"
3435
run: |
@@ -37,8 +38,7 @@ jobs:
3738
python -m pip install --upgrade pip setuptools wheel
3839
python -m pip install --upgrade virtualenv tox tox-gh-actions
3940
40-
- name: "Run tox targets for ${{ matrix.python-version }}"
41-
run: "python -m tox"
41+
- run: "python -m tox"
4242

4343
- name: Upload coverage data
4444
uses: "actions/upload-artifact@v2"
@@ -49,7 +49,7 @@ jobs:
4949

5050

5151
coverage:
52-
runs-on: "ubuntu-latest"
52+
runs-on: ubuntu-latest
5353
needs: tests
5454

5555
steps:
@@ -59,21 +59,20 @@ jobs:
5959
# Use latest Python, so it understands all syntax.
6060
python-version: ${{env.PYTHON_LATEST}}
6161

62-
- name: Install Coverage.py
63-
run: python -m pip install --upgrade coverage[toml]
62+
- run: python -m pip install --upgrade coverage[toml]
6463

6564
- name: Download coverage data
6665
uses: actions/download-artifact@v2
6766
with:
6867
name: coverage-data
6968

70-
- name: Combine coverage and fail if it's <100%
69+
- name: Combine coverage and fail if it's <100%.
7170
run: |
7271
python -m coverage combine
7372
python -m coverage html --skip-covered --skip-empty
7473
python -m coverage report --fail-under=100
7574
76-
- name: Upload HTML report for failed check
75+
- name: Upload HTML report if check failed.
7776
uses: actions/upload-artifact@v2
7877
with:
7978
name: html-report
@@ -82,35 +81,34 @@ jobs:
8281

8382

8483
package:
85-
name: "Build & verify package"
86-
runs-on: "ubuntu-latest"
84+
name: Build & verify package
85+
runs-on: ubuntu-latest
8786

8887
steps:
89-
- uses: "actions/checkout@v2"
90-
- uses: "actions/setup-python@v2"
88+
- uses: actions/checkout@v2
89+
- uses: actions/setup-python@v2
9190
with:
9291
python-version: ${{env.PYTHON_LATEST}}
9392

94-
- run: "python -m pip install build twine check-wheel-contents"
95-
- run: "python -m build --sdist --wheel ."
96-
- run: "ls -l dist"
97-
- run: "check-wheel-contents dist/*.whl"
98-
- name: "Check long_description"
99-
run: "python -m twine check dist/*"
93+
- run: python -m pip install build twine check-wheel-contents
94+
- run: python -m build --sdist --wheel .
95+
- run: ls -l dist
96+
- run: check-wheel-contents dist/*.whl
97+
- name: Check long_description
98+
run: python -m twine check dist/*
10099

101100

102101
install-dev:
103-
name: "Verify dev env"
104-
runs-on: "${{ matrix.os }}"
102+
name: Verify dev env
103+
runs-on: ${{ matrix.os }}
105104
strategy:
106105
matrix:
107106
os: ["ubuntu-latest", "windows-latest"]
108107

109108
steps:
110-
- uses: "actions/checkout@v2"
111-
- uses: "actions/setup-python@v2"
109+
- uses: actions/checkout@v2
110+
- uses: actions/setup-python@v2
112111
with:
113112
python-version: ${{env.PYTHON_LATEST}}
114-
- run: "python -m pip install -e .[dev]"
115-
- name: "Import package"
116-
run: "python -c 'import attr; print(attr.__version__)'"
113+
- run: python -m pip install -e .[dev]
114+
- run: python -c 'import attr; print(attr.__version__)'

.pre-commit-config.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@ repos:
3333
language_version: python3.10
3434

3535
- repo: https://github.com/pre-commit/pre-commit-hooks
36-
rev: v4.0.1
36+
rev: v4.1.0
3737
hooks:
3838
- id: trailing-whitespace
3939
- id: end-of-file-fixer
4040
- id: debug-statements
4141
language_version: python3.10
4242
- id: check-toml
43+
- id: check-yaml

CHANGELOG.rst

+94-9
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ Changelog
33

44
Versions follow `CalVer <https://calver.org>`_ with a strict backwards-compatibility policy.
55

6-
The **first digit** of the version is the year.
7-
The **second digit** is incremented with each release, starting at 1 for each year.
8-
The **third digit** is when we need to start branches for older releases (only for emergencies).
6+
The **first number** of the version is the year.
7+
The **second number** is incremented with each release, starting at 1 for each year.
8+
The **third number** is when we need to start branches for older releases (only for emergencies).
99

1010
Put simply, you shouldn't ever be afraid to upgrade ``attrs`` if you're only using its public APIs.
1111
Whenever there is a need to break compatibility, it is announced here in the changelog, and raises a ``DeprecationWarning`` for a year (if possible) before it's finally really broken.
1212

1313
.. warning::
1414

15-
The structure of the `attr.Attribute` class is exempt from this rule.
15+
The structure of the `attrs.Attribute` class is exempt from this rule.
1616
It *will* change in the future, but since it should be considered read-only, that shouldn't matter.
1717

1818
However if you intend to build extensions on top of ``attrs`` you have to anticipate that.
@@ -28,6 +28,91 @@ Changes for the upcoming release can be found in the `"changelog.d" directory <h
2828

2929
.. towncrier release notes start
3030
31+
21.4.0 (2021-12-29)
32+
-------------------
33+
34+
Changes
35+
^^^^^^^
36+
37+
- Fixed the test suite on PyPy3.8 where ``cloudpickle`` does not work.
38+
`#892 <https://github.com/python-attrs/attrs/issues/892>`_
39+
- Fixed ``coverage report`` for projects that use ``attrs`` and don't set a ``--source``.
40+
`#895 <https://github.com/python-attrs/attrs/issues/895>`_,
41+
`#896 <https://github.com/python-attrs/attrs/issues/896>`_
42+
43+
44+
----
45+
46+
47+
21.3.0 (2021-12-28)
48+
-------------------
49+
50+
Backward-incompatible Changes
51+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
52+
53+
- When using ``@define``, converters are now run by default when setting an attribute on an instance -- additionally to validators.
54+
I.e. the new default is ``on_setattr=[attrs.setters.convert, attrs.setters.validate]``.
55+
56+
This is unfortunately a breaking change, but it was an oversight, impossible to raise a ``DeprecationWarning`` about, and it's better to fix it now while the APIs are very fresh with few users.
57+
`#835 <https://github.com/python-attrs/attrs/issues/835>`_,
58+
`#886 <https://github.com/python-attrs/attrs/issues/886>`_
59+
- ``import attrs`` has finally landed!
60+
As of this release, you can finally import ``attrs`` using its proper name.
61+
62+
Not all names from the ``attr`` namespace have been transferred; most notably ``attr.s`` and ``attr.ib`` are missing.
63+
See ``attrs.define`` and ``attrs.field`` if you haven't seen our next-generation APIs yet.
64+
A more elaborate explanation can be found `On The Core API Names <https://www.attrs.org/en/latest/names.html>`_
65+
66+
This feature is at least for one release **provisional**.
67+
We don't *plan* on changing anything, but such a big change is unlikely to go perfectly on the first strike.
68+
69+
The API docs have been mostly updated, but it will be an ongoing effort to change everything to the new APIs.
70+
Please note that we have **not** moved -- or even removed -- anything from ``attr``!
71+
72+
Please do report any bugs or documentation inconsistencies!
73+
`#887 <https://github.com/python-attrs/attrs/issues/887>`_
74+
75+
76+
Changes
77+
^^^^^^^
78+
79+
- ``attr.asdict(retain_collection_types=False)`` (default) dumps collection-esque keys as tuples.
80+
`#646 <https://github.com/python-attrs/attrs/issues/646>`_,
81+
`#888 <https://github.com/python-attrs/attrs/issues/888>`_
82+
- ``__match_args__`` are now generated to support Python 3.10's
83+
`Structural Pattern Matching <https://docs.python.org/3.10/whatsnew/3.10.html#pep-634-structural-pattern-matching>`_.
84+
This can be controlled by the ``match_args`` argument to the class decorators on Python 3.10 and later.
85+
On older versions, it is never added and the argument is ignored.
86+
`#815 <https://github.com/python-attrs/attrs/issues/815>`_
87+
- If the class-level *on_setattr* is set to ``attrs.setters.validate`` (default in ``@define`` and ``@mutable``) but no field defines a validator, pretend that it's not set.
88+
`#817 <https://github.com/python-attrs/attrs/issues/817>`_
89+
- The generated ``__repr__`` is significantly faster on Pythons with f-strings.
90+
`#819 <https://github.com/python-attrs/attrs/issues/819>`_
91+
- Attributes transformed via ``field_transformer`` are wrapped with ``AttrsClass`` again.
92+
`#824 <https://github.com/python-attrs/attrs/issues/824>`_
93+
- Generated source code is now cached more efficiently for identical classes.
94+
`#828 <https://github.com/python-attrs/attrs/issues/828>`_
95+
- Added ``attrs.converters.to_bool()``.
96+
`#830 <https://github.com/python-attrs/attrs/issues/830>`_
97+
- ``attrs.resolve_types()`` now resolves types of subclasses after the parents are resolved.
98+
`#842 <https://github.com/python-attrs/attrs/issues/842>`_
99+
`#843 <https://github.com/python-attrs/attrs/issues/843>`_
100+
- Added new validators: ``lt(val)`` (< val), ``le(va)`` (≤ val), ``ge(val)`` (≥ val), ``gt(val)`` (> val), and ``maxlen(n)``.
101+
`#845 <https://github.com/python-attrs/attrs/issues/845>`_
102+
- ``attrs`` classes are now fully compatible with `cloudpickle <https://github.com/cloudpipe/cloudpickle>`_ (no need to disable ``repr`` anymore).
103+
`#857 <https://github.com/python-attrs/attrs/issues/857>`_
104+
- Added new context manager ``attrs.validators.disabled()`` and functions ``attrs.validators.(set|get)_disabled()``.
105+
They deprecate ``attrs.(set|get)_run_validators()``.
106+
All functions are interoperable and modify the same internal state.
107+
They are not – and never were – thread-safe, though.
108+
`#859 <https://github.com/python-attrs/attrs/issues/859>`_
109+
- ``attrs.validators.matches_re()`` now accepts pre-compiled regular expressions in addition to pattern strings.
110+
`#877 <https://github.com/python-attrs/attrs/issues/877>`_
111+
112+
113+
----
114+
115+
31116
21.2.0 (2021-05-07)
32117
-------------------
33118

@@ -76,7 +161,7 @@ Changes
76161
- It's now possible to customize the behavior of ``eq`` and ``order`` by passing in a callable.
77162
`#435 <https://github.com/python-attrs/attrs/issues/435>`_,
78163
`#627 <https://github.com/python-attrs/attrs/issues/627>`_
79-
- The instant favorite `next-generation APIs <https://www.attrs.org/en/stable/api.html#next-gen>`_ are not provisional anymore!
164+
- The instant favorite next-generation APIs are not provisional anymore!
80165

81166
They are also officially supported by Mypy as of their `0.800 release <https://mypy-lang.blogspot.com/2021/01/mypy-0800-released.html>`_.
82167

@@ -115,7 +200,7 @@ Changes
115200

116201
See the `new docs on comparison <https://www.attrs.org/en/stable/comparison.html>`_ for more details.
117202
`#787 <https://github.com/python-attrs/attrs/issues/787>`_
118-
- Added **provisional** support for static typing in ``pyright`` via the `dataclass_transforms specification <https://github.com/microsoft/pyright/blob/master/specs/dataclass_transforms.md>`_.
203+
- Added **provisional** support for static typing in ``pyright`` via the `dataclass_transforms specification <https://github.com/microsoft/pyright/blob/main/specs/dataclass_transforms.md>`_.
119204
Both the ``pyright`` specification and ``attrs`` implementation may change in future versions of both projects.
120205

121206
Your constructive feedback is welcome in both `attrs#795 <https://github.com/python-attrs/attrs/issues/795>`_ and `pyright#1782 <https://github.com/microsoft/pyright/discussions/1782>`_.
@@ -234,7 +319,7 @@ Deprecations
234319
Please check out the linked issue for more details.
235320

236321
These new APIs have been added *provisionally* as part of #666 so you can try them out today and provide feedback.
237-
Learn more in the `API docs <https://www.attrs.org/en/stable/api.html#provisional-apis>`_.
322+
Learn more in the `API docs <https://www.attrs.org/en/stable/api.html>`_.
238323
`#408 <https://github.com/python-attrs/attrs/issues/408>`_
239324

240325

@@ -511,7 +596,7 @@ Changes
511596
`#349 <https://github.com/python-attrs/attrs/issues/349>`_
512597
- The order of attributes that are passed into ``attr.make_class()`` or the *these* argument of ``@attr.s()`` is now retained if the dictionary is ordered (i.e. ``dict`` on Python 3.6 and later, ``collections.OrderedDict`` otherwise).
513598

514-
Before, the order was always determined by the order in which the attributes have been defined which may not be desirable when creating classes programatically.
599+
Before, the order was always determined by the order in which the attributes have been defined which may not be desirable when creating classes programmatically.
515600

516601
`#300 <https://github.com/python-attrs/attrs/issues/300>`_,
517602
`#339 <https://github.com/python-attrs/attrs/issues/339>`_,
@@ -523,7 +608,7 @@ Changes
523608
- Setting the cell type is now completely best effort.
524609
This fixes ``attrs`` on Jython.
525610

526-
We cannot make any guarantees regarding Jython though, because our test suite cannot run due to dependency incompatabilities.
611+
We cannot make any guarantees regarding Jython though, because our test suite cannot run due to dependency incompatibilities.
527612

528613
`#321 <https://github.com/python-attrs/attrs/issues/321>`_,
529614
`#334 <https://github.com/python-attrs/attrs/issues/334>`_

MANIFEST.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ include LICENSE *.rst *.toml *.yml *.yaml *.ini
22
graft .github
33

44
# Stubs
5-
include src/attr/py.typed
65
recursive-include src *.pyi
6+
recursive-include src py.typed
77

88
# Tests
99
include tox.ini conftest.py

0 commit comments

Comments
 (0)