Add __len__ method to _LazyAutoMapping (#21522)

Add `__len__` method to `_LazyAutoMapping`

Co-authored-by: ydshieh <ydshieh@users.noreply.github.com>
This commit is contained in:
Yih-Dar 2023-02-08 20:35:14 +01:00 committed by GitHub
parent 9960506cbe
commit c35bb6de54
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -582,6 +582,10 @@ class _LazyAutoMapping(OrderedDict):
self._extra_content = {}
self._modules = {}
def __len__(self):
common_keys = set(self._config_mapping.keys()).intersection(self._model_mapping.keys())
return len(common_keys) + len(self._extra_content)
def __getitem__(self, key):
if key in self._extra_content:
return self._extra_content[key]