Re:Attrs – the Python library everyone needs (2016)
by ledauphin on Friday December 24, 2021 @05:44PM
(#29678488)
can you tell me which parts feel verbose? In my recent usage, I've not found myself using the older, more verbose approaches.
Re:Attrs – the Python library everyone needs (2016)
by skrtskrt on Friday December 24, 2021 @06:02PM
(#29678645)
If you use the runtime type validators along with the python builtin type hints you constantly repeat yourself:
id: UUID = attr.ib(validator=instance_of(UUID), …other parameters)
The type hint helps mypy and pylint work, while the validator is a runtime check by AttrsIf your attribute name is longer or you have other parameters to set, that can be a very long line (or lines) of code that you repeat for every attribute
Attrs just has the features I need for now. It certainly feel a touch verbose but I’m happy to pay the price.