fix: correct FeatureUsageFlag to use IntFlag and return str from __str__ #1036
+117
−3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.



Overview
The
FeatureUsageFlagenum has two issues that cause runtime errors and prevent proper bitwise operations:__str__returns int instead of str: The__str__method returnsself.value(an int), violating Python's data model requirement that__str__must return a string. This causesTypeError: __str__ returned non-string (type int)on all Python versions when callingstr()on enum members.Incorrect base class for bit flags: The class inherits from
(int, Enum)instead ofIntFlag, even though the values are clearly bit flags (powers of 2: 0, 1, 2, 4, 8, 16). This prevents proper bitwise operations - combining flags with|returns plainintinstead ofFeatureUsageFlag.Demo
Before (broken):
After (fixed):
Notes
IntFlagis a subclass of bothintandEnum, so existingisinstance()checks continue to workFeatureUsageFlagwas affected;APIVersionandNationalCloudsalready work correctly as they inherit fromstrTesting Instructions
pytest tests/test_enums.py -v__str__returns string type for all enum classesFeatureUsageFlagis anIntFlagsubclassFeatureUsageFlag__str__