Skip to content

Commit 70327da

Browse files
Add design for int enums (#51)
Co-authored-by: Nate Prewitt <[email protected]>
1 parent e4cebbc commit 70327da

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

designs/shapes.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,30 @@ We also have to generate getters/setters to make sure they stay in sync, which
130130
dramatically increases the amount of code generated since these need to
131131
appear in every referencing structure.
132132

133+
### intEnums
134+
135+
```python```
136+
class MyIntEnum(IntEnum):
137+
SPAM = 1
138+
EGGS = 2
139+
``````
140+
141+
IntEnums will use the native `IntEnum` type. This will allow customers to
142+
easily specify the enum value without having to reference the actual number. It
143+
also gives them a programmatic way to list known values.
144+
145+
Like string enums, members targeting IntEnums will use plain integers to enable
146+
forwards compatibility and type checking. Documentation for those members will
147+
reference the generated classes for discoverability.
148+
149+
#### Alternative: target the generated enums
150+
151+
In this alternative, members targeting IntEnums would reference the generated
152+
classes. This wasn't chosen for both forwards and backwards compatibility reasons.
153+
While one can mostly use IntEnums and integers interchangeably, the types *are*
154+
different. Type checking would fail if you provided a base integer, known or
155+
unknown.
156+
133157
### streaming blobs
134158
135159
A blob with the streaming trait will continue to support `bytes` as input.

0 commit comments

Comments
 (0)