Skip to content

Commit

Permalink
Use Optional[T] instead of T | None for Python 3.9 compatibility
Browse files Browse the repository at this point in the history
This converts the spelling to the latter form only for type
declarations consumed in beanquery, the others are left as an exercise
for someone else.
  • Loading branch information
dnicolodi committed Jan 2, 2025
1 parent 82586a4 commit 4760629
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions beancount/core/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from typing import Any
from typing import Iterator
from typing import NamedTuple
from typing import Optional
from typing import Protocol
from typing import Union
from typing import overload
Expand Down Expand Up @@ -111,7 +112,7 @@ class Open(NamedTuple):
date: datetime.date
account: Account
currencies: list[Currency]
booking: Booking | None
booking: Optional[Booking]


class Close(NamedTuple):
Expand Down Expand Up @@ -198,8 +199,8 @@ class Balance(NamedTuple):
date: datetime.date
account: Account
amount: Amount
tolerance: Decimal | None
diff_amount: Amount | None
tolerance: Optional[Decimal]
diff_amount: Optional[Amount]


class Posting(NamedTuple):
Expand Down Expand Up @@ -228,11 +229,11 @@ class Posting(NamedTuple):
"""

account: Account
units: Amount | None
cost: Cost | CostSpec | None
price: Amount | None
flag: Flag | None
meta: Meta | None
units: Optional[Amount]
cost: Cost | Optional[CostSpec]
price: Optional[Amount]
flag: Optional[Flag]
meta: Optional[Meta]


class Transaction(NamedTuple):
Expand Down Expand Up @@ -261,8 +262,8 @@ class Transaction(NamedTuple):
meta: Meta
date: datetime.date
flag: Flag
payee: str | None
narration: str | None
payee: Optional[str]
narration: Optional[str]
tags: frozenset[str]
links: frozenset[str]
postings: list[Posting]
Expand Down

0 comments on commit 4760629

Please sign in to comment.