MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/programming/comments/8ue8st/python_370_released/e1fs2th/?context=3
r/programming • u/sply • Jun 27 '18
383 comments sorted by
View all comments
Show parent comments
71
There is a backport of the data classes for 3.6 if you want to use it.
21 u/ProfessorPhi Jun 28 '18 Isn't attrs still superior? 54 u/dhiltonp Jun 28 '18 Attrs definitely has more features (slots comes to mind), but I think it looks a little wonky.(full disclosure, I haven't used attrs just read the docs)@dataclass class InventoryItem: name: str unit_price: float quantity_on_hand: int = 0vs.@attr.s class InventoryItem: name: str = attr.ib() unit_price = attr.ib(type=float) quantity_on_hand = attr.ib(type=int, default=0)Does PyCharm recognize type annotations when they're set via attr.ib(type=float)? 6 u/bluetech Jun 28 '18 The annotations-based syntax works with attrs too (you need to set auto_attribs=True).
21
Isn't attrs still superior?
54 u/dhiltonp Jun 28 '18 Attrs definitely has more features (slots comes to mind), but I think it looks a little wonky.(full disclosure, I haven't used attrs just read the docs)@dataclass class InventoryItem: name: str unit_price: float quantity_on_hand: int = 0vs.@attr.s class InventoryItem: name: str = attr.ib() unit_price = attr.ib(type=float) quantity_on_hand = attr.ib(type=int, default=0)Does PyCharm recognize type annotations when they're set via attr.ib(type=float)? 6 u/bluetech Jun 28 '18 The annotations-based syntax works with attrs too (you need to set auto_attribs=True).
54
Attrs definitely has more features (slots comes to mind), but I think it looks a little wonky.
(full disclosure, I haven't used attrs just read the docs)
@dataclass class InventoryItem: name: str unit_price: float quantity_on_hand: int = 0
vs.
@attr.s class InventoryItem: name: str = attr.ib() unit_price = attr.ib(type=float) quantity_on_hand = attr.ib(type=int, default=0)
Does PyCharm recognize type annotations when they're set via attr.ib(type=float)?
6 u/bluetech Jun 28 '18 The annotations-based syntax works with attrs too (you need to set auto_attribs=True).
6
The annotations-based syntax works with attrs too (you need to set auto_attribs=True).
auto_attribs=True
71
u/joshuaavalon Jun 28 '18
There is a backport of the data classes for 3.6 if you want to use it.