attrs/tests
Alex Ford 2fdf92997c
Clarify next-gen auto_attribs inference rules (#742)
* Clarify next-gen auto_attribs inference rules

The next-gen auto_attribs api documentation does not clearly describe
cases where (a) only a subset of attributes are annotated and (b)
`field` definitions are provided for a subset of fields. Update
docstring to reflect current, desirable, behavior.

Add tests to clarify `.define` behavior focused on fully-annotated
classes with partially-defined fields, which is commonly used to add
non-default behavior to a subset of a classes fields. For example:

```python

@attr.define
class NewSchool:
    x: int
    y: list = attr.field()

    @y.validator
    def _validate_y(self, attribute, value):
        if value < 0:
            raise ValueError("y must be positive")

```

The previous docstring *could* be read to imply that:

* The new-school API will not infer auto_attribs if there are any
  unannotated attributes.
* The new-school API will not infer auto_attribs if *any* attr.ib are
  defined, even if those attr.ibs are type annotated.

* Update test to match PR example

* Fix lint error

Co-authored-by: Hynek Schlawack <hs@ox.cx>
2020-12-30 12:53:43 +01:00
..
__init__.py Move test helpers into an utils module 2016-08-15 15:27:13 +02:00
strategies.py Refactor Hypothesis strategy for self-tests (#706) 2020-10-21 07:04:12 +02:00
test_annotations.py Infer type annotations from converters (#710) 2020-12-13 16:30:06 +01:00
test_config.py Check type of set_run_validators' arg 2015-06-05 20:28:50 +02:00
test_converters.py Rename converters.chain to converters.pipe 2020-07-21 14:43:09 +02:00
test_dunders.py Make NOTHING falsey (#732) 2020-12-21 06:39:58 +01:00
test_filters.py Fade to Black (#392) 2018-06-10 19:40:07 +02:00
test_funcs.py Treat frozensets like sets in asdict/astuple (#704) 2020-10-19 10:17:25 +02:00
test_functional.py Ensure objects live long enough in hash test 2020-10-16 08:35:42 +02:00
test_hooks.py Attribute.assoc → evolve 2020-10-17 07:27:36 +02:00
test_init_subclass.py Be consistent in calling slotted classes slotted 2019-02-25 16:09:57 +01:00
test_make.py [RFC] kw_only python 2 backport (#700) 2020-10-19 11:00:00 +02:00
test_mypy.yml Move some of the mypy tests over. (#738) 2020-12-28 07:50:29 +01:00
test_next_gen.py Clarify next-gen auto_attribs inference rules (#742) 2020-12-30 12:53:43 +01:00
test_setattr.py Don't reset custom __setattr__ in slotted classes (#681) 2020-09-05 09:46:06 +02:00
test_slots.py Fixed slots inheritance (#718) 2020-12-13 17:22:34 +01:00
test_validators.py Make `zope` a semi-optional test dependency (#685) 2020-09-03 06:56:17 +02:00
test_version_info.py Rename _version.py into _version_info.py 2019-10-02 16:12:03 +02:00
typing_example.py Tighten up mypy configuration 2020-11-04 08:40:16 +01:00
utils.py Fix attribute collection (#635) 2020-04-06 11:41:52 +02:00