Azure / Azure/azure-sdk-for-python
Generate an `__eq__` method for case insensitive enums
- Dominant language
- Python
- Stars
- 5.6k
- Forks
- 3.4k
- Avg merge
- 1d 21h
- Merged PRs (30d)
- 193
Description
**Is your feature request related to a problem? Please describe.**
Using `==` when testing equality of strings to case-insensitive enum types like
`if my_model.change_type == StackModels.DeploymentStacksWhatIfPropertyChangeType.ARRAY:`
tests it case sensitively. Same result if the operands are flipped. See case insensitive enums in https://pypi.org/project/azure-mgmt-resource-deploymentstacks/ @ 1.0.0
**Describe the solution you'd like**
The python code generator will generate an `__eq__` method on case-insensitive enums that does a case-insensitive equality check if the other value is a `str`.
**Describe alternatives you've considered**
Have to write a helper function and remember to use it. Can manually call `lower()` on both operands but python has no `?.` operator if the value could be null. Having overridden operator will keep things simpler.
**Additional context**
It's not consistent with other SDK language code gen, such as .NET, which implements these as structs with an overridden equality method that ignores case.
Contributor guide
Assessment
This issue has not been assessed yet.