Skip to content

Commit 3b6eeda

Browse files
committed
Fixes from pydocstyle
1 parent e1c8b8e commit 3b6eeda

27 files changed

+93
-102
lines changed

src/_pytest/_argcomplete.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171

7272

7373
class FastFilesCompleter:
74-
"Fast file completer class."
74+
"""Fast file completer class."""
7575

7676
def __init__(self, directories: bool = True) -> None:
7777
self.directories = directories

src/_pytest/_code/code.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ def from_exc_info(
411411
exc_info: Tuple["Type[_E]", "_E", TracebackType],
412412
exprinfo: Optional[str] = None,
413413
) -> "ExceptionInfo[_E]":
414-
"""Returns an ExceptionInfo for an existing exc_info tuple.
414+
"""Return an ExceptionInfo for an existing exc_info tuple.
415415
416416
.. warning::
417417
@@ -436,7 +436,7 @@ def from_exc_info(
436436
def from_current(
437437
cls, exprinfo: Optional[str] = None
438438
) -> "ExceptionInfo[BaseException]":
439-
"""Returns an ExceptionInfo matching the current traceback.
439+
"""Return an ExceptionInfo matching the current traceback.
440440
441441
.. warning::
442442
@@ -1011,7 +1011,7 @@ class ReprEntry(TerminalRepr):
10111011
style = attr.ib(type="_TracebackStyle")
10121012

10131013
def _write_entry_lines(self, tw: TerminalWriter) -> None:
1014-
"""Writes the source code portions of a list of traceback entries with syntax highlighting.
1014+
"""Write the source code portions of a list of traceback entries with syntax highlighting.
10151015
10161016
Usually entries are lines like these:
10171017

src/_pytest/assertion/rewrite.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ def exec_module(self, module: types.ModuleType) -> None:
170170
exec(co, module.__dict__)
171171

172172
def _early_rewrite_bailout(self, name: str, state: "AssertionState") -> bool:
173-
"""This is a fast way to get out of rewriting modules.
173+
"""A fast way to get out of rewriting modules.
174174
175175
Profiling has shown that the call to PathFinder.find_spec (inside of
176176
the find_spec from this class) is a major slowdown, so, this method
@@ -350,7 +350,7 @@ def _write_pyc(
350350

351351

352352
def _rewrite_test(fn: Path, config: Config) -> Tuple[os.stat_result, types.CodeType]:
353-
"""read and rewrite *fn* and return the code object."""
353+
"""Read and rewrite *fn* and return the code object."""
354354
fn_ = fspath(fn)
355355
stat = os.stat(fn_)
356356
with open(fn_, "rb") as f:
@@ -411,7 +411,7 @@ def rewrite_asserts(
411411

412412

413413
def _saferepr(obj: object) -> str:
414-
"""Get a safe repr of an object for assertion error messages.
414+
r"""Get a safe repr of an object for assertion error messages.
415415
416416
The assertion formatting (util.format_explanation()) requires
417417
newlines to be escaped since they are a special character for it.
@@ -424,7 +424,7 @@ def _saferepr(obj: object) -> str:
424424

425425

426426
def _format_assertmsg(obj: object) -> str:
427-
"""Format the custom assertion message given.
427+
r"""Format the custom assertion message given.
428428
429429
For strings this simply replaces newlines with '\n~' so that
430430
util.format_explanation() will preserve them instead of escaping
@@ -489,7 +489,7 @@ def _call_assertion_pass(lineno: int, orig: str, expl: str) -> None:
489489

490490

491491
def _check_if_assertion_pass_impl() -> bool:
492-
"""Checks if any plugins implement the pytest_assertion_pass hook
492+
"""Check if any plugins implement the pytest_assertion_pass hook
493493
in order not to generate explanation unecessarily (might be expensive)."""
494494
return True if util._assertion_pass else False
495495

@@ -539,7 +539,7 @@ def _fix(node, lineno, col_offset):
539539

540540

541541
def _get_assertion_exprs(src: bytes) -> Dict[int, str]:
542-
"""Returns a mapping from {lineno: "assertion test expression"}."""
542+
"""Return a mapping from {lineno: "assertion test expression"}."""
543543
ret = {} # type: Dict[int, str]
544544

545545
depth = 0
@@ -1066,7 +1066,7 @@ def visit_Compare(self, comp: ast.Compare) -> Tuple[ast.expr, str]:
10661066

10671067

10681068
def try_makedirs(cache_dir: Path) -> bool:
1069-
"""Attempts to create the given directory and sub-directories exist.
1069+
"""Attempt to create the given directory and sub-directories exist.
10701070
10711071
Returns True if successful or if it already exists.
10721072
"""
@@ -1088,7 +1088,7 @@ def try_makedirs(cache_dir: Path) -> bool:
10881088

10891089

10901090
def get_cache_dir(file_path: Path) -> Path:
1091-
"""Returns the cache directory to write .pyc files for the given .py file path."""
1091+
"""Return the cache directory to write .pyc files for the given .py file path."""
10921092
if sys.version_info >= (3, 8) and sys.pycache_prefix:
10931093
# given:
10941094
# prefix = '/tmp/pycs'

src/_pytest/assertion/truncate.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
"""
2-
Utilities for truncating assertion output.
1+
"""Utilities for truncating assertion output.
32
43
Current default behaviour is to truncate assertion explanations at
54
~8 terminal lines, unless running in "-vv" mode or running on CI.

src/_pytest/cacheprovider.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def for_config(cls, config: Config) -> "Cache":
7070

7171
@classmethod
7272
def clear_cache(cls, cachedir: Path) -> None:
73-
"""Clears the sub-directories used to hold cached directories and values."""
73+
"""Clear the sub-directories used to hold cached directories and values."""
7474
for prefix in (cls._CACHE_PREFIX_DIRS, cls._CACHE_PREFIX_VALUES):
7575
d = cachedir / prefix
7676
if d.is_dir():
@@ -263,7 +263,7 @@ def __init__(self, config: Config) -> None:
263263
)
264264

265265
def get_last_failed_paths(self) -> Set[Path]:
266-
"""Returns a set with all Paths()s of the previously failed nodeids."""
266+
"""Return a set with all Paths()s of the previously failed nodeids."""
267267
rootpath = Path(str(self.config.rootdir))
268268
result = {rootpath / nodeid.split("::")[0] for nodeid in self.lastfailed}
269269
return {x for x in result if x.exists()}

src/_pytest/capture.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ def resume(self) -> None:
458458
self._state = "started"
459459

460460
def writeorg(self, data):
461-
""" write to original file descriptor. """
461+
"""Write to original file descriptor."""
462462
self._assert_state("writeorg", ("started", "suspended"))
463463
os.write(self.targetfd_save, data)
464464

src/_pytest/compat.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
"""
2-
python version compatibility code
3-
"""
1+
"""Python version compatibility code."""
42
import enum
53
import functools
64
import inspect
@@ -143,13 +141,13 @@ def getfuncargnames(
143141
is_method: bool = False,
144142
cls: Optional[type] = None
145143
) -> Tuple[str, ...]:
146-
"""Returns the names of a function's mandatory arguments.
144+
"""Return the names of a function's mandatory arguments.
147145
148-
This should return the names of all function arguments that:
149-
* Aren't bound to an instance or type as in instance or class methods.
150-
* Don't have default values.
151-
* Aren't bound with functools.partial.
152-
* Aren't replaced with mocks.
146+
Should return the names of all function arguments that:
147+
* Aren't bound to an instance or type as in instance or class methods.
148+
* Don't have default values.
149+
* Aren't bound with functools.partial.
150+
* Aren't replaced with mocks.
153151
154152
The is_method and cls arguments indicate that the function should
155153
be treated as a bound method even though it's not unless, only in

src/_pytest/config/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
""" command line options, ini-file and conftest.py processing. """
1+
"""Command line options, ini-file and conftest.py processing."""
22
import argparse
33
import collections.abc
44
import contextlib
@@ -173,7 +173,7 @@ def main(
173173

174174

175175
def console_main() -> int:
176-
"""pytest's CLI entry point.
176+
"""The CLI entry point of pytest.
177177
178178
This function is not meant for programmable use; use `main()` instead.
179179
"""
@@ -1354,11 +1354,11 @@ def getoption(self, name: str, default=notset, skip: bool = False):
13541354
raise ValueError("no option named {!r}".format(name)) from e
13551355

13561356
def getvalue(self, name: str, path=None):
1357-
"""(deprecated, use getoption())"""
1357+
"""Deprecated, use getoption() instead."""
13581358
return self.getoption(name)
13591359

13601360
def getvalueorskip(self, name: str, path=None):
1361-
"""(deprecated, use getoption(skip=True))"""
1361+
"""Deprecated, use getoption(skip=True) instead."""
13621362
return self.getoption(name, skip=True)
13631363

13641364
def _warn_about_missing_assertion(self, mode: str) -> None:

src/_pytest/config/argparsing.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,16 +140,15 @@ def parse_known_args(
140140
args: Sequence[Union[str, py.path.local]],
141141
namespace: Optional[argparse.Namespace] = None,
142142
) -> argparse.Namespace:
143-
"""Parses and returns a namespace object with known arguments at this
144-
point."""
143+
"""Parse and return a namespace object with known arguments at this point."""
145144
return self.parse_known_and_unknown_args(args, namespace=namespace)[0]
146145

147146
def parse_known_and_unknown_args(
148147
self,
149148
args: Sequence[Union[str, py.path.local]],
150149
namespace: Optional[argparse.Namespace] = None,
151150
) -> Tuple[argparse.Namespace, List[str]]:
152-
"""Parses and returns a namespace object with known arguments, and
151+
"""Parse and return a namespace object with known arguments, and
153152
the remaining arguments unknown at this point."""
154153
optparser = self._getparser()
155154
strargs = [str(x) if isinstance(x, py.path.local) else x for x in args]
@@ -402,7 +401,7 @@ def parse_args( # type: ignore
402401
args: Optional[Sequence[str]] = None,
403402
namespace: Optional[argparse.Namespace] = None,
404403
) -> argparse.Namespace:
405-
"""allow splitting of positional arguments"""
404+
"""Allow splitting of positional arguments."""
406405
parsed, unrecognized = self.parse_known_args(args, namespace)
407406
if unrecognized:
408407
for arg in unrecognized:

src/_pytest/debugging.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
""" interactive debugging with PDB, the Python Debugger. """
1+
"""Interactive debugging with PDB, the Python Debugger."""
22
import argparse
33
import functools
44
import sys
@@ -298,10 +298,10 @@ def pytest_pyfunc_call(self, pyfuncitem) -> Generator[None, None, None]:
298298

299299

300300
def wrap_pytest_function_for_tracing(pyfuncitem):
301-
"""Changes the python function object of the given Function item by a wrapper which actually
302-
enters pdb before calling the python function itself, effectively leaving the user
303-
in the pdb prompt in the first statement of the function.
304-
"""
301+
"""Change the Python function object of the given Function item by a
302+
wrapper which actually enters pdb before calling the python function
303+
itself, effectively leaving the user in the pdb prompt in the first
304+
statement of the function."""
305305
_pdb = pytestPDB._init_pdb("runcall")
306306
testfunction = pyfuncitem.obj
307307

src/_pytest/deprecated.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
"""This module contains deprecation messages and bits of code used elsewhere
2-
in the codebase that is planned to be removed in the next pytest release.
1+
"""Deprecation messages and bits of code used elsewhere in the codebase that
2+
is planned to be removed in the next pytest release.
33
44
Keeping it in a central location makes it easy to track what is deprecated and should
55
be removed when the time comes.

src/_pytest/helpconfig.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
""" version info, help messages, tracing configuration. """
1+
"""Version info, help messages, tracing configuration."""
22
import os
33
import sys
44
from argparse import Action

src/_pytest/hookspec.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ def pytest_make_parametrize_id(
375375

376376
@hookspec(firstresult=True)
377377
def pytest_runtestloop(session: "Session") -> Optional[object]:
378-
"""Performs the main runtest loop (after collection finished).
378+
"""Perform the main runtest loop (after collection finished).
379379
380380
The default hook implementation performs the runtest protocol for all items
381381
collected in the session (``session.items``), unless the collection failed
@@ -398,7 +398,7 @@ def pytest_runtestloop(session: "Session") -> Optional[object]:
398398
def pytest_runtest_protocol(
399399
item: "Item", nextitem: "Optional[Item]"
400400
) -> Optional[object]:
401-
"""Performs the runtest protocol for a single test item.
401+
"""Perform the runtest protocol for a single test item.
402402
403403
The default runtest protocol is this (see individual hooks for full details):
404404

src/_pytest/junitxml.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ def test_foo(record_testsuite_property):
380380
__tracebackhide__ = True
381381

382382
def record_func(name: str, value: object) -> None:
383-
"""noop function in case --junitxml was not passed in the command-line."""
383+
"""No-op function in case --junitxml was not passed in the command-line."""
384384
__tracebackhide__ = True
385385
_check_record_param_type("name", name)
386386

src/_pytest/logging.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ class LogCaptureHandler(logging.StreamHandler):
317317
stream = None # type: StringIO
318318

319319
def __init__(self) -> None:
320-
"""Creates a new log handler."""
320+
"""Create a new log handler."""
321321
super().__init__(StringIO())
322322
self.records = [] # type: List[logging.LogRecord]
323323

@@ -348,7 +348,7 @@ def __init__(self, item: nodes.Node) -> None:
348348
self._initial_logger_levels = {} # type: Dict[Optional[str], int]
349349

350350
def _finalize(self) -> None:
351-
"""Finalizes the fixture.
351+
"""Finalize the fixture.
352352
353353
This restores the log levels changed by :meth:`set_level`.
354354
"""
@@ -511,7 +511,7 @@ class LoggingPlugin:
511511
"""Attaches to the logging module and captures log messages for each test."""
512512

513513
def __init__(self, config: Config) -> None:
514-
"""Creates a new plugin to capture log messages.
514+
"""Create a new plugin to capture log messages.
515515
516516
The formatter can be safely shared across all handlers so
517517
create a single one for the entire test session here.

src/_pytest/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ def validate_basetemp(path: str) -> str:
205205
raise argparse.ArgumentTypeError(msg)
206206

207207
def is_ancestor(base: Path, query: Path) -> bool:
208-
""" return True if query is an ancestor of base, else False."""
208+
"""Return whether query is an ancestor of base."""
209209
if base == query:
210210
return True
211211
for parent in base.parents:

src/_pytest/mark/structures.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ def extract_from(
108108
parameterset: Union["ParameterSet", Sequence[object], object],
109109
force_tuple: bool = False,
110110
) -> "ParameterSet":
111-
"""
111+
"""Extract from an object or objects.
112+
112113
:param parameterset:
113114
A legacy style parameterset that may or may not be a tuple,
114115
and may or may not be wrapped into a mess of mark objects.

src/_pytest/pathlib.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def ensure_extended_length_path(path: Path) -> Path:
126126

127127

128128
def get_extended_length_path_str(path: str) -> str:
129-
"""Converts to extended length path as a str."""
129+
"""Convert a path to a Windows extended length path."""
130130
long_path_prefix = "\\\\?\\"
131131
unc_long_path_prefix = "\\\\?\\UNC\\"
132132
if path.startswith((long_path_prefix, unc_long_path_prefix)):
@@ -154,10 +154,10 @@ def find_prefixed(root: Path, prefix: str) -> Iterator[Path]:
154154

155155

156156
def extract_suffixes(iter: Iterable[PurePath], prefix: str) -> Iterator[str]:
157-
"""
157+
"""Return the parts of the paths following the prefix.
158+
158159
:param iter: Iterator over path names.
159160
:param prefix: Expected prefix of the path names.
160-
:returns: The parts of the paths following the prefix.
161161
"""
162162
p_len = len(prefix)
163163
for p in iter:
@@ -283,7 +283,7 @@ def maybe_delete_a_numbered_dir(path: Path) -> None:
283283

284284

285285
def ensure_deletable(path: Path, consider_lock_dead_if_created_before: float) -> bool:
286-
"""checks if a lock exists and breaks it if its considered dead"""
286+
"""Check if a lock exists and breaks it if it's considered dead."""
287287
if path.is_symlink():
288288
return False
289289
lock = get_lock_path(path)
@@ -372,7 +372,7 @@ def resolve_from_str(input: str, root: py.path.local) -> Path:
372372

373373

374374
def fnmatch_ex(pattern: str, path) -> bool:
375-
"""FNMatcher port from py.path.common which works with PurePath() instances.
375+
"""A port of FNMatcher from py.path.common which works with PurePath() instances.
376376
377377
The difference between this algorithm and PurePath.match() is that the
378378
latter matches "**" glob expressions for each part of the path, while

0 commit comments

Comments
 (0)