Skip to content

Couldn't use numpy arrays as defaults on attrs 19.2 #585

@igortg

Description

@igortg

The following code stops working when upgrading from attrs 19.1 to 19.2:

@attr.s(auto_attribs=True)
class NumParams:
    N = 3
    alpha = np.zeros((N, Ng))

Seems that change #556 requires that default attributes should implement __eq__, which is not the case for numpy arrays.

Taceback is:

    @attr.s(auto_attribs=True)
../../../../miniconda/envs/attests/lib/python3.6/site-packages/attr/_make.py:1010: in wrap
    return builder.build_class()
../../../../miniconda/envs/attests/lib/python3.6/site-packages/attr/_make.py:498: in build_class
    return self._patch_original_class()
../../../../miniconda/envs/attests/lib/python3.6/site-packages/attr/_make.py:512: in _patch_original_class
    and getattr(cls, name, _sentinel) != _sentinel
E   ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions