Skip to content

Added draft chapter to typing spec for enumerations.#1591

Closed
erictraut wants to merge 27 commits intopython:mainfrom
erictraut:enum_spec
Closed

Added draft chapter to typing spec for enumerations.#1591
erictraut wants to merge 27 commits intopython:mainfrom
erictraut:enum_spec

Conversation

@erictraut
Copy link
Copy Markdown
Collaborator

No description provided.

Comment thread docs/spec/enums.rst Outdated
Comment thread docs/spec/enums.rst Outdated
Comment thread docs/spec/enums.rst Outdated
Comment thread docs/spec/enums.rst Outdated
Comment thread docs/spec/enums.rst Outdated
Comment thread docs/spec/enums.rst Outdated
Comment thread docs/spec/enums.rst
Comment thread docs/spec/enums.rst Outdated
Comment thread docs/spec/enums.rst Outdated
Comment thread docs/spec/enums.rst Outdated
Comment thread docs/spec/enums.rst
Comment thread docs/spec/enums.rst Outdated
Comment thread docs/spec/enums.rst
Comment thread docs/spec/enums.rst
Copy link
Copy Markdown
Member

@ethanfurman ethanfurman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some corrections and suggestions.

Comment thread docs/spec/enums.rst Outdated
Comment thread docs/spec/enums.rst Outdated
Comment thread 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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure this should be an error, commented on Discuss

Comment thread docs/spec/enums.rst Outdated
Comment thread docs/spec/enums.rst Outdated
Comment thread docs/spec/enums.rst
@erictraut
Copy link
Copy Markdown
Collaborator Author

@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.
Copy link
Copy Markdown

@Hnasar Hnasar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very well written, thank you!

Comment thread docs/spec/enums.rst Outdated
erictraut and others added 2 commits April 1, 2024 07:06
…ther an attribute is an enum member. Attributes with private (mangled) names are exempt.
Copy link
Copy Markdown
Contributor

@stroxler stroxler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for writing this, I've never actually known enum behavior as well as I should and learned quite a few things from reading.

Comment thread docs/spec/enums.rst Outdated
Comment thread docs/spec/enums.rst Outdated
@ghost
Copy link
Copy Markdown

ghost commented May 23, 2024

The following commit authors need to sign the Contributor License Agreement:

  • 66853113+pre-commit-ci[bot]@users.noreply.github.com

Click the button to sign:
CLA not signed

Comment thread docs/spec/enums.rst
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.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

Copy link
Copy Markdown
Member

@carljm carljm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, thanks for writing this.

Comment thread docs/spec/enums.rst
Comment thread docs/spec/enums.rst
Comment thread docs/spec/enums.rst Outdated
@erictraut erictraut marked this pull request as ready for review June 3, 2024 05:46
erictraut added a commit to erictraut/typing that referenced this pull request Jun 3, 2024
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.
@erictraut
Copy link
Copy Markdown
Collaborator Author

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.

@erictraut erictraut closed this Jun 3, 2024
erictraut added a commit that referenced this pull request Jun 3, 2024
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.
@erictraut erictraut deleted the enum_spec branch June 3, 2024 05:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.