Skip to content

Commit be31633

Browse files
committed
Autoformat with ruff
1 parent 60ef001 commit be31633

19 files changed

+88
-162
lines changed

doc/conf.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,15 @@
44
# list see the documentation:
55
# https://www.sphinx-doc.org/en/master/usage/configuration.html
66

7-
from datetime import date
8-
import numpydoc
9-
107
# -- Path setup --------------------------------------------------------------
11-
128
# If extensions (or modules to document with autodoc) are in another directory,
139
# add these directories to sys.path here. If the directory is relative to the
1410
# documentation root, use os.path.abspath to make it absolute, like shown here.
15-
1611
import os
1712
import sys
13+
from datetime import date
14+
15+
import numpydoc
1816

1917
# for example.py
2018
sys.path.insert(0, os.path.abspath("."))

doc/example.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,3 @@ def foo(var1, var2, *args, long_var_name="hi", only_seldom_used_keyword=0, **kwa
127127
# separate following codes (according to PEP257).
128128
# But for function, method and module, there should be no blank lines
129129
# after closing the docstring.
130-
pass

numpydoc/cli.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
import argparse
44
import ast
5+
from collections.abc import Sequence
56
from pathlib import Path
6-
from typing import List, Sequence, Union
7+
from typing import List, Union
78

89
from .docscrape_sphinx import get_doc_object
910
from .hooks import utils, validate_docstrings

numpydoc/docscrape.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
1-
"""Extract reference documentation from the NumPy source tree.
2-
3-
"""
1+
"""Extract reference documentation from the NumPy source tree."""
42

3+
import copy
54
import inspect
6-
import textwrap
7-
import re
85
import pydoc
9-
from warnings import warn
6+
import re
7+
import sys
8+
import textwrap
109
from collections import namedtuple
1110
from collections.abc import Callable, Mapping
12-
import copy
13-
import sys
14-
1511
from functools import cached_property
12+
from warnings import warn
1613

1714

1815
def strip_blank_lines(l):

numpydoc/docscrape_sphinx.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
1-
import re
21
import inspect
3-
import textwrap
4-
import pydoc
5-
from collections.abc import Callable
62
import os
3+
import pydoc
4+
import re
5+
import textwrap
76

87
from jinja2 import FileSystemLoader
98
from jinja2.sandbox import SandboxedEnvironment
10-
import sphinx
119
from sphinx.jinja2glue import BuiltinTemplateLoader
1210

13-
from .docscrape import NumpyDocString, FunctionDoc, ClassDoc, ObjDoc
11+
from .docscrape import ClassDoc, FunctionDoc, NumpyDocString, ObjDoc
1412
from .docscrape import get_doc_object as get_doc_object_orig
1513
from .xref import make_xref
1614

17-
1815
IMPORT_MATPLOTLIB_RE = r"\b(import +matplotlib|from +matplotlib +import)\b"
1916

2017

numpydoc/hooks/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import itertools
44
import os
5+
from collections.abc import Sequence
56
from pathlib import Path
6-
from typing import Sequence
77

88

99
def find_project_root(srcs: Sequence[str]):
@@ -31,7 +31,7 @@ def find_project_root(srcs: Sequence[str]):
3131
`Black <https://github.com/psf/black/blob/main/src/black/files.py>`_.
3232
"""
3333
if not srcs:
34-
return Path(".").resolve(), "current directory"
34+
return Path().resolve(), "current directory"
3535

3636
common_path = Path(
3737
os.path.commonpath([Path(src).expanduser().resolve() for src in srcs])

numpydoc/numpydoc.py

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,22 @@
1717
1818
"""
1919

20-
from copy import deepcopy
21-
import re
22-
import pydoc
23-
import inspect
24-
from collections.abc import Callable
2520
import hashlib
21+
import inspect
2622
import itertools
23+
import pydoc
24+
import re
25+
from collections.abc import Callable
26+
from copy import deepcopy
2727

28-
from docutils.nodes import citation, Text, section, comment, reference, inline
29-
import sphinx
30-
from sphinx.addnodes import pending_xref, desc_content
28+
from docutils.nodes import Text, citation, comment, inline, reference, section
29+
from sphinx.addnodes import desc_content, pending_xref
3130
from sphinx.util import logging
32-
from sphinx.errors import ExtensionError
3331

32+
from . import __version__
3433
from .docscrape_sphinx import get_doc_object
35-
from .validate import validate, ERROR_MSGS, get_validation_checks
34+
from .validate import get_validation_checks, validate
3635
from .xref import DEFAULT_LINKS
37-
from . import __version__
3836

3937
logger = logging.getLogger(__name__)
4038

@@ -248,10 +246,10 @@ def mangle_signature(app, what, name, obj, options, sig, retann):
248246
return "", ""
249247

250248
if not (isinstance(obj, Callable) or hasattr(obj, "__argspec_is_invalid_")):
251-
return
249+
return None
252250

253251
if not hasattr(obj, "__doc__"):
254-
return
252+
return None
255253
doc = get_doc_object(obj, config={"show_class_members": False})
256254
sig = doc["Signature"] or _clean_text_signature(
257255
getattr(obj, "__text_signature__", None)
@@ -275,7 +273,7 @@ def _clean_text_signature(sig):
275273

276274
def setup(app, get_doc_object_=get_doc_object):
277275
if not hasattr(app, "add_config_value"):
278-
return # probably called by nose, better bail out
276+
return None # probably called by nose, better bail out
279277

280278
global get_doc_object
281279
get_doc_object = get_doc_object_
@@ -417,12 +415,18 @@ def match_items(lines, content_old):
417415
418416
Examples
419417
--------
420-
>>> lines = ['', 'A', '', 'B', ' ', '', 'C', 'D']
421-
>>> lines_old = ['a', '', '', 'b', '', 'c']
422-
>>> items_old = [('file1.py', 0), ('file1.py', 1), ('file1.py', 2),
423-
... ('file2.py', 0), ('file2.py', 1), ('file2.py', 2)]
418+
>>> lines = ["", "A", "", "B", " ", "", "C", "D"]
419+
>>> lines_old = ["a", "", "", "b", "", "c"]
420+
>>> items_old = [
421+
... ("file1.py", 0),
422+
... ("file1.py", 1),
423+
... ("file1.py", 2),
424+
... ("file2.py", 0),
425+
... ("file2.py", 1),
426+
... ("file2.py", 2),
427+
... ]
424428
>>> content_old = ViewList(lines_old, items=items_old)
425-
>>> match_items(lines, content_old) # doctest: +NORMALIZE_WHITESPACE
429+
>>> match_items(lines, content_old) # doctest: +NORMALIZE_WHITESPACE
426430
[('file1.py', 0), ('file1.py', 0), ('file2.py', 0), ('file2.py', 0),
427431
('file2.py', 2), ('file2.py', 2), ('file2.py', 2), ('file2.py', 2)]
428432
>>> # first 2 ``lines`` are matched to 'a', second 2 to 'b', rest to 'c'

numpydoc/tests/hooks/example_module.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
def some_function(name):
55
"""Welcome to some function."""
6-
pass
76

87

98
class MyClass:
@@ -23,11 +22,9 @@ def do_something(self, *args, **kwargs):
2322
----------
2423
*args
2524
"""
26-
pass
2725

2826
def process(self):
2927
"""Process stuff."""
30-
pass
3128

3229

3330
class NewClass:

numpydoc/tests/hooks/test_validate_hook.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from numpydoc.hooks.validate_docstrings import run_hook
99

1010

11-
@pytest.fixture
11+
@pytest.fixture()
1212
def example_module(request):
1313
fullpath = (
1414
Path(request.config.rootdir)

numpydoc/tests/test_docscrape.py

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
1-
from collections import namedtuple
2-
from copy import deepcopy
31
import re
42
import textwrap
53
import warnings
4+
from collections import namedtuple
5+
from copy import deepcopy
66

77
import jinja2
8+
import pytest
9+
from pytest import warns as assert_warns
810

9-
from numpydoc.numpydoc import update_config
10-
from numpydoc.xref import DEFAULT_LINKS
11-
from numpydoc.docscrape import NumpyDocString, FunctionDoc, ClassDoc, ParseError
11+
from numpydoc.docscrape import ClassDoc, FunctionDoc, NumpyDocString
1212
from numpydoc.docscrape_sphinx import (
13-
SphinxDocString,
1413
SphinxClassDoc,
14+
SphinxDocString,
1515
SphinxFunctionDoc,
1616
get_doc_object,
1717
)
18-
import pytest
19-
from pytest import raises as assert_raises
20-
from pytest import warns as assert_warns
21-
18+
from numpydoc.numpydoc import update_config
19+
from numpydoc.xref import DEFAULT_LINKS
2220

2321
doc_txt = """\
2422
numpy.multivariate_normal(mean, cov, shape=None, spam=None)
@@ -316,11 +314,9 @@ class Dummy:
316314

317315
def spam(self, a, b):
318316
"""Spam\n\nSpam spam."""
319-
pass
320317

321318
def ham(self, c, d):
322319
"""Cheese\n\nNo cheese."""
323-
pass
324320

325321
def dummy_func(arg):
326322
"""
@@ -897,8 +893,6 @@ class Dummy:
897893
func_d
898894
"""
899895

900-
pass
901-
902896
s = str(FunctionDoc(Dummy, role="func"))
903897
assert ":func:`func_a`, :func:`func_b`" in s
904898
assert " some relationship" in s
@@ -941,8 +935,6 @@ class BadSection:
941935
This class has a nope section.
942936
"""
943937

944-
pass
945-
946938
with pytest.warns(UserWarning, match="Unknown section Mope") as record:
947939
NumpyDocString(doc_text)
948940
assert len(record) == 1
@@ -1085,11 +1077,9 @@ class Dummy:
10851077

10861078
def spam(self, a, b):
10871079
"""Spam\n\nSpam spam."""
1088-
pass
10891080

10901081
def ham(self, c, d):
10911082
"""Cheese\n\nNo cheese."""
1092-
pass
10931083

10941084
@property
10951085
def spammity(self):
@@ -1099,8 +1089,6 @@ def spammity(self):
10991089
class Ignorable:
11001090
"""local class, to be ignored"""
11011091

1102-
pass
1103-
11041092
for cls in (ClassDoc, SphinxClassDoc):
11051093
doc = cls(Dummy, config=dict(show_class_members=False))
11061094
assert "Methods" not in str(doc), (cls, str(doc))
@@ -1128,11 +1116,9 @@ class SubDummy(Dummy):
11281116

11291117
def ham(self, c, d):
11301118
"""Cheese\n\nNo cheese.\nOverloaded Dummy.ham"""
1131-
pass
11321119

11331120
def bar(self, a, b):
11341121
"""Bar\n\nNo bar"""
1135-
pass
11361122

11371123
for cls in (ClassDoc, SphinxClassDoc):
11381124
doc = cls(
@@ -1274,7 +1260,7 @@ class Foo:
12741260
@property
12751261
def an_attribute(self):
12761262
"""Test attribute"""
1277-
return None
1263+
return
12781264

12791265
@property
12801266
def no_docstring(self):
@@ -1288,12 +1274,12 @@ def no_docstring2(self):
12881274
def multiline_sentence(self):
12891275
"""This is a
12901276
sentence. It spans multiple lines."""
1291-
return None
1277+
return
12921278

12931279
@property
12941280
def midword_period(self):
12951281
"""The sentence for numpy.org."""
1296-
return None
1282+
return
12971283

12981284
@property
12991285
def no_period(self):
@@ -1302,7 +1288,7 @@ def no_period(self):
13021288
13031289
Apparently.
13041290
"""
1305-
return None
1291+
return
13061292

13071293
doc = SphinxClassDoc(Foo, class_doc_txt)
13081294
line_by_line_compare(
@@ -1378,7 +1364,7 @@ class Foo:
13781364
@property
13791365
def an_attribute(self):
13801366
"""Test attribute"""
1381-
return None
1367+
return
13821368

13831369
attr_doc = """:Attributes:
13841370

numpydoc/tests/test_full.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import os.path as op
22
import re
33
import shutil
4-
from packaging import version
54

65
import pytest
7-
import sphinx
6+
from docutils import __version__ as docutils_version
7+
from packaging import version
88
from sphinx.application import Sphinx
99
from sphinx.util.docutils import docutils_namespace
10-
from docutils import __version__ as docutils_version
1110

1211

1312
# Test framework adapted from sphinx-gallery (BSD 3-clause)

numpydoc/tests/test_main.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def _capture_stdout(func_name, *args, **kwargs):
3333
3434
Examples
3535
--------
36-
>>> _capture_stdout(print, 'hello world')
36+
>>> _capture_stdout(print, "hello world")
3737
'hello world'
3838
"""
3939
f = io.StringIO()
@@ -53,7 +53,6 @@ def _docstring_with_errors():
5353
----------
5454
made_up_param : str
5555
"""
56-
pass
5756

5857

5958
def _invalid_docstring():
@@ -64,7 +63,6 @@ def _invalid_docstring():
6463
--------
6564
: this is invalid
6665
"""
67-
pass
6866

6967

7068
def test_renders_package_docstring():

0 commit comments

Comments
 (0)