Title: 3.11 creates doctests for Enum subclasses brittle against `globs` and overridden `__repr__` · Issue #93976 · python/cpython · GitHub
Open Graph Title: 3.11 creates doctests for Enum subclasses brittle against `globs` and overridden `__repr__` · Issue #93976 · python/cpython
X Title: 3.11 creates doctests for Enum subclasses brittle against `globs` and overridden `__repr__` · Issue #93976 · python/cpython
Description: Bug report In 3.11, subclassing Enum without providing a docstring causes tests to be added to a module's doctest suite. This lengthens test suites This creates failures if Enum is not provided in the globs argument to doctest test runne...
Open Graph Description: Bug report In 3.11, subclassing Enum without providing a docstring causes tests to be added to a module's doctest suite. This lengthens test suites This creates failures if Enum is not provided in ...
X Description: Bug report In 3.11, subclassing Enum without providing a docstring causes tests to be added to a module's doctest suite. This lengthens test suites This creates failures if Enum is not provided...
Opengraph URL: https://github.com/python/cpython/issues/93976
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"3.11 creates doctests for Enum subclasses brittle against `globs` and overridden `__repr__`","articleBody":"**Bug report**\r\n\r\nIn 3.11, subclassing `Enum` _without providing a docstring_ causes tests to be added to a module's doctest suite.\r\n\r\n- This lengthens test suites\r\n- This creates failures if `Enum` is not provided in the `globs` argument to `doctest` test runners\r\n- This creates failures if `__repr__` is overridden\r\n\r\n```python\r\nimport re\r\nfrom enum import Enum\r\n\r\nclass MyEnum(Enum):\r\n def __repr__(self):\r\n \"\"\"Suppress the trailing colon and integer\"\"\"\r\n return re.sub(r': \\d+', '', super().__repr__())\r\n\r\n\r\nclass FinalEnum(MyEnum):\r\n MEMBER = 1\r\n\r\n\r\nif __name__ == \"__main__\":\r\n import doctest\r\n doctest.testmod(globs={'MyEnum': MyEnum, 'FinalEnum': FinalEnum})\r\n```\r\n\r\n**3.10**\r\n```shell\r\n$ python3.10 e.py -v\r\n4 items had no tests:\r\n __main__\r\n __main__.FinalEnum\r\n __main__.MyEnum\r\n __main__.MyEnum.__repr__\r\n0 tests in 4 items.\r\n0 passed and 0 failed.\r\nTest passed.\r\n```\r\n\r\n**3.11**\r\n```shell\r\n$ python3.11 e.py\r\n**********************************************************************\r\nFile \"/Users/.../e.py\", line ?, in __main__.FinalEnum\r\nFailed example:\r\n FinalEnum.MEMBER\r\nExpected:\r\n \u003cFinalEnum.MEMBER: 1\u003e\r\nGot:\r\n \u003cFinalEnum.MEMBER\u003e\r\n**********************************************************************\r\nFile \"/Users/.../e.py\", line ?, in __main__.FinalEnum\r\nFailed example:\r\n FinalEnum(1)\r\nExpected:\r\n \u003cFinalEnum.MEMBER: 1\u003e\r\nGot:\r\n \u003cFinalEnum.MEMBER\u003e\r\n**********************************************************************\r\nFile \"/Users/.../e.py\", line ?, in __main__.FinalEnum\r\nFailed example:\r\n FinalEnum['MEMBER']\r\nExpected:\r\n \u003cFinalEnum.MEMBER: 1\u003e\r\nGot:\r\n \u003cFinalEnum.MEMBER\u003e\r\n**********************************************************************\r\nFile \"/Users/.../e.py\", line ?, in __main__.FinalEnum\r\nFailed example:\r\n list(FinalEnum)\r\nExpected:\r\n [\u003cFinalEnum.MEMBER: 1\u003e]\r\nGot:\r\n [\u003cFinalEnum.MEMBER\u003e]\r\n**********************************************************************\r\nFile \"/Users/.../e.py\", line 10, in __main__.MyEnum\r\nFailed example:\r\n class Color(Enum):\r\n RED = 1\r\n BLUE = 2\r\n GREEN = 3\r\nException raised:\r\n Traceback (most recent call last):\r\n File \"/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/doctest.py\", line 1350, in __run\r\n exec(compile(example.source, filename, \"single\",\r\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\r\n File \"\u003cdoctest __main__.MyEnum[0]\u003e\", line 1, in \u003cmodule\u003e\r\n class Color(Enum):\r\n ^^^^\r\n NameError: name 'Enum' is not defined\r\n**********************************************************************\r\nFile \"/Users/.../e.py\", line 19, in __main__.MyEnum\r\nFailed example:\r\n Color.RED\r\nException raised:\r\n Traceback (most recent call last):\r\n File \"/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/doctest.py\", line 1350, in __run\r\n exec(compile(example.source, filename, \"single\",\r\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\r\n File \"\u003cdoctest __main__.MyEnum[1]\u003e\", line 1, in \u003cmodule\u003e\r\n Color.RED\r\n ^^^^^\r\n NameError: name 'Color' is not defined\r\n**********************************************************************\r\nFile \"/Users/.../e.py\", line 24, in __main__.MyEnum\r\nFailed example:\r\n Color(1)\r\nException raised:\r\n Traceback (most recent call last):\r\n File \"/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/doctest.py\", line 1350, in __run\r\n exec(compile(example.source, filename, \"single\",\r\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\r\n File \"\u003cdoctest __main__.MyEnum[2]\u003e\", line 1, in \u003cmodule\u003e\r\n Color(1)\r\n ^^^^^\r\n NameError: name 'Color' is not defined\r\n**********************************************************************\r\nFile \"/Users/.../e.py\", line 29, in __main__.MyEnum\r\nFailed example:\r\n Color['RED']\r\nException raised:\r\n Traceback (most recent call last):\r\n File \"/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/doctest.py\", line 1350, in __run\r\n exec(compile(example.source, filename, \"single\",\r\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\r\n File \"\u003cdoctest __main__.MyEnum[3]\u003e\", line 1, in \u003cmodule\u003e\r\n Color['RED']\r\n ^^^^^\r\n NameError: name 'Color' is not defined\r\n**********************************************************************\r\nFile \"/Users/.../e.py\", line 34, in __main__.MyEnum\r\nFailed example:\r\n len(Color)\r\nException raised:\r\n Traceback (most recent call last):\r\n File \"/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/doctest.py\", line 1350, in __run\r\n exec(compile(example.source, filename, \"single\",\r\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\r\n File \"\u003cdoctest __main__.MyEnum[4]\u003e\", line 1, in \u003cmodule\u003e\r\n len(Color)\r\n ^^^^^\r\n NameError: name 'Color' is not defined\r\n**********************************************************************\r\nFile \"/Users/.../e.py\", line 37, in __main__.MyEnum\r\nFailed example:\r\n list(Color)\r\nException raised:\r\n Traceback (most recent call last):\r\n File \"/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/doctest.py\", line 1350, in __run\r\n exec(compile(example.source, filename, \"single\",\r\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\r\n File \"\u003cdoctest __main__.MyEnum[5]\u003e\", line 1, in \u003cmodule\u003e\r\n list(Color)\r\n ^^^^^\r\n NameError: name 'Color' is not defined\r\n**********************************************************************\r\n2 items had failures:\r\n 4 of 5 in __main__.FinalEnum\r\n 6 of 6 in __main__.MyEnum\r\n***Test Failed*** 10 failures.\r\n```\r\n***\r\n**Your environment**\r\n\r\nPython 3.11.0b3\r\n\r\ncc/ @mscuthbert (FYI: a potential workaround is to add docstrings)","author":{"url":"https://github.com/jacobtylerwalls","@type":"Person","name":"jacobtylerwalls"},"datePublished":"2022-06-18T01:25:42.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/93976/cpython/issues/93976"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:521deaf8-4643-e290-408e-17be7cf41f1f |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9D2E:32294B:8B54A9:BA0C9F:69697DAF |
| html-safe-nonce | 1f96886989b7cd539dd5c0b9dcec70faedd3e998f78761e4fcea7dcaf14dca6a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5RDJFOjMyMjk0Qjo4QjU0QTk6QkEwQzlGOjY5Njk3REFGIiwidmlzaXRvcl9pZCI6IjI4OTk5MzcyMTUzNzU4MzQ1NDMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 71cae2338190f0437d3cfa39044da295f8a75e40c8a52cb0d085f0679306bb5f |
| hovercard-subject-tag | issue:1275626933 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/93976/issue_layout |
| twitter:image | https://opengraph.githubassets.com/2ccb2c23e503a5a59fb308afba79e8dc537d682f04aae5a9ec820876c1309129/python/cpython/issues/93976 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/2ccb2c23e503a5a59fb308afba79e8dc537d682f04aae5a9ec820876c1309129/python/cpython/issues/93976 |
| og:image:alt | Bug report In 3.11, subclassing Enum without providing a docstring causes tests to be added to a module's doctest suite. This lengthens test suites This creates failures if Enum is not provided in ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | jacobtylerwalls |
| hostname | github.com |
| expected-hostname | github.com |
| None | f33e4b94c8824ab2b434d82a94139432fb5ebee9df4b75304140ad22508c4a77 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 48f380098b30acbb700b04f1724481ca10d574fc |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width