Skip to content

Commit

Permalink
Run pyupgrade --py39-plus on all files
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoddemus committed Dec 17, 2024
1 parent f2511e9 commit 9f41630
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 26 deletions.
11 changes: 5 additions & 6 deletions src/pytest_regressions/common.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import difflib
import os
from collections.abc import MutableMapping
from collections.abc import MutableSequence
from pathlib import Path
from typing import Callable
from typing import List
from typing import MutableMapping
from typing import MutableSequence
from typing import Optional
from typing import TypeVar
from typing import Union
Expand All @@ -19,7 +18,7 @@ def import_error_message(libname: str) -> str:
def check_text_files(
obtained_fn: "os.PathLike[str]",
expected_fn: "os.PathLike[str]",
fix_callback: Callable[[List[str]], List[str]] = lambda x: x,
fix_callback: Callable[[list[str]], list[str]] = lambda x: x,
encoding: Optional[str] = None,
) -> None:
"""
Expand Down Expand Up @@ -94,7 +93,7 @@ def perform_regression_check(
force_regen: bool = False,
with_test_class_names: bool = False,
obtained_filename: Optional["os.PathLike[str]"] = None,
dump_aux_fn: Callable[[Path], List[str]] = lambda filename: [],
dump_aux_fn: Callable[[Path], list[str]] = lambda filename: [],
) -> None:
"""
First run of this check will generate a expected file. Following attempts will always try to
Expand Down Expand Up @@ -144,7 +143,7 @@ def perform_regression_check(
filename = datadir / (basename + extension)
source_filename = original_datadir / (basename + extension)

def make_location_message(banner: str, filename: Path, aux_files: List[str]) -> str:
def make_location_message(banner: str, filename: Path, aux_files: list[str]) -> str:
msg = [banner, f"- {filename}"]
if aux_files:
msg.append("Auxiliary:")
Expand Down
3 changes: 1 addition & 2 deletions src/pytest_regressions/data_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from pathlib import Path
from typing import Any
from typing import Callable
from typing import Dict
from typing import Optional

import pytest
Expand All @@ -30,7 +29,7 @@ def __init__(

def check(
self,
data_dict: Dict[str, Any],
data_dict: dict[str, Any],
basename: Optional[str] = None,
fullpath: Optional["os.PathLike[str]"] = None,
round_digits: Optional[int] = None,
Expand Down
9 changes: 4 additions & 5 deletions src/pytest_regressions/dataframe_regression.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import os
from pathlib import Path
from typing import Any
from typing import Dict
from typing import Optional

import pytest
Expand All @@ -22,8 +21,8 @@ class DataFrameRegressionFixture:
def __init__(
self, datadir: Path, original_datadir: Path, request: pytest.FixtureRequest
) -> None:
self._tolerances_dict: Dict[str, Dict[str, float]] = {}
self._default_tolerance: Dict[str, float] = {}
self._tolerances_dict: dict[str, dict[str, float]] = {}
self._default_tolerance: dict[str, float] = {}

self.request = request
self.datadir = datadir
Expand Down Expand Up @@ -187,8 +186,8 @@ def check(
data_frame: Any,
basename: Optional[str] = None,
fullpath: Optional["os.PathLike[str]"] = None,
tolerances: Optional[Dict[str, Dict[str, float]]] = None,
default_tolerance: Optional[Dict[str, float]] = None,
tolerances: Optional[dict[str, dict[str, float]]] = None,
default_tolerance: Optional[dict[str, float]] = None,
) -> None:
"""
Checks a pandas dataframe, containing only numeric data, against a previously recorded version, or generate a new file.
Expand Down
15 changes: 7 additions & 8 deletions src/pytest_regressions/ndarrays_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import zipfile
from pathlib import Path
from typing import Any
from typing import Dict
from typing import Optional

import pytest
Expand All @@ -22,8 +21,8 @@ class NDArraysRegressionFixture:
def __init__(
self, datadir: Path, original_datadir: Path, request: pytest.FixtureRequest
) -> None:
self._tolerances_dict: Dict[str, Dict[str, float]] = {}
self._default_tolerance: Dict[str, float] = {}
self._tolerances_dict: dict[str, dict[str, float]] = {}
self._default_tolerance: dict[str, float] = {}

self.request = request
self.datadir = datadir
Expand Down Expand Up @@ -239,7 +238,7 @@ def _check_fn(self, obtained_filename: Path, expected_filename: Path) -> None:

raise AssertionError(error_msg)

def _load_fn(self, filename: Path) -> Dict[str, Any]:
def _load_fn(self, filename: Path) -> dict[str, Any]:
"""
Load dict contents from the given filename.
"""
Expand All @@ -260,7 +259,7 @@ def _load_fn(self, filename: Path) -> Dict[str, Any]:
) from e
return result

def _dump_fn(self, data_dict: Dict[str, Any], filename: Path) -> None:
def _dump_fn(self, data_dict: dict[str, Any], filename: Path) -> None:
"""
Dump dict contents to the given filename.
"""
Expand All @@ -273,11 +272,11 @@ def _dump_fn(self, data_dict: Dict[str, Any], filename: Path) -> None:

def check(
self,
data_dict: Dict[str, Any],
data_dict: dict[str, Any],
basename: Optional[str] = None,
fullpath: Optional["os.PathLike[str]"] = None,
tolerances: Optional[Dict[str, Dict[str, float]]] = None,
default_tolerance: Optional[Dict[str, float]] = None,
tolerances: Optional[dict[str, dict[str, float]]] = None,
default_tolerance: Optional[dict[str, float]] = None,
) -> None:
"""
Checks a dictionary of NumPy ndarrays, containing only numeric data, against a previously recorded version, or generate a new file.
Expand Down
9 changes: 4 additions & 5 deletions src/pytest_regressions/num_regression.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import os
from collections.abc import Sequence
from typing import Any
from typing import Dict
from typing import Optional
from typing import Sequence

from .common import import_error_message
from .dataframe_regression import DataFrameRegressionFixture
Expand All @@ -15,11 +14,11 @@ class NumericRegressionFixture(DataFrameRegressionFixture):

def check(
self,
data_dict: Dict[str, Any],
data_dict: dict[str, Any],
basename: Optional[str] = None,
fullpath: Optional["os.PathLike[str]"] = None,
tolerances: Optional[Dict[str, Dict[str, float]]] = None,
default_tolerance: Optional[Dict[str, float]] = None,
tolerances: Optional[dict[str, dict[str, float]]] = None,
default_tolerance: Optional[dict[str, float]] = None,
data_index: Optional[Sequence[int]] = None,
fill_different_shape_with_nan: bool = True,
) -> None:
Expand Down

0 comments on commit 9f41630

Please sign in to comment.