Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Open
@George-Ogden

Description

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

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

        AltStyle によって変換されたページ (->オリジナル) /