Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Oct 17, 2024
1 parent a2b9f05 commit 6e34a89
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 21 deletions.
2 changes: 1 addition & 1 deletion auditlog/migrations/0015_alter_logentry_changes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.db import migrations, models


def two_step_migrations() -> List:
def two_step_migrations() -> list:
if settings.AUDITLOG_TWO_STEP_MIGRATION:
return [
migrations.RenameField(
Expand Down
14 changes: 7 additions & 7 deletions auditlog/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,8 @@ def _get_copy_with_python_typed_fields(self, instance):
return instance_copy

def _get_applicable_model_fields(
self, instance, model_fields: Dict[str, List[str]]
) -> List[str]:
self, instance, model_fields: dict[str, list[str]]
) -> list[str]:
include_fields = model_fields["include_fields"]
exclude_fields = model_fields["exclude_fields"]
all_field_names = [field.name for field in instance._meta.fields]
Expand All @@ -287,8 +287,8 @@ def _get_applicable_model_fields(
return list(set(include_fields or all_field_names).difference(exclude_fields))

def _mask_serialized_fields(
self, data: Dict[str, Any], mask_fields: List[str]
) -> Dict[str, Any]:
self, data: dict[str, Any], mask_fields: list[str]
) -> dict[str, Any]:
all_field_data = data.pop("fields")

masked_field_data = {}
Expand Down Expand Up @@ -595,16 +595,16 @@ def bulk_related_objects(self, objs, using=DEFAULT_DB_ALIAS):
changes_func = None


def _changes_func() -> Callable[[LogEntry], Dict]:
def json_then_text(instance: LogEntry) -> Dict:
def _changes_func() -> Callable[[LogEntry], dict]:
def json_then_text(instance: LogEntry) -> dict:
if instance.changes:
return instance.changes
elif instance.changes_text:
with contextlib.suppress(ValueError):
return json.loads(instance.changes_text)
return {}

def default(instance: LogEntry) -> Dict:
def default(instance: LogEntry) -> dict:
return instance.changes or {}

if settings.AUDITLOG_USE_TEXT_CHANGES_IF_JSON_IS_NOT_PRESENT:
Expand Down
25 changes: 12 additions & 13 deletions auditlog/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
from typing import (
Any,
Callable,
Collection,
Dict,
Iterable,
List,
Optional,
Tuple,
Union,
)
from collections.abc import Collection, Iterable

from django.apps import apps
from django.db.models import ManyToManyField, Model
Expand All @@ -26,7 +25,7 @@
from auditlog.conf import settings
from auditlog.signals import accessed

DispatchUID = Tuple[int, int, int]
DispatchUID = tuple[int, int, int]


class AuditLogRegistrationError(Exception):
Expand All @@ -47,7 +46,7 @@ def __init__(
delete: bool = True,
access: bool = True,
m2m: bool = True,
custom: Optional[Dict[ModelSignal, Callable]] = None,
custom: Optional[dict[ModelSignal, Callable]] = None,
):
from auditlog.receivers import log_access, log_create, log_delete, log_update

Expand All @@ -71,13 +70,13 @@ def __init__(
def register(
self,
model: ModelBase = None,
include_fields: Optional[List[str]] = None,
exclude_fields: Optional[List[str]] = None,
mapping_fields: Optional[Dict[str, str]] = None,
mask_fields: Optional[List[str]] = None,
include_fields: Optional[list[str]] = None,
exclude_fields: Optional[list[str]] = None,
mapping_fields: Optional[dict[str, str]] = None,
mask_fields: Optional[list[str]] = None,
m2m_fields: Optional[Collection[str]] = None,
serialize_data: bool = False,
serialize_kwargs: Optional[Dict[str, Any]] = None,
serialize_kwargs: Optional[dict[str, Any]] = None,
serialize_auditlog_fields_only: bool = False,
):
"""
Expand Down Expand Up @@ -169,7 +168,7 @@ def unregister(self, model: ModelBase) -> None:
else:
self._disconnect_signals(model)

def get_models(self) -> List[ModelBase]:
def get_models(self) -> list[ModelBase]:
return list(self._registry.keys())

def get_model_fields(self, model: ModelBase):
Expand Down Expand Up @@ -235,7 +234,7 @@ def _dispatch_uid(self, signal, receiver) -> DispatchUID:
"""Generate a dispatch_uid which is unique for a combination of self, signal, and receiver."""
return id(self), id(signal), id(receiver)

def _get_model_classes(self, app_model: str) -> List[ModelBase]:
def _get_model_classes(self, app_model: str) -> list[ModelBase]:
try:
try:
app_label, model_name = app_model.split(".")
Expand All @@ -247,7 +246,7 @@ def _get_model_classes(self, app_model: str) -> List[ModelBase]:

def _get_exclude_models(
self, exclude_tracking_models: Iterable[str]
) -> List[ModelBase]:
) -> list[ModelBase]:
exclude_models = [
model
for app_model in tuple(exclude_tracking_models)
Expand All @@ -256,7 +255,7 @@ def _get_exclude_models(
]
return exclude_models

def _register_models(self, models: Iterable[Union[str, Dict[str, Any]]]) -> None:
def _register_models(self, models: Iterable[Union[str, dict[str, Any]]]) -> None:
models = copy.deepcopy(models)
for model in models:
if isinstance(model, str):
Expand Down

0 comments on commit 6e34a89

Please sign in to comment.