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

collections.OrderedDict is not hashable #133

Closed
hhcs9527 opened this issue Jul 29, 2023 · 10 comments · Fixed by #134
Closed

collections.OrderedDict is not hashable #133

hhcs9527 opened this issue Jul 29, 2023 · 10 comments · Fixed by #134
Labels
bug Something isn't working

Comments

@hhcs9527
Copy link

  • mashumaro version: 3.8.1
  • Python version: 3.11 / 3.10
  • Operating System: Ubuntu 20.04

Description

  1. Try to run the following code
  2. it keeps showing TypeError: unhashable type: 'collections.OrderedDict', but the readme shows it supports this type

What I Did

import json
from enum import Enum
from typing import List, Any, Union, Generic, TypeVar, Tuple, cast, Optional, Annotated, OrderedDict, Type
import typing
import collections
from dataclasses import dataclass, field
from dataclasses_json import dataclass_json, DataClassJsonMixin
from mashumaro.mixins.json import DataClassJSONMixin
from mashumaro.types import SerializationStrategy



def kwtypes(**kwargs) -> OrderedDict[str, Type]:
    """
    This is a small helper function to convert the keyword arguments to an OrderedDict of types.

    .. code-block:: python

        kwtypes(a=int, b=str)
    """
    d = collections.OrderedDict()
    for k, v in kwargs.items():
        d[k] = v
    return d

@dataclass
class test(DataClassJSONMixin):
    b: typing.List[Annotated[int, "parquet"]]
    c: typing.Dict[str, Annotated[int, kwtypes(Name=str, Age=int)]]

Thanks for the help!

@Fatal1ty Fatal1ty added the bug Something isn't working label Jul 29, 2023
@Fatal1ty
Copy link
Owner

@hhcs9527

Thank you for opening this issue. This is definitely a bug related to how Annotated types are handled. Let me debug it and I'll fix it soon.

@Fatal1ty
Copy link
Owner

Hey @hhcs9527

I merged the fix, you can take a look.

@hhcs9527
Copy link
Author

Hi,
@Fatal1ty thanks for the quick fix.
Should I do something to get the latest version of code? I installed it from pip

@Fatal1ty
Copy link
Owner

I’m going to make a new release this week, so if you find another issue, it will most likely be fixed in it. Until then you can install mashumaro from git:

pip install git+https://github.com/Fatal1ty/mashumaro

@hhcs9527
Copy link
Author

Thanks for the explanation, so I can expect this change will be in
pip install version with 3.8.2?

Thanks.

@Fatal1ty
Copy link
Owner

@hhcs9527 it will be 3.9

@hhcs9527
Copy link
Author

Thanks for the notification!
Is there an expected release date?

@Fatal1ty
Copy link
Owner

Thanks for the notification!
Is there an expected release date?

I'm waiting for @gshank to answer on another issue but in any case it won't be later than Thursday.

@hhcs9527
Copy link
Author

Thanks for the response.

@Fatal1ty
Copy link
Owner

Fatal1ty commented Aug 2, 2023

@hhcs9527

Release 3.9 is ready! I hope you enjoy it :)

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

Successfully merging a pull request may close this issue.

2 participants