Skip to content

Commit 940b32c

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 2660a52 commit 940b32c

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

pr_body_1.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@ The `Enum` field's by-name deserialization uses `getattr(self.enum, val)` to loo
77
```python
88
from enum import Enum
99

10+
1011
class Color(Enum):
1112
RED = 1
1213
GREEN = 2
1314

15+
1416
# Current behavior - these don't raise errors:
15-
getattr(Color, "mro") # <built-in method mro>
17+
getattr(Color, "mro") # <built-in method mro>
1618
getattr(Color, "__members__") # mappingproxy({...})
17-
getattr(Color, "__class__") # <class 'EnumType'>
19+
getattr(Color, "__class__") # <class 'EnumType'>
1820
```
1921

2022
When a user submits one of these attribute names as input, the `Enum` field returns the raw attribute/method object instead of an Enum member. Downstream code expecting an Enum member would break or behave unpredictably.
@@ -25,9 +27,9 @@ Replace `getattr(self.enum, val)` with `self.enum[val]`. The `[]` operator on En
2527

2628
```python
2729
# Before
28-
getattr(Color, "mro") # returns <built-in method mro>
30+
getattr(Color, "mro") # returns <built-in method mro>
2931

30-
# After
31-
Color["mro"] # raises KeyError
32-
Color["RED"] # returns Color.RED ✓
32+
# After
33+
Color["mro"] # raises KeyError
34+
Color["RED"] # returns Color.RED ✓
3335
```

0 commit comments

Comments
 (0)