Skip to content
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

Alias option won't work with slots enabled #68

Closed
amirotin opened this issue Jan 31, 2022 · 3 comments
Closed

Alias option won't work with slots enabled #68

amirotin opened this issue Jan 31, 2022 · 3 comments
Labels
bug Something isn't working

Comments

@amirotin
Copy link

Hi!
Just noticed that if i enable slots (to reduce memory usage) alias option doesn't work

@dataclass(slots=True)
class DataClass(DataClassJSONMixin):
    a: int = field(metadata=field_options(alias="FieldA"))
    b: int = field(metadata=field_options(alias="#invalid"))

x = DataClass.from_dict({"FieldA": 1, "#invalid": 2})  # DataClass(a=1, b=2)
print(x)
x.to_dict()  # {"a": 1, "b": 2}  # no aliases on serialization by default

got error

Traceback (most recent call last):
  File "test.py", line 9, in <module>
    x = DataClass.from_dict({"FieldA": 1, "#invalid": 2})  # DataClass(a=1, b=2)
  File "<string>", line 26, in from_dict
TypeError: DataClass.__init__() missing 2 required positional arguments: 'a' and 'b'

don't know if there is some workaround, probably better to mention that in docs

@Fatal1ty
Copy link
Owner

Seems like a bug, thank you for spotting it! I'll see how it could be fixed.

@Fatal1ty Fatal1ty added the bug Something isn't working label Jan 31, 2022
@Fatal1ty
Copy link
Owner

Fatal1ty commented Feb 5, 2022

I fixed it here, so it's ready to be included in the next release.

@Fatal1ty
Copy link
Owner

Fatal1ty commented Feb 9, 2022

Hi @amirotin

It it's fixed in 3.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants