Skip to content

Commit

Permalink
bump: drop support for python 3.8 (#2827)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
Borda and pre-commit-ci[bot] authored Nov 8, 2024
1 parent bf030e0 commit ea29c89
Show file tree
Hide file tree
Showing 274 changed files with 1,323 additions and 1,181 deletions.
12 changes: 6 additions & 6 deletions .github/assistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import os
import re
import sys
from typing import List, Optional, Tuple, Union
from typing import Optional, Union

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

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

@staticmethod
def set_oldest_versions(req_files: List[str] = REQUIREMENTS_FILES) -> None:
def set_oldest_versions(req_files: list[str] = REQUIREMENTS_FILES) -> None:
"""Set the oldest version for requirements."""
AssistantCLI.set_min_torch_by_python()
if isinstance(req_files, str):
Expand All @@ -109,8 +109,8 @@ def changed_domains(
pr: Optional[int] = None,
auth_token: Optional[str] = None,
as_list: bool = False,
general_sub_pkgs: Tuple[str] = _PKG_WIDE_SUBPACKAGES,
) -> Union[str, List[str]]:
general_sub_pkgs: tuple[str] = _PKG_WIDE_SUBPACKAGES,
) -> Union[str, list[str]]:
"""Determine what domains were changed in particular PR."""
import github

Expand Down Expand Up @@ -139,7 +139,7 @@ def changed_domains(
return "unittests"

# parse domains
def _crop_path(fname: str, paths: List[str]) -> str:
def _crop_path(fname: str, paths: list[str]) -> str:
for p in paths:
fname = fname.replace(p, "")
return fname
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/_focus-diff.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
#with:
# python-version: 3.8

- name: Get PR diff
id: diff-domains
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
testing-matrix: |
{
"os": ["ubuntu-22.04", "macos-13", "windows-2022"],
"python-version": ["3.8", "3.11"]
"python-version": ["3.9", "3.11"]
}
check-md-links:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
- "2.5.0"
include:
# cover additional python and PT combinations
- { os: "ubuntu-20.04", python-version: "3.8", pytorch-version: "2.0.1", requires: "oldest" }
- { os: "ubuntu-20.04", python-version: "3.9", pytorch-version: "2.0.1", requires: "oldest" }
- { os: "ubuntu-22.04", python-version: "3.11", pytorch-version: "2.4.1" }
- { os: "ubuntu-22.04", python-version: "3.12", pytorch-version: "2.5.0" }
# standard mac machine, not the M1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-pkg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.8
python-version: "3.10"

- name: Install dependencies
run: >-
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Changed minimum supported Pytorch version to 2.0 ([#2671](https://github.com/Lightning-AI/torchmetrics/pull/2671))


- Dropped support for Python 3.8 ([#2827](https://github.com/Lightning-AI/torchmetrics/pull/2827))


- Removed `num_outputs` in `R2Score` ([#2800](https://github.com/Lightning-AI/torchmetrics/pull/2800))


Expand Down
8 changes: 4 additions & 4 deletions _samples/bert_score-own_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"""

from pprint import pprint
from typing import Dict, List, Union
from typing import Union

import torch
from torch import Tensor, nn
Expand Down Expand Up @@ -53,7 +53,7 @@ def __init__(self) -> None:
self.PAD_TOKEN: torch.zeros(1, _MODEL_DIM),
}

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


def user_forward_fn(model: Module, batch: Dict[str, Tensor]) -> Tensor:
def user_forward_fn(model: Module, batch: dict[str, Tensor]) -> Tensor:
"""User forward function used for the computation of model embeddings.
This function might be arbitrarily complicated inside. However, to ensure functionality, it should obey the
Expand Down
2 changes: 1 addition & 1 deletion _samples/rouge_score-own_normalizer_and_tokenizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
"""

import re
from collections.abc import Sequence
from pprint import pprint
from typing import Sequence

from torchmetrics.text.rouge import ROUGEScore

Expand Down
3 changes: 1 addition & 2 deletions examples/audio/signal_to_noise_ratio.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

# %%
# Import necessary libraries
from typing import Tuple

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


def generate_clean_signal(length: int = 1000) -> Tuple[np.ndarray, np.ndarray]:
def generate_clean_signal(length: int = 1000) -> tuple[np.ndarray, np.ndarray]:
"""Generate a clean signal (sine wave)"""
t = np.linspace(0, 1, length)
signal = np.sin(2 * np.pi * 10 * t) # 10 Hz sine wave, representing the clean recording
Expand Down
7 changes: 3 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ requires = [
]

[tool.ruff]
target-version = "py38"
target-version = "py39"
line-length = 120

#[tool.ruff.pycodestyle]
Expand Down Expand Up @@ -68,6 +68,8 @@ lint.per-file-ignores."setup.py" = [
lint.per-file-ignores."src/**" = [
"ANN401",
"S310", # todo: Audit URL open for permitted schemes. Allowing use of `file:` or custom schemes is often unexpected.
"UP006", # todo: Use `list` instead of `List` for type annotation
"UP035", # todo: `typing.List` is deprecated, use `list` instead
]
lint.per-file-ignores."tests/**" = [
"ANN001",
Expand All @@ -77,9 +79,6 @@ lint.per-file-ignores."tests/**" = [
"S101",
"S301", # todo: `pickle` and modules that wrap it can be unsafe when used to deserialize untrusted data, possible security issue
]
lint.unfixable = [
"F401",
]
# Unlike Flake8, default to a complexity level of 10.
lint.mccabe.max-complexity = 10
# Use Google-style docstrings.
Expand Down
9 changes: 5 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
import glob
import os
import re
from collections.abc import Iterable, Iterator
from functools import partial
from importlib.util import module_from_spec, spec_from_file_location
from itertools import chain
from pathlib import Path
from typing import Any, Iterable, Iterator, List, Optional, Tuple, Union
from typing import Any, Optional, Union

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

def _load_requirements(
path_dir: str, file_name: str = "base.txt", unfreeze: bool = not _FREEZE_REQUIREMENTS
) -> List[str]:
) -> list[str]:
"""Load requirements from a file.
>>> _load_requirements(_PATH_REQUIRE)
Expand Down Expand Up @@ -161,7 +162,7 @@ def _load_py_module(fname: str, pkg: str = "torchmetrics"):
BASE_REQUIREMENTS = _load_requirements(path_dir=_PATH_REQUIRE, file_name="base.txt")


def _prepare_extras(skip_pattern: str = "^_", skip_files: Tuple[str] = ("base.txt",)) -> dict:
def _prepare_extras(skip_pattern: str = "^_", skip_files: tuple[str] = ("base.txt",)) -> dict:
"""Preparing extras for the package listing requirements.
Args:
Expand Down Expand Up @@ -215,7 +216,7 @@ def _prepare_extras(skip_pattern: str = "^_", skip_files: Tuple[str] = ("base.tx
include_package_data=True,
zip_safe=False,
keywords=["deep learning", "machine learning", "pytorch", "metrics", "AI"],
python_requires=">=3.8",
python_requires=">=3.9",
setup_requires=[],
install_requires=BASE_REQUIREMENTS,
extras_require=_prepare_extras(),
Expand Down
7 changes: 4 additions & 3 deletions src/torchmetrics/aggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import Any, Callable, List, Optional, Sequence, Tuple, Union
from collections.abc import Sequence
from typing import Any, Callable, Optional, Union

import torch
from torch import Tensor
Expand Down Expand Up @@ -55,7 +56,7 @@ class BaseAggregator(Metric):
def __init__(
self,
fn: Union[Callable, str],
default_value: Union[Tensor, List],
default_value: Union[Tensor, list],
nan_strategy: Union[str, float] = "error",
state_name: str = "value",
**kwargs: Any,
Expand All @@ -74,7 +75,7 @@ def __init__(

def _cast_and_nan_check_input(
self, x: Union[float, Tensor], weight: Optional[Union[float, Tensor]] = None
) -> Tuple[Tensor, Tensor]:
) -> tuple[Tensor, Tensor]:
"""Convert input ``x`` to a tensor and check for Nans."""
if not isinstance(x, Tensor):
x = torch.as_tensor(x, dtype=self.dtype, device=self.device)
Expand Down
3 changes: 2 additions & 1 deletion src/torchmetrics/audio/dnsmos.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import Any, Optional, Sequence, Union
from collections.abc import Sequence
from typing import Any, Optional, Union

import torch
from torch import Tensor, tensor
Expand Down
3 changes: 2 additions & 1 deletion src/torchmetrics/audio/nisqa.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import Any, Optional, Sequence, Union
from collections.abc import Sequence
from typing import Any, Optional, Union

from torch import Tensor, tensor

Expand Down
3 changes: 2 additions & 1 deletion src/torchmetrics/audio/pesq.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import Any, Optional, Sequence, Union
from collections.abc import Sequence
from typing import Any, Optional, Union

from torch import Tensor, tensor

Expand Down
5 changes: 3 additions & 2 deletions src/torchmetrics/audio/pit.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import Any, Callable, Dict, Optional, Sequence, Union
from collections.abc import Sequence
from typing import Any, Callable, Optional, Union

from torch import Tensor, tensor
from typing_extensions import Literal
Expand Down Expand Up @@ -87,7 +88,7 @@ def __init__(
eval_func: Literal["max", "min"] = "max",
**kwargs: Any,
) -> None:
base_kwargs: Dict[str, Any] = {
base_kwargs: dict[str, Any] = {
"dist_sync_on_step": kwargs.pop("dist_sync_on_step", False),
"process_group": kwargs.pop("process_group", None),
"dist_sync_fn": kwargs.pop("dist_sync_fn", None),
Expand Down
3 changes: 2 additions & 1 deletion src/torchmetrics/audio/sdr.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import Any, Optional, Sequence, Union
from collections.abc import Sequence
from typing import Any, Optional, Union

from torch import Tensor, tensor

Expand Down
3 changes: 2 additions & 1 deletion src/torchmetrics/audio/snr.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import Any, Optional, Sequence, Union
from collections.abc import Sequence
from typing import Any, Optional, Union

from torch import Tensor, tensor

Expand Down
3 changes: 2 additions & 1 deletion src/torchmetrics/audio/srmr.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import Any, Optional, Sequence, Union
from collections.abc import Sequence
from typing import Any, Optional, Union

from torch import Tensor, tensor

Expand Down
3 changes: 2 additions & 1 deletion src/torchmetrics/audio/stoi.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import Any, Optional, Sequence, Union
from collections.abc import Sequence
from typing import Any, Optional, Union

from torch import Tensor, tensor

Expand Down
5 changes: 3 additions & 2 deletions src/torchmetrics/classification/accuracy.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import Any, Optional, Sequence, Type, Union
from collections.abc import Sequence
from typing import Any, Optional, Union

from torch import Tensor
from typing_extensions import Literal
Expand Down Expand Up @@ -489,7 +490,7 @@ class Accuracy(_ClassificationTaskWrapper):
"""

def __new__( # type: ignore[misc]
cls: Type["Accuracy"],
cls: type["Accuracy"],
task: Literal["binary", "multiclass", "multilabel"],
threshold: float = 0.5,
num_classes: Optional[int] = None,
Expand Down
Loading

0 comments on commit ea29c89

Please sign in to comment.