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

Clarify next-gen auto_attribs inference rules #742

Merged
merged 4 commits into from Dec 30, 2020

Commits on Dec 25, 2020

  1. 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.
    asford committed Dec 25, 2020
    Configuration menu
    Copy the full SHA
    0bdeee9 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    33e60a6 View commit details
    Browse the repository at this point in the history
  3. Fix lint error

    asford committed Dec 25, 2020
    Configuration menu
    Copy the full SHA
    f6aca14 View commit details
    Browse the repository at this point in the history

Commits on Dec 30, 2020

  1. Configuration menu
    Copy the full SHA
    c1bcd40 View commit details
    Browse the repository at this point in the history