diff --git a/docs/source/examples.rst b/docs/source/examples.rst index 538f50d..e0d91d3 100644 --- a/docs/source/examples.rst +++ b/docs/source/examples.rst @@ -37,7 +37,7 @@ The following is an example configuration for *Mia! Accounting*. return redirect("/login") @property - def cls(self) -> t.Type[User]: + def cls(self) -> type[User]: return User @property diff --git a/src/accounting/journal_entry/forms/journal_entry.py b/src/accounting/journal_entry/forms/journal_entry.py index 839d801..014c3a2 100644 --- a/src/accounting/journal_entry/forms/journal_entry.py +++ b/src/accounting/journal_entry/forms/journal_entry.py @@ -19,7 +19,6 @@ """ import datetime as dt from abc import ABC, abstractmethod -from typing import Type import sqlalchemy as sa from flask_babel import LazyString @@ -122,7 +121,7 @@ class JournalEntryForm(FlaskForm): super().__init__(*args, **kwargs) self.is_modified: bool = False """Whether the journal entry is modified during populate_obj().""" - self.collector: Type[LineItemCollector] = LineItemCollector + self.collector: type[LineItemCollector] = LineItemCollector """The line item collector. The default is the base abstract collector only to provide the correct type. The subclass forms should provide their own collectors.""" @@ -153,7 +152,7 @@ class JournalEntryForm(FlaskForm): self.__set_date(obj, self.date.data) obj.note = self.note.data - collector_cls: Type[LineItemCollector] = self.collector + collector_cls: type[LineItemCollector] = self.collector collector: collector_cls = collector_cls(self, obj) collector.collect() diff --git a/src/accounting/journal_entry/utils/operators.py b/src/accounting/journal_entry/utils/operators.py index 57d438a..d132226 100644 --- a/src/accounting/journal_entry/utils/operators.py +++ b/src/accounting/journal_entry/utils/operators.py @@ -18,7 +18,6 @@ """ from abc import ABC, abstractmethod -from typing import Type from flask import render_template, request, abort from flask_wtf import FlaskForm @@ -38,7 +37,7 @@ class JournalEntryOperator(ABC): @property @abstractmethod - def form(self) -> Type[JournalEntryForm]: + def form(self) -> type[JournalEntryForm]: """Returns the form class. :return: The form class. @@ -99,7 +98,7 @@ class CashReceiptJournalEntry(JournalEntryOperator): """The order when checking the journal entry operator.""" @property - def form(self) -> Type[JournalEntryForm]: + def form(self) -> type[JournalEntryForm]: """Returns the form class. :return: The form class. @@ -169,7 +168,7 @@ class CashDisbursementJournalEntry(JournalEntryOperator): """The order when checking the journal entry operator.""" @property - def form(self) -> Type[JournalEntryForm]: + def form(self) -> type[JournalEntryForm]: """Returns the form class. :return: The form class. @@ -242,7 +241,7 @@ class TransferJournalEntry(JournalEntryOperator): """The order when checking the journal entry operator.""" @property - def form(self) -> Type[JournalEntryForm]: + def form(self) -> type[JournalEntryForm]: """Returns the form class. :return: The form class. diff --git a/src/accounting/models.py b/src/accounting/models.py index a46022d..090eb8f 100644 --- a/src/accounting/models.py +++ b/src/accounting/models.py @@ -22,7 +22,7 @@ from __future__ import annotations import datetime as dt import re from decimal import Decimal -from typing import Type, Self +from typing import Self import sqlalchemy as sa from babel import Locale @@ -269,7 +269,7 @@ class Account(db.Model): :return: None. """ AccountL10n.query.filter(AccountL10n.account == self).delete() - cls: Type[Self] = self.__class__ + cls: type[Self] = self.__class__ cls.query.filter(cls.id == self.id).delete() @classmethod @@ -473,7 +473,7 @@ class Currency(db.Model): :return: None. """ CurrencyL10n.query.filter(CurrencyL10n.currency == self).delete() - cls: Type[Self] = self.__class__ + cls: type[Self] = self.__class__ cls.query.filter(cls.code == self.code).delete() @@ -815,7 +815,7 @@ class JournalEntryLineItem(db.Model): :return: The offset items. """ if not hasattr(self, "__offsets"): - cls: Type[Self] = self.__class__ + cls: type[Self] = self.__class__ offsets: list[Self] = cls.query.join(JournalEntry)\ .filter(JournalEntryLineItem.original_line_item_id == self.id)\ .order_by(JournalEntry.date, JournalEntry.no, diff --git a/src/accounting/report/period/parser.py b/src/accounting/report/period/parser.py index cbd9c49..2ba5eac 100644 --- a/src/accounting/report/period/parser.py +++ b/src/accounting/report/period/parser.py @@ -1,7 +1,7 @@ # The Mia! Accounting Project. # Author: imacat@mail.imacat.idv.tw (imacat), 2023/3/4 -# Copyright (c) 2023 imacat. +# Copyright (c) 2023-2026 imacat. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -21,7 +21,6 @@ import calendar import datetime as dt import re from collections.abc import Callable -from typing import Type from .period import Period from .shortcuts import ThisMonth, LastMonth, SinceLastMonth, ThisYear, \ @@ -40,7 +39,7 @@ def get_period(spec: str | None = None) -> Period: """ if spec is None: return ThisMonth() - named_periods: dict[str, Type[Callable[[], Period]]] = { + named_periods: dict[str, type[Callable[[], Period]]] = { "this-month": lambda: ThisMonth(), "last-month": lambda: LastMonth(), "since-last-month": lambda: SinceLastMonth(), diff --git a/src/accounting/report/utils/base_page_params.py b/src/accounting/report/utils/base_page_params.py index e0b95b2..009522a 100644 --- a/src/accounting/report/utils/base_page_params.py +++ b/src/accounting/report/utils/base_page_params.py @@ -19,7 +19,6 @@ """ from abc import ABC, abstractmethod from collections.abc import Callable -from typing import Type from urllib.parse import urlparse, ParseResult, parse_qsl, urlencode, \ urlunparse @@ -53,7 +52,7 @@ class BasePageParams(ABC): """ @property - def journal_entry_types(self) -> Type[JournalEntryType]: + def journal_entry_types(self) -> type[JournalEntryType]: """Returns the journal entry types. :return: The journal entry types. diff --git a/src/accounting/utils/random_id.py b/src/accounting/utils/random_id.py index e9ec95c..e37ba80 100644 --- a/src/accounting/utils/random_id.py +++ b/src/accounting/utils/random_id.py @@ -20,12 +20,11 @@ This module should not import any other module from the application. """ from secrets import randbelow -from typing import Type from .. import db -def new_id(cls: Type[db.Model]): +def new_id(cls: type[db.Model]): """Generates and returns a new, unused random ID for the data model. :param cls: The data model. diff --git a/src/accounting/utils/user.py b/src/accounting/utils/user.py index 646d227..8891d1b 100644 --- a/src/accounting/utils/user.py +++ b/src/accounting/utils/user.py @@ -1,7 +1,7 @@ # The Mia! Accounting Project. # Author: imacat@mail.imacat.idv.tw (imacat), 2023/2/1 -# Copyright (c) 2023-2024 imacat. +# Copyright (c) 2023-2026 imacat. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -20,7 +20,6 @@ This module should not import any other module from the application. """ from abc import ABC, abstractmethod -from typing import Type import sqlalchemy as sa from flask import g, Response @@ -70,7 +69,7 @@ class UserUtilityInterface[T: Model](ABC): @property @abstractmethod - def cls(self) -> Type[T]: + def cls(self) -> type[T]: """Returns the class of the user data model. :return: The class of the user data model. diff --git a/tests/test_site/__init__.py b/tests/test_site/__init__.py index 96b844a..3a020c6 100644 --- a/tests/test_site/__init__.py +++ b/tests/test_site/__init__.py @@ -1,7 +1,7 @@ # The Mia! Accounting Demonstration Website. # Author: imacat@mail.imacat.idv.tw (imacat), 2023/1/27 -# Copyright (c) 2023 imacat. +# Copyright (c) 2023-2026 imacat. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -19,7 +19,6 @@ """ import os from secrets import token_urlsafe -from typing import Type from click.testing import Result from flask import Flask, Blueprint, render_template, redirect, Response, \ @@ -101,7 +100,7 @@ def create_app(is_testing: bool = False, is_skip_accounts: bool = False, return redirect(append_next(url_for("auth.login-form"))) @property - def cls(self) -> Type[auth.User]: + def cls(self) -> type[auth.User]: return auth.User @property