Skip to content

Commit 0240ee0

Browse files
authored
build(pyproject.toml): drop support for python 3.9 (require 3.10+) (#641)
* build(pyproject.toml): drop support for python 3.9 (require 3.10+) In upgrading via #592 and #622, requires stable use of __qualname__, not supported in dataclasses in python3.9 (solves #637). * style: Replace isinstance calls that use tuples to the `|` operator as per ruff UP038 * refactor(cli.py): exchange union use for '|' as per ruff UP007 * refactor(test_docscrape): explicitly declare strict=True for testing zips * test(test_docscrape.py): use strict and include 4th parameter check for the docscrape test * refactor(validate.py): remove `Optional[X]` for use of `X | None` ruff UP007, UP045 * refactor(test_docscrape.py): ruff formatting
1 parent afca43f commit 0240ee0

File tree

10 files changed

+25
-20
lines changed

10 files changed

+25
-20
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
strategy:
1717
matrix:
1818
os: [Ubuntu]
19-
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
19+
python-version: ["3.10", "3.11", "3.12", "3.13"]
2020
sphinx-version:
2121
["sphinx==6.0", "sphinx==6.2", "sphinx==7.0", "sphinx>=7.3"]
2222
include:

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ docstrings formatted according to the NumPy documentation format.
1717
The extension also adds the code description directives
1818
``np:function``, ``np-c:function``, etc.
1919

20-
numpydoc requires Python 3.9+ and sphinx 6+.
20+
numpydoc requires Python 3.10+ and sphinx 6+.
2121

2222
For usage information, please refer to the `documentation
2323
<https://numpydoc.readthedocs.io/>`_.

doc/install.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Getting started
55
Installation
66
============
77

8-
This extension requires Python 3.9+, sphinx 6+ and is available from:
8+
This extension requires Python 3.10+, sphinx 6+ and is available from:
99

1010
* `numpydoc on PyPI <http://pypi.python.org/pypi/numpydoc>`_
1111
* `numpydoc on GitHub <https://github.com/numpy/numpydoc/>`_

numpydoc/cli.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
import ast
55
from collections.abc import Sequence
66
from pathlib import Path
7-
from typing import List, Union
7+
from typing import List
88

99
from .docscrape_sphinx import get_doc_object
1010
from .hooks import utils, validate_docstrings
1111
from .validate import ERROR_MSGS, Validator, validate
1212

1313

14-
def render_object(import_path: str, config: Union[List[str], None] = None) -> int:
14+
def render_object(import_path: str, config: List[str] | None = None) -> int:
1515
"""Test numpydoc docstring generation for a given object."""
1616
# TODO: Move Validator._load_obj to a better place than validate
1717
print(get_doc_object(Validator._load_obj(import_path), config=dict(config or [])))
@@ -117,7 +117,7 @@ def _parse_config(s):
117117
return ap
118118

119119

120-
def main(argv: Union[Sequence[str], None] = None) -> int:
120+
def main(argv: Sequence[str] | None = None) -> int:
121121
"""CLI for numpydoc."""
122122
ap = get_parser()
123123

numpydoc/docscrape.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,7 @@ def properties(self):
701701
and not self._should_skip_member(name, self._cls)
702702
and (
703703
func is None
704-
or isinstance(func, (property, cached_property))
704+
or isinstance(func, property | cached_property)
705705
or inspect.isdatadescriptor(func)
706706
)
707707
and self._is_show_member(name)

numpydoc/hooks/validate_docstrings.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def name(self) -> str:
6363

6464
@property
6565
def is_function_or_method(self) -> bool:
66-
return isinstance(self.node, (ast.FunctionDef, ast.AsyncFunctionDef))
66+
return isinstance(self.node, ast.FunctionDef | ast.AsyncFunctionDef)
6767

6868
@property
6969
def is_mod(self) -> bool:
@@ -236,7 +236,7 @@ def visit(self, node: ast.AST) -> None:
236236
The node to visit.
237237
"""
238238
if isinstance(
239-
node, (ast.Module, ast.ClassDef, ast.FunctionDef, ast.AsyncFunctionDef)
239+
node, ast.Module | ast.ClassDef | ast.FunctionDef | ast.AsyncFunctionDef
240240
):
241241
self.stack.append(node)
242242

@@ -395,8 +395,8 @@ def process_file(filepath: os.PathLike, config: dict) -> "list[list[str]]":
395395
def run_hook(
396396
files: List[str],
397397
*,
398-
config: Union[Dict[str, Any], None] = None,
399-
ignore: Union[List[str], None] = None,
398+
config: Dict[str, Any] | None = None,
399+
ignore: List[str] | None = None,
400400
) -> int:
401401
"""
402402
Run the numpydoc validation hook.

numpydoc/numpydoc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def _is_cite_in_numpydoc_docstring(citation_node):
8888
section_node = citation_node.parent
8989

9090
def is_docstring_section(node):
91-
return isinstance(node, (section, desc_content))
91+
return isinstance(node, section | desc_content)
9292

9393
while not is_docstring_section(section_node):
9494
section_node = section_node.parent

numpydoc/tests/test_docscrape.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,9 @@ def test_extended_summary(doc):
187187
def test_parameters(doc):
188188
assert len(doc["Parameters"]) == 4
189189
names = [n for n, _, _ in doc["Parameters"]]
190-
assert all(a == b for a, b in zip(names, ["mean", "cov", "shape"]))
190+
assert all(
191+
a == b for a, b in zip(names, ["mean", "cov", "shape", "dtype"], strict=True)
192+
)
191193

192194
arg, arg_type, desc = doc["Parameters"][1]
193195
assert arg_type == "(N, N) ndarray"
@@ -242,7 +244,9 @@ def test_yields():
242244
("b", "int", "bananas."),
243245
("", "int", "unknowns."),
244246
]
245-
for (arg, arg_type, desc), (arg_, arg_type_, end) in zip(section, truth):
247+
for (arg, arg_type, desc), (arg_, arg_type_, end) in zip(
248+
section, truth, strict=True
249+
):
246250
assert arg == arg_
247251
assert arg_type == arg_type_
248252
assert desc[0].startswith("The number of")
@@ -253,7 +257,9 @@ def test_sent():
253257
section = doc_sent["Receives"]
254258
assert len(section) == 2
255259
truth = [("b", "int", "bananas."), ("c", "int", "oranges.")]
256-
for (arg, arg_type, desc), (arg_, arg_type_, end) in zip(section, truth):
260+
for (arg, arg_type, desc), (arg_, arg_type_, end) in zip(
261+
section, truth, strict=True
262+
):
257263
assert arg == arg_
258264
assert arg_type == arg_type_
259265
assert desc[0].startswith("The number of")
@@ -374,7 +380,7 @@ def line_by_line_compare(a, b, n_lines=None):
374380
a = [l.rstrip() for l in _strip_blank_lines(a).split("\n")][:n_lines]
375381
b = [l.rstrip() for l in _strip_blank_lines(b).split("\n")][:n_lines]
376382
assert len(a) == len(b)
377-
for ii, (aa, bb) in enumerate(zip(a, b)):
383+
for ii, (aa, bb) in enumerate(zip(a, b, strict=True)):
378384
assert aa == bb
379385

380386

numpydoc/validate.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import textwrap
1818
import tokenize
1919
from copy import deepcopy
20-
from typing import Any, Dict, List, Optional, Set
20+
from typing import Any, Dict, List, Set
2121

2222
from .docscrape import get_doc_object
2323

@@ -124,7 +124,7 @@ def _unwrap(obj):
124124
# and pandas, and they had between ~500 and ~1300 .py files as of 2023-08-16.
125125
@functools.lru_cache(maxsize=2000)
126126
def extract_ignore_validation_comments(
127-
filepath: Optional[os.PathLike],
127+
filepath: os.PathLike | None,
128128
encoding: str = "utf-8",
129129
) -> Dict[int, List[str]]:
130130
"""

pyproject.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ requires = ['setuptools>=61.2']
66
name = 'numpydoc'
77
description = 'Sphinx extension to support docstrings in Numpy format'
88
readme = 'README.rst'
9-
requires-python = '>=3.9'
9+
requires-python = '>=3.10'
1010
dynamic = ['version']
1111
keywords = [
1212
'sphinx',
@@ -20,7 +20,6 @@ classifiers = [
2020
'Operating System :: OS Independent',
2121
'Programming Language :: Python',
2222
'Programming Language :: Python :: 3',
23-
'Programming Language :: Python :: 3.9',
2423
'Programming Language :: Python :: 3.10',
2524
'Programming Language :: Python :: 3.11',
2625
'Programming Language :: Python :: 3.12',

0 commit comments

Comments
 (0)