Skip to content

Commit ea29c89

Browse files
bump: drop support for python 3.8 (#2827)
* drop support for python 3.8 * setup + lint * List... * Dict * chlog + linter --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent bf030e0 commit ea29c89

File tree

274 files changed

+1323
-1181
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

274 files changed

+1323
-1181
lines changed

.github/assistant.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import os
1717
import re
1818
import sys
19-
from typing import List, Optional, Tuple, Union
19+
from typing import Optional, Union
2020

2121
import fire
2222
from packaging.version import parse
@@ -83,7 +83,7 @@ def _replace_requirement(fpath: str, old_str: str = "", new_str: str = "") -> No
8383
fp.write(req)
8484

8585
@staticmethod
86-
def replace_str_requirements(old_str: str, new_str: str, req_files: List[str] = REQUIREMENTS_FILES) -> None:
86+
def replace_str_requirements(old_str: str, new_str: str, req_files: list[str] = REQUIREMENTS_FILES) -> None:
8787
"""Replace a particular string in all requirements files."""
8888
if isinstance(req_files, str):
8989
req_files = [req_files]
@@ -96,7 +96,7 @@ def replace_min_requirements(fpath: str) -> None:
9696
AssistantCLI._replace_requirement(fpath, old_str=">=", new_str="==")
9797

9898
@staticmethod
99-
def set_oldest_versions(req_files: List[str] = REQUIREMENTS_FILES) -> None:
99+
def set_oldest_versions(req_files: list[str] = REQUIREMENTS_FILES) -> None:
100100
"""Set the oldest version for requirements."""
101101
AssistantCLI.set_min_torch_by_python()
102102
if isinstance(req_files, str):
@@ -109,8 +109,8 @@ def changed_domains(
109109
pr: Optional[int] = None,
110110
auth_token: Optional[str] = None,
111111
as_list: bool = False,
112-
general_sub_pkgs: Tuple[str] = _PKG_WIDE_SUBPACKAGES,
113-
) -> Union[str, List[str]]:
112+
general_sub_pkgs: tuple[str] = _PKG_WIDE_SUBPACKAGES,
113+
) -> Union[str, list[str]]:
114114
"""Determine what domains were changed in particular PR."""
115115
import github
116116

@@ -139,7 +139,7 @@ def changed_domains(
139139
return "unittests"
140140

141141
# parse domains
142-
def _crop_path(fname: str, paths: List[str]) -> str:
142+
def _crop_path(fname: str, paths: list[str]) -> str:
143143
for p in paths:
144144
fname = fname.replace(p, "")
145145
return fname

.github/workflows/_focus-diff.yml

-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ jobs:
1818
steps:
1919
- uses: actions/checkout@v4
2020
- uses: actions/setup-python@v5
21-
#with:
22-
# python-version: 3.8
2321

2422
- name: Get PR diff
2523
id: diff-domains

.github/workflows/ci-checks.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
testing-matrix: |
3232
{
3333
"os": ["ubuntu-22.04", "macos-13", "windows-2022"],
34-
"python-version": ["3.8", "3.11"]
34+
"python-version": ["3.9", "3.11"]
3535
}
3636
3737
check-md-links:

.github/workflows/ci-tests.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
- "2.5.0"
4343
include:
4444
# cover additional python and PT combinations
45-
- { os: "ubuntu-20.04", python-version: "3.8", pytorch-version: "2.0.1", requires: "oldest" }
45+
- { os: "ubuntu-20.04", python-version: "3.9", pytorch-version: "2.0.1", requires: "oldest" }
4646
- { os: "ubuntu-22.04", python-version: "3.11", pytorch-version: "2.4.1" }
4747
- { os: "ubuntu-22.04", python-version: "3.12", pytorch-version: "2.5.0" }
4848
# standard mac machine, not the M1

.github/workflows/publish-pkg.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
- uses: actions/checkout@v4
2121
- uses: actions/setup-python@v5
2222
with:
23-
python-version: 3.8
23+
python-version: "3.10"
2424

2525
- name: Install dependencies
2626
run: >-

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4545
- Changed minimum supported Pytorch version to 2.0 ([#2671](https://github.com/Lightning-AI/torchmetrics/pull/2671))
4646

4747

48+
- Dropped support for Python 3.8 ([#2827](https://github.com/Lightning-AI/torchmetrics/pull/2827))
49+
50+
4851
- Removed `num_outputs` in `R2Score` ([#2800](https://github.com/Lightning-AI/torchmetrics/pull/2800))
4952

5053

_samples/bert_score-own_model.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"""
1919

2020
from pprint import pprint
21-
from typing import Dict, List, Union
21+
from typing import Union
2222

2323
import torch
2424
from torch import Tensor, nn
@@ -53,7 +53,7 @@ def __init__(self) -> None:
5353
self.PAD_TOKEN: torch.zeros(1, _MODEL_DIM),
5454
}
5555

56-
def __call__(self, sentences: Union[str, List[str]], max_len: int = _MAX_LEN) -> Dict[str, Tensor]:
56+
def __call__(self, sentences: Union[str, list[str]], max_len: int = _MAX_LEN) -> dict[str, Tensor]:
5757
"""Call method to tokenize user input.
5858
5959
The `__call__` method must be defined for this class. To ensure the functionality, the `__call__` method
@@ -69,7 +69,7 @@ def __call__(self, sentences: Union[str, List[str]], max_len: int = _MAX_LEN) ->
6969
Python dictionary containing the keys `input_ids` and `attention_mask` with corresponding values.
7070
7171
"""
72-
output_dict: Dict[str, Tensor] = {}
72+
output_dict: dict[str, Tensor] = {}
7373
if isinstance(sentences, str):
7474
sentences = [sentences]
7575
# Add special tokens
@@ -96,7 +96,7 @@ def get_user_model_encoder(num_layers: int = _NUM_LAYERS, d_model: int = _MODEL_
9696
return nn.TransformerEncoder(encoder_layer, num_layers=num_layers)
9797

9898

99-
def user_forward_fn(model: Module, batch: Dict[str, Tensor]) -> Tensor:
99+
def user_forward_fn(model: Module, batch: dict[str, Tensor]) -> Tensor:
100100
"""User forward function used for the computation of model embeddings.
101101
102102
This function might be arbitrarily complicated inside. However, to ensure functionality, it should obey the

_samples/rouge_score-own_normalizer_and_tokenizer.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
"""
1919

2020
import re
21+
from collections.abc import Sequence
2122
from pprint import pprint
22-
from typing import Sequence
2323

2424
from torchmetrics.text.rouge import ROUGEScore
2525

examples/audio/signal_to_noise_ratio.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
# %%
1010
# Import necessary libraries
11-
from typing import Tuple
1211

1312
import matplotlib.animation as animation
1413
import matplotlib.pyplot as plt
@@ -20,7 +19,7 @@
2019
# Generate a clean signal (simulating a high-quality recording)
2120

2221

23-
def generate_clean_signal(length: int = 1000) -> Tuple[np.ndarray, np.ndarray]:
22+
def generate_clean_signal(length: int = 1000) -> tuple[np.ndarray, np.ndarray]:
2423
"""Generate a clean signal (sine wave)"""
2524
t = np.linspace(0, 1, length)
2625
signal = np.sin(2 * np.pi * 10 * t) # 10 Hz sine wave, representing the clean recording

pyproject.toml

+3-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ requires = [
55
]
66

77
[tool.ruff]
8-
target-version = "py38"
8+
target-version = "py39"
99
line-length = 120
1010

1111
#[tool.ruff.pycodestyle]
@@ -68,6 +68,8 @@ lint.per-file-ignores."setup.py" = [
6868
lint.per-file-ignores."src/**" = [
6969
"ANN401",
7070
"S310", # todo: Audit URL open for permitted schemes. Allowing use of `file:` or custom schemes is often unexpected.
71+
"UP006", # todo: Use `list` instead of `List` for type annotation
72+
"UP035", # todo: `typing.List` is deprecated, use `list` instead
7173
]
7274
lint.per-file-ignores."tests/**" = [
7375
"ANN001",
@@ -77,9 +79,6 @@ lint.per-file-ignores."tests/**" = [
7779
"S101",
7880
"S301", # todo: `pickle` and modules that wrap it can be unsafe when used to deserialize untrusted data, possible security issue
7981
]
80-
lint.unfixable = [
81-
"F401",
82-
]
8382
# Unlike Flake8, default to a complexity level of 10.
8483
lint.mccabe.max-complexity = 10
8584
# Use Google-style docstrings.

setup.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
import glob
33
import os
44
import re
5+
from collections.abc import Iterable, Iterator
56
from functools import partial
67
from importlib.util import module_from_spec, spec_from_file_location
78
from itertools import chain
89
from pathlib import Path
9-
from typing import Any, Iterable, Iterator, List, Optional, Tuple, Union
10+
from typing import Any, Optional, Union
1011

1112
from pkg_resources import Requirement, yield_lines
1213
from setuptools import find_packages, setup
@@ -97,7 +98,7 @@ def _parse_requirements(strs: Union[str, Iterable[str]]) -> Iterator[_Requiremen
9798

9899
def _load_requirements(
99100
path_dir: str, file_name: str = "base.txt", unfreeze: bool = not _FREEZE_REQUIREMENTS
100-
) -> List[str]:
101+
) -> list[str]:
101102
"""Load requirements from a file.
102103
103104
>>> _load_requirements(_PATH_REQUIRE)
@@ -161,7 +162,7 @@ def _load_py_module(fname: str, pkg: str = "torchmetrics"):
161162
BASE_REQUIREMENTS = _load_requirements(path_dir=_PATH_REQUIRE, file_name="base.txt")
162163

163164

164-
def _prepare_extras(skip_pattern: str = "^_", skip_files: Tuple[str] = ("base.txt",)) -> dict:
165+
def _prepare_extras(skip_pattern: str = "^_", skip_files: tuple[str] = ("base.txt",)) -> dict:
165166
"""Preparing extras for the package listing requirements.
166167
167168
Args:
@@ -215,7 +216,7 @@ def _prepare_extras(skip_pattern: str = "^_", skip_files: Tuple[str] = ("base.tx
215216
include_package_data=True,
216217
zip_safe=False,
217218
keywords=["deep learning", "machine learning", "pytorch", "metrics", "AI"],
218-
python_requires=">=3.8",
219+
python_requires=">=3.9",
219220
setup_requires=[],
220221
install_requires=BASE_REQUIREMENTS,
221222
extras_require=_prepare_extras(),

src/torchmetrics/aggregation.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
from typing import Any, Callable, List, Optional, Sequence, Tuple, Union
14+
from collections.abc import Sequence
15+
from typing import Any, Callable, Optional, Union
1516

1617
import torch
1718
from torch import Tensor
@@ -55,7 +56,7 @@ class BaseAggregator(Metric):
5556
def __init__(
5657
self,
5758
fn: Union[Callable, str],
58-
default_value: Union[Tensor, List],
59+
default_value: Union[Tensor, list],
5960
nan_strategy: Union[str, float] = "error",
6061
state_name: str = "value",
6162
**kwargs: Any,
@@ -74,7 +75,7 @@ def __init__(
7475

7576
def _cast_and_nan_check_input(
7677
self, x: Union[float, Tensor], weight: Optional[Union[float, Tensor]] = None
77-
) -> Tuple[Tensor, Tensor]:
78+
) -> tuple[Tensor, Tensor]:
7879
"""Convert input ``x`` to a tensor and check for Nans."""
7980
if not isinstance(x, Tensor):
8081
x = torch.as_tensor(x, dtype=self.dtype, device=self.device)

src/torchmetrics/audio/dnsmos.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
from typing import Any, Optional, Sequence, Union
14+
from collections.abc import Sequence
15+
from typing import Any, Optional, Union
1516

1617
import torch
1718
from torch import Tensor, tensor

src/torchmetrics/audio/nisqa.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from typing import Any, Optional, Sequence, Union
15+
from collections.abc import Sequence
16+
from typing import Any, Optional, Union
1617

1718
from torch import Tensor, tensor
1819

src/torchmetrics/audio/pesq.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
from typing import Any, Optional, Sequence, Union
14+
from collections.abc import Sequence
15+
from typing import Any, Optional, Union
1516

1617
from torch import Tensor, tensor
1718

src/torchmetrics/audio/pit.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
from typing import Any, Callable, Dict, Optional, Sequence, Union
14+
from collections.abc import Sequence
15+
from typing import Any, Callable, Optional, Union
1516

1617
from torch import Tensor, tensor
1718
from typing_extensions import Literal
@@ -87,7 +88,7 @@ def __init__(
8788
eval_func: Literal["max", "min"] = "max",
8889
**kwargs: Any,
8990
) -> None:
90-
base_kwargs: Dict[str, Any] = {
91+
base_kwargs: dict[str, Any] = {
9192
"dist_sync_on_step": kwargs.pop("dist_sync_on_step", False),
9293
"process_group": kwargs.pop("process_group", None),
9394
"dist_sync_fn": kwargs.pop("dist_sync_fn", None),

src/torchmetrics/audio/sdr.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
from typing import Any, Optional, Sequence, Union
14+
from collections.abc import Sequence
15+
from typing import Any, Optional, Union
1516

1617
from torch import Tensor, tensor
1718

src/torchmetrics/audio/snr.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
from typing import Any, Optional, Sequence, Union
14+
from collections.abc import Sequence
15+
from typing import Any, Optional, Union
1516

1617
from torch import Tensor, tensor
1718

src/torchmetrics/audio/srmr.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
from typing import Any, Optional, Sequence, Union
14+
from collections.abc import Sequence
15+
from typing import Any, Optional, Union
1516

1617
from torch import Tensor, tensor
1718

src/torchmetrics/audio/stoi.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
from typing import Any, Optional, Sequence, Union
14+
from collections.abc import Sequence
15+
from typing import Any, Optional, Union
1516

1617
from torch import Tensor, tensor
1718

src/torchmetrics/classification/accuracy.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
from typing import Any, Optional, Sequence, Type, Union
14+
from collections.abc import Sequence
15+
from typing import Any, Optional, Union
1516

1617
from torch import Tensor
1718
from typing_extensions import Literal
@@ -489,7 +490,7 @@ class Accuracy(_ClassificationTaskWrapper):
489490
"""
490491

491492
def __new__( # type: ignore[misc]
492-
cls: Type["Accuracy"],
493+
cls: type["Accuracy"],
493494
task: Literal["binary", "multiclass", "multilabel"],
494495
threshold: float = 0.5,
495496
num_classes: Optional[int] = None,

0 commit comments

Comments
 (0)