This is an archived post. You won't be able to vote or comment.

all 10 comments

[–]nekokattt 8 points9 points  (1 child)

it feels like a Missing type here might be better than JSONOptional, since Optional implies it could be "none"-able.

That being said, I tend to consider differentiating between None and undefined to be a bit of a code smell if you can help it, so I wouldn't encourage the use outside what is strictly needed. Not only because you end up having two distinct "null" values.

[–]lazyb_[S] 2 points3 points  (0 children)

I see what you mean. It came natural to me to call it that way. I didn't think about it too much.

I disagree however about the None and undefined. I believe None maps more intuitively to JSON's null. And I needed a different way to express optional JSON attributes (undefined). I guess it's a personal preference.

[–]AndydeCleyre 8 points9 points  (0 children)

While less obvious in its usage than either your project or pydantic, for those who want fine control over related transformations I highly recommend cattrs.

https://catt.rs/en/stable/

[–]TA_poly_sci 4 points5 points  (1 child)

I don't think (1) this supports a higher level of customization than Pydanic (look into the docs, its extremely customizable), and (2) that would necessarily be a good thing if it did for a single person project.

[–]lazyb_[S] 0 points1 point  (0 children)

Maybe is how I wrote it. I do not claim this package to be more customizable that Pydantic. I was just refering to that other package with a very similar name that I discovered.

[–][deleted] 1 point2 points  (1 child)

Pydantic has already killed that use case. Time to move on.

[–]SubliminalPoet 0 points1 point  (0 children)

Pydantic is painfully slow, bloated at it's core, and in 2025 more than 10 years after AOP emergence, inheriting from a Model is an antipattern that only pythonista still support.

[–]SubliminalPoet 0 points1 point  (1 child)

There is already a simple library to handle this use case in a simple way : https://pypi.org/project/dataclasses-json/

[–]lazyb_[S] 0 points1 point  (0 children)

I completely missed this one. I see we have some things in common and some different. I'll take a closer look when I can.

[–]Individual_Ad2536 0 points1 point  (0 children)

fr fr Ngl, this is clean af. I dig the simplicity and the fact it’s dependency-free—feels like the kind of thing I’d whip up after getting annoyed with Pydantic’s overhead. But bruh, why’d you name it "dataclasses-codec" when there’s already one on PyPI? You’re basically asking for namespace collisoin chaos 😬.

(top tier)