8000 bpo-46242: better error message for extending `Enum` with members by sobolevn · Pull Request #30357 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-46242: better error message f 8000 or extending Enum with members #30357

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

Merged
merged 3 commits into from
Jan 14, 2022

Conversation

sobolevn
Copy link
Member
@sobolevn sobolevn commented Jan 3, 2022

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
Copy link
Member Author
sobolevn commented Jan 3, 2022

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
Copy link
Member Author
sobolevn commented Jan 8, 2022

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

@ethanfurman
Copy link
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
0