Skip to content

Override keys to avoid KeysView usage. #526

@braingram

Description

@braingram

The KeysView repr contains all nested items. This differs from dict_keys which contains only the "top-level" keys. Here's a minimal example with UserDict (although not used in roman_datamodels, the abcs that are used like MutableMapping for DNode behave similarly).

>> import collections
>> d = collections.UserDict({"a": {"b": {"c": [1, 2, 3]}}})
>> d.keys()
KeysView({'a': {'b': {'c': [1, 2, 3]}}})
>> d['a'].keys()
dict_keys(['b'])

There is some discussion about changing this within python:
python/cpython#76481
but the general consensus at the moment appears to be for subclasses/classes to override the methods to control the behavior.

xref: #524 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions