Skip to content
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

enum.Enum.__dir__ docs do not mention enum members in return value #104235

Open
chgnrdv opened this issue May 6, 2023 · 1 comment
Open

enum.Enum.__dir__ docs do not mention enum members in return value #104235

chgnrdv opened this issue May 6, 2023 · 1 comment
Assignees
Labels
3.11 only security fixes 3.12 bugs and security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@chgnrdv
Copy link
Contributor

chgnrdv commented May 6, 2023

3.12 documentation for enum.Enum.__dir__ says that this method returns "['__class__', '__doc__', '__module__', 'name', 'value'] and any public methods defined on self.__class__", but this is not true, e.g. when using the code provided:

>>> from enum import Enum
>>> from datetime import date
>>> class Weekday(Enum):
...     MONDAY = 1
...     TUESDAY = 2
...     WEDNESDAY = 3
...     THURSDAY = 4
...     FRIDAY = 5
...     SATURDAY = 6
...     SUNDAY = 7
...     @classmethod
...     def today(cls):
...         print('today is %s' % cls(date.today().isoweekday()).name)
... 
>>> dir(Weekday.SATURDAY)
['FRIDAY', 'MONDAY', 'SATURDAY', 'SUNDAY', 'THURSDAY', 'TUESDAY', 'WEDNESDAY', '__class__', '__doc__', '__eq__', '__hash__', '__module__', 'name', 'today', 'value']

Also it seems that test_enum has bug in it, because it doesn't detect the error above if invoked through libregrtest (as ./python -m test test_enum), but direct run of test_enum or doctest on enum documentation fails:

$ ./python -m test.test_enum
...........................................................................................................................................s.s......s........................................................................................................................................................................................................................................................................................................................s...........................................s...............................................................................................F
======================================================================
FAIL: /home/chgnrdv/cpython/Lib/test/../../Doc/library/enum.rst
Doctest: enum.rst
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/chgnrdv/cpython/Lib/doctest.py", line 2228, in runTest
    raise self.failureException(self.format_failure(new.getvalue()))
AssertionError: Failed doctest test for enum.rst
  File "/home/chgnrdv/cpython/Lib/test/../../Doc/library/enum.rst", line 0

----------------------------------------------------------------------
File "/home/chgnrdv/cpython/Lib/test/../../Doc/library/enum.rst", line 297, in enum.rst
Failed example:
    dir(Weekday.SATURDAY)
Expected:
    ['__class__', '__doc__', '__eq__', '__hash__', '__module__', 'name', 'today', 'value']
Got:
    ['FRIDAY', 'MONDAY', 'SATURDAY', 'SUNDAY', 'THURSDAY', 'TUESDAY', 'WEDNESDAY', '__class__', '__doc__', '__eq__', '__hash__', '__module__', 'name', 'today', 'value']


----------------------------------------------------------------------
Ran 602 tests in 5.113s

FAILED (failures=1, skipped=5)
./python -m doctest Doc/library/enum.rst 
**********************************************************************
File "Doc/library/enum.rst", line 297, in enum.rst
Failed example:
    dir(Weekday.SATURDAY)
Expected:
    ['__class__', '__doc__', '__eq__', '__hash__', '__module__', 'name', 'today', 'value']
Got:
    ['FRIDAY', 'MONDAY', 'SATURDAY', 'SUNDAY', 'THURSDAY', 'TUESDAY', 'WEDNESDAY', '__class__', '__doc__', '__eq__', '__hash__', '__module__', 'name', 'today', 'value']
**********************************************************************
1 items had failures:
   1 of  88 in enum.rst
***Test Failed*** 1 failures.

I'm working on fixes for both errors.

Linked PRs

@chgnrdv chgnrdv added the type-bug An unexpected behavior, bug, or error label May 6, 2023
@arhadthedev arhadthedev added the stdlib Python modules in the Lib dir label May 6, 2023
@sunmy2019
Copy link
Member

This behavior change is probably due to the new Enum implementation in 3.11. Also confirmed on 3.11.

No need to backport to 3.10.

@sunmy2019 sunmy2019 added 3.11 only security fixes 3.12 bugs and security fixes labels May 6, 2023
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 bugs and security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
4 participants