i'm looking at <https://github.com/pantsbuild/pant...
# development
a
i'm looking at https://github.com/pantsbuild/pants/issues/7074 right now / today and i think dataclasses actually might solve some of the things we've been wanting from
datatype
, specifically things like factory methods to coerce individual arguments: https://docs.python.org/3/library/dataclasses.html#dataclasses.field.
h
That’d be great! See https://github.com/pantsbuild/pants/pull/8180 for installing the py36 backport 🙂
a
yes!
and i think it will work with mypy with a hack
h
And allow us to ergonomically express complex types like
Union[str, List[str]]
. The
typing
library is really nice
a
it really is!!
...i might have made...a lot of progress...we'll see...
💯 1
i have something that i think people will really like
writing the PR description now
h
Woot! Excited to review it
a
i tried to allow using `@dataclass`es as `datatype()`s and i think it works, we also get static mypy type checking! https://github.com/pantsbuild/pants/pull/8181
❤️ 1
💪 1
thinking of deprecating
datatype()
as well, actually
h
If we could make the engine work without datatype(), I’d be a big proponent of that. It’s a really impressive and clever abstraction, but if we could replace it with a free abstraction from the standard library that other tools like MyPy understand and first time contributors are more familiar with, that would be great!
a
that's exactly i think what this PR is doing
it's not clear we need an object wrapper at all when mypy and dataclasses do exactly the type checking and efficient tuple construction we're looking for, much more efficiently
i like the idea of
@dataclasstype
in this PR because it means that we can expect python code for pants rules to work regardless of any breaking changes in
@dataclass
in future python versions, for example -- rule writers can make sure to instead just write against the stable (or at least, pants-controlled)
DatatypeMixin
API. this allows us to swap out the backend again later (e.g. for something that generates rust struct/enum definitions for all datatypes!!!)!!!
(interested in thoughts on that)
just pushed a change to the engine readme for the above PR which i think should make everything somewhat more clear
❤️ 1