biqqles / dataclassy

A fast and flexible reimplementation of data classes
https://pypi.org/project/dataclassy
Mozilla Public License 2.0
81 stars 9 forks source link

Code Completion in Visual Code missing #5

Closed bertcornelissen closed 3 years ago

bertcornelissen commented 3 years ago

Hi,

Great stuff. Only one question:

Old way: from dataclasses import dataclass

@dataclass class Try: a : str b : str

p = Try()

While typing "Try(" visual code gives me: (a: str, b: str) -> None as a hint

When I am using dataclassy this is not presented.

Did I miss something or is there a simple solution.

Thanks in advance.

Bert

biqqles commented 3 years ago

Hi. Python code completion features aren't truly able to determine signatures for data classes as their methods are generated at runtime. Therefore I assume what VSCode is doing is applying a custom rule when it sees @dataclasses.dataclass on a class. The conclusion is that, annoyingly, there is no way to get similar completion from dataclassy, unless you can somehow edit those rules yourself (which is likely to be possible, albeit inconvenient).

(Incidentally, I believe PyCharm used to nicely support dataclassy because it simply applied a similar rule whenever it saw any decorator called dataclass, but at some point this changed and it now checks that that name resolves to a module named dataclasses – less hacky but less convenient for us :frowning_face:)