Open hugoake opened 1 month ago
I learned that it is the Pylance extension that gives rise to this info box.
There seemed to be two reasons for this not working.
@dataclass_transform()
from the typing package. This somehow tells Python/Pylance(?) that this worksI have implemented these changes in a fork: https://github.com/hugoake/dataclassy. I would open a pull request but I am not certain how the @dataclass_tranform()
decorator will affect other things, and which arguments to pass to it (for example field_specifier
).
I'm currently trying to build an own dataclass-like framework and took a look at dataclass_transform()
, too.
Unfortunately it seems extremely inflexible. I think it won't work well with anything except dataclasses
itself, or something that effectively duplicates its semantics.
In particular, this does not provide a way to support custom field ordering. AFAICS, all semantics and parameter names are hardcoded, except defaults and field specifiers.
IDEs should really come up with better mechanisms to deal with such transforms, like a generic plugin API to tell analyzers where to look. On the other hand, I suppose that's harder than it sounds... Nevertheless, it's sad to see how key features, such as more flexible placement of parent fields, are being rejected by certain class creator projects, merely because there isn't currently a way to teach this to IDEs.
like a generic plugin API to tell analyzers where to look
See also https://github.com/microsoft/pyright/issues/607 and https://github.com/davidhalter/jedi/issues/1787 (both rejected, unfortunately :/)
Interestingly, MyPy does have a plugin mechanism, but it is only a type checker, and not a language server.
In VSCode,
dataclass
fromdataclasses
allows me to see the attributes of my dataclass when creating an object. For example, if I have a dataclass calledMyClass
and I write somewhereMyClass(
I would get a small box/widget next to my cursor specifying all the attributes and their types. This is extremely useful when I don't remember exactly the names of the attributes.