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

pprint: added support for mapping proxy #67690

Closed
serhiy-storchaka opened this issue Feb 23, 2015 · 2 comments
Closed

pprint: added support for mapping proxy #67690

serhiy-storchaka opened this issue Feb 23, 2015 · 2 comments
Assignees
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@serhiy-storchaka
Copy link
Member

BPO 23502
Nosy @freddrake, @rhettinger, @pitrou, @serhiy-storchaka
Files
  • pprint_mappingproxy.patch
  • 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/serhiy-storchaka'
    closed_at = <Date 2015-03-24.17:33:09.654>
    created_at = <Date 2015-02-23.19:21:48.535>
    labels = ['type-feature', 'library']
    title = 'pprint: added support for mapping proxy'
    updated_at = <Date 2015-03-24.17:33:09.653>
    user = 'https://github.com/serhiy-storchaka'

    bugs.python.org fields:

    activity = <Date 2015-03-24.17:33:09.653>
    actor = 'serhiy.storchaka'
    assignee = 'serhiy.storchaka'
    closed = True
    closed_date = <Date 2015-03-24.17:33:09.654>
    closer = 'serhiy.storchaka'
    components = ['Library (Lib)']
    creation = <Date 2015-02-23.19:21:48.535>
    creator = 'serhiy.storchaka'
    dependencies = []
    files = ['38215']
    hgrepos = []
    issue_num = 23502
    keywords = ['patch']
    message_count = 2.0
    messages = ['236460', '239160']
    nosy_count = 5.0
    nosy_names = ['fdrake', 'rhettinger', 'pitrou', 'python-dev', 'serhiy.storchaka']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue23502'
    versions = ['Python 3.5']

    @serhiy-storchaka
    Copy link
    Member Author

    Mapping proxy is quite often used in building . For example types __dict__ are mapping proxy.

    >>> bool.__dict__
    mappingproxy({'__or__': <slot wrapper '__or__' of 'bool' objects>, '__doc__': 'bool(x) -> bool\n\nReturns True when the argument x is true, False otherwise.\nThe builtins True and False are the only two instances of the class bool.\nThe class bool is a subclass of the class int, and cannot be subclassed.', '__xor__': <slot wrapper '__xor__' of 'bool' objects>, '__and__': <slot wrapper '__and__' of 'bool' objects>, '__rxor__': <slot wrapper '__rxor__' of 'bool' objects>, '__repr__': <slot wrapper '__repr__' of 'bool' objects>, '__new__': <built-in method __new__ of type object at 0x82a1140>, '__rand__': <slot wrapper '__rand__' of 'bool' objects>, '__str__': <slot wrapper '__str__' of 'bool' objects>, '__ror__': <slot wrapper '__ror__' of 'bool' objects>})

    Mapping proxy is not a subclass of dict, so pprint doesn't print it pretty. Proposed patch adds support for mapping proxies in pprint.

    >>> from pprint import pprint as pp
    >>> pp(bool.__dict__)
    mappingproxy({'__and__': <slot wrapper '__and__' of 'bool' objects>,
                  '__doc__': 'bool(x) -> bool\n'
                             '\n'
                             'Returns True when the argument x is true, False '
                             'otherwise.\n'
                             'The builtins True and False are the only two '
                             'instances of the class bool.\n'
                             'The class bool is a subclass of the class int, and '
                             'cannot be subclassed.',
                  '__new__': <built-in method __new__ of type object at 0x82a1140>,
                  '__or__': <slot wrapper '__or__' of 'bool' objects>,
                  '__rand__': <slot wrapper '__rand__' of 'bool' objects>,
                  '__repr__': <slot wrapper '__repr__' of 'bool' objects>,
                  '__ror__': <slot wrapper '__ror__' of 'bool' objects>,
                  '__rxor__': <slot wrapper '__rxor__' of 'bool' objects>,
                  '__str__': <slot wrapper '__str__' of 'bool' objects>,
                  '__xor__': <slot wrapper '__xor__' of 'bool' objects>})

    @serhiy-storchaka serhiy-storchaka added stdlib Python modules in the Lib dir type-feature A feature request or enhancement labels Feb 23, 2015
    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Mar 24, 2015

    New changeset 646a7e1da7f0 by Serhiy Storchaka in branch 'default':
    Issue bpo-23502: The pprint module now supports mapping proxies.
    https://hg.python.org/cpython/rev/646a7e1da7f0

    @serhiy-storchaka serhiy-storchaka self-assigned this Mar 24, 2015
    @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
    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