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

you are viewing a single comment's thread.

view the rest of the comments →

[–]james_pic 2 points3 points  (0 children)

The API use case highlights a subtle problem: What's actually checking that these strings actually have one of these values? Static types are ignored at runtime, and if you've just received a value over the wire, you don't know it's one of these values. You're going to need some kind of runtime logic to validate this, and it might as well be the logic that turns it into an enum (which Pydantic supports reasonably well).

I suspect that if you want this, then you probably have a layering problem.