fix: correct FeatureUsageFlag to use IntFlag and return str from __str__#1036
Open
proazr wants to merge 1 commit intomicrosoftgraph:mainfrom
Open
fix: correct FeatureUsageFlag to use IntFlag and return str from __str__#1036proazr wants to merge 1 commit intomicrosoftgraph:mainfrom
proazr wants to merge 1 commit intomicrosoftgraph:mainfrom
Conversation
The FeatureUsageFlag enum has two issues: 1. The __str__ method returns self.value (an int) instead of a string, violating Python's data model requirement that __str__ must return str. This causes TypeError on all Python versions when calling str() on enum members. 2. The class inherits from (int, Enum) instead of IntFlag, even though the values are clearly bit flags (powers of 2). This prevents proper bitwise operations - combining flags with | returns plain int instead of FeatureUsageFlag. Changes Made: - Changed FeatureUsageFlag base class from (int, Enum) to IntFlag - Fixed __str__ to return str(self.value) instead of self.value - Added test suite for all enum classes
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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__