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

Add keyword argument support to ChainMap.new_child() #87411

Closed
rhettinger opened this issue Feb 17, 2021 · 2 comments
Closed

Add keyword argument support to ChainMap.new_child() #87411

rhettinger opened this issue Feb 17, 2021 · 2 comments
Assignees
Labels
3.10 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@rhettinger
Copy link
Contributor

BPO 43245
Nosy @rhettinger, @kamilturek
PRs
  • bpo-43245: Add keyword argument support to ChainMap.new_child() #24788
  • 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/rhettinger'
    closed_at = <Date 2021-03-14.03:16:08.548>
    created_at = <Date 2021-02-17.19:48:44.619>
    labels = ['type-bug', 'library', '3.10']
    title = 'Add keyword argument support to ChainMap.new_child()'
    updated_at = <Date 2021-03-14.03:16:08.547>
    user = 'https://github.com/rhettinger'

    bugs.python.org fields:

    activity = <Date 2021-03-14.03:16:08.547>
    actor = 'rhettinger'
    assignee = 'rhettinger'
    closed = True
    closed_date = <Date 2021-03-14.03:16:08.548>
    closer = 'rhettinger'
    components = ['Library (Lib)']
    creation = <Date 2021-02-17.19:48:44.619>
    creator = 'rhettinger'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 43245
    keywords = ['patch']
    message_count = 2.0
    messages = ['387186', '388652']
    nosy_count = 2.0
    nosy_names = ['rhettinger', 'kamilturek']
    pr_nums = ['24788']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue43245'
    versions = ['Python 3.10']

    @rhettinger
    Copy link
    Contributor Author

    This would it more convenient to extend chains for local contexts. Currently, we write:

        local = parent.new_child(dict(foreground='white', background='cyan'))

    Instead, it would be easier to write:

        local = parent.new_child(foreground='white', background='cyan')

    The new code would look like this:

        def new_child(self, m=None, **kwargs):
            '''New ChainMap with a new map followed by all previous maps.
            If no map is provided, an empty dict is used.
            Keyword arguments update the map or new empty dict:
            '''
            if m is None:
                m = kwargs
            elif kwargs:
                m.update(kwargs)
            return self.__class__(m, *self.maps)

    @rhettinger rhettinger added the 3.10 only security fixes label Feb 17, 2021
    @rhettinger rhettinger self-assigned this Feb 17, 2021
    @rhettinger rhettinger added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error 3.10 only security fixes labels Feb 17, 2021
    @rhettinger rhettinger self-assigned this Feb 17, 2021
    @rhettinger
    Copy link
    Contributor Author

    New changeset 9923df9 by Kamil Turek in branch 'master':
    bpo-43245: Add keyword argument support to ChainMap.new_child() (GH-24788)
    9923df9

    @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.10 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant