Skip to content

Commit 96a0fe3

Browse files
committed
Merge pull request #29 from tacaswell/DocString_keys
ENH : NumpyDocString subclass collections.Mapping
2 parents 87fff99 + 7853c76 commit 96a0fe3

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

numpydoc/docscrape.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def is_empty(self):
8686
return not ''.join(self._str).strip()
8787

8888

89-
class NumpyDocString(object):
89+
class NumpyDocString(collections.Mapping):
9090
def __init__(self, docstring, config={}):
9191
docstring = textwrap.dedent(docstring).split('\n')
9292

@@ -113,15 +113,21 @@ def __init__(self, docstring, config={}):
113113

114114
self._parse()
115115

116-
def __getitem__(self,key):
116+
def __getitem__(self, key):
117117
return self._parsed_data[key]
118118

119-
def __setitem__(self,key,val):
119+
def __setitem__(self, key, val):
120120
if key not in self._parsed_data:
121121
warn("Unknown section %s" % key)
122122
else:
123123
self._parsed_data[key] = val
124124

125+
def __iter__(self):
126+
return iter(self._parsed_data)
127+
128+
def __len__(self):
129+
return len(self._parsed_data)
130+
125131
def _is_at_section(self):
126132
self._doc.seek_next_non_empty_line()
127133

0 commit comments

Comments
 (0)