summaryrefslogtreecommitdiff
path: root/numpydoc
diff options
context:
space:
mode:
authorJarrod Millman <jarrod.millman@gmail.com>2022-04-05 14:04:42 -0700
committerGitHub <noreply@github.com>2022-04-05 17:04:42 -0400
commit032dbc7d7ce1a2d2c0439b5b138838909907ec55 (patch)
tree92b6b1bef5b3b69ef17a48a37087a97c0690cf08 /numpydoc
parent4181a80a86b88de2e8379694a2f8791dc1bcf8b5 (diff)
downloadnumpydoc-032dbc7d7ce1a2d2c0439b5b138838909907ec55.tar.gz
Add pre-commit hook / linter (#374)
* Add pre-commit hook / linter * Run linter * Fix GH workflow
Diffstat (limited to 'numpydoc')
-rw-r--r--numpydoc/docscrape.py2
-rw-r--r--numpydoc/docscrape_sphinx.py4
-rw-r--r--numpydoc/tests/test_docscrape.py1
-rw-r--r--numpydoc/tests/test_full.py8
-rw-r--r--numpydoc/tests/test_numpydoc.py7
-rw-r--r--numpydoc/tests/test_xref.py1
6 files changed, 10 insertions, 13 deletions
diff --git a/numpydoc/docscrape.py b/numpydoc/docscrape.py
index d6544b2..1587797 100644
--- a/numpydoc/docscrape.py
+++ b/numpydoc/docscrape.py
@@ -378,7 +378,7 @@ class NumpyDocString(Mapping):
self._parse_summary()
sections = list(self._read_sections())
- section_names = set([section for section, content in sections])
+ section_names = {section for section, content in sections}
has_returns = 'Returns' in section_names
has_yields = 'Yields' in section_names
diff --git a/numpydoc/docscrape_sphinx.py b/numpydoc/docscrape_sphinx.py
index 5ded4f0..b15afd2 100644
--- a/numpydoc/docscrape_sphinx.py
+++ b/numpydoc/docscrape_sphinx.py
@@ -268,7 +268,7 @@ class SphinxDocString(NumpyDocString):
out += [''] + autosum
if others:
- maxlen_0 = max(3, max([len(p.name) + 4 for p in others]))
+ maxlen_0 = max(3, max(len(p.name) + 4 for p in others))
hdr = "=" * maxlen_0 + " " + "=" * 10
fmt = '%%%ds %%s ' % (maxlen_0,)
out += ['', '', hdr]
@@ -382,7 +382,7 @@ class SphinxDocString(NumpyDocString):
else self._str_member_list('Attributes'),
'methods': self._str_member_list('Methods'),
}
- ns = dict((k, '\n'.join(v)) for k, v in ns.items())
+ ns = {k: '\n'.join(v) for k, v in ns.items()}
rendered = self.template.render(**ns)
return '\n'.join(self._str_indent(rendered.split('\n'), indent))
diff --git a/numpydoc/tests/test_docscrape.py b/numpydoc/tests/test_docscrape.py
index 83a8d5b..9644008 100644
--- a/numpydoc/tests/test_docscrape.py
+++ b/numpydoc/tests/test_docscrape.py
@@ -1,4 +1,3 @@
-# -*- encoding:utf-8 -*-
from collections import namedtuple
from copy import deepcopy
import re
diff --git a/numpydoc/tests/test_full.py b/numpydoc/tests/test_full.py
index 5756d6d..16e60e5 100644
--- a/numpydoc/tests/test_full.py
+++ b/numpydoc/tests/test_full.py
@@ -41,12 +41,12 @@ def test_MyClass(sphinx_app):
src_dir, out_dir = sphinx_app.srcdir, sphinx_app.outdir
class_rst = op.join(src_dir, 'generated',
'numpydoc_test_module.MyClass.rst')
- with open(class_rst, 'r') as fid:
+ with open(class_rst) as fid:
rst = fid.read()
assert r'numpydoc\_test\_module' in rst # properly escaped
class_html = op.join(out_dir, 'generated',
'numpydoc_test_module.MyClass.html')
- with open(class_html, 'r') as fid:
+ with open(class_html) as fid:
html = fid.read()
# ensure that no autodoc weirdness ($) occurs
assert '$self' not in html
@@ -66,7 +66,7 @@ def test_my_function(sphinx_app):
out_dir = sphinx_app.outdir
function_html = op.join(out_dir, 'generated',
'numpydoc_test_module.my_function.html')
- with open(function_html, 'r') as fid:
+ with open(function_html) as fid:
html = fid.read()
assert r'\*args' not in html
assert '*args' in html
@@ -83,7 +83,7 @@ def test_reference(sphinx_app, html_file, expected_length):
"""Test for bad references"""
out_dir = sphinx_app.outdir
- with open(op.join(out_dir, *html_file), 'r') as fid:
+ with open(op.join(out_dir, *html_file)) as fid:
html = fid.read()
reference_list = re.findall(r'<a class="fn-backref" href="\#id\d+">(.*)<\/a>', html)
diff --git a/numpydoc/tests/test_numpydoc.py b/numpydoc/tests/test_numpydoc.py
index f319269..5888d9e 100644
--- a/numpydoc/tests/test_numpydoc.py
+++ b/numpydoc/tests/test_numpydoc.py
@@ -1,4 +1,3 @@
-# -*- encoding:utf-8 -*-
import pytest
from io import StringIO
from copy import deepcopy
@@ -123,9 +122,9 @@ def f():
# Validation configured off - expect no warnings
(set(), [], []),
# Validation on with expected warnings
- (set(['SA01', 'EX01']), ('SA01', 'EX01'), []),
+ ({'SA01', 'EX01'}, ('SA01', 'EX01'), []),
# Validation on with only one activated check
- (set(['SA01']), ('SA01',), ('EX01',)),
+ ({'SA01'}, ('SA01',), ('EX01',)),
),
)
def test_mangle_docstring_validation_warnings(
@@ -190,7 +189,7 @@ def test_update_config_exclude_str():
app = MockApp()
app.config.numpydoc_validation_checks = set()
app.config.numpydoc_validation_exclude = "shouldnt-be-a-str"
- with pytest.raises(ValueError, match="\['shouldnt-be-a-str'\]"):
+ with pytest.raises(ValueError, match=r"\['shouldnt-be-a-str'\]"):
update_config(app)
diff --git a/numpydoc/tests/test_xref.py b/numpydoc/tests/test_xref.py
index aa14970..175cb98 100644
--- a/numpydoc/tests/test_xref.py
+++ b/numpydoc/tests/test_xref.py
@@ -1,4 +1,3 @@
-# -*- encoding:utf-8 -*-
import pytest
from numpydoc.xref import make_xref, DEFAULT_LINKS