Skip to content

Where is the dict_keys (and dict_values (and dict_items)) class? #138557

@George-Ogden

Description

@George-Ogden

How can I check if an object is a dict_keys() in Python?

My current options are:

  1. seems bad style:
dict_keys = type(dict().keys())
is_dict_keys = isinstance(foo, dict_keys)
  1. overzealously matches:
from collections.abc import KeysView
is_dict_keys = isinstance(foo, KeysView)

There's no way to import this from the types library and there's no documentation about it in the Dictionary view objects section of the documentation.
Is there a better way to do this? Is dict_keys intentionally excluded from the documentation?

Metadata

Metadata

Assignees

No one assigned

    Labels

    pendingThe issue will be closed if no feedback is provided

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions