Skip to content

enum: Member names accidentally removed from "invalid enum member name(s)" message #93118

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

Closed
The-Compiler opened this issue May 23, 2022 · 1 comment
Assignees
Labels
3.11 only security fixes 3.12 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@The-Compiler
Copy link
Contributor

Bug report

In acf7403 (#30582), @ethanfurman changed the "Invalid enum member name" error message to "invalid enum member name(s)":

cpython/Lib/enum.py

Lines 482 to 484 in b2694ab

if invalid_names:
raise ValueError('invalid enum member name(s) '.format(
','.join(repr(n) for n in invalid_names)))

(This was later reverted in 42a64c0 and reintroduced in 83d544b, but I believe the code to be the same).

However, the commit also removed {0} from the format string, thus removing the invalid names from the error messages. As a result, the error message is now less descriptive:

$ python3.10 -c "import enum; enum.Enum('A', ['mro'])"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib/python3.10/enum.py", line 387, in __call__
    return cls._create_(
  File "/usr/lib/python3.10/enum.py", line 518, in _create_
    enum_class = metacls.__new__(metacls, class_name, bases, classdict)
  File "/usr/lib/python3.10/enum.py", line 208, in __new__
    raise ValueError('Invalid enum member name: {0}'.format(
ValueError: Invalid enum member name: mro
$ python3.11 -c "import enum; enum.Enum('A', ['mro'])"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib/python3.11/enum.py", line 791, in __call__
    return cls._create_(
           ^^^^^^^^^^^^^
  File "/usr/lib/python3.11/enum.py", line 966, in _create_
    return metacls.__new__(metacls, class_name, bases, classdict, boundary=boundary)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/enum.py", line 483, in __new__
    raise ValueError('invalid enum member name(s) '.format(
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: invalid enum member name(s) 

Given that the .format() is still there, I'm assuming that was an accident.

(Found by running flake8 over Lib/ out of curiosity, see #93010 (comment))

Your environment

  • CPython versions tested on: Python 3.11.0b1
  • Operating system and architecture: Archlinux x86_64
@The-Compiler The-Compiler added the type-bug An unexpected behavior, bug, or error label May 23, 2022
@AlexWaygood AlexWaygood added stdlib Python modules in the Lib dir 3.11 only security fixes 3.12 only security fixes labels May 23, 2022
ethanfurman added a commit that referenced this issue May 23, 2022
Include member names in error message.
miss-islington pushed a commit to miss-islington/cpython that referenced this issue May 23, 2022
Include member names in error message.
(cherry picked from commit a49721e)

Co-authored-by: Ethan Furman <[email protected]>
@ethanfurman
Copy link
Member

Fixed.

ethanfurman pushed a commit that referenced this issue May 23, 2022
Include member names in error message.
(cherry picked from commit a49721e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.11 only security fixes 3.12 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants