-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Use enums instead of manually assigning small integers #1243
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This would be a reasonable thing to refactor, though not high priority. |
I have a working branch, with 4 new Enums. By order of impact:
|
Maybe do one at a time? Do you use enum34 from PyPI or would this imply dropping Python 3.3? |
I did it only as an experiment. the Literal part is pretty trivial (and not very helpful). I'm not familiar with enum34; I can try it. |
As for Variance, I think that (I used |
I don't know if that's common knowledge, but I've found out that enum access is very very slow. I guess it won't be noticeable in this project, but that's another thing to take into account. |
I've heard bad things about enum performance. Improving mypy performance is going to be a main focus of the core team, and switching to enum carries some risk. It's not worth it, even if the risk is small. I'm not closing this issue since this may make sense in the long term, after we are happy with mypy performance. |
How about using NewType? |
NewType creates a subtype so it's less safe than an enum. I'd prefer to (eventually) switch to enums. |
There is a discussion on python-dev about improving Python start-up time and enums being slow is one of the issues discussed. There is a chance performance will be improved in Python 3.7. |
We use manually rolled enum equivalents in a number of places instead of just using the 3.4 enum module. Using real enums would make debugging a lot nicer in some cases.
The main downside to this change is that it'll add an additional dependency when running on 3.3 and below.
The text was updated successfully, but these errors were encountered: