Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kw_only python 2 backport #700

Merged
merged 27 commits into from
Oct 19, 2020
Merged

kw_only python 2 backport #700

merged 27 commits into from
Oct 19, 2020

Conversation

Drino
Copy link
Contributor

@Drino Drino commented Oct 12, 2020

Hello!

Thank you for bringing an awesome package and supporting Python 2 in 2020!

In my experience I find kw_only attributes really addictive, as they allow to inherit from classes ignoring attributes with defaults. Unfortunately, they don't work on Python 2, so it's actually impossible to write some compatible code.

Even writing __init__ by hand:

@attr.s(kw_only=not PY2)
class Base(object):
    kw_only1 = attr.ib(default=None)
    kw_only2 = attr.ib(default=42)

@attr.s(init=not PY2)
class Child(Base):
    attr1 = attr.ib()
    attr2 = attr.ib()

    if PY2:
        def __init__(self, attr1, attr2, **kwargs):
            super(Child, self).__init__(**kwargs)
            self.attr1, self.attr2 = attr1, attr2

Will fail, as attrs disallows mandatory attributes after an attribute with a default value or factory. Even this non-working code snippet seems as boilerplate, so in this PR I propose a backport of kw_only attr.ib to Python 2.

There are four approaches to implementation that I've tested:

  1. Just move kw_only attributes to the end of __init__. It's the fastest approach, on my benckmark (3 positional args, 3 kw_only args) it's about ~100ns for argument parsing. However, it doesn't allow kw_only attributes without default values and also doesn't make them real kw_only.
  2. Pop from a dictionary of kwargs. This is the slowest approach with a somewhat-reasonable error message, ~400ns for argument parsing.
  3. On every __init__ call create a function that takes kw_only attributes and returns a tuple of unpacked arguments (implemented in this PR). It's slightly faster than previous approach, ~390ns for argument parsing.
  4. Cache that function on class instance - it saves ~40-50ns, giving 340ns. I plan to rewrite this PR to use this approach.

Both approaches with function have error message lacking some information, however it's a default py2 error and the constructor call should be somewhere in the stacktrace.

Is this a desired feature or should it not happen? Should I add some fancy error handling?

P.S. I'm unfamiliar with changelog.d - should I just add an rst file to the dir?

Pull Request Check List

This is just a friendly reminder about the most common mistakes. Please make sure that you tick all boxes. But please read our contribution guide at least once, it will save you unnecessary review cycles!

If an item doesn't apply to your pull request, check it anyway to make it apparent that there's nothing left to do. If your pull request is a documentation fix or a trivial typo, feel free to delete the whole thing.

  • Added tests for changed code.
  • New features have been added to our Hypothesis testing strategy.
  • Changes or additions to public APIs are reflected in our type stubs (files ending in .pyi).
    • ...and used in the stub test file tests/typing_example.py.
  • Updated documentation for changed code.
    • New functions/classes have to be added to docs/api.rst by hand.
    • Changes to the signature of @attr.s() have to be added by hand too.
    • Changed/added classes/methods/functions have appropriate versionadded, versionchanged, or deprecated directives. Find the appropriate next version in our __init__.py file.
  • Documentation in .rst files is written using semantic newlines.
  • Changes (and possible deprecations) have news fragments in changelog.d.

If you have any questions to any of the points above, just submit and ask! This checklist is here to help you, not to deter you from contributing!

@hynek
Copy link
Member

hynek commented Oct 15, 2020

I honestly don’t care about the micro-performance on Python 2 since it’s only run on class creation anyways. So I say keep it as simple as possible.

But it looks really gnarly…could you isolate it into a function please (not the much simpler Python 3 path, I don’t want the function call overhead in the common case)?

Speaking of performance: please avoid the usage of str.format if you can. I know attrs is still full of it but it’s slow af and I don’t want it in new code. 🙏

You can find details on changelog.d in our contribution guide: https://www.attrs.org/en/latest/contributing.html#changelog

@Drino
Copy link
Contributor Author

Drino commented Oct 15, 2020

@hynek thank you for the answer!

As we don't care about performance in this case I rewritten it to poping from a dict (approach 2) and added fancy error-handling - now error-message is much closer to python2/python3 native ones for __init__().

Am I correct that this change doesn't need a testing strategy?

@Drino
Copy link
Contributor Author

Drino commented Oct 15, 2020

@hynek could you please help me with the failing codecov check?

I don't understand why the coverage decreased. I've added two functions, both are PY2-only and hidden under if PY2:. The only branching depends on presence of default value, but we have tests for both cases (kw_only with default and kw_only without default).

UPD: The line that is "not covered" is this list comprehension: https://codecov.io/gh/python-attrs/attrs/src/edd79f21aeb7bf71b6ea4af13af66992e04e42e2/src/attr/_make.py#L1949

UPD2: Seems like this only occurs if I use list comprehension - changed lines += to lines.extend and got rid of this issue.

docs/examples.rst Outdated Show resolved Hide resolved
src/attr/_make.py Outdated Show resolved Hide resolved
src/attr/_make.py Show resolved Hide resolved
src/attr/_make.py Outdated Show resolved Hide resolved
src/attr/_make.py Outdated Show resolved Hide resolved
@Drino Drino requested a review from hynek October 16, 2020 09:09
@hynek hynek merged commit bc527b9 into python-attrs:master Oct 19, 2020
@hynek
Copy link
Member

hynek commented Oct 19, 2020

Thanks, let's hope it doesn't fall apart in production. :)

@Drino Drino deleted the py2_kw_only branch October 19, 2020 09:28
@hynek hynek changed the title [RFC] kw_only python 2 backport kw_only python 2 backport Oct 19, 2020
aio-libs-github-bot bot pushed a commit to aio-libs/aiohttp that referenced this pull request Nov 6, 2020
Bumps [attrs](https://github.com/python-attrs/attrs) from 20.2.0 to 20.3.0.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a href="https://github.com/python-attrs/attrs/releases">attrs's releases</a>.</em></p>
<blockquote>
<h2>20.3.0</h2>
<h2>Backward-incompatible Changes</h2>
<ul>
<li>
<p><code>attr.define()</code>, <code>attr.frozen()</code>, <code>attr.mutable()</code>, and <code>attr.field()</code> remain <strong>provisional</strong>.</p>
<p>This release does <strong>not</strong> change change anything about them and they are already used widely in production though.</p>
<p>If you wish to use them together with mypy, you can simply drop <a href="https://gist.github.com/hynek/1e3844d0c99e479e716169034b5fa963#file-attrs_ng_plugin-py">this plugin</a> into your project.</p>
<p>Feel free to provide feedback to them in the linked issue <a href="https://github-redirect.dependabot.com/python-attrs/attrs/issues/668">#668</a>.</p>
<p>We will release the <code>attrs</code> namespace once we have the feeling that the APIs have properly settled. <a href="https://github-redirect.dependabot.com/python-attrs/attrs/issues/668">#668</a></p>
</li>
</ul>
<h2>Changes</h2>
<ul>
<li><code>attr.s()</code> now has a <em>field_transformer</em> hook that is called for all <code>Attribute</code>s and returns a (modified or updated) list of <code>Attribute</code> instances. <code>attr.asdict()</code> has a <em>value_serializer</em> hook that can change the way values are converted. Both hooks are meant to help with data (de-)serialization workflows. <a href="https://github-redirect.dependabot.com/python-attrs/attrs/issues/653">#653</a></li>
<li><code>kw_only=True</code> now works on Python 2. <a href="https://github-redirect.dependabot.com/python-attrs/attrs/issues/700">#700</a></li>
<li><code>raise from</code> now works on frozen classes on PyPy. <a href="https://github-redirect.dependabot.com/python-attrs/attrs/issues/703">#703</a>, <a href="https://github-redirect.dependabot.com/python-attrs/attrs/issues/712">#712</a></li>
<li><code>attr.asdict()</code> and <code>attr.astuple()</code> now treat <code>frozenset</code>s like <code>set</code>s with regards to the <em>retain_collection_types</em> argument. <a href="https://github-redirect.dependabot.com/python-attrs/attrs/issues/704">#704</a></li>
<li>The type stubs for <code>attr.s()</code> and <code>attr.make_class()</code> are not missing the <em>collect_by_mro</em> argument anymore. <a href="https://github-redirect.dependabot.com/python-attrs/attrs/issues/711">#711</a></li>
</ul>
</blockquote>
</details>
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a href="https://github.com/python-attrs/attrs/blob/master/CHANGELOG.rst">attrs's changelog</a>.</em></p>
<blockquote>
<h2>20.3.0 (2020-11-05)</h2>
<p>Backward-incompatible Changes
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^</p>
<ul>
<li>
<p><code>attr.define()</code>, <code>attr.frozen()</code>, <code>attr.mutable()</code>, and <code>attr.field()</code> remain <strong>provisional</strong>.</p>
<p>This release does <strong>not</strong> change change anything about them and they are already used widely in production though.</p>
<p>If you wish to use them together with mypy, you can simply drop <code>this plugin &lt;https://gist.github.com/hynek/1e3844d0c99e479e716169034b5fa963#file-attrs_ng_plugin-py&gt;</code>_ into your project.</p>
<p>Feel free to provide feedback to them in the linked issue <a href="https://github-redirect.dependabot.com/python-attrs/attrs/issues/668">#668</a>.</p>
<p>We will release the <code>attrs</code> namespace once we have the feeling that the APIs have properly settled.
<code>[#668](python-attrs/attrs#668) &lt;https://github.com/python-attrs/attrs/issues/668&gt;</code>_</p>
</li>
</ul>
<p>Changes
^^^^^^^</p>
<ul>
<li><code>attr.s()</code> now has a <em>field_transformer</em> hook that is called for all <code>Attribute</code>\ s and returns a (modified or updated) list of <code>Attribute</code> instances.
<code>attr.asdict()</code> has a <em>value_serializer</em> hook that can change the way values are converted.
Both hooks are meant to help with data (de-)serialization workflows.
<code>[#653](python-attrs/attrs#653) &lt;https://github.com/python-attrs/attrs/issues/653&gt;</code>_</li>
<li><code>kw_only=True</code> now works on Python 2.
<code>[#700](python-attrs/attrs#700) &lt;https://github.com/python-attrs/attrs/issues/700&gt;</code>_</li>
<li><code>raise from</code> now works on frozen classes on PyPy.
<code>[#703](python-attrs/attrs#703) &lt;https://github.com/python-attrs/attrs/issues/703&gt;</code><em>,
<code>[#712](python-attrs/attrs#712) &lt;https://github.com/python-attrs/attrs/issues/712&gt;</code></em></li>
<li><code>attr.asdict()</code> and <code>attr.astuple()</code> now treat <code>frozenset</code>\ s like <code>set</code>\ s with regards to the <em>retain_collection_types</em> argument.
<code>[#704](python-attrs/attrs#704) &lt;https://github.com/python-attrs/attrs/issues/704&gt;</code>_</li>
<li>The type stubs for <code>attr.s()</code> and <code>attr.make_class()</code> are not missing the <em>collect_by_mro</em> argument anymore.
<code>[#711](python-attrs/attrs#711) &lt;https://github.com/python-attrs/attrs/issues/711&gt;</code>_</li>
</ul>
<hr />
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a href="https://github.com/python-attrs/attrs/commit/f3762ba07bf0cec8bebdaaeca2212ba1d662ff13"><code>f3762ba</code></a> Prepare 20.3.0</li>
<li><a href="https://github.com/python-attrs/attrs/commit/3d66e5727b93d3463feb0fd780ae739192e7c363"><code>3d66e57</code></a> Exclude GitHub issues from linkcheck to avoid rate limits</li>
<li><a href="https://github.com/python-attrs/attrs/commit/06d0f8eda63b3f08cb5d94fff9fddf4fe6695621"><code>06d0f8e</code></a> Add funding URLs to metadata</li>
<li><a href="https://github.com/python-attrs/attrs/commit/d23924f765d09f77e87a5c51c1685df0d721b469"><code>d23924f</code></a> Add provisional notice</li>
<li><a href="https://github.com/python-attrs/attrs/commit/cd2f886d6372dca288abf9d999b3e35dacd9ced6"><code>cd2f886</code></a> Use 'i' and 'k' to better distinguish variables in an example (<a href="https://github-redirect.dependabot.com/python-attrs/attrs/issues/713">#713</a>)</li>
<li><a href="https://github.com/python-attrs/attrs/commit/f2dabeae82c75abe174aafc7a726481ded929872"><code>f2dabea</code></a> Fix exception chaining on PyPy (<a href="https://github-redirect.dependabot.com/python-attrs/attrs/issues/712">#712</a>)</li>
<li><a href="https://github.com/python-attrs/attrs/commit/6b4a1f1ce65162afe54e7101b263859bf8b2177e"><code>6b4a1f1</code></a> Tighten up mypy configuration</li>
<li><a href="https://github.com/python-attrs/attrs/commit/9f7d11e415bc789c9cbab255cb9a5b8903c1b122"><code>9f7d11e</code></a> Add types to collect_by_mro annotations m(</li>
<li><a href="https://github.com/python-attrs/attrs/commit/7020c8b5b55adefc76cf369fb071b1a4b15554a9"><code>7020c8b</code></a> pre-commit autoupdate</li>
<li><a href="https://github.com/python-attrs/attrs/commit/56c73081c5d767e30f529ac4f15a6bdd43e23d9f"><code>56c7308</code></a> Add missing collect_by_mro to typing stubs</li>
<li>Additional commits viewable in <a href="https://github.com/python-attrs/attrs/compare/20.2.0...20.3.0">compare view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=attrs&package-manager=pip&previous-version=20.2.0&new-version=20.3.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/configuring-github-dependabot-security-updates)

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)
commonism pushed a commit to commonism/aiohttp that referenced this pull request Apr 27, 2021
Bumps [attrs](https://github.com/python-attrs/attrs) from 20.2.0 to 20.3.0.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a href="https://github.com/python-attrs/attrs/releases">attrs's releases</a>.</em></p>
<blockquote>
<h2>20.3.0</h2>
<h2>Backward-incompatible Changes</h2>
<ul>
<li>
<p><code>attr.define()</code>, <code>attr.frozen()</code>, <code>attr.mutable()</code>, and <code>attr.field()</code> remain <strong>provisional</strong>.</p>
<p>This release does <strong>not</strong> change change anything about them and they are already used widely in production though.</p>
<p>If you wish to use them together with mypy, you can simply drop <a href="https://gist.github.com/hynek/1e3844d0c99e479e716169034b5fa963#file-attrs_ng_plugin-py">this plugin</a> into your project.</p>
<p>Feel free to provide feedback to them in the linked issue <a href="https://github-redirect.dependabot.com/python-attrs/attrs/issues/668">#668</a>.</p>
<p>We will release the <code>attrs</code> namespace once we have the feeling that the APIs have properly settled. <a href="https://github-redirect.dependabot.com/python-attrs/attrs/issues/668">#668</a></p>
</li>
</ul>
<h2>Changes</h2>
<ul>
<li><code>attr.s()</code> now has a <em>field_transformer</em> hook that is called for all <code>Attribute</code>s and returns a (modified or updated) list of <code>Attribute</code> instances. <code>attr.asdict()</code> has a <em>value_serializer</em> hook that can change the way values are converted. Both hooks are meant to help with data (de-)serialization workflows. <a href="https://github-redirect.dependabot.com/python-attrs/attrs/issues/653">#653</a></li>
<li><code>kw_only=True</code> now works on Python 2. <a href="https://github-redirect.dependabot.com/python-attrs/attrs/issues/700">#700</a></li>
<li><code>raise from</code> now works on frozen classes on PyPy. <a href="https://github-redirect.dependabot.com/python-attrs/attrs/issues/703">#703</a>, <a href="https://github-redirect.dependabot.com/python-attrs/attrs/issues/712">#712</a></li>
<li><code>attr.asdict()</code> and <code>attr.astuple()</code> now treat <code>frozenset</code>s like <code>set</code>s with regards to the <em>retain_collection_types</em> argument. <a href="https://github-redirect.dependabot.com/python-attrs/attrs/issues/704">#704</a></li>
<li>The type stubs for <code>attr.s()</code> and <code>attr.make_class()</code> are not missing the <em>collect_by_mro</em> argument anymore. <a href="https://github-redirect.dependabot.com/python-attrs/attrs/issues/711">#711</a></li>
</ul>
</blockquote>
</details>
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a href="https://github.com/python-attrs/attrs/blob/master/CHANGELOG.rst">attrs's changelog</a>.</em></p>
<blockquote>
<h2>20.3.0 (2020-11-05)</h2>
<p>Backward-incompatible Changes
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^</p>
<ul>
<li>
<p><code>attr.define()</code>, <code>attr.frozen()</code>, <code>attr.mutable()</code>, and <code>attr.field()</code> remain <strong>provisional</strong>.</p>
<p>This release does <strong>not</strong> change change anything about them and they are already used widely in production though.</p>
<p>If you wish to use them together with mypy, you can simply drop <code>this plugin &lt;https://gist.github.com/hynek/1e3844d0c99e479e716169034b5fa963#file-attrs_ng_plugin-py&gt;</code>_ into your project.</p>
<p>Feel free to provide feedback to them in the linked issue <a href="https://github-redirect.dependabot.com/python-attrs/attrs/issues/668">#668</a>.</p>
<p>We will release the <code>attrs</code> namespace once we have the feeling that the APIs have properly settled.
<code>[aio-libs#668](python-attrs/attrs#668) &lt;https://github.com/python-attrs/attrs/issues/668&gt;</code>_</p>
</li>
</ul>
<p>Changes
^^^^^^^</p>
<ul>
<li><code>attr.s()</code> now has a <em>field_transformer</em> hook that is called for all <code>Attribute</code>\ s and returns a (modified or updated) list of <code>Attribute</code> instances.
<code>attr.asdict()</code> has a <em>value_serializer</em> hook that can change the way values are converted.
Both hooks are meant to help with data (de-)serialization workflows.
<code>[aio-libs#653](python-attrs/attrs#653) &lt;https://github.com/python-attrs/attrs/issues/653&gt;</code>_</li>
<li><code>kw_only=True</code> now works on Python 2.
<code>[aio-libs#700](python-attrs/attrs#700) &lt;https://github.com/python-attrs/attrs/issues/700&gt;</code>_</li>
<li><code>raise from</code> now works on frozen classes on PyPy.
<code>[aio-libs#703](python-attrs/attrs#703) &lt;https://github.com/python-attrs/attrs/issues/703&gt;</code><em>,
<code>[aio-libs#712](python-attrs/attrs#712) &lt;https://github.com/python-attrs/attrs/issues/712&gt;</code></em></li>
<li><code>attr.asdict()</code> and <code>attr.astuple()</code> now treat <code>frozenset</code>\ s like <code>set</code>\ s with regards to the <em>retain_collection_types</em> argument.
<code>[aio-libs#704](python-attrs/attrs#704) &lt;https://github.com/python-attrs/attrs/issues/704&gt;</code>_</li>
<li>The type stubs for <code>attr.s()</code> and <code>attr.make_class()</code> are not missing the <em>collect_by_mro</em> argument anymore.
<code>[aio-libs#711](python-attrs/attrs#711) &lt;https://github.com/python-attrs/attrs/issues/711&gt;</code>_</li>
</ul>
<hr />
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a href="https://github.com/python-attrs/attrs/commit/f3762ba07bf0cec8bebdaaeca2212ba1d662ff13"><code>f3762ba</code></a> Prepare 20.3.0</li>
<li><a href="https://github.com/python-attrs/attrs/commit/3d66e5727b93d3463feb0fd780ae739192e7c363"><code>3d66e57</code></a> Exclude GitHub issues from linkcheck to avoid rate limits</li>
<li><a href="https://github.com/python-attrs/attrs/commit/06d0f8eda63b3f08cb5d94fff9fddf4fe6695621"><code>06d0f8e</code></a> Add funding URLs to metadata</li>
<li><a href="https://github.com/python-attrs/attrs/commit/d23924f765d09f77e87a5c51c1685df0d721b469"><code>d23924f</code></a> Add provisional notice</li>
<li><a href="https://github.com/python-attrs/attrs/commit/cd2f886d6372dca288abf9d999b3e35dacd9ced6"><code>cd2f886</code></a> Use 'i' and 'k' to better distinguish variables in an example (<a href="https://github-redirect.dependabot.com/python-attrs/attrs/issues/713">#713</a>)</li>
<li><a href="https://github.com/python-attrs/attrs/commit/f2dabeae82c75abe174aafc7a726481ded929872"><code>f2dabea</code></a> Fix exception chaining on PyPy (<a href="https://github-redirect.dependabot.com/python-attrs/attrs/issues/712">#712</a>)</li>
<li><a href="https://github.com/python-attrs/attrs/commit/6b4a1f1ce65162afe54e7101b263859bf8b2177e"><code>6b4a1f1</code></a> Tighten up mypy configuration</li>
<li><a href="https://github.com/python-attrs/attrs/commit/9f7d11e415bc789c9cbab255cb9a5b8903c1b122"><code>9f7d11e</code></a> Add types to collect_by_mro annotations m(</li>
<li><a href="https://github.com/python-attrs/attrs/commit/7020c8b5b55adefc76cf369fb071b1a4b15554a9"><code>7020c8b</code></a> pre-commit autoupdate</li>
<li><a href="https://github.com/python-attrs/attrs/commit/56c73081c5d767e30f529ac4f15a6bdd43e23d9f"><code>56c7308</code></a> Add missing collect_by_mro to typing stubs</li>
<li>Additional commits viewable in <a href="https://github.com/python-attrs/attrs/compare/20.2.0...20.3.0">compare view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=attrs&package-manager=pip&previous-version=20.2.0&new-version=20.3.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/configuring-github-dependabot-security-updates)

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)
commonism pushed a commit to commonism/aiohttp that referenced this pull request Apr 27, 2021
Bumps [attrs](https://github.com/python-attrs/attrs) from 20.2.0 to 20.3.0.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a href="https://github.com/python-attrs/attrs/releases">attrs's releases</a>.</em></p>
<blockquote>
<h2>20.3.0</h2>
<h2>Backward-incompatible Changes</h2>
<ul>
<li>
<p><code>attr.define()</code>, <code>attr.frozen()</code>, <code>attr.mutable()</code>, and <code>attr.field()</code> remain <strong>provisional</strong>.</p>
<p>This release does <strong>not</strong> change change anything about them and they are already used widely in production though.</p>
<p>If you wish to use them together with mypy, you can simply drop <a href="https://gist.github.com/hynek/1e3844d0c99e479e716169034b5fa963#file-attrs_ng_plugin-py">this plugin</a> into your project.</p>
<p>Feel free to provide feedback to them in the linked issue <a href="https://github-redirect.dependabot.com/python-attrs/attrs/issues/668">#668</a>.</p>
<p>We will release the <code>attrs</code> namespace once we have the feeling that the APIs have properly settled. <a href="https://github-redirect.dependabot.com/python-attrs/attrs/issues/668">#668</a></p>
</li>
</ul>
<h2>Changes</h2>
<ul>
<li><code>attr.s()</code> now has a <em>field_transformer</em> hook that is called for all <code>Attribute</code>s and returns a (modified or updated) list of <code>Attribute</code> instances. <code>attr.asdict()</code> has a <em>value_serializer</em> hook that can change the way values are converted. Both hooks are meant to help with data (de-)serialization workflows. <a href="https://github-redirect.dependabot.com/python-attrs/attrs/issues/653">#653</a></li>
<li><code>kw_only=True</code> now works on Python 2. <a href="https://github-redirect.dependabot.com/python-attrs/attrs/issues/700">#700</a></li>
<li><code>raise from</code> now works on frozen classes on PyPy. <a href="https://github-redirect.dependabot.com/python-attrs/attrs/issues/703">#703</a>, <a href="https://github-redirect.dependabot.com/python-attrs/attrs/issues/712">#712</a></li>
<li><code>attr.asdict()</code> and <code>attr.astuple()</code> now treat <code>frozenset</code>s like <code>set</code>s with regards to the <em>retain_collection_types</em> argument. <a href="https://github-redirect.dependabot.com/python-attrs/attrs/issues/704">#704</a></li>
<li>The type stubs for <code>attr.s()</code> and <code>attr.make_class()</code> are not missing the <em>collect_by_mro</em> argument anymore. <a href="https://github-redirect.dependabot.com/python-attrs/attrs/issues/711">#711</a></li>
</ul>
</blockquote>
</details>
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a href="https://github.com/python-attrs/attrs/blob/master/CHANGELOG.rst">attrs's changelog</a>.</em></p>
<blockquote>
<h2>20.3.0 (2020-11-05)</h2>
<p>Backward-incompatible Changes
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^</p>
<ul>
<li>
<p><code>attr.define()</code>, <code>attr.frozen()</code>, <code>attr.mutable()</code>, and <code>attr.field()</code> remain <strong>provisional</strong>.</p>
<p>This release does <strong>not</strong> change change anything about them and they are already used widely in production though.</p>
<p>If you wish to use them together with mypy, you can simply drop <code>this plugin &lt;https://gist.github.com/hynek/1e3844d0c99e479e716169034b5fa963#file-attrs_ng_plugin-py&gt;</code>_ into your project.</p>
<p>Feel free to provide feedback to them in the linked issue <a href="https://github-redirect.dependabot.com/python-attrs/attrs/issues/668">#668</a>.</p>
<p>We will release the <code>attrs</code> namespace once we have the feeling that the APIs have properly settled.
<code>[aio-libs#668](python-attrs/attrs#668) &lt;https://github.com/python-attrs/attrs/issues/668&gt;</code>_</p>
</li>
</ul>
<p>Changes
^^^^^^^</p>
<ul>
<li><code>attr.s()</code> now has a <em>field_transformer</em> hook that is called for all <code>Attribute</code>\ s and returns a (modified or updated) list of <code>Attribute</code> instances.
<code>attr.asdict()</code> has a <em>value_serializer</em> hook that can change the way values are converted.
Both hooks are meant to help with data (de-)serialization workflows.
<code>[aio-libs#653](python-attrs/attrs#653) &lt;https://github.com/python-attrs/attrs/issues/653&gt;</code>_</li>
<li><code>kw_only=True</code> now works on Python 2.
<code>[aio-libs#700](python-attrs/attrs#700) &lt;https://github.com/python-attrs/attrs/issues/700&gt;</code>_</li>
<li><code>raise from</code> now works on frozen classes on PyPy.
<code>[aio-libs#703](python-attrs/attrs#703) &lt;https://github.com/python-attrs/attrs/issues/703&gt;</code><em>,
<code>[aio-libs#712](python-attrs/attrs#712) &lt;https://github.com/python-attrs/attrs/issues/712&gt;</code></em></li>
<li><code>attr.asdict()</code> and <code>attr.astuple()</code> now treat <code>frozenset</code>\ s like <code>set</code>\ s with regards to the <em>retain_collection_types</em> argument.
<code>[aio-libs#704](python-attrs/attrs#704) &lt;https://github.com/python-attrs/attrs/issues/704&gt;</code>_</li>
<li>The type stubs for <code>attr.s()</code> and <code>attr.make_class()</code> are not missing the <em>collect_by_mro</em> argument anymore.
<code>[aio-libs#711](python-attrs/attrs#711) &lt;https://github.com/python-attrs/attrs/issues/711&gt;</code>_</li>
</ul>
<hr />
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a href="https://github.com/python-attrs/attrs/commit/f3762ba07bf0cec8bebdaaeca2212ba1d662ff13"><code>f3762ba</code></a> Prepare 20.3.0</li>
<li><a href="https://github.com/python-attrs/attrs/commit/3d66e5727b93d3463feb0fd780ae739192e7c363"><code>3d66e57</code></a> Exclude GitHub issues from linkcheck to avoid rate limits</li>
<li><a href="https://github.com/python-attrs/attrs/commit/06d0f8eda63b3f08cb5d94fff9fddf4fe6695621"><code>06d0f8e</code></a> Add funding URLs to metadata</li>
<li><a href="https://github.com/python-attrs/attrs/commit/d23924f765d09f77e87a5c51c1685df0d721b469"><code>d23924f</code></a> Add provisional notice</li>
<li><a href="https://github.com/python-attrs/attrs/commit/cd2f886d6372dca288abf9d999b3e35dacd9ced6"><code>cd2f886</code></a> Use 'i' and 'k' to better distinguish variables in an example (<a href="https://github-redirect.dependabot.com/python-attrs/attrs/issues/713">#713</a>)</li>
<li><a href="https://github.com/python-attrs/attrs/commit/f2dabeae82c75abe174aafc7a726481ded929872"><code>f2dabea</code></a> Fix exception chaining on PyPy (<a href="https://github-redirect.dependabot.com/python-attrs/attrs/issues/712">#712</a>)</li>
<li><a href="https://github.com/python-attrs/attrs/commit/6b4a1f1ce65162afe54e7101b263859bf8b2177e"><code>6b4a1f1</code></a> Tighten up mypy configuration</li>
<li><a href="https://github.com/python-attrs/attrs/commit/9f7d11e415bc789c9cbab255cb9a5b8903c1b122"><code>9f7d11e</code></a> Add types to collect_by_mro annotations m(</li>
<li><a href="https://github.com/python-attrs/attrs/commit/7020c8b5b55adefc76cf369fb071b1a4b15554a9"><code>7020c8b</code></a> pre-commit autoupdate</li>
<li><a href="https://github.com/python-attrs/attrs/commit/56c73081c5d767e30f529ac4f15a6bdd43e23d9f"><code>56c7308</code></a> Add missing collect_by_mro to typing stubs</li>
<li>Additional commits viewable in <a href="https://github.com/python-attrs/attrs/compare/20.2.0...20.3.0">compare view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=attrs&package-manager=pip&previous-version=20.2.0&new-version=20.3.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/configuring-github-dependabot-security-updates)

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants