* wip: support custom repr() callable for attributes
see #567
* extend ‘repr=...’ arg type in .pyi stubs
* expand docstring for attr.ib()
* add changelog entry
* add docs with example
* improve my copy/paste skills 🙈
* fix grammar
* fix typo in changelog entry
* fix and improve attrib() docstring
* detect custom repr() once, not per call. be strict about bool.
* use rst syntax, not markdown
* apply hynek's suggestions for changelog entry
* add ‘versionchanged’ note in docstring
* add custom attribute repr= to typing example
* simplify comment
* Make unique_filename not depend on repr.
For debugging purposes, when a method is created it needs to be put
into a "filename". This filename was generated using `repr(attrs)`
however this meant that the filename could change every time the
program was loaded depending on the whims of repr. (In particular
free functions and lambdas would include ids)
This solves the problem by changing the name to be <attrs generated
{method} {module}.{qualname}> If it should happen that the name is
taken then -2 will be appended and incremented until a free filename
is found.
* Add tests
* Fix tests and changelog
* Don't cache hash codes across deserialization.
Because the hash code cache field gets serialized and deserialized by
Pickle, previously when you deserialize a cache_hash=True attrs object, the
hashcode will be the hashcode the object had at serialization-time.
However, if your object had fields with hash codes which were not
deterministic between interpreter runs, then on a new interpreter run
your deserialized object would have a hash code which differs from a
newly created identical object.
This commit fixes that by clearing the cache on deserialization. It
needs to override the __setstate__ method to do so, so this commit
also forbids using a custom __setstate__ on a cache_hash=True object.
Closes#482 .
* Improve exception type
* Minor tweaks to comments formatting
* Fix test for Python 2.7
* Fix error in comment
* Make nomenclature consistent for slotted/dict classes
* Remove hasattr()
* Improve comments and error message for custom __setstate__ + cache_hash=True
* Drop use of for test classes for cache hash serialization
* Make changelog note this is a breaking change
* Make exception message point to tracking issue
* Fix test classes for Python 2.7
* First stab at implementing hashcode caching (#423)
Currently all existing tests pass but no cache_hash tests have yet
been added.
* Existing hash tests now pass on cache_hash classes
* Add towncrier change log
* Add documentation for cache_hash
* Fixes bug with check that init=True if cache_hash=True
* Fix long lines
* Fix documentation issues
* Add test for cache_hash requiring init
* Improve test coverage
* Remove now unnecessary 'pass'
* Add periods to the end of exception strings
* Add test docstrings for cache_hash tests
* Clarify documentation of cache_hash
* Recommend that hashable classes be frozen
* Fix test references for exception messages
* Stop setting attributes on class bodies
This behavior has been deprecated since 16.1 and can now be removed in
accordance with our backward-compatibility policy.
* We don't need iterkeys anymore
Previously:
```pycon
>>> import attr
>>> @attr.s(str=True, slots=True)
... class A(object):
... a = attr.ib()
...
>>> a = A(1)
>>> str(a)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unbound method repr_() must be called with A instance as first argument (got nothing instead)
```
Fixes#198.