dataclasses-json: [BUG] #411 introduced even worse side effect than it fixed.
Description
https://github.com/lidatong/dataclasses-json/pull/411 try to fix the pylance cannot resolve to_json(), etc.
However, this breaks all auto-completion of dataclass_json decorated classes.
I think 99% use cases, we need the IDE to treat the decorated class as dataclass instead of DataClassJsonMixin.
Because we all know what kind of method it adds. Thus # type: ignore is totally acceptable.
Moreover, the to_json kind of method is used far less frequent that the dataclass __init__ and its other methods.
I think we should prioritize the IDE support from dataclass itself than the DataClassJsonMixin.
Expected type expression but received "((cls: Unknown) -> type[DataClassJsonMixin]) | type[DataClassJsonMixin]"
"(cls: Unknown) -> type[DataClassJsonMixin]" is not a class
Expected no arguments to "DataClassJsonMixin" constructor
Can we please revert that change till we found a better solution about that?
The thing is the returned class should be a sub class of both original cls and the DataClassjsonMixin, not just the ABC class.
Code snippet that reproduces the issue
from dataclasses import dataclass
from dataclasses_json import dataclass_json, DataClassJsonMixin
from typing import List
@dataclass_json
@dataclass
class Person:
x: List[int]
def test(a: Person):
pass
p = Person([1,])
Describe the results you expected
pylance should now show error and should auto-complete the Person class.
Python version you are using
Python 3.10.6
Environment description
dataclasses-json==0.5.9 marshmallow==3.19.0 marshmallow-enum==1.5.1 mypy-extensions==1.0.0 packaging==23.1 typing-inspect==0.9.0 typing_extensions==4.7.1
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 22 (4 by maintainers)
I can try when I get some free time. I’ve already have some pipeline about pyright, but I guess I need to add some unit test first.
0.5.13 with #411 reverted and one more bugfix-to-bugifx has been released. I’ll work on a new issue with broader scope and transfer some comments from the OP and others there. Feel free to reopen if you still encounter some issues with static code analysis that you didn’t have before.