This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: HTTPStatus has incomplete dir() listing
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.10, Python 3.9, Python 3.8
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: ethan.furman Nosy List: ethan.furman, lem2clide, miss-islington, rhettinger, serhiy.storchaka, xtreak
Priority: normal Keywords: newcomer friendly, patch

Created on 2020-03-27 07:16 by rhettinger, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 19219 merged lem2clide, 2020-03-29 20:56
PR 22338 closed miss-islington, 2020-09-21 13:11
PR 22339 closed miss-islington, 2020-09-21 13:12
PR 22853 merged miss-islington, 2020-10-21 08:51
PR 22854 closed miss-islington, 2020-10-21 08:51
PR 23746 merged miss-islington, 2020-12-13 00:27
Messages (5)
msg365138 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2020-03-27 07:16
The dir() listing omits the attributes "description" and "phrase":

>>> import http
>>> from pprint import pp
>>> r = http.HTTPStatus(404)
>>> pp(vars(r))
{'_value_': 404,
 'phrase': 'Not Found',
 'description': 'Nothing matches the given URI',
 '_name_': 'NOT_FOUND',
 '__objclass__': <enum 'HTTPStatus'>}
>>> r.value
404
>>> r.name
'NOT_FOUND'
>>> r.description
'Nothing matches the given URI'
>>> r.phrase
'Not Found'
>>> dir(r)
['__class__', '__doc__', '__module__', 'as_integer_ratio', 'bit_length', 'conjugate', 'denominator', 'from_bytes', 'imag', 'name', 'numerator', 'real', 'to_bytes', 'value']

One fix would be to teach IntEnum.__dir__() to include entries in the instance dict.  Another fix would be to provide a way for a IntEnum subclass to add to the known members list.
msg365180 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2020-03-27 18:15
Adding to the existing dir() is as easy as writing one's own __dir__.

I think using the instance dict and omitting any keys with a leading underscore will do the right thing most of the time.

The fix should into `Enum` and not just `IntEnum` as other enumerations could also have extra attributes.
msg377254 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2020-09-21 13:11
New changeset 68526fe258da8c01196fd7cf48e8e5f1280bf8fd by Angelin BOOZ in branch 'master':
bpo-40084: Enum - dir() includes member attributes (GH-19219)
https://github.com/python/cpython/commit/68526fe258da8c01196fd7cf48e8e5f1280bf8fd
msg382803 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2020-12-09 19:25
New changeset f6d1520219899874d78e7710934c9b21af880f9a by Miss Islington (bot) in branch '3.8':
bpo-40084: [Enum] dir() includes member attributes (GH-19219) (GH-22853)
https://github.com/python/cpython/commit/f6d1520219899874d78e7710934c9b21af880f9a
msg383011 - (view) Author: miss-islington (miss-islington) Date: 2020-12-14 22:43
New changeset 33cbb04986d0dabb9c542edc52bb4ea6106d3a81 by Miss Islington (bot) in branch '3.9':
bpo-40084: Enum - dir() includes member attributes (GH-19219)
https://github.com/python/cpython/commit/33cbb04986d0dabb9c542edc52bb4ea6106d3a81
History
Date User Action Args
2022-04-11 14:59:28adminsetgithub: 84265
2020-12-14 23:59:07ethan.furmansetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2020-12-14 22:43:57miss-islingtonsetmessages: + msg383011
2020-12-13 00:27:24miss-islingtonsetpull_requests: + pull_request22604
2020-12-09 19:25:15ethan.furmansetmessages: + msg382803
2020-10-21 08:51:59miss-islingtonsetpull_requests: + pull_request21798
2020-10-21 08:51:48miss-islingtonsetpull_requests: + pull_request21797
2020-09-21 13:12:00miss-islingtonsetpull_requests: + pull_request21384
2020-09-21 13:11:50miss-islingtonsetnosy: + miss-islington
pull_requests: + pull_request21383
2020-09-21 13:11:10ethan.furmansetmessages: + msg377254
2020-09-21 11:46:57ethan.furmansetversions: + Python 3.10, - Python 3.7
2020-03-29 20:56:08lem2clidesetkeywords: + patch
nosy: + lem2clide

pull_requests: + pull_request18581
stage: needs patch -> patch review
2020-03-27 18:15:47ethan.furmansetkeywords: + newcomer friendly
assignee: ethan.furman
messages: + msg365180

stage: needs patch
2020-03-27 11:27:47xtreaksetnosy: + xtreak
2020-03-27 07:16:45rhettingercreate