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

HTTPStatus has incomplete dir() listing #84265

Closed
rhettinger opened this issue Mar 27, 2020 · 5 comments
Closed

HTTPStatus has incomplete dir() listing #84265

rhettinger opened this issue Mar 27, 2020 · 5 comments
Assignees
Labels
3.8 only security fixes 3.9 only security fixes 3.10 only security fixes easy stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@rhettinger
Copy link
Contributor

BPO 40084
Nosy @rhettinger, @ethanfurman, @serhiy-storchaka, @miss-islington, @tirkarthi, @lem2clide
PRs
  • bpo-40084: Enum.__dir__ listing includes entries from instance dict #19219
  • [3.8] bpo-40084: Enum - dir() includes member attributes (GH-19219) #22338
  • [3.9] bpo-40084: Enum - dir() includes member attributes (GH-19219) #22339
  • [3.8] bpo-40084: Enum - dir() includes member attributes (GH-19219) #22853
  • [3.9] bpo-40084: Enum - dir() includes member attributes (GH-19219) #22854
  • [3.9] bpo-40084: Enum - dir() includes member attributes (GH-19219) #23746
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/ethanfurman'
    closed_at = <Date 2020-12-14.23:59:07.569>
    created_at = <Date 2020-03-27.07:16:45.111>
    labels = ['easy', 'type-bug', '3.8', '3.9', '3.10', 'library']
    title = 'HTTPStatus has incomplete dir() listing'
    updated_at = <Date 2020-12-14.23:59:07.569>
    user = 'https://github.com/rhettinger'

    bugs.python.org fields:

    activity = <Date 2020-12-14.23:59:07.569>
    actor = 'ethan.furman'
    assignee = 'ethan.furman'
    closed = True
    closed_date = <Date 2020-12-14.23:59:07.569>
    closer = 'ethan.furman'
    components = ['Library (Lib)']
    creation = <Date 2020-03-27.07:16:45.111>
    creator = 'rhettinger'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 40084
    keywords = ['patch', 'newcomer friendly']
    message_count = 5.0
    messages = ['365138', '365180', '377254', '382803', '383011']
    nosy_count = 6.0
    nosy_names = ['rhettinger', 'ethan.furman', 'serhiy.storchaka', 'miss-islington', 'xtreak', 'lem2clide']
    pr_nums = ['19219', '22338', '22339', '22853', '22854', '23746']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue40084'
    versions = ['Python 3.8', 'Python 3.9', 'Python 3.10']

    @rhettinger
    Copy link
    Contributor Author

    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.

    @rhettinger rhettinger added 3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Mar 27, 2020
    @ethanfurman
    Copy link
    Member

    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.

    @ethanfurman ethanfurman self-assigned this Mar 27, 2020
    @ethanfurman ethanfurman self-assigned this Mar 27, 2020
    @ethanfurman ethanfurman added 3.10 only security fixes and removed 3.7 (EOL) end of life labels Sep 21, 2020
    @ethanfurman
    Copy link
    Member

    New changeset 68526fe by Angelin BOOZ in branch 'master':
    bpo-40084: Enum - dir() includes member attributes (GH-19219)
    68526fe

    @ethanfurman
    Copy link
    Member

    New changeset f6d1520 by Miss Islington (bot) in branch '3.8':
    bpo-40084: [Enum] dir() includes member attributes (GH-19219) (GH-22853)
    f6d1520

    @miss-islington
    Copy link
    Contributor

    New changeset 33cbb04 by Miss Islington (bot) in branch '3.9':
    bpo-40084: Enum - dir() includes member attributes (GH-19219)
    33cbb04

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.8 only security fixes 3.9 only security fixes 3.10 only security fixes easy 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