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

AttributeError: can't set attribute with namedtuple #77

Closed
SamuelMarks opened this issue Nov 2, 2020 · 1 comment
Closed

AttributeError: can't set attribute with namedtuple #77

SamuelMarks opened this issue Nov 2, 2020 · 1 comment

Comments

@SamuelMarks
Copy link

SamuelMarks commented Nov 2, 2020

Been debugging this issue for a while, can't seem to resolve it, this line:

enforce/enforce/decorators.py", line 145, in universal
    result = wrapped(*_args, **_kwargs)
  File "<string>", line 6, in __init__
AttributeError: can't set attribute
from typing import NamedTuple, Any
from dataclass.dataclasses import dataclass

from enforce import runtime_validation


class C(NamedTuple):
    c: Any = None
# Also tried `C = namedtuple('C', ('c',))(None)`


@runtime_validation
@dataclass(init=True, repr=False, eq=False, order=False, unsafe_hash=True)
class A(object):
    b: Any = C.c


if __name__ == "__main__":
    A()

I even tried copying over the stdlib dataclass and modifying it to output what it's getting, and it's getting, for the value of b, this:

<_collections._tuplegetter object at 0x103778ca0>

It looks like it's caused by C.c; as C works.

Any ideas how to fix?

@habnabit
Copy link

habnabit commented Nov 2, 2020

Yes: don't assign a _collections._tuplegetter instance as a class attribute.

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

No branches or pull requests

2 participants