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

Mock.__dir__ lists deleted attributes #79263

Closed
mariocj89 mannequin opened this issue Oct 27, 2018 · 1 comment
Closed

Mock.__dir__ lists deleted attributes #79263

mariocj89 mannequin opened this issue Oct 27, 2018 · 1 comment
Labels
3.7 (EOL) end of life 3.8 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@mariocj89
Copy link
Mannequin

mariocj89 mannequin commented Oct 27, 2018

BPO 35082
Nosy @voidspace, @mariocj89
PRs
  • bpo-35082: Don't report deleted attributes in __dir__ #10148
  • [3.7] bpo-35082: Don't report deleted attributes in __dir__ (GH-10148) #13859
  • 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 = None
    closed_at = <Date 2019-06-06.10:40:24.928>
    created_at = <Date 2018-10-27.10:45:10.273>
    labels = ['3.7', '3.8', 'type-feature', 'library']
    title = 'Mock.__dir__ lists deleted attributes'
    updated_at = <Date 2019-06-06.10:40:30.583>
    user = 'https://github.com/mariocj89'

    bugs.python.org fields:

    activity = <Date 2019-06-06.10:40:30.583>
    actor = 'asvetlov'
    assignee = 'none'
    closed = True
    closed_date = <Date 2019-06-06.10:40:24.928>
    closer = 'asvetlov'
    components = ['Library (Lib)']
    creation = <Date 2018-10-27.10:45:10.273>
    creator = 'mariocj89'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 35082
    keywords = ['patch']
    message_count = 1.0
    messages = ['328647']
    nosy_count = 2.0
    nosy_names = ['michael.foord', 'mariocj89']
    pr_nums = ['10148', '13859']
    priority = 'low'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue35082'
    versions = ['Python 3.7', 'Python 3.8']

    @mariocj89
    Copy link
    Mannequin Author

    mariocj89 mannequin commented Oct 27, 2018

    Calling dir on unittest.mock.Mock will return deleted attributes.

    This is a result of the way del is implemented in Mock, which just sets a sentinel in the child mocks, so an AttributeError is raised if the attribute is later accessed.

    We can just check for such sentinel in the __dir__ method and not return those.

    @mariocj89 mariocj89 mannequin added 3.8 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement labels Oct 27, 2018
    @asvetlov asvetlov closed this as completed Jun 6, 2019
    @asvetlov asvetlov added the 3.7 (EOL) end of life label Jun 6, 2019
    @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.7 (EOL) end of life 3.8 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant