Using enum for clear API
See original GitHub issueThis proposal was originally borned in our discussion here.
Proposal (by @sobolevn):
“Maybe we could use enums more often? It really covers this case easily. And it is possible to statically check your code with enum.”
Here’s the sample code:
from enum import Enum
class PortRange(Enum):
DEFAULT = (1, 65535)
WELL_KNOWN = (1, 1023)
EPHEMERAL = (49152, 65535)
REGISTERED = (1024, 49151)
And then:
def port(self, range_: PortRange = PortRange.DEFAULT) -> int:
So, we want to discuss with community what is better? Let’s discuss.
If you like this idea, add 👍, otherwise 👎.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:8 (5 by maintainers)
Top Results From Across the Web
Enums & APIs - DEV Community
Enums are a double-edged sword. They are extremely useful to create a set of possible values, but they can be a versioning problem...
Read more >How Experienced Developers Use Enums in APIs
Let's say you remove the enum from the API response. You'll break the principle of taking nothing away and redefining things. · Let's...
Read more >How to expose an enum to public API without ... - Stack Overflow
The original problem comes from I want to use Enums and Enums cannot extend your own class. With class hierarchy this would not...
Read more >AIP-126: Enumerations - API Improvement Proposals
APIs may expose enum objects for sets of values that are expected ... An exception to this rule is if there is a...
Read more >Naming conventions for enum values · Issue #530 - GitHub
There are no naming conventions that cover enum values. I've seen several different styles in our APIs so far: MY_VALUE; my-value; my_value.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@sobolevn It’s for returning random gender, maybe it’s good idea to rename it to
RANDOM?I like the second one. That was my original point, when I have fired an issue.
I am not sure about
RANDOMby the way. I have heard a lot of developers said that it does not belong there. Thatenumrepresent items.RANDOMis not an item.Maybe it is not to late to replace it with a function?