From ca9ff34943b506ce23b180cf58ea1ec815dccaaa Mon Sep 17 00:00:00 2001 From: Tim Schilling Date: Tue, 19 Nov 2024 13:58:17 -0600 Subject: [PATCH] Updated pre-commit versions and applied lint changes. --- .pre-commit-config.yaml | 10 +++++----- simple_history/admin.py | 3 ++- simple_history/models.py | 11 ++++++----- simple_history/template_utils.py | 8 ++++---- simple_history/tests/tests/test_template_utils.py | 2 +- simple_history/tests/tests/utils.py | 2 +- 6 files changed, 19 insertions(+), 17 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 97cd6775d..0af416b92 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,13 +1,13 @@ --- repos: - repo: https://github.com/PyCQA/bandit - rev: 1.7.9 + rev: 1.7.10 hooks: - id: bandit exclude: /.*tests/ - repo: https://github.com/psf/black-pre-commit-mirror - rev: 24.8.0 + rev: 24.10.0 hooks: - id: black language_version: python3.9 @@ -25,7 +25,7 @@ repos: - id: isort - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.6.0 + rev: v5.0.0 hooks: - id: requirements-txt-fixer files: requirements/.*\.txt$ @@ -44,7 +44,7 @@ repos: hooks: - id: pyproject-fmt - repo: https://github.com/abravalheri/validate-pyproject - rev: v0.19 + rev: v0.23 hooks: - id: validate-pyproject @@ -56,7 +56,7 @@ repos: - "--strict" - repo: https://github.com/asottile/pyupgrade - rev: v3.17.0 + rev: v3.19.0 hooks: - id: pyupgrade args: [--py39-plus] diff --git a/simple_history/admin.py b/simple_history/admin.py index 6a55e2e1c..0c4b470c5 100644 --- a/simple_history/admin.py +++ b/simple_history/admin.py @@ -1,4 +1,5 @@ -from typing import Any, Sequence +from collections.abc import Sequence +from typing import Any from django import http from django.apps import apps as django_apps diff --git a/simple_history/models.py b/simple_history/models.py index 3ffe42a52..06be31853 100644 --- a/simple_history/models.py +++ b/simple_history/models.py @@ -2,9 +2,10 @@ import importlib import uuid import warnings +from collections.abc import Iterable, Sequence from dataclasses import dataclass from functools import partial -from typing import TYPE_CHECKING, Any, Dict, Iterable, List, Sequence, Type, Union +from typing import TYPE_CHECKING, Any, Dict, List, Type, Union import django from django.apps import apps @@ -1012,7 +1013,7 @@ def _get_field_changes_for_diff( old_history: "HistoricalChanges", fields: Iterable[str], foreign_keys_are_objs: bool, - ) -> List["ModelChange"]: + ) -> list["ModelChange"]: """Helper method for ``diff_against()``.""" changes = [] @@ -1053,7 +1054,7 @@ def _get_m2m_field_changes_for_diff( old_history: "HistoricalChanges", m2m_fields: Iterable[str], foreign_keys_are_objs: bool, - ) -> List["ModelChange"]: + ) -> list["ModelChange"]: """Helper method for ``diff_against()``.""" changes = [] @@ -1122,7 +1123,7 @@ def get_value(obj, through_field): @dataclass(frozen=True) class DeletedObject: - model: Type[models.Model] + model: type[models.Model] pk: Any def __str__(self): @@ -1147,7 +1148,7 @@ def __str__(self): # The PK of the through model's related objects. # # - Any of the other possible values of a model field. -ModelChangeValue = Union[Any, DeletedObject, List[Dict[str, Union[Any, DeletedObject]]]] +ModelChangeValue = Union[Any, DeletedObject, list[dict[str, Union[Any, DeletedObject]]]] @dataclass(frozen=True) diff --git a/simple_history/template_utils.py b/simple_history/template_utils.py index ae02d02e9..b4efc1159 100644 --- a/simple_history/template_utils.py +++ b/simple_history/template_utils.py @@ -40,7 +40,7 @@ class HistoricalRecordContextHelper: def __init__( self, - model: Type[Model], + model: type[Model], historical_record: HistoricalChanges, *, max_displayed_delta_change_chars=DEFAULT_MAX_DISPLAYED_DELTA_CHANGE_CHARS, @@ -50,7 +50,7 @@ def __init__( self.max_displayed_delta_change_chars = max_displayed_delta_change_chars - def context_for_delta_changes(self, delta: ModelDelta) -> List[Dict[str, Any]]: + def context_for_delta_changes(self, delta: ModelDelta) -> list[dict[str, Any]]: """ Return the template context for ``delta.changes``. By default, this is a list of dicts with the keys ``"field"``, @@ -119,7 +119,7 @@ def prepare_delta_change_value( def stringify_delta_change_values( self, change: ModelChange, old: Any, new: Any - ) -> Tuple[SafeString, SafeString]: + ) -> tuple[SafeString, SafeString]: """ Called by ``format_delta_change()`` after ``old`` and ``new`` have been prepared by ``prepare_delta_change_value()``. @@ -196,7 +196,7 @@ def __init__( ) assert self.min_diff_len >= 0 # nosec - def common_shorten_repr(self, *args: Any) -> Tuple[str, ...]: + def common_shorten_repr(self, *args: Any) -> tuple[str, ...]: """ Returns ``args`` with each element converted into a string representation. If any of the strings are longer than ``self.max_length``, they're all shortened diff --git a/simple_history/tests/tests/test_template_utils.py b/simple_history/tests/tests/test_template_utils.py index b094588f9..9d2c21d9d 100644 --- a/simple_history/tests/tests/test_template_utils.py +++ b/simple_history/tests/tests/test_template_utils.py @@ -225,7 +225,7 @@ def test_context_dict( ) def test__context_for_delta_changes__preserves_html_safe_strings(self): - def get_context_dict_old_and_new(old_value, new_value) -> Tuple[str, str]: + def get_context_dict_old_and_new(old_value, new_value) -> tuple[str, str]: # The field doesn't really matter, as long as it exists on the model # passed to `HistoricalRecordContextHelper` change = ModelChange("question", old_value, new_value) diff --git a/simple_history/tests/tests/utils.py b/simple_history/tests/tests/utils.py index ae6fe949c..a68b9de0a 100644 --- a/simple_history/tests/tests/utils.py +++ b/simple_history/tests/tests/utils.py @@ -15,7 +15,7 @@ class HistoricalTestCase(TestCase): - def assertRecordValues(self, record, klass: Type[Model], values_dict: dict): + def assertRecordValues(self, record, klass: type[Model], values_dict: dict): """ Fail if ``record`` doesn't contain the field values in ``values_dict``. ``record.history_object`` is also checked.