Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Add option to collect annotated fields #262
Since I’m sick of hearing that “PEP 557 is like attrs, but using variable annotations for field declarations”, I’d like to have an option to collect annotated fields that have no attr.ib definition.
@attr.s(collect_bare=True) class C: x: int
should be equivalent to:
@attr.s class C: x: int = attr.ib()
I’m open to better/shorter names.
Volunteers? @chadrik maybe? :)
So I gave this a lackluster shot and I’ve run into a problem:
def test_auto_attribs(self): """ If *auto_attribs* is True, bare annotations are collected too. """ @attr.s(auto_attribs=True) class C: x: typing.List[int] b = attr.ib() y: int assert "C(x=1, b=2, y=3)" == repr(C(1, 2, 3))
To me it looks like all we can do is to allow either 100% annotations or 100%
@attr.s(auto_attribs=True, check_types=True) class Point: x: float y: float
or am I missing something? (since we can’t attach any more meta data to the fields, this has to be something that happens in
This kind of smells like a
Or am I missing something?.