[Python-modules-commits] [python-attrs] 01/13: Import python-attrs_17.4.0.orig.tar.gz
Tristan Seligmann
mithrandi at moszumanska.debian.org
Tue Jan 23 13:09:35 UTC 2018
This is an automated email from the git hooks/post-receive script.
mithrandi pushed a commit to tag debian/17.4.0-1
in repository python-attrs.
commit 1597ed3ba5b2e0ff7faf1fc17936b8fce4776aae
Author: Tristan Seligmann <mithrandi at mithrandi.net>
Date: Tue Jan 23 14:02:56 2018 +0200
Import python-attrs_17.4.0.orig.tar.gz
---
CODE_OF_CONDUCT.rst => .github/CODE_OF_CONDUCT.rst | 2 +-
CONTRIBUTING.rst => .github/CONTRIBUTING.rst | 92 ++-
.../PULL_REQUEST_TEMPLATE.md | 2 +-
.readthedocs.yml | 6 +
.travis.yml | 16 +-
CHANGELOG.rst | 149 +++-
MANIFEST.in | 13 +-
README.rst | 41 +-
changelog.d/.gitignore | 0
changelog.d/261.change.rst | 4 +
changelog.d/280.change.rst | 2 +
changelog.d/284.change.rst | 2 +
changelog.d/285.change.rst | 2 +
changelog.d/286.change.rst | 2 +
changelog.d/287.change.rst | 2 +
changelog.d/291.change.rst | 1 +
changelog.d/292.change.rst | 1 +
changelog.d/295.change.rst | 4 +
changelog.d/296.change.rst | 4 +
changelog.d/298.breaking.rst | 7 +
changelog.d/299.breaking.rst | 7 +
changelog.d/304.breaking.rst | 7 +
changelog.d/306.change.rst | 1 +
changelog.d/307.deprecation.rst | 5 +
changelog.d/308.breaking.rst | 20 +
changelog.d/309.change.rst | 1 +
changelog.d/towncrier_template.rst | 35 +
conftest.py | 18 +-
dev-requirements.txt | 6 -
docs-requirements.txt | 3 -
docs/_static/attrs_logo.svg | 1 +
docs/api.rst | 79 +-
docs/conf.py | 6 +-
docs/contributing.rst | 4 +-
docs/examples.rst | 125 ++-
docs/extending.rst | 36 +-
docs/how-does-it-work.rst | 13 +-
docs/index.rst | 67 +-
docs/overview.rst | 36 +-
docs/why.rst | 128 +--
pyproject.toml | 27 +
setup.cfg | 23 +-
setup.py | 19 +-
src/attr/__init__.py | 36 +-
src/attr/_compat.py | 61 +-
src/attr/_funcs.py | 6 +-
src/attr/_make.py | 892 ++++++++++++++++-----
src/attr/exceptions.py | 9 +
src/attr/validators.py | 20 +-
tests/test_annotations.py | 156 ++++
tests/test_dark_magic.py | 119 ++-
tests/test_dunders.py | 80 +-
tests/test_filters.py | 16 +-
tests/test_funcs.py | 83 +-
tests/test_init_subclass.py | 44 +
tests/test_make.py | 571 +++++++++----
tests/test_slots.py | 129 ++-
tests/test_validators.py | 14 +-
tests/utils.py | 41 +-
tox.ini | 51 +-
60 files changed, 2620 insertions(+), 727 deletions(-)
diff --git a/CODE_OF_CONDUCT.rst b/.github/CODE_OF_CONDUCT.rst
similarity index 95%
rename from CODE_OF_CONDUCT.rst
rename to .github/CODE_OF_CONDUCT.rst
index 4f4b8ee..56e8914 100644
--- a/CODE_OF_CONDUCT.rst
+++ b/.github/CODE_OF_CONDUCT.rst
@@ -52,4 +52,4 @@ Project maintainers who do not follow or enforce the Code of Conduct in good fai
Attribution
-----------
-This Code of Conduct is adapted from the `Contributor Covenant <http://contributor-covenant.org>`_, version 1.4, available at http://contributor-covenant.org/version/1/4.
+This Code of Conduct is adapted from the `Contributor Covenant <https://www.contributor-covenant.org>`_, version 1.4, available at <https://www.contributor-covenant.org/version/1/4/code-of-conduct.html>.
diff --git a/CONTRIBUTING.rst b/.github/CONTRIBUTING.rst
similarity index 66%
rename from CONTRIBUTING.rst
rename to .github/CONTRIBUTING.rst
index fa82ca2..ae35dc1 100644
--- a/CONTRIBUTING.rst
+++ b/.github/CONTRIBUTING.rst
@@ -8,6 +8,15 @@ This document is mainly to help you to get started by codifying tribal knowledge
But don't be afraid to open half-finished PRs and ask questions if something is unclear!
+Support
+-------
+
+In case you'd like to help out but don't want to deal with GitHub, there's a great opportunity:
+help your fellow developers on `StackOverflow <https://stackoverflow.com/questions/tagged/python-attrs>`_!
+
+The offical tag is ``python-attrs`` and helping out in support frees us up for improving ``attrs`` instead!
+
+
Workflow
--------
@@ -15,11 +24,10 @@ Workflow
Please submit as many fixes for typos and grammar bloopers as you can!
- Try to limit each pull request to *one* change only.
- *Always* add tests and docs for your code.
- This is a hard rule; patches with missing tests or documentation can't be accepted.
+ This is a hard rule; patches with missing tests or documentation can't be merged.
- Make sure your changes pass our CI_.
You won't get any feedback until it's green unless you ask for it.
-- Once you've addressed review feedback, make sure to bump the pull request with a short note.
- Maintainers don’t receive notifications when you push new commits.
+- Once you've addressed review feedback, make sure to bump the pull request with a short note, so we know you're done.
- Don’t break `backward compatibility`_.
@@ -87,56 +95,89 @@ Documentation
First line of new section.
- If you add a new feature, demonstrate its awesomeness in the `examples page`_!
-- If your change is noteworthy, add an entry to the changelog_.
- Use `semantic newlines`_, and add a link to your pull request:
+
+
+Changelog
+^^^^^^^^^
+
+If your change is noteworthy, there needs to be a changelog entry, so our users can learn about it!
+
+To avoid merge conflicts, we use the towncrier_ package to manage our changelog.
+``towncrier`` uses independent files for each pull request -- so called *news fragments* -- instead of one monolithic changelog file.
+On release those news fragments are compiled into our ``CHANGELOG.rst``.
+
+You don't need to install ``towncrier`` yourself, you just have to abide to a few simple rules:
+
+- For each pull request, add a new file into ``changelog.d`` with a filename adhering to the ``pr#.(change|deprecation|breaking).rst`` schema:
+ For example ``changelog.d/42.change.rst`` for a non-breaking change, that is proposed in pull request number 42.
+- As with other docs, please use `semantic newlines`_ within news fragments.
+- Wrap symbols like modules, functions, or classes into double backticks so they are rendered in a monospaced font.
+- If you mention functions or other callables, add parantheses at the end of their names: ``attr.func()`` or ``attr.Class.method()``.
+ This makes the changelog a lot more readable.
+- Prefer simple past or constructions with "now".
+ For example:
+
+ + Added ``attr.validators.func()``.
+ + ``attr.func()`` now doesn't crash the Large Hadron Collider anymore.
+- If you want to reference multiple issues, copy the news fragment to another filename.
+ ``towncrier`` will merge all news fragments with identical contents into one entry with multiple links to the respective pull requests.
+
+Example entries:
+
+ .. code-block:: rst
+
+ Added ``attr.validators.func()``.
+ The feature really *is* awesome.
+
+or:
.. code-block:: rst
- - Added ``attr.validators.func()``.
- The feature really *is* awesome.
- [`#1 <https://github.com/python-attrs/attrs/pull/1>`_]
- - ``attr.func()`` now doesn't crash the Large Hadron Collider anymore.
- The bug really *was* nasty.
- [`#2 <https://github.com/python-attrs/attrs/pull/2>`_]
+ ``attr.func()`` now doesn't crash the Large Hadron Collider anymore.
+ The bug really *was* nasty.
+
+----
+
+``tox -e changelog`` will render the current changelog to the terminal if you have any doubts.
Local Development Environment
-----------------------------
-You can (and should) run our test suite using tox_ however you’ll probably want a more traditional environment too.
+You can (and should) run our test suite using tox_.
+However you’ll probably want a more traditional environment too.
We highly recommend to develop using the latest Python 3 release because ``attrs`` tries to take advantage of modern features whenever possible.
First create a `virtual environment <https://virtualenv.pypa.io/>`_.
It’s out of scope for this document to list all the ways to manage virtual environments in Python but if you don’t have already a pet way, take some time to look at tools like `pew <https://github.com/berdario/pew>`_, `virtualfish <http://virtualfish.readthedocs.io/>`_, and `virtualenvwrapper <http://virtualenvwrapper.readthedocs.io/>`_.
-Next get an up to date checkout of the ``attrs`` repository:
+Next, get an up to date checkout of the ``attrs`` repository:
.. code-block:: bash
- git checkout git at github.com:python-attrs/attrs.git
+ $ git checkout git at github.com:python-attrs/attrs.git
-Change into the newly created directory and **after activating your virtual environment** install an editable version of ``attrs``:
+Change into the newly created directory and **after activating your virtual environment** install an editable version of ``attrs`` along with its tests and docs requirements:
.. code-block:: bash
- cd attrs
- pip install -e .
-
-If you run the virtual environment’s Python and try to ``import attr`` it should work!
+ $ cd attrs
+ $ pip install -e .[dev]
-To run the test suite, you'll need our development dependencies which can be installed using
+At this point
.. code-block:: bash
- pip install -r dev-requirements.txt
+ $ python -m pytest
-At this point
+should work and pass, as should:
.. code-block:: bash
- python -m pytest
+ $ cd docs
+ $ make html
-should work and pass!
+The built documentation can then be found in ``docs/_build/html/``.
Governance
@@ -163,7 +204,7 @@ Thank you for considering contributing to ``attrs``!
.. _`PEP 8`: https://www.python.org/dev/peps/pep-0008/
.. _`PEP 257`: https://www.python.org/dev/peps/pep-0257/
.. _`good test docstrings`: https://jml.io/pages/test-docstrings.html
-.. _`Code of Conduct`: https://github.com/python-attrs/attrs/blob/master/CODE_OF_CONDUCT.rst
+.. _`Code of Conduct`: https://github.com/python-attrs/attrs/blob/master/.github/CODE_OF_CONDUCT.rst
.. _changelog: https://github.com/python-attrs/attrs/blob/master/CHANGELOG.rst
.. _`backward compatibility`: http://www.attrs.org/en/latest/backward-compatibility.html
.. _tox: https://tox.readthedocs.io/
@@ -175,3 +216,4 @@ Thank you for considering contributing to ``attrs``!
.. _CI: https://travis-ci.org/python-attrs/attrs/
.. _`team of volunteers`: https://github.com/python-attrs
.. _BDFL: https://en.wikipedia.org/wiki/Benevolent_dictator_for_life
+.. _towncrier: https://pypi.org/project/towncrier
diff --git a/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md
similarity index 87%
rename from PULL_REQUEST_TEMPLATE.md
rename to .github/PULL_REQUEST_TEMPLATE.md
index 2a9d712..34c468e 100644
--- a/PULL_REQUEST_TEMPLATE.md
+++ b/.github/PULL_REQUEST_TEMPLATE.md
@@ -7,6 +7,6 @@ This is just a reminder about the most common mistakes. Please make sure that y
- [ ] Updated **documentation** for changed code.
- [ ] Documentation in `.rst` files is written using [semantic newlines](http://rhodesmill.org/brandon/2012/one-sentence-per-line/).
- [ ] Changed/added classes/methods/functions have appropriate `versionadded`, `versionchanged`, or `deprecated` [directives](http://www.sphinx-doc.org/en/stable/markup/para.html#directive-versionadded).
-- [ ] Changes (and possible deprecations) are documented in [`CHANGELOG.rst`](https://github.com/python-attrs/attrs/blob/master/CHANGELOG.rst).
+- [ ] Changes (and possible deprecations) have news fragments in [`changelog.d`](https://github.com/python-attrs/attrs/blob/master/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!
diff --git a/.readthedocs.yml b/.readthedocs.yml
new file mode 100644
index 0000000..a4b6f43
--- /dev/null
+++ b/.readthedocs.yml
@@ -0,0 +1,6 @@
+---
+python:
+ version: 3
+ pip_install: true
+ extra_requirements:
+ - docs
diff --git a/.travis.yml b/.travis.yml
index d3f21dc..e52abac 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,3 +1,4 @@
+dist: trusty
sudo: false
cache:
directories:
@@ -7,6 +8,8 @@ language: python
matrix:
+ fast_finish: true
+
include:
- python: "2.7"
env: TOXENV=py27
@@ -16,8 +19,14 @@ matrix:
env: TOXENV=py35
- python: "3.6"
env: TOXENV=py36
- - python: "pypy"
+ - python: "pypy2.7-5.8.0"
env: TOXENV=pypy
+ - python: "pypy3.5-5.8.0"
+ env: TOXENV=pypy3
+
+ # Prevent breakage by a new release
+ - python: "3.6-dev"
+ env: TOXENV=py36
# Meta
- python: "3.6"
@@ -28,6 +37,11 @@ matrix:
env: TOXENV=docs
- python: "3.6"
env: TOXENV=readme
+ - python: "3.6"
+ env: TOXENV=changelog
+
+ allow_failures:
+ python: "3.6-dev"
install:
diff --git a/CHANGELOG.rst b/CHANGELOG.rst
index fc9148a..ee1da54 100644
--- a/CHANGELOG.rst
+++ b/CHANGELOG.rst
@@ -5,20 +5,147 @@ Versions follow `CalVer <http://calver.org>`_ with a strict backwards compatibil
The third digit is only for regressions.
-17.2.0 (2017-05-24)
+.. towncrier release notes start
+
+17.4.0 (2017-12-30)
-------------------
+Backward-incompatible Changes
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-Backward-incompatible changes:
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+- The traversal of MROs when using multiple inheritance was backward:
+ If you defined a class ``C`` that subclasses ``A`` and ``B`` like ``C(A, B)``, ``attrs`` would have collected the attributes from ``B`` *before* those of ``A``.
-*none*
+ This is now fixed and means that in classes that employ multiple inheritance, the output of ``__repr__`` and the order of positional arguments in ``__init__`` changes.
+ Due to the nature of this bug, a proper deprecation cycle was unfortunately impossible.
+ Generally speaking, it's advisable to prefer ``kwargs``-based initialization anyways – *especially* if you employ multiple inheritance and diamond-shaped hierarchies.
-Deprecations:
-^^^^^^^^^^^^^
+ `#298 <https://github.com/python-attrs/attrs/issues/298>`_,
+ `#299 <https://github.com/python-attrs/attrs/issues/299>`_,
+ `#304 <https://github.com/python-attrs/attrs/issues/304>`_
+- The ``__repr__`` set by ``attrs``
+ no longer produces an ``AttributeError``
+ when the instance is missing some of the specified attributes
+ (either through deleting
+ or after using ``init=False`` on some attributes).
+
+ This can break code
+ that relied on ``repr(attr_cls_instance)`` raising ``AttributeError``
+ to check if any attr-specified members were unset.
+
+ If you were using this,
+ you can implement a custom method for checking this::
+
+ def has_unset_members(self):
+ for field in attr.fields(type(self)):
+ try:
+ getattr(self, field.name)
+ except AttributeError:
+ return True
+ return False
+
+ `#308 <https://github.com/python-attrs/attrs/issues/308>`_
+
+
+Deprecations
+^^^^^^^^^^^^
+
+- The ``attr.ib(convert=callable)`` option is now deprecated in favor of ``attr.ib(converter=callable)``.
+
+ This is done to achieve consistency with other noun-based arguments like *validator*.
+
+ *convert* will keep working until at least January 2019 while raising a ``DeprecationWarning``.
+
+ `#307 <https://github.com/python-attrs/attrs/issues/307>`_
+
+
+Changes
+^^^^^^^
+
+- Generated ``__hash__`` methods now hash the class type along with the attribute values.
+ Until now the hashes of two classes with the same values were identical which was a bug.
+
+ The generated method is also *much* faster now.
+
+ `#261 <https://github.com/python-attrs/attrs/issues/261>`_,
+ `#295 <https://github.com/python-attrs/attrs/issues/295>`_,
+ `#296 <https://github.com/python-attrs/attrs/issues/296>`_
+- ``attr.ib``\ ’s ``metadata`` argument now defaults to a unique empty ``dict`` instance instead of sharing a common empty ``dict`` for all.
+ The singleton empty ``dict`` is still enforced.
+
+ `#280 <https://github.com/python-attrs/attrs/issues/280>`_
+- ``ctypes`` is optional now however if it's missing, a bare ``super()`` will not work in slots classes.
+ This should only happen in special environments like Google App Engine.
+
+ `#284 <https://github.com/python-attrs/attrs/issues/284>`_,
+ `#286 <https://github.com/python-attrs/attrs/issues/286>`_
+- The attribute redefinition feature introduced in 17.3.0 now takes into account if an attribute is redefined via multiple inheritance.
+ In that case, the definition that is closer to the base of the class hierarchy wins.
+
+ `#285 <https://github.com/python-attrs/attrs/issues/285>`_,
+ `#287 <https://github.com/python-attrs/attrs/issues/287>`_
+- Subclasses of ``auto_attribs=True`` can be empty now.
+
+ `#291 <https://github.com/python-attrs/attrs/issues/291>`_,
+ `#292 <https://github.com/python-attrs/attrs/issues/292>`_
+- Equality tests are *much* faster now.
-*none*
+ `#306 <https://github.com/python-attrs/attrs/issues/306>`_
+- All generated methods now have correct ``__module__``, ``__name__``, and (on Python 3) ``__qualname__`` attributes.
+
+ `#309 <https://github.com/python-attrs/attrs/issues/309>`_
+
+
+----
+
+
+17.3.0 (2017-11-08)
+-------------------
+
+Backward-incompatible Changes
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+- Attributes are not defined on the class body anymore.
+
+ This means that if you define a class ``C`` with an attribute ``x``, the class will *not* have an attribute ``x`` for introspection anymore.
+ Instead of ``C.x``, use ``attr.fields(C).x`` or look at ``C.__attrs_attrs__``.
+ The old behavior has been deprecated since version 16.1.
+ (`#253 <https://github.com/python-attrs/attrs/issues/253>`_)
+
+
+Changes
+^^^^^^^
+
+- ``super()`` and ``__class__`` now work on Python 3 when ``slots=True``.
+ (`#102 <https://github.com/python-attrs/attrs/issues/102>`_, `#226 <https://github.com/python-attrs/attrs/issues/226>`_, `#269 <https://github.com/python-attrs/attrs/issues/269>`_, `#270 <https://github.com/python-attrs/attrs/issues/270>`_, `#272 <https://github.com/python-attrs/attrs/issues/272>`_)
+- Added ``type`` argument to ``attr.ib()`` and corresponding ``type`` attribute to ``attr.Attribute``.
+
+ This change paves the way for automatic type checking and serialization (though as of this release ``attrs`` does not make use of it).
+ In Python 3.6 or higher, the value of ``attr.Attribute.type`` can alternately be set using variable type annotations
+ (see `PEP 526 <https://www.python.org/dev/peps/pep-0526/>`_). (`#151 <https://github.com/python-attrs/attrs/issues/151>`_, `#214 <https://github.com/python-attrs/attrs/issues/214>`_, `#215 <https://github.com/python-attrs/attrs/issues/215>`_, `#239 <https://github.com/python-attrs/attrs/issues/239>`_)
+- The combination of ``str=True`` and ``slots=True`` now works on Python 2.
+ (`#198 <https://github.com/python-attrs/attrs/issues/198>`_)
+- ``attr.Factory`` is hashable again. (`#204
+ <https://github.com/python-attrs/attrs/issues/204>`_)
+- Subclasses now can overwrite attribute definitions of their superclass.
+
+ That means that you can -- for example -- change the default value for an attribute by redefining it.
+ (`#221 <https://github.com/python-attrs/attrs/issues/221>`_, `#229 <https://github.com/python-attrs/attrs/issues/229>`_)
+- Added new option ``auto_attribs`` to ``@attr.s`` that allows to collect annotated fields without setting them to ``attr.ib()``.
+
+ Setting a field to an ``attr.ib()`` is still possible to supply options like validators.
+ Setting it to any other value is treated like it was passed as ``attr.ib(default=value)`` -- passing an instance of ``attr.Factory`` also works as expected.
+ (`#262 <https://github.com/python-attrs/attrs/issues/262>`_, `#277 <https://github.com/python-attrs/attrs/issues/277>`_)
+- Instances of classes created using ``attr.make_class()`` can now be pickled.
+ (`#282 <https://github.com/python-attrs/attrs/issues/282>`_)
+
+
+----
+
+
+17.2.0 (2017-05-24)
+-------------------
Changes:
@@ -43,7 +170,7 @@ To encourage more participation, the project has also been moved into a `dedicat
:alt: attrs logo
-Backward-incompatible changes:
+Backward-incompatible Changes:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- ``attrs`` will set the ``__hash__()`` method to ``None`` by default now.
@@ -169,7 +296,7 @@ Changes:
16.1.0 (2016-08-30)
-------------------
-Backward-incompatible changes:
+Backward-incompatible Changes:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- All instances where function arguments were called ``cl`` have been changed to the more Pythonic ``cls``.
@@ -213,7 +340,7 @@ Changes:
16.0.0 (2016-05-23)
-------------------
-Backward-incompatible changes:
+Backward-incompatible Changes:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- Python 3.3 and 2.6 aren't supported anymore.
@@ -228,7 +355,7 @@ Changes:
^^^^^^^^
- ``__slots__`` have arrived!
- Classes now can automatically be `slots <https://docs.python.org/3.5/reference/datamodel.html#slots>`_-style (and save your precious memory) just by passing ``slots=True``.
+ Classes now can automatically be `slots <https://docs.python.org/3/reference/datamodel.html#slots>`_-style (and save your precious memory) just by passing ``slots=True``.
`#35 <https://github.com/python-attrs/attrs/issues/35>`_
- Allow the case of initializing attributes that are set to ``init=False``.
This allows for clean initializer parameter lists while being able to initialize attributes to default values.
diff --git a/MANIFEST.in b/MANIFEST.in
index c7af0b0..663c4ea 100644
--- a/MANIFEST.in
+++ b/MANIFEST.in
@@ -1,15 +1,22 @@
-include LICENSE *.rst
+include LICENSE *.rst *.toml .readthedocs.yml
# Don't package GitHub-specific files.
-exclude *.md .travis.yml
+exclude .github/*.md .travis.yml
# Tests
-include tox.ini .coveragerc conftest.py dev-requirements.txt docs-requirements.txt
+include tox.ini .coveragerc conftest.py
recursive-include tests *.py
+recursive-include .github *.rst
# Documentation
include docs/Makefile docs/docutils.conf
recursive-include docs *.png
+recursive-include docs *.svg
recursive-include docs *.py
recursive-include docs *.rst
prune docs/_build
+
+# Just to keep check-manifest happy; on releases those files are gone.
+# Last rule wins!
+exclude changelog.d/*.rst
+include changelog.d/towncrier_template.rst
diff --git a/README.rst b/README.rst
index 077de68..84d6aa7 100644
--- a/README.rst
+++ b/README.rst
@@ -1,9 +1,9 @@
.. image:: http://www.attrs.org/en/latest/_static/attrs_logo.png
:alt: attrs Logo
-==================================
-attrs: Classes Without Boilerplate
-==================================
+======================================
+``attrs``: Classes Without Boilerplate
+======================================
.. image:: https://readthedocs.org/projects/attrs/badge/?version=stable
:target: http://www.attrs.org/en/stable/?badge=stable
@@ -32,6 +32,7 @@ For that, it gives you a class decorator and a way to declaratively define the a
.. code-block:: pycon
>>> import attr
+
>>> @attr.s
... class SomeClass(object):
... a_number = attr.ib(default=42)
@@ -39,19 +40,25 @@ For that, it gives you a class decorator and a way to declaratively define the a
...
... def hard_math(self, another_number):
... return self.a_number + sum(self.list_of_numbers) * another_number
+
+
>>> sc = SomeClass(1, [1, 2, 3])
>>> sc
SomeClass(a_number=1, list_of_numbers=[1, 2, 3])
+
>>> sc.hard_math(3)
19
>>> sc == SomeClass(1, [1, 2, 3])
True
>>> sc != SomeClass(2, [3, 2, 1])
True
+
>>> attr.asdict(sc)
{'a_number': 1, 'list_of_numbers': [1, 2, 3]}
+
>>> SomeClass()
SomeClass(a_number=42, list_of_numbers=[])
+
>>> C = attr.make_class("C", ["a", "b"])
>>> C("foo", "bar")
C(a='foo', b='bar')
@@ -67,7 +74,7 @@ After *declaring* your attributes ``attrs`` gives you:
*without* writing dull boilerplate code again and again and *without* runtime performance penalties.
-This gives you the power to use actual classes with actual types in your code instead of confusing ``tuple``\ s or confusingly behaving ``namedtuple``\ s.
+This gives you the power to use actual classes with actual types in your code instead of confusing ``tuple``\ s or `confusingly behaving <http://www.attrs.org/en/stable/why.html#namedtuples>`_ ``namedtuple``\ s.
Which in turn encourages you to write *small classes* that do `one thing well <https://www.destroyallsoftware.com/talks/boundaries>`_.
Never again violate the `single responsibility principle <https://en.wikipedia.org/wiki/Single_responsibility_principle>`_ just because implementing ``__init__`` et al is a painful drag.
@@ -77,31 +84,39 @@ Never again violate the `single responsibility principle <https://en.wikipedia.o
Testimonials
============
- *I’m looking forward to is being able to program in Python-with-attrs everywhere.
- It exerts a subtle, but positive, design influence in all the codebases I’ve see it used in.*
+**Amber Hawkie Brown**, Twisted Release Manager and Computer Owl:
- -- **Glyph Lefkowitz**, creator of `Twisted <https://twistedmatrix.com/>`_, `Automat <https://pypi.python.org/pypi/Automat>`_, and other open source software, in `The One Python Library Everyone Needs <https://glyph.twistedmatrix.com/2016/08/attrs.html>`_
+ Writing a fully-functional class using attrs takes me less time than writing this testimonial.
- *I'm increasingly digging your attr.ocity. Good job!*
+**Glyph Lefkowitz**, creator of `Twisted <https://twistedmatrix.com/>`_, `Automat <https://pypi.python.org/pypi/Automat>`_, and other open source software, in `The One Python Library Everyone Needs <https://glyph.twistedmatrix.com/2016/08/attrs.html>`_:
- -- **Łukasz Langa**, prolific CPython core developer and Production Engineer at Facebook
+ I’m looking forward to is being able to program in Python-with-attrs everywhere.
+ It exerts a subtle, but positive, design influence in all the codebases I’ve see it used in.
- *Writing a fully-functional class using attrs takes me less time than writing this testimonial.*
+**Kenneth Reitz**, author of `requests <http://www.python-requests.org/>`_, Python Overlord at Heroku, `on paper no less <https://twitter.com/hynek/status/866817877650751488>`_:
- -- **Amber Hawkie Brown**, Twisted Release Manager and Computer Owl
+ attrs—classes for humans. I like it.
- *attrs—classes for humans. I like it.*
+**Łukasz Langa**, prolific CPython core developer and Production Engineer at Facebook:
- -- **Kenneth Reitz**, author of `requests <http://www.python-requests.org/>`_, Python Overlord at Heroku, `on paper no less <https://twitter.com/hynek/status/866817877650751488>`_
+ I'm increasingly digging your attr.ocity. Good job!
.. -end-
.. -project-information-
+Getting Help
+============
+
+Please use the ``python-attrs`` tag on `StackOverflow <https://stackoverflow.com/questions/tagged/python-attrs>`_ to get help.
+
+Answering questions of your fellow developers is also great way to help the project!
+
+
Project Information
===================
diff --git a/changelog.d/.gitignore b/changelog.d/.gitignore
new file mode 100644
index 0000000..e69de29
diff --git a/changelog.d/261.change.rst b/changelog.d/261.change.rst
new file mode 100644
index 0000000..6867f66
--- /dev/null
+++ b/changelog.d/261.change.rst
@@ -0,0 +1,4 @@
+Generated ``__hash__`` methods now hash the class type along with the attribute values.
+Until now the hashes of two classes with the same values were identical which was a bug.
+
+The generated method is also *much* faster now.
diff --git a/changelog.d/280.change.rst b/changelog.d/280.change.rst
new file mode 100644
index 0000000..edd21e9
--- /dev/null
+++ b/changelog.d/280.change.rst
@@ -0,0 +1,2 @@
+``attr.ib``\ ’s ``metadata`` argument now defaults to a unique empty ``dict`` instance instead of sharing a common empty ``dict`` for all.
+The singleton empty ``dict`` is still enforced.
diff --git a/changelog.d/284.change.rst b/changelog.d/284.change.rst
new file mode 100644
index 0000000..266599d
--- /dev/null
+++ b/changelog.d/284.change.rst
@@ -0,0 +1,2 @@
+``ctypes`` is optional now however if it's missing, a bare ``super()`` will not work in slots classes.
+This should only happen in special environments like Google App Engine.
diff --git a/changelog.d/285.change.rst b/changelog.d/285.change.rst
new file mode 100644
index 0000000..c3fbb79
--- /dev/null
+++ b/changelog.d/285.change.rst
@@ -0,0 +1,2 @@
+The attribute redefinition feature introduced in 17.3.0 now takes into account if an attribute is redefined via multiple inheritance.
+In that case, the definition that is closer to the base of the class hierarchy wins.
diff --git a/changelog.d/286.change.rst b/changelog.d/286.change.rst
new file mode 100644
index 0000000..266599d
--- /dev/null
+++ b/changelog.d/286.change.rst
@@ -0,0 +1,2 @@
+``ctypes`` is optional now however if it's missing, a bare ``super()`` will not work in slots classes.
+This should only happen in special environments like Google App Engine.
diff --git a/changelog.d/287.change.rst b/changelog.d/287.change.rst
new file mode 100644
index 0000000..c3fbb79
--- /dev/null
+++ b/changelog.d/287.change.rst
@@ -0,0 +1,2 @@
+The attribute redefinition feature introduced in 17.3.0 now takes into account if an attribute is redefined via multiple inheritance.
+In that case, the definition that is closer to the base of the class hierarchy wins.
diff --git a/changelog.d/291.change.rst b/changelog.d/291.change.rst
new file mode 100644
index 0000000..0d5438f
--- /dev/null
+++ b/changelog.d/291.change.rst
@@ -0,0 +1 @@
+Subclasses of ``auto_attribs=True`` can be empty now.
diff --git a/changelog.d/292.change.rst b/changelog.d/292.change.rst
new file mode 100644
index 0000000..0d5438f
--- /dev/null
+++ b/changelog.d/292.change.rst
@@ -0,0 +1 @@
+Subclasses of ``auto_attribs=True`` can be empty now.
diff --git a/changelog.d/295.change.rst b/changelog.d/295.change.rst
new file mode 100644
index 0000000..6867f66
--- /dev/null
+++ b/changelog.d/295.change.rst
@@ -0,0 +1,4 @@
+Generated ``__hash__`` methods now hash the class type along with the attribute values.
+Until now the hashes of two classes with the same values were identical which was a bug.
+
+The generated method is also *much* faster now.
diff --git a/changelog.d/296.change.rst b/changelog.d/296.change.rst
new file mode 100644
index 0000000..6867f66
--- /dev/null
+++ b/changelog.d/296.change.rst
@@ -0,0 +1,4 @@
+Generated ``__hash__`` methods now hash the class type along with the attribute values.
+Until now the hashes of two classes with the same values were identical which was a bug.
+
+The generated method is also *much* faster now.
diff --git a/changelog.d/298.breaking.rst b/changelog.d/298.breaking.rst
new file mode 100644
index 0000000..6015bc8
--- /dev/null
+++ b/changelog.d/298.breaking.rst
@@ -0,0 +1,7 @@
+The traversal of MROs when using multiple inheritance was backward:
+If you defined a class ``C`` that subclasses ``A`` and ``B`` like ``C(A, B)``, ``attrs`` would have collected the attributes from ``B`` *before* those of ``A``.
+
+This is now fixed and means that in classes that employ multiple inheritance, the output of ``__repr__`` and the order of positional arguments in ``__init__`` changes.
+Due to the nature of this bug, a proper deprecation cycle was unfortunately impossible.
+
+Generally speaking, it's advisable to prefer ``kwargs``-based initialization anyways – *especially* if you employ multiple inheritance and diamond-shaped hierarchies.
diff --git a/changelog.d/299.breaking.rst b/changelog.d/299.breaking.rst
new file mode 100644
index 0000000..6015bc8
--- /dev/null
+++ b/changelog.d/299.breaking.rst
@@ -0,0 +1,7 @@
+The traversal of MROs when using multiple inheritance was backward:
+If you defined a class ``C`` that subclasses ``A`` and ``B`` like ``C(A, B)``, ``attrs`` would have collected the attributes from ``B`` *before* those of ``A``.
+
+This is now fixed and means that in classes that employ multiple inheritance, the output of ``__repr__`` and the order of positional arguments in ``__init__`` changes.
+Due to the nature of this bug, a proper deprecation cycle was unfortunately impossible.
+
+Generally speaking, it's advisable to prefer ``kwargs``-based initialization anyways – *especially* if you employ multiple inheritance and diamond-shaped hierarchies.
diff --git a/changelog.d/304.breaking.rst b/changelog.d/304.breaking.rst
new file mode 100644
index 0000000..6015bc8
--- /dev/null
+++ b/changelog.d/304.breaking.rst
@@ -0,0 +1,7 @@
+The traversal of MROs when using multiple inheritance was backward:
+If you defined a class ``C`` that subclasses ``A`` and ``B`` like ``C(A, B)``, ``attrs`` would have collected the attributes from ``B`` *before* those of ``A``.
+
+This is now fixed and means that in classes that employ multiple inheritance, the output of ``__repr__`` and the order of positional arguments in ``__init__`` changes.
+Due to the nature of this bug, a proper deprecation cycle was unfortunately impossible.
+
+Generally speaking, it's advisable to prefer ``kwargs``-based initialization anyways – *especially* if you employ multiple inheritance and diamond-shaped hierarchies.
diff --git a/changelog.d/306.change.rst b/changelog.d/306.change.rst
new file mode 100644
index 0000000..ef2e75e
--- /dev/null
+++ b/changelog.d/306.change.rst
@@ -0,0 +1 @@
+Equality tests are *much* faster now.
diff --git a/changelog.d/307.deprecation.rst b/changelog.d/307.deprecation.rst
new file mode 100644
index 0000000..df3842a
--- /dev/null
+++ b/changelog.d/307.deprecation.rst
@@ -0,0 +1,5 @@
+The ``attr.ib(convert=callable)`` option is now deprecated in favor of ``attr.ib(converter=callable)``.
+
+This is done to achieve consistency with other noun-based arguments like *validator*.
+
+*convert* will keep working until at least January 2019 while raising a ``DeprecationWarning``.
diff --git a/changelog.d/308.breaking.rst b/changelog.d/308.breaking.rst
new file mode 100644
index 0000000..7c06f5a
--- /dev/null
+++ b/changelog.d/308.breaking.rst
@@ -0,0 +1,20 @@
+The ``__repr__`` set by ``attrs``
+no longer produces an ``AttributeError``
+when the instance is missing some of the specified attributes
+(either through deleting
+or after using ``init=False`` on some attributes).
+
+This can break code
+that relied on ``repr(attr_cls_instance)`` raising ``AttributeError``
+to check if any attr-specified members were unset.
+
+If you were using this,
+you can implement a custom method for checking this::
+
+ def has_unset_members(self):
+ for field in attr.fields(type(self)):
+ try:
+ getattr(self, field.name)
+ except AttributeError:
+ return True
+ return False
diff --git a/changelog.d/309.change.rst b/changelog.d/309.change.rst
new file mode 100644
index 0000000..6a8e4fc
--- /dev/null
+++ b/changelog.d/309.change.rst
@@ -0,0 +1 @@
+All generated methods now have correct ``__module__``, ``__name__``, and (on Python 3) ``__qualname__`` attributes.
diff --git a/changelog.d/towncrier_template.rst b/changelog.d/towncrier_template.rst
new file mode 100644
index 0000000..29ca74c
--- /dev/null
+++ b/changelog.d/towncrier_template.rst
@@ -0,0 +1,35 @@
+{% for section, _ in sections.items() %}
+{% set underline = underlines[0] %}{% if section %}{{section}}
+{{ underline * section|length }}{% set underline = underlines[1] %}
+
+{% endif %}
+
+{% if sections[section] %}
+{% for category, val in definitions.items() if category in sections[section]%}
+{{ definitions[category]['name'] }}
+{{ underline * definitions[category]['name']|length }}
+
+{% if definitions[category]['showcontent'] %}
+{% for text, values in sections[section][category].items() %}
+- {{ text }}
+ {{ values|join(',\n ') }}
+{% endfor %}
+
+{% else %}
+- {{ sections[section][category]['']|join(', ') }}
+
+{% endif %}
+{% if sections[section][category]|length == 0 %}
+No significant changes.
+
+{% else %}
+{% endif %}
+
+{% endfor %}
+{% else %}
+No significant changes.
+
+
+{% endif %}
+{% endfor %}
+----
diff --git a/conftest.py b/conftest.py
index be9968c..ed4d652 100644
--- a/conftest.py
+++ b/conftest.py
@@ -1,5 +1,7 @@
from __future__ import absolute_import, division, print_function
+import sys
+
import pytest
@@ -8,11 +10,19 @@ def C():
"""
Return a simple but fully featured attrs class with an x and a y attribute.
"""
- from attr import attributes, attr
+ import attr
- @attributes
+ @attr.s
class C(object):
- x = attr()
- y = attr()
+ x = attr.ib()
+ y = attr.ib()
return C
+
+
+collect_ignore = []
+if sys.version_info[:2] < (3, 6):
+ collect_ignore.extend([
+ "tests/test_annotations.py",
+ "tests/test_init_subclass.py",
+ ])
diff --git a/dev-requirements.txt b/dev-requirements.txt
deleted file mode 100644
index ce39a48..0000000
--- a/dev-requirements.txt
+++ /dev/null
@@ -1,6 +0,0 @@
-coverage
-pytest
-zope.interface
-pympler
-hypothesis
-six
diff --git a/docs-requirements.txt b/docs-requirements.txt
deleted file mode 100644
index c473e1e..0000000
--- a/docs-requirements.txt
+++ /dev/null
@@ -1,3 +0,0 @@
--e .
-sphinx
-zope.interface
diff --git a/docs/_static/attrs_logo.svg b/docs/_static/attrs_logo.svg
new file mode 100644
index 0000000..1bb3e4b
--- /dev/null
+++ b/docs/_static/attrs_logo.svg
@@ -0,0 +1 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg width="100%" height="100%" viewBox="0 0 142 118" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:1.41421;"><rect id="ArtBoard1" x="0" y="0" width="141.578" height="117.638" style="fill:no [...]
\ No newline at end of file
diff --git a/docs/api.rst b/docs/api.rst
index edbe891..120b295 100644
--- a/docs/api.rst
+++ b/docs/api.rst
@@ -1,7 +1,7 @@
.. _api:
-API
-===
+API Reference
+=============
.. currentmodule:: attr
@@ -89,8 +89,8 @@ Core
>>> @attr.s
... class C(object):
... x = attr.ib()
- >>> C.x
- Attribute(name='x', default=NOTHING, validator=None, repr=True, cmp=True, hash=None, init=True, convert=None, metadata=mappingproxy({}))
+ >>> attr.fields(C).x
+ Attribute(name='x', default=NOTHING, validator=None, repr=True, cmp=True, hash=None, init=True, metadata=mappingproxy({}), type=None, converter=None)
.. autofunction:: attr.make_class
@@ -133,6 +133,63 @@ Core
.. autoexception:: attr.exceptions.AttrsAttributeNotFoundError
.. autoexception:: attr.exceptions.NotAnAttrsClassError
.. autoexception:: attr.exceptions.DefaultAlreadySetError
+.. autoexception:: attr.exceptions.UnannotatedAttributeError
+
+ For example::
+
+ @attr.s(auto_attribs=True)
+ class C:
+ x: int
+ y = attr.ib()
+
+
+Influencing Initialization
+++++++++++++++++++++++++++
+
+Generally speaking, it's best to keep logic out of your ``__init__``.
+The moment you need a finer control over how your class is instantiated, it's usually best to use a classmethod factory or to apply the `builder pattern <https://en.wikipedia.org/wiki/Builder_pattern>`_.
+
+However, sometimes you need to do that one quick thing after your class is initialized.
+And for that ``attrs`` offers the ``__attrs_post_init__`` hook that is automatically detected and run after ``attrs`` is done initializing your instance:
+
+.. doctest::
+
+ >>> @attr.s
+ ... class C(object):
+ ... x = attr.ib()
+ ... y = attr.ib(init=False)
+ ... def __attrs_post_init__(self):
+ ... self.y = self.x + 1
+ >>> C(1)
+ C(x=1, y=2)
+
+Please note that you can't directly set attributes on frozen classes:
+
+.. doctest::
+
+ >>> @attr.s(frozen=True)
+ ... class FrozenBroken(object):
+ ... x = attr.ib()
+ ... y = attr.ib(init=False)
... 4678 lines suppressed ...
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-attrs.git
More information about the Python-modules-commits
mailing list