diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1fa15182..0e15402b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -25,7 +25,7 @@ repos: args: [--prose-wrap=preserve] - repo: https://github.com/astral-sh/ruff-pre-commit - rev: "971923581912ef60a6b70dbf0c3e9a39563c9d47" # frozen: v0.11.4 + rev: "0b19ef1fd6ad680ed7752d6daba883ce1265a6de" # frozen: v0.12.2 hooks: - id: ruff args: ["--fix", "--show-fixes", "--exit-non-zero-on-fix"] diff --git a/numpydoc/__init__.py b/numpydoc/__init__.py index 5458b67f..381a4ab8 100644 --- a/numpydoc/__init__.py +++ b/numpydoc/__init__.py @@ -7,6 +7,6 @@ def setup(app, *args, **kwargs): - from .numpydoc import setup + from .numpydoc import setup # noqa: PLC0415 return setup(app, *args, **kwargs) diff --git a/numpydoc/docscrape.py b/numpydoc/docscrape.py index 54863d5f..09d3b69e 100644 --- a/numpydoc/docscrape.py +++ b/numpydoc/docscrape.py @@ -627,7 +627,7 @@ def __init__(self, cls, doc=None, modulename="", func_doc=FunctionDoc, config=No self._cls = cls if "sphinx" in sys.modules: - from sphinx.ext.autodoc import ALL + from sphinx.ext.autodoc import ALL # noqa: PLC0415 else: ALL = object() diff --git a/numpydoc/tests/test_docscrape.py b/numpydoc/tests/test_docscrape.py index f10adc45..09cfa4ce 100644 --- a/numpydoc/tests/test_docscrape.py +++ b/numpydoc/tests/test_docscrape.py @@ -2,7 +2,9 @@ import textwrap import warnings from collections import namedtuple +from collections.abc import Callable from copy import deepcopy +from functools import cached_property import jinja2 import pytest @@ -1623,7 +1625,6 @@ def test__error_location_no_name_attr(): See gh-362 """ - from collections.abc import Callable # Create a Callable that doesn't have a __name__ attribute class Foo: @@ -1644,7 +1645,6 @@ def __call__(self): def test_class_docstring_cached_property(): """Ensure that properties marked with the `cached_property` decorator are listed in the Methods section. See gh-432.""" - from functools import cached_property class Foo: _x = [1, 2, 3] @@ -1664,8 +1664,6 @@ def test_namedtuple_no_duplicate_attributes(): See gh-257 """ - from collections import namedtuple - foo = namedtuple("Foo", ("bar", "baz")) # Create the SphinxClassDoc object via get_doc_object @@ -1678,8 +1676,6 @@ def test_namedtuple_class_docstring(): See gh-257 """ - from collections import namedtuple - foo = namedtuple("Foo", ("bar", "baz")) class MyFoo(foo): diff --git a/numpydoc/tests/test_validate.py b/numpydoc/tests/test_validate.py index 9f0f7942..96d688d2 100644 --- a/numpydoc/tests/test_validate.py +++ b/numpydoc/tests/test_validate.py @@ -1390,12 +1390,9 @@ def test_bad_class(self, capsys): "too_short_header_underline", ], ) - def test_bad_generic_functions(self, capsys, func): - with pytest.warns(UserWarning): - errors = validate_one( - self._import_path(klass="WarnGenericFormat", func=func) - ) - assert "is too short" in w.msg + def test_bad_generic_functions_new(self, capsys, func): + with pytest.warns(UserWarning, match="is too short"): + validate_one(self._import_path(klass="WarnGenericFormat", func=func)) @pytest.mark.parametrize( "func",