ericvsmith / dataclasses

Apache License 2.0
587 stars 53 forks source link

Test needed: Check items in class and instance dicts #38

Closed ericvsmith closed 7 years ago

ericvsmith commented 7 years ago

I want to make sure that the instance dict is being initialized when I think it should be.

In:

@dataclass
class C:
    a: int
    b: list = field(default_factory=list, init=False)
    c: list = field(default_factory=list)
    d: int = field(default=4, init=False)
    e: int = 0

c=C(0)

Then:

The reasoning is:

The generated __init__ looks like:

def __init__(self,a:_type_a,c:_type_c=_MISSING,e:_type_e=_dflt_e)->_return_type:
    self.a = a
    self.b = _dflt_b()
    self.c = _dflt_c() if c is _MISSING else c
    self.e = e

locals: {'_type_a': <class 'int'>, '_type_b': <class 'list'>, '_type_c': <class 'list'>, '_type_d': <class 'int'>, '_type_e': <class 'int'>, '_return_type': None}
globals: {'_MISSING': <object object at 0x10ea26100>, '_dflt_b': <class 'list'>, '_dflt_c': <class 'list'>, '_dflt_e': 0}
ericvsmith commented 7 years ago

Closed by #43.