Skip to content

Commit eac0a72

Browse files
committed
Docstring -> Validator.
1 parent 94f4121 commit eac0a72

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

numpydoc/__main__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
import ast
77

88
from .docscrape_sphinx import get_doc_object
9-
from .validate import validate, Docstring
9+
from .validate import validate, Validator
1010

1111

1212
def render_object(import_path, config=None):
1313
"""Test numpydoc docstring generation for a given object"""
14-
# TODO: Move Docstring._load_obj to a better place than validate
15-
print(get_doc_object(Docstring(import_path).obj,
14+
# TODO: Move Validator._load_obj to a better place than validate
15+
print(get_doc_object(Validator._load_obj(import_path),
1616
config=dict(config or [])))
1717
return 0
1818

numpydoc/tests/test_validate.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1312,12 +1312,12 @@ def test_bad_docstrings(self, capsys, klass, func, msgs):
13121312
assert msg in " ".join(err[1] for err in result["errors"])
13131313

13141314

1315-
class TestDocstringClass:
1315+
class TestValidatorClass:
13161316
@pytest.mark.parametrize("invalid_name", ["unknown_mod", "unknown_mod.MyClass"])
13171317
def test_raises_for_invalid_module_name(self, invalid_name):
13181318
msg = 'No module can be imported from "{}"'.format(invalid_name)
13191319
with pytest.raises(ImportError, match=msg):
1320-
numpydoc.validate.Docstring(invalid_name)
1320+
numpydoc.validate.Validator._load_obj(invalid_name)
13211321

13221322
@pytest.mark.parametrize(
13231323
"invalid_name", ["datetime.BadClassName", "datetime.bad_method_name"]
@@ -1327,4 +1327,4 @@ def test_raises_for_invalid_attribute_name(self, invalid_name):
13271327
obj_name, invalid_attr_name = name_components[-2], name_components[-1]
13281328
msg = "'{}' has no attribute '{}'".format(obj_name, invalid_attr_name)
13291329
with pytest.raises(AttributeError, match=msg):
1330-
numpydoc.validate.Docstring(invalid_name)
1330+
numpydoc.validate.Validator._load_obj(invalid_name)

numpydoc/validate.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,17 +121,18 @@ def error(code, **kwargs):
121121
return (code, ERROR_MSGS[code].format(**kwargs))
122122

123123

124-
class Docstring:
124+
class Validator:
125125
# TODO Can all this class be merged into NumpyDocString?
126-
def __init__(self, name):
127-
self.name = name
128-
obj = self._load_obj(name)
129-
self.doc = get_doc_object(obj)
126+
def __init__(self, doc_object):
127+
self.doc = doc_object
130128
self.obj = self.doc._obj
131129
self.code_obj = inspect.unwrap(self.obj)
132130
self.raw_doc = self.obj.__doc__ or ""
133131
self.clean_doc = pydoc.getdoc(self.obj)
134-
# self.doc = NumpyDocString(self.clean_doc)
132+
133+
@property
134+
def name(self):
135+
return '.'.join([self.obj.__module__, self.obj.__name__])
135136

136137
@staticmethod
137138
def _load_obj(name):
@@ -150,7 +151,7 @@ def _load_obj(name):
150151
151152
Examples
152153
--------
153-
>>> Docstring._load_obj('datetime.datetime')
154+
>>> Validator._load_obj('datetime.datetime')
154155
<class 'datetime.datetime'>
155156
"""
156157
for maxsplit in range(0, name.count(".") + 1):
@@ -469,7 +470,8 @@ def validate(obj_name):
469470
they are validated, are not documented more than in the source code of this
470471
function.
471472
"""
472-
doc = Docstring(obj_name)
473+
obj = Validator._load_obj(obj_name)
474+
doc = Validator(get_doc_object(obj))
473475

474476
errs = []
475477
if not doc.raw_doc:

0 commit comments

Comments
 (0)