Skip to content

Commit

Permalink
Fix type annotations in Python 3.9 (#232)
Browse files Browse the repository at this point in the history
`TypeAlias` was introduced in 3.10.
  • Loading branch information
bbguimaraes authored Jan 20, 2025
1 parent f9daf6e commit 733aff4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
8 changes: 7 additions & 1 deletion bw2data/backends/proxies.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import copy
import uuid
from collections.abc import Iterable
from typing import Callable, List, Optional, TypeAlias
import sys
from typing import Callable, List, Optional

import pandas as pd

Expand All @@ -22,6 +23,11 @@
from bw2data.search import IndexManager
from bw2data.signals import on_activity_code_change, on_activity_database_change

if sys.version_info < (3, 10):
from typing_extensions import TypeAlias
else:
from typing import TypeAlias


class Exchanges(Iterable):
"""Iterator for exchanges with some additional methods.
Expand Down
12 changes: 8 additions & 4 deletions bw2data/revisions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import itertools
import json
import sys
from typing import (
TYPE_CHECKING,
Any,
Expand All @@ -8,7 +9,6 @@
Iterator,
Optional,
Sequence,
TypeAlias,
TypeVar,
Union,
)
Expand All @@ -33,10 +33,14 @@
from bw2data.snowflake_ids import snowflake_id_generator
from bw2data.utils import get_node

try:
from typing import Self
except ImportError:
if sys.version_info < (3, 10):
from typing_extensions import TypeAlias
else:
from typing import TypeAlias
if sys.version_info < (3, 11):
from typing_extensions import Self
else:
from typing import Self

if TYPE_CHECKING:
import typing
Expand Down

0 comments on commit 733aff4

Please sign in to comment.