Added draft chapter to typing spec for enumerations.#1591
Added draft chapter to typing spec for enumerations.#1591erictraut wants to merge 27 commits intopython:mainfrom
Conversation
ethanfurman
left a comment
There was a problem hiding this comment.
Added some corrections and suggestions.
Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
docs/spec/enums.rst
Outdated
| consistency. That is, if the type is assigned to a variable, the name of | ||
| the variable must match the name of the enum class:: | ||
|
|
||
| WrongName = Enum('Color', 'RED GREEN BLUE') # Type checker error |
There was a problem hiding this comment.
Not sure this should be an error, commented on Discuss
…or enums declared with functional syntax.
… an attribute is a member.
|
@JelleZijlstra, did mypy 1.9 fix the issue in stubtest that was blocking us from making the necessary changes in typeshed for enums? If not, is that something that could be prioritized for mypy 1.10? |
…'t apply to enum classes that derive from `enum.Flags` because these classes support enum members with values of zero and all combinations of the defined flags.
Co-authored-by: Hashem <Hnasar@users.noreply.github.com>
…ther an attribute is an enum member. Attributes with private (mangled) names are exempt.
stroxler
left a comment
There was a problem hiding this comment.
Thanks for writing this, I've never actually known enum behavior as well as I should and learned quite a few things from reading.
| reveal_type(Color["RED"]) # Revealed type is 'Literal[Color.RED]' (or 'Color') | ||
| reveal_type(Color(3)) # Revealed type is 'Literal[Color.BLUE]' (or 'Color') | ||
|
|
||
| Unlike most Python classes, Calling an enum class does not invoke its constructor. |
There was a problem hiding this comment.
| Unlike most Python classes, Calling an enum class does not invoke its constructor. | |
| Unlike most Python classes, calling an enum class does not invoke its constructor. |
carljm
left a comment
There was a problem hiding this comment.
Looks good to me, thanks for writing this.
This is the same set of changes as PR python#1591. The CI script that enforces CLA signing was confused, so it didn't permit merging the original PR.
|
I'm not sure how to fix the CLA Signing issue with this PR, so I'm going to close it and submit a fresh PR. See #1759. |
This is the same set of changes as PR #1591. The CI script that enforces CLA signing was confused, so it didn't permit merging the original PR.
No description provided.