We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
msgspec.convert
dec_hook
Hi,
I am not sure if this is really a bug it might be expected behavior depending of how different json.decode is from convert
json.decode
convert
The issue I am facing is that dec_hook is not called for a custom dict key when using convert
I refer to the tests suite that was added for this issue
from msgspec import convert, json class Custom: def __init__(self, value): self.value = value def __hash__(self): return hash(self.value) def __eq__(self, other): return self.value == other.value def __repr__(self): return f"Custom({self.value})" def dec_hook(typ, obj): if typ == Custom: return Custom(obj) raise NotImplementedError # This works as expected json.decode('{"a": true, "b": false}', type=dict[Custom, bool], dec_hook=dec_hook) # Output: {Custom(a): True, Custom(b): False} # This does not return Custom as dict keys convert(dict(a=True, b=False), dict[Custom, bool], dec_hook=dec_hook) # Output: {'a': True, 'b': False} # But works for dict values convert(dict(a=True, b=False), dict[Custom, Custom], dec_hook=dec_hook) # Output: {'a': Custom(True), 'b': Custom(False)}
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Description
Hi,
I am not sure if this is really a bug it might be expected behavior depending of how different
json.decode
is fromconvert
The issue I am facing is that
dec_hook
is not called for a custom dict key when usingconvert
I refer to the tests suite that was added for this issue
The text was updated successfully, but these errors were encountered: