Replace typing.Type with built-in type[] for Python 3.12.

This commit is contained in:
2026-04-05 21:49:17 +08:00
parent cca3f89bf1
commit 356950e2c7
9 changed files with 19 additions and 26 deletions
+1 -1
View File
@@ -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
@@ -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()
@@ -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.
+4 -4
View File
@@ -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,
+2 -3
View File
@@ -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(),
@@ -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.
+1 -2
View File
@@ -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.
+2 -3
View File
@@ -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.
+2 -3
View File
@@ -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