Skip to content

Commit 3097f47

Browse files
authored
maintain: Drop Python 3.9 support. Modernize with pyupgrade (#541)
1 parent d944a56 commit 3097f47

File tree

10 files changed

+18
-24
lines changed

10 files changed

+18
-24
lines changed

.github/workflows/tests.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
runs-on: ${{ matrix.os }}
3434
strategy:
3535
matrix:
36-
python-version: ['3.9', '3.10', '3.11', '3.12', '3.13', '3.14-dev']
36+
python-version: ['3.10', '3.11', '3.12', '3.13', '3.14-dev']
3737
os: [ubuntu-latest, macos-latest, windows-latest]
3838
continue-on-error: ${{ matrix.python-version == '3.14-dev' }}
3939

pyproject.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@ authors = [
1111
{ name = "Taneli Hukkinen", email = "[email protected]" },
1212
]
1313
license = { file = "LICENSE" }
14-
requires-python = ">=3.9"
14+
requires-python = ">=3.10"
1515
dependencies = [
1616
'markdown-it-py>=1,<5',
1717
'tomli >=1.1.0; python_version < "3.11"',
18-
'importlib-metadata >=3.6.0; python_version < "3.10"',
1918
]
2019
readme = "README.md"
2120
classifiers = [
@@ -62,7 +61,7 @@ xfail_strict = true
6261
[tool.tox]
6362
requires = ["tox>=4.21.1"]
6463
# Only run pytest envs when no args given to tox
65-
env_list = ["3.9", "3.10", "3.11", "3.12", "3.13"]
64+
env_list = ["3.10", "3.11", "3.12", "3.13"]
6665

6766
[tool.tox.env_run_base]
6867
description = "run tests under {base_python}"

src/mdformat/_cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ def wrap_paragraphs(paragraphs: Iterable[str]) -> str:
452452
@contextlib.contextmanager
453453
def log_handler_applied(
454454
logger: logging.Logger, handler: logging.Handler
455-
) -> Generator[None, None, None]:
455+
) -> Generator[None]:
456456
logger.addHandler(handler)
457457
try:
458458
yield

src/mdformat/_compat.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
1-
__all__ = ("importlib_metadata", "tomllib")
1+
__all__ = ("tomllib",)
22

33
import sys
44

55
if sys.version_info >= (3, 11): # pragma: >=3.11 cover
66
import tomllib
77
else: # pragma: <3.11 cover
88
import tomli as tomllib
9-
10-
if sys.version_info >= (3, 10): # pragma: >=3.10 cover
11-
from importlib import metadata as importlib_metadata
12-
else: # pragma: <3.10 cover
13-
import importlib_metadata

src/mdformat/_conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
from __future__ import annotations
22

3+
from collections.abc import Mapping
34
import functools
45
from pathlib import Path
56
from types import MappingProxyType
6-
from typing import Mapping
77

88
from mdformat._compat import tomllib
99
from mdformat._util import EMPTY_MAP
@@ -32,7 +32,7 @@ class InvalidConfError(Exception):
3232
"""
3333

3434

35-
@functools.lru_cache()
35+
@functools.lru_cache
3636
def read_toml_opts(conf_dir: Path) -> tuple[Mapping, Path | None]:
3737
conf_path = conf_dir / ".mdformat.toml"
3838
if not conf_path.is_file():

src/mdformat/plugins.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
from __future__ import annotations
22

3+
import importlib.metadata
34
from typing import TYPE_CHECKING, Any, Protocol
45

5-
from mdformat._compat import importlib_metadata
6-
76
if TYPE_CHECKING:
87
import argparse
98
from collections.abc import Callable, Mapping
@@ -14,7 +13,7 @@
1413

1514

1615
def _load_entrypoints(
17-
eps: importlib_metadata.EntryPoints,
16+
eps: importlib.metadata.EntryPoints,
1817
) -> tuple[dict[str, Any], dict[str, tuple[str, list[str]]]]:
1918
loaded_ifaces: dict[str, Any] = {}
2019
dist_versions: dict[str, tuple[str, list[str]]] = {}
@@ -95,7 +94,7 @@ def __getattr__(name: str) -> Mapping[str, Any]:
9594
"""
9695
if name in {"CODEFORMATTERS", "_CODEFORMATTER_DISTS"}:
9796
formatters, formatter_dists = _load_entrypoints(
98-
importlib_metadata.entry_points(group="mdformat.codeformatter")
97+
importlib.metadata.entry_points(group="mdformat.codeformatter")
9998
)
10099
# Cache the values in this module for next time, so that `__getattr__`
101100
# is only called once per `name`.
@@ -105,7 +104,7 @@ def __getattr__(name: str) -> Mapping[str, Any]:
105104
return formatters if name == "CODEFORMATTERS" else formatter_dists
106105
if name in {"PARSER_EXTENSIONS", "_PARSER_EXTENSION_DISTS"}:
107106
extensions, extension_dists = _load_entrypoints(
108-
importlib_metadata.entry_points(group="mdformat.parser_extension")
107+
importlib.metadata.entry_points(group="mdformat.parser_extension")
109108
)
110109
# Cache the value in this module for next time, so that `__getattr__`
111110
# is only called once per `name`.

src/mdformat/renderer/_context.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ class RenderContext(NamedTuple):
631631
env: MutableMapping
632632

633633
@contextmanager
634-
def indented(self, width: int) -> Generator[None, None, None]:
634+
def indented(self, width: int) -> Generator[None]:
635635
self.env["indent_width"] += width
636636
try:
637637
yield

src/mdformat/renderer/_util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ def escape_square_brackets(text: str, used_refs: Iterable[str]) -> str:
231231
enclosure_start: int | None = None
232232
while True:
233233
bracket_match = RE_SQUARE_BRACKET.search(text, pos)
234-
if not bracket_match: # pragma: >=3.10 cover
234+
if not bracket_match:
235235
if enclosure_start is not None:
236236
escape_before_pos.append(enclosure_start)
237237
break

src/mdformat/renderer/typing.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
from typing import TYPE_CHECKING, Any, Callable
1+
from collections.abc import Callable
2+
from typing import TYPE_CHECKING, Any
23

34
if TYPE_CHECKING:
4-
from mdformat.renderer import RenderTreeNode
5+
from mdformat.renderer import RenderTreeNode # noqa: F401
56

67
# There should be `mdformat.renderer.RenderContext` instead of `Any`
78
# here and in `Postprocess` below but that results in recursive typing

tests/test_plugins.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import argparse
2+
import importlib.metadata
23
from textwrap import dedent
34
from unittest.mock import patch
45

@@ -7,7 +8,6 @@
78

89
import mdformat
910
from mdformat._cli import run
10-
from mdformat._compat import importlib_metadata
1111
from mdformat.plugins import (
1212
_PARSER_EXTENSION_DISTS,
1313
CODEFORMATTERS,
@@ -439,7 +439,7 @@ def test_load_entrypoints(tmp_path, monkeypatch):
439439
Version: 0.3.6
440440
"""
441441
)
442-
distro = importlib_metadata.PathDistribution(dist_info_path)
442+
distro = importlib.metadata.PathDistribution(dist_info_path)
443443
entrypoints = distro.entry_points
444444

445445
loaded_eps, dist_infos = _load_entrypoints(entrypoints)

0 commit comments

Comments
 (0)