Skip to content

Fix pydocstyle D209 (Multi-line docstring closing separate line) #16874

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ ignore =
N801, N802, N803, N806, N812,
# pydocstyle
D100, D101, D102, D103, D104, D105, D106, D107,
D200, D202, D203, D204, D205, D207, D209, D212, D213,
D200, D202, D203, D204, D205, D207, D212, D213,
D301
D400, D401, D402, D403, D413,

Expand Down
28 changes: 19 additions & 9 deletions lib/matplotlib/backends/backend_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,12 @@


def fill(strings, linelen=75):
"""Make one string from sequence of strings, with whitespace
in between. The whitespace is chosen to form lines of at most
linelen characters, if possible."""
"""
Make one string from sequence of strings, with whitespace in between.

The whitespace is chosen to form lines of at most *linelen* characters,
if possible.
"""
currpos = 0
lasti = 0
result = []
Expand Down Expand Up @@ -295,8 +298,7 @@ def pdfRepr(self):


class Verbatim:
"""Store verbatim PDF command content for later inclusion in the
stream."""
"""Store verbatim PDF command content for later inclusion in the stream."""
def __init__(self, x):
self._x = x

Expand All @@ -322,9 +324,16 @@ def pdfRepr(self):


def _paint_path(fill, stroke):
"""Return the PDF operator to paint a path in the following way:
fill: fill the path with the fill color
stroke: stroke the outline of the path with the line color"""
"""
Return the PDF operator to paint a path.

Parameters
----------
fill: bool
Fill the path with the fill color.
stroke: bool
Stroke the outline of the path with the line color.
"""
if stroke:
if fill:
return Op.fill_stroke
Expand All @@ -339,7 +348,8 @@ def _paint_path(fill, stroke):


class Stream:
"""PDF stream object.
"""
PDF stream object.

This has no pdfRepr method. Instead, call begin(), then output the
contents of the stream by calling write(), and finally call end().
Expand Down
37 changes: 24 additions & 13 deletions lib/matplotlib/dviread.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,45 +69,55 @@
# argument bytes in this delta.

def _arg_raw(dvi, delta):
"""Return *delta* without reading anything more from the dvi file"""
"""Return *delta* without reading anything more from the dvi file."""
return delta


def _arg(bytes, signed, dvi, _):
"""Read *bytes* bytes, returning the bytes interpreted as a
signed integer if *signed* is true, unsigned otherwise."""
"""
Read *bytes* bytes, returning the bytes interpreted as a signed integer
if *signed* is true, unsigned otherwise.
"""
return dvi._arg(bytes, signed)


def _arg_slen(dvi, delta):
"""Signed, length *delta*
"""
Signed, length *delta*

Read *delta* bytes, returning None if *delta* is zero, and
the bytes interpreted as a signed integer otherwise."""
Read *delta* bytes, returning None if *delta* is zero, and the bytes
interpreted as a signed integer otherwise.
"""
if delta == 0:
return None
return dvi._arg(delta, True)


def _arg_slen1(dvi, delta):
"""Signed, length *delta*+1
"""
Signed, length *delta*+1

Read *delta*+1 bytes, returning the bytes interpreted as signed."""
Read *delta*+1 bytes, returning the bytes interpreted as signed.
"""
return dvi._arg(delta+1, True)


def _arg_ulen1(dvi, delta):
"""Unsigned length *delta*+1
"""
Unsigned length *delta*+1

Read *delta*+1 bytes, returning the bytes interpreted as unsigned."""
Read *delta*+1 bytes, returning the bytes interpreted as unsigned.
"""
return dvi._arg(delta+1, False)


def _arg_olen1(dvi, delta):
"""Optionally signed, length *delta*+1
"""
Optionally signed, length *delta*+1

Read *delta*+1 bytes, returning the bytes interpreted as
unsigned integer for 0<=*delta*<3 and signed if *delta*==3."""
unsigned integer for 0<=*delta*<3 and signed if *delta*==3.
"""
return dvi._arg(delta + 1, delta == 3)


Expand All @@ -122,7 +132,8 @@ def _arg_olen1(dvi, delta):


def _dispatch(table, min, max=None, state=None, args=('raw',)):
"""Decorator for dispatch by opcode. Sets the values in *table*
"""
Decorator for dispatch by opcode. Sets the values in *table*
from *min* to *max* to this method, adds a check that the Dvi state
matches *state* if not None, reads arguments from the file according
to *args*.
Expand Down
47 changes: 31 additions & 16 deletions lib/matplotlib/tests/test_colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -592,8 +592,10 @@ def test_light_source_topo_surface():


def test_light_source_shading_default():
"""Array comparison test for the default "hsv" blend mode. Ensure the
default result doesn't change without warning."""
"""
Array comparison test for the default "hsv" blend mode. Ensure the
default result doesn't change without warning.
"""
y, x = np.mgrid[-1.2:1.2:8j, -1.2:1.2:8j]
z = 10 * np.cos(x**2 + y**2)

Expand Down Expand Up @@ -647,8 +649,10 @@ def test_light_source_shading_default():
# additional elements being masked when calculating the gradient thus
# the output is different with earlier numpy versions.
def test_light_source_masked_shading():
"""Array comparison test for a surface with a masked portion. Ensures that
we don't wind up with "fringes" of odd colors around masked regions."""
"""
Array comparison test for a surface with a masked portion. Ensures that
we don't wind up with "fringes" of odd colors around masked regions.
"""
y, x = np.mgrid[-1.2:1.2:8j, -1.2:1.2:8j]
z = 10 * np.cos(x**2 + y**2)

Expand Down Expand Up @@ -701,8 +705,10 @@ def test_light_source_masked_shading():


def test_light_source_hillshading():
"""Compare the current hillshading method against one that should be
mathematically equivalent. Illuminates a cone from a range of angles."""
"""
Compare the current hillshading method against one that should be
mathematically equivalent. Illuminates a cone from a range of angles.
"""

def alternative_hillshade(azimuth, elev, z):
illum = _sph2cart(*_azimuth2math(azimuth, elev))
Expand Down Expand Up @@ -730,20 +736,25 @@ def alternative_hillshade(azimuth, elev, z):


def test_light_source_planar_hillshading():
"""Ensure that the illumination intensity is correct for planar
surfaces."""
"""
Ensure that the illumination intensity is correct for planar surfaces.
"""

def plane(azimuth, elevation, x, y):
"""Create a plane whose normal vector is at the given azimuth and
elevation."""
"""
Create a plane whose normal vector is at the given azimuth and
elevation.
"""
theta, phi = _azimuth2math(azimuth, elevation)
a, b, c = _sph2cart(theta, phi)
z = -(a*x + b*y) / c
return z

def angled_plane(azimuth, elevation, angle, x, y):
"""Create a plane whose normal vector is at an angle from the given
azimuth and elevation."""
"""
Create a plane whose normal vector is at an angle from the given
azimuth and elevation.
"""
elevation = elevation + angle
if elevation > 90:
azimuth = (azimuth + 180) % 360
Expand Down Expand Up @@ -775,8 +786,10 @@ def _sph2cart(theta, phi):


def _azimuth2math(azimuth, elevation):
"""Converts from clockwise-from-north and up-from-horizontal to
mathematical conventions."""
"""
Convert from clockwise-from-north and up-from-horizontal to mathematical
conventions.
"""
theta = np.radians((90 - azimuth) % 360)
phi = np.radians(90 - elevation)
return theta, phi
Expand All @@ -795,8 +808,10 @@ def test_pandas_iterable(pd):

@pytest.mark.parametrize('name', sorted(cm.cmap_d))
def test_colormap_reversing(name):
"""Check the generated _lut data of a colormap and corresponding
reversed colormap if they are almost the same."""
"""
Check the generated _lut data of a colormap and corresponding reversed
colormap if they are almost the same.
"""
cmap = plt.get_cmap(name)
cmap_r = cmap.reversed()
if not cmap_r._isinit:
Expand Down
24 changes: 8 additions & 16 deletions lib/matplotlib/tests/test_mlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -1561,44 +1561,38 @@ def test_single_dataset_element(self):
mlab.GaussianKDE([42])

def test_silverman_multidim_dataset(self):
"""Use a multi-dimensional array as the dataset and test silverman's
output"""
"""Test silverman's for a multi-dimensional array."""
x1 = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
with pytest.raises(np.linalg.LinAlgError):
mlab.GaussianKDE(x1, "silverman")

def test_silverman_singledim_dataset(self):
"""Use a single dimension list as the dataset and test silverman's
output."""
"""Test silverman's output for a single dimension list."""
x1 = np.array([-7, -5, 1, 4, 5])
mygauss = mlab.GaussianKDE(x1, "silverman")
y_expected = 0.76770389927475502
assert_almost_equal(mygauss.covariance_factor(), y_expected, 7)

def test_scott_multidim_dataset(self):
"""Use a multi-dimensional array as the dataset and test scott's output
"""
"""Test scott's output for a multi-dimensional array."""
x1 = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
with pytest.raises(np.linalg.LinAlgError):
mlab.GaussianKDE(x1, "scott")

def test_scott_singledim_dataset(self):
"""Use a single-dimensional array as the dataset and test scott's
output"""
"""Test scott's output a single-dimensional array."""
x1 = np.array([-7, -5, 1, 4, 5])
mygauss = mlab.GaussianKDE(x1, "scott")
y_expected = 0.72477966367769553
assert_almost_equal(mygauss.covariance_factor(), y_expected, 7)

def test_scalar_empty_dataset(self):
"""Use an empty array as the dataset and test the scalar's cov factor
"""
"""Test the scalar's cov factor for an empty array."""
with pytest.raises(ValueError):
mlab.GaussianKDE([], bw_method=5)

def test_scalar_covariance_dataset(self):
"""Use a dataset and test a scalar's cov factor
"""
"""Test a scalar's cov factor."""
np.random.seed(8765678)
n_basesample = 50
multidim_data = [np.random.randn(n_basesample) for i in range(5)]
Expand All @@ -1607,8 +1601,7 @@ def test_scalar_covariance_dataset(self):
assert kde.covariance_factor() == 0.5

def test_callable_covariance_dataset(self):
"""Use a multi-dimensional array as the dataset and test the callable's
cov factor"""
"""Test the callable's cov factor for a multi-dimensional array."""
np.random.seed(8765678)
n_basesample = 50
multidim_data = [np.random.randn(n_basesample) for i in range(5)]
Expand All @@ -1619,8 +1612,7 @@ def callable_fun(x):
assert kde.covariance_factor() == 0.55

def test_callable_singledim_dataset(self):
"""Use a single-dimensional array as the dataset and test the
callable's cov factor"""
"""Test the callable's cov factor for a single-dimensional array."""
np.random.seed(8765678)
n_basesample = 50
multidim_data = np.random.randn(n_basesample)
Expand Down