@@ -34,15 +34,15 @@ class HttpMethod(StrEnum):
3434
3535assert HttpMethod.GET == " GET"
3636
37- # # You can use StrEnum values just like strings:
37+ # You can use StrEnum values just like strings:
3838
3939import urllib.request
4040
4141req = urllib.request.Request(' https://www.python.org/' , method = HttpMethod.HEAD )
4242with urllib.request.urlopen(req) as response:
43- html = response.read()
43+ html = response.read()
4444
45- assert len (html) == 0 # HEAD requests do not (usually) include a body
45+ assert len (html) == 0 # HEAD requests do not (usually) include a body
4646```
4747
4848There are classes whose ` auto() ` value folds each member name to upper or lower
@@ -52,20 +52,24 @@ case:
5252from enum import auto
5353from strenum import LowercaseStrEnum, UppercaseStrEnum
5454
55+
5556class Tag (LowercaseStrEnum ):
5657 Head = auto()
5758 Body = auto()
5859 Div = auto()
5960
61+
6062assert Tag.Head == " head"
6163assert Tag.Body == " body"
6264assert Tag.Div == " div"
6365
66+
6467class HttpMethod (UppercaseStrEnum ):
6568 Get = auto()
6669 Head = auto()
6770 Post = auto()
6871
72+
6973assert HttpMethod.Get == " GET"
7074assert HttpMethod.Head == " HEAD"
7175assert HttpMethod.Post == " POST"
@@ -80,6 +84,7 @@ from strenum import CamelCaseStrEnum, PascalCaseStrEnum
8084from strenum import KebabCaseStrEnum, SnakeCaseStrEnum
8185from strenum import MacroCaseStrEnum
8286
87+
8388class CamelTestEnum (CamelCaseStrEnum ):
8489 OneTwoThree = auto()
8590
@@ -95,24 +100,28 @@ class KebabTestEnum(KebabCaseStrEnum):
95100class SnakeTestEnum (SnakeCaseStrEnum ):
96101 OneTwoThree = auto()
97102
98- class SnakeTestEnum (MacroCaseStrEnum ):
103+
104+ class MacroTestEnum (MacroCaseStrEnum ):
99105 OneTwoThree = auto()
100106
107+
101108assert CamelTestEnum.OneTwoThree == " oneTwoThree"
102109assert PascalTestEnum.OneTwoThree == " OneTwoThree"
103110assert KebabTestEnum.OneTwoThree == " one-two-three"
104111assert SnakeTestEnum.OneTwoThree == " one_two_three"
105- assert MacroCaseStrEnum .OneTwoThree == " ONE_TWO_THREE"
112+ assert MacroTestEnum .OneTwoThree == " ONE_TWO_THREE"
106113```
107114
108115As with any Enum you can, of course, manually assign values.
109116
110117``` python
111118from strenum import StrEnum
112119
120+
113121class Shape (StrEnum ):
114122 CIRCLE = " Circle"
115123
124+
116125assert Shape.CIRCLE == " Circle"
117126```
118127
@@ -122,12 +131,12 @@ values--whatever you assign is the value they end up with.
122131``` python
123132from strenum import KebabCaseStrEnum
124133
134+
125135class Shape (KebabCaseStrEnum ):
126136 CIRCLE = " Circle"
127137
128- # This will raise an AssertionError because the value wasn't converted to
129- # kebab-case.
130138
139+ # This will raise an AssertionError because the value wasn't converted to kebab-case.
131140assert Shape.CIRCLE == " circle"
132141```
133142
0 commit comments