Skip to content

Commit 5ba0f11

Browse files
committed
Let Ruff automatically drop Python 3.9 code, enable more lints
1 parent 4732d44 commit 5ba0f11

File tree

22 files changed

+111
-142
lines changed

22 files changed

+111
-142
lines changed

properdocs/commands/build.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
import logging
55
import os
66
import time
7-
from typing import TYPE_CHECKING, Sequence
7+
from collections.abc import Sequence
8+
from typing import TYPE_CHECKING
89
from urllib.parse import urljoin, urlsplit
910

1011
import jinja2

properdocs/config/base.py

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,9 @@
66
import sys
77
import warnings
88
from collections import UserDict
9+
from collections.abc import Iterator, Mapping, Sequence
910
from contextlib import contextmanager
10-
from typing import (
11-
IO,
12-
TYPE_CHECKING,
13-
Any,
14-
Generic,
15-
Iterator,
16-
List,
17-
Mapping,
18-
Sequence,
19-
Tuple,
20-
TypeVar,
21-
overload,
22-
)
11+
from typing import IO, TYPE_CHECKING, Any, Generic, TypeVar, overload
2312

2413
from properdocs import exceptions, utils
2514
from properdocs.utils import weak_property
@@ -111,11 +100,11 @@ def __eq__(self, other):
111100
return type(self) is type(other) and str(self) == str(other)
112101

113102

114-
PlainConfigSchemaItem = Tuple[str, BaseConfigOption]
103+
PlainConfigSchemaItem = tuple[str, BaseConfigOption]
115104
PlainConfigSchema = Sequence[PlainConfigSchemaItem]
116105

117-
ConfigErrors = List[Tuple[str, Exception]]
118-
ConfigWarnings = List[Tuple[str, str]]
106+
ConfigErrors = list[tuple[str, Exception]]
107+
ConfigWarnings = list[tuple[str, str]]
119108

120109

121110
class Config(UserDict):
@@ -268,7 +257,7 @@ def user_configs(self) -> Sequence[Mapping[str, Any]]:
268257
return self.__user_configs
269258

270259

271-
@functools.lru_cache(maxsize=None)
260+
@functools.cache
272261
def get_schema(cls: type) -> PlainConfigSchema:
273262
"""Extract ConfigOptions defined in a class (used just as a container) and put them into a schema tuple."""
274263
if issubclass(cls, Config):

properdocs/config/config_options.py

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,9 @@
1010
import types
1111
import warnings
1212
from collections import Counter, UserString
13+
from collections.abc import Callable, Collection, Iterator, Mapping, MutableMapping
1314
from types import SimpleNamespace
14-
from typing import (
15-
Any,
16-
Callable,
17-
Collection,
18-
Dict,
19-
Generic,
20-
Iterator,
21-
List,
22-
Mapping,
23-
MutableMapping,
24-
NamedTuple,
25-
TypeVar,
26-
Union,
27-
overload,
28-
)
15+
from typing import Any, Generic, NamedTuple, TypeVar, Union, overload
2916
from urllib.parse import quote as urlquote
3017
from urllib.parse import urlsplit, urlunsplit
3118

@@ -184,7 +171,7 @@ def validate(self, value):
184171
return self.run_validation(value)
185172

186173

187-
class ListOfItems(Generic[T], BaseConfigOption[List[T]]):
174+
class ListOfItems(Generic[T], BaseConfigOption[list[T]]):
188175
"""
189176
Validates a homogeneous list of items.
190177
@@ -239,7 +226,7 @@ def run_validation(self, value: object) -> list[T]:
239226
return [fake_config[k] for k in fake_keys]
240227

241228

242-
class DictOfItems(Generic[T], BaseConfigOption[Dict[str, T]]):
229+
class DictOfItems(Generic[T], BaseConfigOption[dict[str, T]]):
243230
"""
244231
Validates a dict of items. Keys are always strings.
245232
@@ -942,7 +929,7 @@ def run_validation(self, value: object) -> ExtraScriptValue | str:
942929
return self.option_type.run_validation(value)
943930

944931

945-
class MarkdownExtensions(OptionallyRequired[List[str]]):
932+
class MarkdownExtensions(OptionallyRequired[list[str]]):
946933
"""
947934
Markdown Extensions Config Option.
948935
@@ -1078,8 +1065,7 @@ def _parse_configs(cls, value: list | tuple | dict) -> Iterator[tuple[str, dict]
10781065
def load_plugin_with_namespace(self, name: str, config) -> tuple[str, plugins.BasePlugin]:
10791066
if '/' in name: # It's already specified with a namespace.
10801067
# Special case: allow to explicitly skip namespaced loading:
1081-
if name.startswith('/'):
1082-
name = name[1:]
1068+
name = name.removeprefix('/')
10831069
else:
10841070
# Attempt to load with prepended namespace for the current theme.
10851071
if self.theme_key and self._config:
@@ -1155,7 +1141,7 @@ def load_plugin(self, name: str, config) -> plugins.BasePlugin:
11551141
return plugin
11561142

11571143

1158-
class Hooks(BaseConfigOption[List[types.ModuleType]]):
1144+
class Hooks(BaseConfigOption[list[types.ModuleType]]):
11591145
"""A list of Python scripts to be treated as instances of plugins."""
11601146

11611147
def __init__(self, plugins_key: str) -> None:
@@ -1177,7 +1163,7 @@ def run_validation(self, value: object) -> Mapping[str, Any]:
11771163
hooks[name] = self._load_hook(name, path)
11781164
return hooks
11791165

1180-
@functools.lru_cache(maxsize=None)
1166+
@functools.cache
11811167
def _load_hook(self, name, path):
11821168
import importlib.util
11831169

properdocs/config/defaults.py

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

33
import logging
4-
from typing import IO, Dict, Mapping
4+
from collections.abc import Mapping
5+
from typing import IO
56

67
from properdocs.config import base
78
from properdocs.config import config_options as c
@@ -134,7 +135,7 @@ class ProperDocsConfig(base.Config):
134135
)
135136
"""PyMarkdown extension names."""
136137

137-
mdx_configs = c.Private[Dict[str, dict]]()
138+
mdx_configs = c.Private[dict[str, dict]]()
138139
"""PyMarkdown extension configs. Populated from `markdown_extensions`."""
139140

140141
strict = c.Type(bool, default=False)

properdocs/contrib/search/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import logging
44
import os
5-
from typing import TYPE_CHECKING, List
5+
from typing import TYPE_CHECKING
66

77
from properdocs import utils
88
from properdocs.config import base
@@ -20,7 +20,7 @@
2020
base_path = os.path.dirname(os.path.abspath(__file__))
2121

2222

23-
class LangOption(c.OptionallyRequired[List[str]]):
23+
class LangOption(c.OptionallyRequired[list[str]]):
2424
"""Validate Language(s) provided in config are known languages."""
2525

2626
def get_lunr_supported_lang(self, lang):

properdocs/livereload/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
import webbrowser
2222
import wsgiref.simple_server
2323
import wsgiref.util
24-
from typing import Any, BinaryIO, Callable, Iterable
24+
from collections.abc import Callable, Iterable
25+
from typing import Any, BinaryIO
2526

2627
import watchdog.events
2728
import watchdog.observers.polling

properdocs/localization.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
import logging
44
import os
5-
from typing import TYPE_CHECKING, Sequence
5+
from collections.abc import Sequence
6+
from typing import TYPE_CHECKING
67

78
from jinja2.ext import Extension, InternationalizationExtension
89

properdocs/plugins.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,9 @@
33
from __future__ import annotations
44

55
import logging
6-
import sys
7-
from typing import TYPE_CHECKING, Any, Callable, Generic, Literal, MutableMapping, TypeVar, overload
8-
9-
if sys.version_info >= (3, 10):
10-
from importlib.metadata import EntryPoint, entry_points
11-
else:
12-
from importlib_metadata import EntryPoint, entry_points
6+
from collections.abc import Callable, MutableMapping
7+
from importlib.metadata import EntryPoint, entry_points
8+
from typing import TYPE_CHECKING, Any, Generic, Literal, TypeVar, overload
139

1410
if TYPE_CHECKING:
1511
import jinja2.environment
@@ -32,7 +28,9 @@
3228
from properdocs.utils.templates import TemplateContext
3329

3430
if TYPE_CHECKING:
35-
from typing_extensions import Concatenate, ParamSpec
31+
from typing import Concatenate
32+
33+
from typing_extensions import ParamSpec
3634
else:
3735
ParamSpec = TypeVar
3836

properdocs/structure/__init__.py

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

33
import abc
4-
from typing import TYPE_CHECKING, Iterable
4+
from collections.abc import Iterable
5+
from typing import TYPE_CHECKING
56

67
if TYPE_CHECKING:
78
from properdocs.structure.nav import Section

properdocs/structure/files.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
import posixpath
88
import shutil
99
import warnings
10+
from collections.abc import Callable, Iterable, Iterator, Mapping, Sequence
1011
from functools import cached_property
1112
from pathlib import PurePath, PurePosixPath
12-
from typing import TYPE_CHECKING, Callable, Iterable, Iterator, Mapping, Sequence, overload
13+
from typing import TYPE_CHECKING, overload
1314
from urllib.parse import quote as urlquote
1415

1516
import pathspec

0 commit comments

Comments
 (0)