LarsHill / metadict

MetaDict is a powerful dict subclass enabling (nested) attribute-style item access/assignment and IDE autocompletion support.
Apache License 2.0
31 stars 1 forks source link

Why does keys() not work same as keys() for dict. Returns KeysView instead #8

Closed jj-github-jj closed 1 year ago

jj-github-jj commented 1 year ago

dict.keys() returns list but using .keys() function with metadict returns KeysView object

LarsHill commented 1 year ago

Hi,

dict.keys() does actually not return a list but a dict_keys (dictionary view) object. See here for more infos.

MetaDict also returns a dictionary view object.

from metadict import MetaDict
print(isinstance({}.keys(), type(MetaDict(a=1).keys())))
>> True

So the return type of MetaDict.keys() is compatible to dict.keys().