Skip to content

Commit 02dec09

Browse files
authored
Drop Python 3.9 support (#82)
1 parent f4dec02 commit 02dec09

File tree

14 files changed

+44
-49
lines changed

14 files changed

+44
-49
lines changed

.github/workflows/tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
runs-on: ubuntu-latest
2626
strategy:
2727
matrix:
28-
python-version: [ "3.13", "3.9" ]
28+
python-version: [ "3.13", "3.10" ]
2929
tox-command: [ "lint", "pyroma", "mypy" ]
3030
steps:
3131
- uses: actions/checkout@v4
@@ -76,7 +76,7 @@ jobs:
7676
strategy:
7777
matrix:
7878
os: [ ubuntu-latest ]
79-
python-version: [ "3.13", "3.9" ]
79+
python-version: [ "3.13", "3.10" ]
8080
steps:
8181
- uses: actions/checkout@v4
8282
- name: "Install uv"

CITATION.cff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ message: "If you use this software, please cite it as below."
33
title: "Class Resolver"
44
authors:
55
- name: "Charles Tapley Hoyt"
6-
version: 0.6.2-dev
6+
version: 0.7.0-dev
77
doi:
88
url: "https://github.com/cthoyt/class-resolver"

docs/source/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
author = "Charles Tapley Hoyt"
2525

2626
# The full version, including alpha/beta/rc tags.
27-
release = "0.6.2-dev"
27+
release = "0.7.0-dev"
2828

2929
# The short X.Y version.
3030
parsed_version = re.match(

pyproject.toml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
[build-system]
2-
requires = ["uv_build>=0.6.6,<0.7"]
2+
requires = ["uv_build>=0.6.6,<1.0"]
33
build-backend = "uv_build"
44

55
[project]
66
name = "class_resolver"
7-
version = "0.6.2-dev"
7+
version = "0.7.0-dev"
88
description = "Lookup and instantiate classes with style."
99
readme = "README.md"
1010
authors = [
@@ -27,7 +27,6 @@ classifiers = [
2727
"Framework :: Sphinx",
2828
"Natural Language :: English",
2929
"Programming Language :: Python",
30-
"Programming Language :: Python :: 3.9",
3130
"Programming Language :: Python :: 3.10",
3231
"Programming Language :: Python :: 3.11",
3332
"Programming Language :: Python :: 3.12",
@@ -48,9 +47,8 @@ license-files = [
4847
"LICENSE",
4948
]
5049

51-
requires-python = ">=3.9"
50+
requires-python = ">=3.10"
5251
dependencies = [
53-
"importlib-metadata > 3.6; python_version<'3.10'",
5452
"typing-extensions",
5553
]
5654

@@ -108,7 +106,7 @@ release = [
108106
# see https://packaging.python.org/en/latest/guides/writing-pyproject-toml/#dependencies-optional-dependencies
109107
[project.optional-dependencies]
110108
click = [
111-
"click<8.2"
109+
"click>=8.2"
112110
]
113111
torch = [
114112
"torch"
@@ -256,7 +254,7 @@ known-first-party = [
256254
docstring-code-format = true
257255

258256
[tool.bumpversion]
259-
current_version = "0.6.2-dev"
257+
current_version = "0.7.0-dev"
260258
parse = "(?P<major>\\d+)\\.(?P<minor>\\d+)\\.(?P<patch>\\d+)(?:-(?P<release>[0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*))?(?:\\+(?P<build>[0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*))?"
261259
serialize = [
262260
"{major}.{minor}.{patch}-{release}+{build}",

src/class_resolver/api.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ def make(
198198
**kwargs: Any,
199199
) -> X:
200200
"""Instantiate a class with optional kwargs."""
201-
if query is None or isinstance(query, (str, type)):
201+
if query is None or isinstance(query, str | type):
202202
cls: type[X] = self.lookup(query)
203203
try:
204204
return cls(**(pos_kwargs or {}), **kwargs)
@@ -288,7 +288,7 @@ def make_many(
288288
raise ValueError("Mismatch in number number of queries and kwargs")
289289
return [
290290
self.make(query=_result_tracker, pos_kwargs=_result_tracker_kwargs, **common_kwargs)
291-
for _result_tracker, _result_tracker_kwargs in zip(_query_list, _kwargs_list)
291+
for _result_tracker, _result_tracker_kwargs in zip(_query_list, _kwargs_list, strict=False)
292292
]
293293

294294
def make_table(
@@ -339,7 +339,7 @@ def get_cls(
339339
if default is None:
340340
raise ValueError(f"No default {base.__name__} set")
341341
return default
342-
elif not isinstance(query, (str, type, base)):
342+
elif not isinstance(query, str | type | base):
343343
raise TypeError(f"Invalid {base.__name__} type: {type(query)} - {query}")
344344
elif isinstance(query, str):
345345
key = normalize_string(query, suffix=suffix)

src/class_resolver/base.py

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

55
import logging
6-
import sys
76
from abc import ABC, abstractmethod
8-
from collections.abc import Collection, Iterable, Iterator, Mapping
9-
from typing import TYPE_CHECKING, Any, Callable, Generic, overload
7+
from collections.abc import Callable, Collection, Iterable, Iterator, Mapping
8+
from importlib.metadata import entry_points
9+
from typing import TYPE_CHECKING, Any, Generic, overload
1010

1111
from typing_extensions import Self
1212

13-
if sys.version_info[:2] >= (3, 10):
14-
from importlib.metadata import entry_points
15-
else:
16-
from importlib_metadata import entry_points
17-
1813
from .utils import Hint, OptionalKwargs, X, Y, make_callback, normalize_string
1914

2015
if TYPE_CHECKING:
@@ -258,7 +253,7 @@ def _get_reverse_synonyms(self) -> dict[str, list[str]]:
258253

259254
def _get_click_choice(
260255
self, prefix: str | None = None, delimiter: str | None = None, suffix: str | None = None
261-
) -> click.Choice:
256+
) -> click.Choice[str]:
262257
"""Get a dynamically generated :class:`click.Choice` that shows values and synonyms.
263258
264259
:param prefix: The string shown after the opening square bracket, before the
@@ -274,14 +269,14 @@ def _get_click_choice(
274269
rev = self._get_reverse_synonyms()
275270
norm_func = self.normalize
276271

277-
class _Choice(click.Choice):
272+
class _Choice(click.Choice[str]):
278273
"""An extended choice that is aware of synonyms."""
279274

280275
def convert(self, value: Any, param: click.Parameter | None, ctx: click.Context | None) -> Any:
281276
"""Normalize."""
282277
return super().convert(norm_func(value), param=param, ctx=ctx)
283278

284-
def get_metavar(self, param: click.Parameter) -> str:
279+
def get_metavar(self, param: click.Parameter, ctx: click.Context) -> str:
285280
"""Get the text that shows the choices, including synonyms."""
286281
choices_lst = []
287282
for key, synonyms in rev.items():

src/class_resolver/contrib/numpy.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
"""NumPy is a numerical package for Python."""
22

3-
from typing import Callable
3+
from collections.abc import Callable
4+
from typing import TypeAlias
45

56
import numpy as np
67
from numpy.typing import ArrayLike
7-
from typing_extensions import TypeAlias
88

99
from ..func import FunctionResolver
1010

src/class_resolver/contrib/torch.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
to make it possible to more easily parametrize models and training loops.
55
""" # noqa: D205
66

7-
from typing import Callable
7+
from collections.abc import Callable
8+
from typing import TypeAlias
89

910
import torch
1011
from torch import nn
1112
from torch.nn import init
1213
from torch.nn.modules import activation
1314
from torch.optim import Adam, Optimizer
1415
from torch.optim.lr_scheduler import ExponentialLR, ReduceLROnPlateau
15-
from typing_extensions import TypeAlias
1616

1717
try:
1818
# when torch >= 2.0

src/class_resolver/docs.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
import inspect
77
import textwrap
88
from collections import defaultdict
9-
from typing import Any, Callable, TypeVar
9+
from collections.abc import Callable
10+
from typing import Any, TypeVar
1011

1112
from typing_extensions import ParamSpec
1213

src/class_resolver/func.py

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

33
from __future__ import annotations
44

5+
from collections.abc import Callable
56
from functools import partial
6-
from typing import Any, Callable, Generic, TypeVar
7+
from typing import Any, Generic, TypeVar
78

89
from typing_extensions import ParamSpec
910

0 commit comments

Comments
 (0)