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

Add support for MappingProxyType #218

Merged
merged 2 commits into from
Apr 28, 2024
Merged

Add support for MappingProxyType #218

merged 2 commits into from
Apr 28, 2024

Conversation

Fatal1ty
Copy link
Owner

This adds support for types.MappingProxyType:

from types import MappingProxyType

from mashumaro.codecs import BasicDecoder, BasicEncoder


decoder = BasicDecoder(MappingProxyType[int, float])
encoder = BasicEncoder(MappingProxyType[int, float])

assert repr(decoder.decode({"42": "42"})) == "mappingproxy({42: 42.0})"
assert encoder.encode(MappingProxyType({42: 42.0})) == {42: 42.0}
from dataclasses import dataclass
from types import MappingProxyType

from mashumaro import DataClassDictMixin


@dataclass
class MyClass(DataClassDictMixin):
    x: MappingProxyType[int, float]

obj = MyClass.from_dict({"x": {"42": "42"}})
assert repr(obj) == "MyClass(x=mappingproxy({42: 42.0}))"
assert repr(obj.to_dict()) == "{'x': {42: 42.0}}"

@Fatal1ty Fatal1ty merged commit c076075 into master Apr 28, 2024
47 of 49 checks passed
@Fatal1ty Fatal1ty deleted the mappingproxy branch April 28, 2024 20:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant