diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3bdb30c..787b1f2 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,4 +1,10 @@ repos: + - repo: https://github.com/asottile/pyupgrade + rev: v3.21.0 + hooks: + - id: pyupgrade + args: ["--py39-plus"] + - repo: https://github.com/psf/black rev: 23.3.0 hooks: diff --git a/django_typesense/collections.py b/django_typesense/collections.py index 50c8c97..8b0b50e 100644 --- a/django_typesense/collections.py +++ b/django_typesense/collections.py @@ -2,7 +2,7 @@ import logging from operator import methodcaller -from typing import Dict, Iterable, List, Union +from collections.abc import Iterable from django.db.models import QuerySet from django.utils.functional import cached_property @@ -68,11 +68,11 @@ class TypesenseCollection(metaclass=TypesenseCollectionMeta): default_sorting_field: str = "" token_separators: list = [] symbols_to_index: list = [] - synonyms: List[Synonym] = [] + synonyms: list[Synonym] = [] def __init__( self, - obj: Union[object, QuerySet, Iterable] = None, + obj: object | QuerySet | Iterable = None, many: bool = False, data: list = None, update_fields: list = None, @@ -117,7 +117,7 @@ def get_data(self): return data @classmethod - def get_fields(cls) -> Dict[str, TypesenseField]: + def get_fields(cls) -> dict[str, TypesenseField]: """ Returns: A dictionary of the fields names to the field definition for this collection diff --git a/django_typesense/paginator.py b/django_typesense/paginator.py index a41df6e..b0e8083 100644 --- a/django_typesense/paginator.py +++ b/django_typesense/paginator.py @@ -19,7 +19,7 @@ def prepare_results(self): """ documents = (hit['document'] for hit in self.object_list["hits"]) collection = self.model.get_collection(data=documents) - model_field_names = set((local_field.name for local_field in self.model._meta.local_fields)) + model_field_names = {local_field.name for local_field in self.model._meta.local_fields} results = [] for _data in collection.validated_data: diff --git a/django_typesense/utils.py b/django_typesense/utils.py index b106d73..a8c152d 100644 --- a/django_typesense/utils.py +++ b/django_typesense/utils.py @@ -3,7 +3,6 @@ import logging import os from datetime import date, datetime, time -from typing import List from django.core.exceptions import FieldError from django.core.paginator import Paginator @@ -212,9 +211,9 @@ def get_unix_timestamp(datetime_object) -> int: def export_documents( collection_name, filter_by: str = None, - include_fields: List[str] = None, - exclude_fields: List[str] = None, -) -> List[dict]: + include_fields: list[str] = None, + exclude_fields: list[str] = None, +) -> list[dict]: from django_typesense.typesense_client import client params = {}