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

Can't infer serializer for PurePosixPath subclass since 0.14.2 #515

Closed
davetapley opened this issue Apr 22, 2024 · 0 comments · Fixed by #519
Closed

Can't infer serializer for PurePosixPath subclass since 0.14.2 #515

davetapley opened this issue Apr 22, 2024 · 0 comments · Fixed by #519
Labels
bug Bug report or fix

Comments

@davetapley
Copy link
Contributor

Since 0.14.2 (aka #486) this:

from pathlib import PurePosixPath

from serde import to_dict

class SubPath(PurePosixPath):
    ...

if __name__ == '__main__':
    s = SubPath('a', 'b')
    to_dict(s)

Throws:

serde.compat.SerdeError: Unsupported type: SubPath

I assume that's a regression since #360 implies it should work (and it worked prior to 0.14.2).


Note deserialization still works, and can workaround with explicit casting, e.g.:

    d = to_dict(PurePosixPath(s))
    print(from_dict(Sensor, d))

It also only seems to effect PurePosixPath, not other builtins, e.g. these work as expected:

from email.message import EmailMessage

class SubStr(str):
    ...
class SubEmail(EmailMessage):
    ...

Note also changes to pathlib between Python 3.11 and 3.12 which I learned about here, but that doesn't appear to be related. I can reproduce the error on both 3.11 and 3.12.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug report or fix
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants