Replaced importing the "typing" module as "t" with importing the individual names in the "typing" module. Since Python 3.9 introduced type hinting generics in standard collections, we do not have as many names to import now. This is also to be consistent with the practices of most major and standard packages and examples.
This commit is contained in:
@ -18,8 +18,8 @@
|
||||
|
||||
"""
|
||||
import csv
|
||||
import typing as t
|
||||
import unittest
|
||||
from typing import Any
|
||||
|
||||
import sqlalchemy as sa
|
||||
from click.testing import Result
|
||||
@ -80,7 +80,7 @@ class ConsoleCommandTestCase(unittest.TestCase):
|
||||
from accounting.models import BaseAccount
|
||||
|
||||
with open(data_dir / "base_accounts.csv") as fp:
|
||||
data: dict[dict[str, t.Any]] \
|
||||
data: dict[dict[str, Any]] \
|
||||
= {x["code"]: {"code": x["code"],
|
||||
"title": x["title"],
|
||||
"l10n": {y[5:]: x[y]
|
||||
@ -135,7 +135,7 @@ class ConsoleCommandTestCase(unittest.TestCase):
|
||||
from accounting.models import Currency
|
||||
|
||||
with open(data_dir / "currencies.csv") as fp:
|
||||
data: dict[dict[str, t.Any]] \
|
||||
data: dict[dict[str, Any]] \
|
||||
= {x["code"]: {"code": x["code"],
|
||||
"name": x["name"],
|
||||
"l10n": {y[5:]: x[y]
|
||||
|
@ -18,8 +18,8 @@
|
||||
|
||||
"""
|
||||
import os
|
||||
import typing as t
|
||||
from secrets import token_urlsafe
|
||||
from typing import Type
|
||||
|
||||
from click.testing import Result
|
||||
from flask import Flask, Blueprint, render_template, redirect, Response, \
|
||||
@ -94,7 +94,7 @@ def create_app(is_testing: bool = False) -> Flask:
|
||||
return redirect(append_next(url_for("auth.login-form")))
|
||||
|
||||
@property
|
||||
def cls(self) -> t.Type[auth.User]:
|
||||
def cls(self) -> Type[auth.User]:
|
||||
return auth.User
|
||||
|
||||
@property
|
||||
|
@ -17,7 +17,7 @@
|
||||
"""The authentication for the Mia! Accounting demonstration website.
|
||||
|
||||
"""
|
||||
import typing as t
|
||||
from collections.abc import Callable
|
||||
|
||||
from flask import Blueprint, render_template, Flask, redirect, url_for, \
|
||||
session, request, g, Response, abort
|
||||
@ -96,7 +96,7 @@ def current_user() -> User | None:
|
||||
return g.user
|
||||
|
||||
|
||||
def admin_required(view: t.Callable) -> t.Callable:
|
||||
def admin_required(view: Callable) -> Callable:
|
||||
"""The view decorator to require the user to be an administrator.
|
||||
|
||||
:param view: The view.
|
||||
|
@ -20,10 +20,10 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import datetime as dt
|
||||
import typing as t
|
||||
from abc import ABC, abstractmethod
|
||||
from decimal import Decimal
|
||||
from secrets import randbelow
|
||||
from typing import Any
|
||||
|
||||
import sqlalchemy as sa
|
||||
from flask import Flask
|
||||
@ -193,8 +193,8 @@ class BaseTestData(ABC):
|
||||
.filter(User.username == username).first()
|
||||
assert current_user is not None
|
||||
self.__current_user_id: int = current_user.id
|
||||
self.__journal_entries: list[dict[str, t.Any]] = []
|
||||
self.__line_items: list[dict[str, t.Any]] = []
|
||||
self.__journal_entries: list[dict[str, Any]] = []
|
||||
self.__line_items: list[dict[str, Any]] = []
|
||||
self._init_data()
|
||||
|
||||
@abstractmethod
|
||||
@ -258,7 +258,7 @@ class BaseTestData(ABC):
|
||||
assert account is not None
|
||||
debit_no = debit_no + 1
|
||||
line_item.id = self.__new_id(existing_l_id)
|
||||
data: dict[str, t.Any] \
|
||||
data: dict[str, Any] \
|
||||
= {"id": line_item.id,
|
||||
"journal_entry_id": journal_entry_data.id,
|
||||
"is_debit": True,
|
||||
@ -277,7 +277,7 @@ class BaseTestData(ABC):
|
||||
assert account is not None
|
||||
credit_no = credit_no + 1
|
||||
line_item.id = self.__new_id(existing_l_id)
|
||||
data: dict[str, t.Any] \
|
||||
data: dict[str, Any] \
|
||||
= {"id": line_item.id,
|
||||
"journal_entry_id": journal_entry_data.id,
|
||||
"is_debit": False,
|
||||
|
@ -20,7 +20,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import re
|
||||
import typing as t
|
||||
from typing import Literal
|
||||
|
||||
import httpx
|
||||
from flask import Flask, render_template_string
|
||||
@ -108,7 +108,7 @@ def get_client(app: Flask, username: str) -> tuple[httpx.Client, str]:
|
||||
|
||||
|
||||
def set_locale(client: httpx.Client, csrf_token: str,
|
||||
locale: t.Literal["en", "zh_Hant", "zh_Hans"]) -> None:
|
||||
locale: Literal["en", "zh_Hant", "zh_Hans"]) -> None:
|
||||
"""Sets the current locale.
|
||||
|
||||
:param client: The test client.
|
||||
|
Reference in New Issue
Block a user