dataclasses-json icon indicating copy to clipboard operation
dataclasses-json copied to clipboard

[Bug]: Intellisense Not Working

Open mahyarmirrashed opened this issue 1 year ago • 4 comments

I am using dataclasses-json in my project. I am using the following sample code:

from dataclasses import dataclass
from dataclasses_json import dataclass_json


@dataclass_json
@dataclass(frozen=True)
class Minion:
  name: str


minion = Minion("very evil minion")
minion.to_json()

However, the .to_json() method is not in VSCode's intellisense. I cannot seem to understand why. Some of the fields provided by dataclass decorator are there, however. Can anybody replicate?

mahyarmirrashed avatar Feb 21 '23 23:02 mahyarmirrashed

It's written in the README that there is better support when subclassing DataClassJsonMixin over using the decorator.


from dataclasses import dataclass
from dataclasses_json import DataClassJsonMixin

@dataclass
class Person(DataClassJsonMixin):
    name: str

lidatong = Person('lidatong')

rpmcginty avatar Mar 03 '23 12:03 rpmcginty

Hey @rpmcginty I found a really nice way around this: change https://github.com/lidatong/dataclasses-json/blob/39b4c2f4462282576d72a72ade048ef49e2133bb/dataclasses_json/api.py#L127 to

def _process_class(cls, letter_case, undefined) -> Type[DataClassJsonMixin]:

When I made this change locally, pycharm immediately recognized all the methods. I imagine VSCode will benefit similarly. I'd open a PR myself but you seem to know your way around this repo :-)

PayemSaba avatar Mar 22 '23 14:03 PayemSaba

@PayemSaba , I say go for it and create a PR if you can get it working. I can help if you'd like.

mahyarmirrashed avatar Apr 28 '23 05:04 mahyarmirrashed

Reopening this issue as https://github.com/lidatong/dataclasses-json/pull/411 has been reverted and it seems we don't have a good solution right now with the current API

george-zubrienko avatar Jul 20 '23 19:07 george-zubrienko