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:
2023-04-26 18:22:45 +08:00
parent ee5b447c23
commit cda9e4e3c6
25 changed files with 116 additions and 113 deletions

View File

@ -21,7 +21,7 @@ This file is largely taken from the NanoParma ERP project, first written in
"""
import datetime as dt
import typing as t
from collections.abc import Callable
from accounting.models import JournalEntry
from .period import Period
@ -32,13 +32,13 @@ from .shortcuts import ThisMonth, LastMonth, SinceLastMonth, ThisYear, \
class PeriodChooser:
"""The period chooser."""
def __init__(self, get_url: t.Callable[[Period], str]):
def __init__(self, get_url: Callable[[Period], str]):
"""Constructs a period chooser.
:param get_url: The callback to return the URL of the current report in
a period.
"""
self.__get_url: t.Callable[[Period], str] = get_url
self.__get_url: Callable[[Period], str] = get_url
"""The callback to return the URL of the current report in a period."""
# Shortcut periods

View File

@ -20,7 +20,8 @@
import calendar
import datetime as dt
import re
import typing as t
from collections.abc import Callable
from typing import Type
from .period import Period
from .shortcuts import ThisMonth, LastMonth, SinceLastMonth, ThisYear, \
@ -39,7 +40,7 @@ def get_period(spec: str | None = None) -> Period:
"""
if spec is None:
return ThisMonth()
named_periods: dict[str, t.Type[t.Callable[[], Period]]] = {
named_periods: dict[str, Type[Callable[[], Period]]] = {
"this-month": lambda: ThisMonth(),
"last-month": lambda: LastMonth(),
"since-last-month": lambda: SinceLastMonth(),

View File

@ -21,7 +21,7 @@ This file is largely taken from the NanoParma ERP project, first written in
"""
import datetime as dt
import typing as t
from typing import Self
from .description import get_desc
from .month_end import month_end
@ -119,7 +119,7 @@ class Period:
and not self.is_a_day
@property
def before(self) -> t.Self | None:
def before(self) -> Self | None:
"""Returns the period before this period.
:return: The period before this period.

View File

@ -17,8 +17,9 @@
"""The page parameters of a report.
"""
import typing as t
from abc import ABC, abstractmethod
from collections.abc import Callable
from typing import Type
from urllib.parse import urlparse, ParseResult, parse_qsl, urlencode, \
urlunparse
@ -52,7 +53,7 @@ class BasePageParams(ABC):
"""
@property
def journal_entry_types(self) -> t.Type[JournalEntryType]:
def journal_entry_types(self) -> Type[JournalEntryType]:
"""Returns the journal entry types.
:return: The journal entry types.
@ -72,7 +73,7 @@ class BasePageParams(ABC):
return urlunparse(parts)
@staticmethod
def _get_currency_options(get_url: t.Callable[[Currency], str],
def _get_currency_options(get_url: Callable[[Currency], str],
active_currency: Currency) -> list[OptionLink]:
"""Returns the currency options.

View File

@ -21,7 +21,7 @@ This file is largely taken from the NanoParma ERP project, first written in
"""
import re
import typing as t
from collections.abc import Iterator
from flask_babel import LazyString
@ -190,7 +190,7 @@ class ReportChooser:
self.__active_report == ReportType.UNMATCHED,
fa_icon="fa-solid fa-file-circle-question")
def __iter__(self) -> t.Iterator[OptionLink]:
def __iter__(self) -> Iterator[OptionLink]:
"""Returns the iteration of the reports.
:return: The iteration of the reports.