-
Notifications
You must be signed in to change notification settings - Fork 154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
_decode_dataclass ignores InitVars because of use of fields #472
Comments
Seems to be a duplicate of #281 |
Oh! seems I missed it @classmethod
def _get_initvar_names(cls) -> list[str]:
annotations = cls.__annotations__.copy()
for base in cls.__bases__:
if hasattr(base, "__annotations__"):
annotations.update(base.__annotations__)
return [name for name, typ in annotations.items() if isinstance(typ, dataclasses.InitVar)] On another note, I saw that the issue remains open from 2021, are there currently any intentions to resolve it? |
Hi @NiroHaim, this repo has been without much activity for a long time, so issues have been piling up. A few new maintainers have been added (including myself), so we will try to reduce the backlog as much as possible. This includes looking into the issue described here. I cannot guarantee when, but we will definitely have a look when time allows. |
When I am looking at the documentation for @NiroHaim What are you expectations to handling this discrepancy? Looping in contributors of the original issue @AbdulRahmanAlHamali and @ALiangLiang. Feel free to contribute to the discussion. |
Hey @matt035343 , Thanks for the response **Do note that adding the option for passing initvars to |
Description
My usecase requires me to work with initvars and override the to_dict method slightly.
Each time I convert my obj to dict, I need to replace a protected attr with its initvar.
The problem is that when I try to create an obj from said dict, I fail because the initvar attr that exists in the class is filtered out.
The initvar is filtered out because in the
_decode_dataclass
function, to create theinit_kwargs
dict, thefields
function is used, which ignores initvars.Code snippet that reproduces the issue
Describe the results you expected
as to_dict is overridable and a_init is an passable attr for A.init, I expect a_init to be included in
init_kwargs
in_decode_dataclass
when creating the obj.Python version you are using
python 3.10
Environment description
dataclasses-json==0.5.14
marshmallow==3.20.1
mypy-extensions==1.0.0
packaging==23.1
typing-inspect==0.9.0
typing_extensions==4.7.1
The text was updated successfully, but these errors were encountered: