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

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

Closed
igortg opened this issue Oct 14, 2019 · 3 comments · Fixed by #586
Closed

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

igortg opened this issue Oct 14, 2019 · 3 comments · Fixed by #586

Comments

@igortg
Copy link

@igortg igortg commented Oct 14, 2019

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()
@RonnyPfannschmidt
Copy link

@RonnyPfannschmidt RonnyPfannschmidt commented Oct 14, 2019

the issue can be resolved by switching the sentinel check from equality to is

@nicoddemus
Copy link
Contributor

@nicoddemus nicoddemus commented Oct 14, 2019

Yep, opening a PR right away

@hynek
Copy link
Member

@hynek hynek commented Oct 15, 2019

FYI 19.3.0 with that fix is on PyPI. Sorry for the regression and thanks to @RonnyPfannschmidt and @nicoddemus for the quick fix while I was sound asleep! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

4 participants