-
Notifications
You must be signed in to change notification settings - Fork 1k
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
[WIP,RFC] Convert Enums to Literals in schema #15774
Conversation
9df75dd
to
3a0aa25
Compare
I am fine with the change - because as a purely practical matter pydantic is clunky with enums - but I think a lot of the code you have in there was more readable before and the mypy does a better job with enums in some important ways so I wanted to push back on "with no practical benefit". Take for instance: Before:
After:
To me - the intent reads a little more clear with the first line. I think the mypy side of things is a bit more objective though. A lot of these lines in the diff are just comparing a variable (typed or not) against some constant string. static checking would catch if the import of
but would both catch the comparable:
(In other news, I finally installed a spell checker in my IDE over last winter break so the damage @jmchilton typos will do should be on a downward trend regardless of mypy.) Showing my work:
|
Thanks a lot @jmchilton for having a look and for the very insightful comment!
The |
*/ | ||
job_source_type?: components["schemas"]["JobSourceType"]; | ||
job_source_type?: "Job" | "ImplicitCollectionJobs" | "WorkflowInvocation"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is a big downside IMO, making reuse harder.
I think I'm still pretty strongly against this for pydantic model fields, which are not serialized in the same way. |
see galaxyproject#15774 for context
see galaxyproject#15774 for context update page =pdf export selenium test update return type to reflect matches being returned cleanup the test file run make format
see galaxyproject#15774 for context update page =pdf export selenium test update return type to reflect matches being returned cleanup the test file run make format
(str, Enum)
is redundant for type annotations, sinceLiteral
was introduced for that use case.Enum
also requires more code and is less readable, both when defining the class and when using the values (e.g.SharingOptions.make_public.value
vs"value"
), with no practical benefit, since any mistyping would be caught by mypy.Enum
also introduced tricky bugs like those fixed in a7ddf89 and #15740.How to test the changes?
(Select all options that apply)
License