I'm new with attrs module & I've encountered something that I didn't understand very well.
For simplicity I have this code below:
import attr
from typing import List
@attr.define
class A:
a: str = attr.ib(init=False, default='hi')
b: str = attr.ib(init=False, default='bye')
ab: List[str] = attr.ib(init=False, default=[a, b])
def main() -> None:
a = A()
print(a.a)
print(a.b)
print(a.ab)
if __name__ == '__main__':
main()
But while I expected to get the output:
hi
bye
["hi", "bye"]
As a beginner, The output I get is a bit strange to me:
hi
bye
[_CountingAttr(counter=18, _default='hi', repr=True, eq=True, order=True, hash=None, init=False, on_setattr=None, metadata={}), _CountingAttr(counter=19, _default='bye', repr=True, eq=True, order=True, hash=None, init=False, on_setattr=None, metadata={})]
I'll appreciate any explanation to understand the reason & how I can handle it.
aandbare literallyattr.ibplaceholders, not their defaults. So[a, b]is a list of the placeholders;attrsdoesn't know that you expect it to peek arbitrarily deep into the default and pick out placeholders there.