Skip to content

Commit

Permalink
Merge pull request #367 from whophil/feature/fields-autocomplete
Browse files Browse the repository at this point in the history
Add fields to EmbeddedDocument.__dir__() to facilitate dynamic code completion
  • Loading branch information
lafrech committed Dec 23, 2021
2 parents 773938e + c03e0d9 commit 10798e6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tests/test_document.py
Expand Up @@ -126,6 +126,13 @@ def test_fields_by_items(self):
with pytest.raises(KeyError):
del john['missing']

def test_dir(self):
john = self.Student.build_from_mongo(data={
'name': 'John Doe', 'birthday': dt.datetime(1995, 12, 12), 'gpa': 3.0})
assert 'name' in dir(john)
assert 'birthday' in dir(john)
assert 'gpa' in dir(john)

def test_property(self):
@self.instance.register
class HeavyStudent(BaseStudent):
Expand Down
3 changes: 3 additions & 0 deletions umongo/embedded_document.py
Expand Up @@ -183,3 +183,6 @@ def __delattr__(self, name):
self._data.delete(name)
else:
super().__delattr__(name)

def __dir__(self):
return dir(type(self)) + list(self._fields)

0 comments on commit 10798e6

Please sign in to comment.