Code review comment for ~cjwatson/launchpad:ci-build-upload-make-spr

Revision history for this message
Colin Watson (cjwatson) wrote :

I find namedtuples awkwardly inflexible in general and usually regret using them; in this case, they aren't really suitable since they don't support optional arguments on construction. I get the general idea, though, so I looked for alternatives. A dataclass would be ideal, but those don't exist until Python 3.7. Type annotations on class attributes don't work in Python 3.6, not even the old comment style unless the attribute has an initializer.

However, `attrs` (https://www.attrs.org/) *does* work, and although Launchpad doesn't currently use it directly, it's already in our virtualenv as an indirect dependency. It's a pretty well-regarded package, it can be integrated with `mypy` (https://www.attrs.org/en/stable/types.html#mypy), it gives us an automatic `__init__` method and such, and it would be easy to convert from a simple use of it to a dataclass once we're on Python >= 3.7.

I've reworked this branch using that. Would you mind having another look?

« Back to merge proposal