Skip to content
This repository has been archived by the owner on Jan 18, 2024. It is now read-only.

[FEATURE] AttrDict get(...) method #90

Closed
jonatasalves-hotmart opened this issue Jan 18, 2023 · 0 comments
Closed

[FEATURE] AttrDict get(...) method #90

jonatasalves-hotmart opened this issue Jan 18, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@jonatasalves-hotmart
Copy link
Contributor

Is your feature request related to a problem?

just like dict, AttrDict could have a get method.

In [1]: from opensearch_dsl import AttrDict
In [2]: a = AttrDict({"a": "b"})
In [3]: a
Out[3]: {'a': 'b'}
In [4]: a.a
Out[4]: 'b'
In [5]: a["a"]
Out[5]: 'b'
In [6]: a.get("a", default="c")
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
File ...venv/lib/python3.8/site-packages/opensearch_dsl/utils.py:168, in AttrDict.__getattr__(self, attr_name)
    167 try:
--> 168     return self.__getitem__(attr_name)
    169 except KeyError:

File .../venv/lib/python3.8/site-packages/opensearch_dsl/utils.py:187, in AttrDict.__getitem__(self, key)
    186 def __getitem__(self, key):
--> 187     return _wrap(self._d_[key])

What solution would you like?

Same behaviour as dict.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants