Skip to content

bpo-46242: better error message for extending Enum with members - #30357

Merged
ethanfurman merged 3 commits into
python:mainfrom
sobolevn:issue-46242
Jan 14, 2022
Merged

bpo-46242: better error message for extending Enum with members#30357
ethanfurman merged 3 commits into
python:mainfrom
sobolevn:issue-46242

Conversation

@sobolevn

@sobolevn sobolevn commented Jan 3, 2022

Copy link
Copy Markdown
Member

Three major changes:

  1. Better error message, which is more informative and is in sync with

    cpython/Lib/enum.py

    Lines 850 to 853 in 549e628

    raise TypeError(
    "%s: cannot extend enumeration %r"
    % (class_name, base.__name__)
    )
    Another idea is too call _check_for_existing_members on first_enum in _get_mixins_. But, since _get_mixins_ is @staticmethod, I've decided not to use explicit EnumType._check_for_existing_members() or not to convert it to @classmethod
  2. For some reason in _create_ wrong type was passed to _get_mixins_, instead of str, Enum was passed
  3. I've also covered this feature with a test case

https://bugs.python.org/issue46242

@sobolevn

sobolevn commented Jan 3, 2022

Copy link
Copy Markdown
Member Author

Another idea is too call _check_for_existing_members on first_enum in get_mixins. But, since get_mixins is @staticmethod, I've decided not to use explicit EnumType._check_for_existing_members() or not to convert it to @classmethod

Here's a commit with this version: 9e7d02c Just to compare. Maybe I even like it more 🤔

@sobolevn

sobolevn commented Jan 8, 2022

Copy link
Copy Markdown
Member Author

Friendly CC @ethanfurman
Maybe you have missed this one? 🙂

@ethanfurman

Copy link
Copy Markdown
Member

Thanks, good fix.

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.

4 participants