-
Notifications
You must be signed in to change notification settings - Fork 949
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
Remplace named tuples with enums #1250
Remplace named tuples with enums #1250
Conversation
Most of the parameters for the API are `ENUM`s Replace the named tuples that are not fitted for that with enums. Each enum hold one of the choices. The actual string value must be extracted in order to pass strings only to the API using the function `extract_enum_value` using the `enum.value` field if the enum is not `None`. this forces us to filter all arguments that are passed when they can possibly be `None`. thouhgt about setting the default value for each instead but this changes the API call made to the API and that could lead to unwanted behavior for the users. closes #1222
I cannot find the comment we discussed it originally, but why not use strEnums, so that you do not have to use |
We can't use |
What about with StrEnum: https://pypi.org/project/StrEnum/ It supports Python 3.7+ |
wow awesome ! 🤩 I'll update the code to use it then it makes like so much easier (If everything goes according to plan lol) |
you already approved but as I made changes I wait for your review before merging. |
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.
Yes that's right, so much easier.
Because the RST documentation format works with indentation. The length (number of whitespaces) need to create a block, a list, a warning etc is aligned with the parent block. All of those where not aligned so I aligned them to properly render the documentation.
Thanks, and thanks to you for finding the str enum class |
Most of the parameters for the API are
ENUM
sReplace the named tuples that are not fitted for that with enums.
Each enum hold one of the choices.
The actual string value must be extracted in order to pass strings only to the API using the function
extract_enum_value
using theenum.value
field if the enum is notNone
.this forces us to filter all arguments that are passed when they can possibly be
None
.thought about setting the default value for each instead but this changes the API call made to the API and that could lead to unwanted behavior for the users.
Possible way was to add a new value to each enum:
default = None
which will result in aNone
value so it won't be part of the API call, but this requires all method to have that value as default value, and if a user (for some reason) sets one of the parameter toparam=None
then the code breaks and requires that user to change toparam=MyEnum.none
which is not user friendly. To me any function with default empty param should be eitherNone
or some default container likeparam=[]
etc.so far this is the less intrusive for users and keeps the API calls as is and use the default behavior from google.
closes #1222