Skip to content

Commit af491fc

Browse files
authored
Fix compatibility with Python 3.8 and 3.9 (#328)
1 parent a5484b9 commit af491fc

File tree

13 files changed

+45
-34
lines changed

13 files changed

+45
-34
lines changed

astrapy/constants.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
from __future__ import annotations
1616

17-
from typing import Any, Iterable, TypeVar
17+
from typing import Any, Dict, Iterable, Optional, Tuple, TypeVar, Union
1818

1919
from astrapy.settings.defaults import (
2020
DATA_API_ENVIRONMENT_CASSANDRA,
@@ -26,12 +26,14 @@
2626
DATA_API_ENVIRONMENT_TEST,
2727
)
2828

29-
DefaultDocumentType = dict[str, Any]
30-
DefaultRowType = dict[str, Any]
31-
ProjectionType = Iterable[str] | dict[str, bool | dict[str, int | Iterable[int]]]
32-
SortType = dict[str, Any]
33-
FilterType = dict[str, Any]
34-
CallerType = tuple[str | None, str | None]
29+
DefaultDocumentType = Dict[str, Any]
30+
DefaultRowType = Dict[str, Any]
31+
ProjectionType = Union[
32+
Iterable[str], Dict[str, Union[bool, Dict[str, Union[int, Iterable[int]]]]]
33+
]
34+
SortType = Dict[str, Any]
35+
FilterType = Dict[str, Any]
36+
CallerType = Tuple[Optional[str], Optional[str]]
3537

3638

3739
ROW = TypeVar("ROW")

astrapy/data/info/table_descriptor/table_altering.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
from abc import ABC, abstractmethod
1818
from dataclasses import dataclass
19-
from typing import Any, cast
19+
from typing import Any, Dict, cast
2020

2121
from astrapy.data.info.table_descriptor.table_columns import (
2222
TableColumnTypeDescriptor,
@@ -251,7 +251,7 @@ def _from_dict(cls, raw_dict: dict[str, Any]) -> AlterTableAddVectorize:
251251
)
252252
return AlterTableAddVectorize(
253253
columns=cast(
254-
dict[str, VectorServiceOptions],
254+
Dict[str, VectorServiceOptions],
255255
_columns,
256256
)
257257
)

astrapy/data/utils/collection_converters.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from __future__ import annotations
1616

1717
import datetime
18-
from typing import Any, cast
18+
from typing import Any, Dict, cast
1919

2020
from astrapy.constants import DefaultDocumentType
2121
from astrapy.data.utils.extended_json_converters import (
@@ -125,7 +125,7 @@ def preprocess_collection_payload(
125125

126126
if payload:
127127
return cast(
128-
dict[str, Any],
128+
Dict[str, Any],
129129
preprocess_collection_payload_value([], payload, options=options),
130130
)
131131
else:

astrapy/data/utils/distinct_extractors.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@
2020
Any,
2121
Callable,
2222
Iterable,
23+
Optional,
24+
Tuple,
2325
)
2426

2527
from astrapy.data.utils.collection_converters import preprocess_collection_payload_value
2628
from astrapy.data_types import DataAPIMap, DataAPISet
2729
from astrapy.utils.api_options import FullSerdesOptions
2830

29-
IndexPairType = tuple[str, int | None]
31+
IndexPairType = Tuple[str, Optional[int]]
3032

3133

3234
def _maybe_valid_list_index(key_block: str) -> int | None:

astrapy/data/utils/table_converters.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import ipaddress
2222
import json
2323
import math
24-
from typing import Any, Callable, Generic, cast
24+
from typing import Any, Callable, Dict, Generic, cast
2525

2626
from astrapy.constants import ROW
2727
from astrapy.data.info.table_descriptor.table_columns import (
@@ -677,7 +677,7 @@ def preprocess_table_payload(
677677

678678
if payload:
679679
return cast(
680-
dict[str, Any],
680+
Dict[str, Any],
681681
preprocess_table_payload_value([], payload, options=options),
682682
)
683683
else:

astrapy/data_types/data_api_map.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
from __future__ import annotations
1616

1717
import math
18-
from collections.abc import Mapping
19-
from typing import Generic, Iterable, Iterator, TypeVar
18+
from typing import Generic, Iterable, Iterator, Mapping, TypeVar
2019

2120
T = TypeVar("T")
2221
U = TypeVar("U")

astrapy/data_types/data_api_set.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414

1515
from __future__ import annotations
1616

17-
from collections.abc import Set
18-
from typing import Any, Generic, Iterable, Iterator, TypeVar
17+
from typing import AbstractSet, Any, Generic, Iterable, Iterator, TypeVar
1918

2019
T = TypeVar("T")
2120

@@ -28,7 +27,7 @@ def _accumulate(destination: list[T], source: Iterable[T]) -> list[T]:
2827
return _new_destination
2928

3029

31-
class DataAPISet(Generic[T], Set[T]):
30+
class DataAPISet(Generic[T], AbstractSet[T]):
3231
"""
3332
An immutable 'set-like' class that preserves the order and can store
3433
non-hashable entries (entries must support __eq__). Not designed for performance.

astrapy/data_types/data_api_vector.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@
1717
import struct
1818
from collections import UserList
1919
from dataclasses import dataclass
20-
from typing import Iterator
20+
from typing import TYPE_CHECKING, Iterator
21+
22+
if TYPE_CHECKING:
23+
FloatList = UserList[float]
24+
else:
25+
FloatList = UserList
2126

2227
# Floats are always encoded big-endian with 4 bytes per float.
2328
ENDIANNESS_CHAR = ">"
@@ -61,7 +66,7 @@ def bytes_to_floats(byte_blob: bytes, n: int | None = None) -> list[float]:
6166

6267

6368
@dataclass
64-
class DataAPIVector(UserList[float]):
69+
class DataAPIVector(FloatList):
6570
r"""
6671
A class wrapping a list of float numbers to be treated as a "vector" within the
6772
Data API. This class has the same functionalities as the underlying `list[float]`,

astrapy/utils/api_commander.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import re
2020
from decimal import Decimal
2121
from types import TracebackType
22-
from typing import Any, Iterable, Sequence, cast
22+
from typing import Any, Dict, Iterable, Sequence, cast
2323

2424
import httpx
2525

@@ -291,14 +291,14 @@ def _raw_response_to_json(
291291
@staticmethod
292292
def _decimal_unaware_parse_json_response(response_text: str) -> dict[str, Any]:
293293
return cast(
294-
dict[str, Any],
294+
Dict[str, Any],
295295
json.loads(response_text),
296296
)
297297

298298
@staticmethod
299299
def _decimal_aware_parse_json_response(response_text: str) -> dict[str, Any]:
300300
return cast(
301-
dict[str, Any],
301+
Dict[str, Any],
302302
json.loads(
303303
response_text,
304304
parse_float=Decimal,

tests/idiomatic/conftest.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
from __future__ import annotations
1818

19-
from typing import Any, Iterable
19+
from typing import Any, Dict, Iterable
2020

2121
import pytest
2222

@@ -37,8 +37,8 @@
3737
sync_fail_if_not_removed,
3838
)
3939

40-
DefaultCollection = Collection[dict[str, Any]]
41-
DefaultAsyncCollection = AsyncCollection[dict[str, Any]]
40+
DefaultCollection = Collection[Dict[str, Any]]
41+
DefaultAsyncCollection = AsyncCollection[Dict[str, Any]]
4242

4343
TEST_COLLECTION_INSTANCE_NAME = "test_coll_instance"
4444
TEST_COLLECTION_NAME = "id_test_collection"

0 commit comments

Comments
 (0)