Skip to content

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

Closed
@The-Compiler

Description

@The-Compiler

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

Metadata

Metadata

Assignees

Labels

3.11only security fixes3.12only security fixesstdlibPython modules in the Lib dirtype-bugAn unexpected behavior, bug, or error

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions