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

proposal: add fields.Enum #637

Closed
dradetsky opened this issue May 31, 2017 · 2 comments
Closed

proposal: add fields.Enum #637

dradetsky opened this issue May 31, 2017 · 2 comments

Comments

@dradetsky
Copy link
Contributor

Although marshmallow is not just for sqlalchemy, I think a reasonable standard for completeness is: "It can be used to serialize the basic types of sqlalchemy." One thing that's kinda inconvenient right now is enums. My current issue is with sqlalchemy columns constructed from pep 435 enums, although it applies equally to the enums themselves.

so I propose adding a new kind* of field, Enum, which would allow some syntax like

  1. fields.Enum(int)
  2. fields.Enum(fields.String)
  3. fields.Enum(MyEnumClass)

it wouldn't really have to do much except fetch via attrname.name or attrname.value** instead of just attrname by default, and, if the enum class is available, autogenerate a OneOf validator expr. It should also appear from the outside (e.g. to consumers like apispec) to be of whatever type the actual value is (i.e. the type of the name or the type of the value, depending).

I've never made a custom field before & don't really know how it's done so it would be awesome if somebody more skilled could do this for me, but I have a feeling I'll have to submit my own PR after figuring it all out <curses under breath>

*Haskell nerds: I use the term 'kind' advisedly

**Perhaps by-name & by-value would be 2 separate kinds

@dradetsky
Copy link
Contributor Author

Accidentally did search for enum in open issues instead of issues and missed #267. Will probably close this soon.

@dradetsky
Copy link
Contributor Author

marshmallow_enum answers my purpose. it's my own fault for not noticing "Ecosystem"

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

No branches or pull requests

1 participant