sweet_sauce
sweet_sauce

Reputation: 95

Type hint for dictionary view objects

I'm not sure the documentation contains any concrete info on the type of view objects. I wasn't able to locate it (i.e. <class 'dict_values'> in the dict's source code. Is there a way to explicitly specify this 'view class'? And does it make sense in the first place? Example:

def func1(arg: dictview) -> None:
    pass

Upvotes: 4

Views: 937

Answers (2)

S.B
S.B

Reputation: 16546

typing.MappingView is now deprecated in python 3.9 , You can use collections.abc.MappingView

collections.abc.MappingView
collections.abc.ItemsView
collections.abc.KeysView
collections.abc.ValuesView

Upvotes: 2

deceze
deceze

Reputation: 522522

You're looking for the typing.MappingView type hint or any of its related types like KeysView, ItemsView, ValuesView.

Upvotes: 6

Related Questions