From 1badc8f41a1aea1b753ba874db929365d7d17493 Mon Sep 17 00:00:00 2001 From: Pip Liggins Date: Thu, 28 Nov 2024 13:43:26 +0000 Subject: [PATCH] fix for 3.9? --- src/adtl/parser.py | 12 ++++++------ tests/test_parser.py | 2 ++ tests/test_python_interface.py | 2 ++ tests/test_transformations.py | 2 ++ 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/adtl/parser.py b/src/adtl/parser.py index 17c2ba9..e953cb9 100644 --- a/src/adtl/parser.py +++ b/src/adtl/parser.py @@ -13,7 +13,7 @@ from datetime import datetime from functools import lru_cache from pathlib import Path -from typing import Any, Callable, Iterable, Literal +from typing import Any, Callable, Iterable, Literal, Union import fastjsonschema import pint @@ -29,8 +29,8 @@ DEFAULT_DATE_FORMAT = "%Y-%m-%d" StrDict = dict[str, Any] -Rule = str | StrDict -Context = dict[str, bool | int | str | list[str]] | None +Rule = Union[str, StrDict] +Context = Union[dict[str, Union[bool, int, str, list[str]]], None] def get_value(row: StrDict, rule: Rule, ctx: Context = None) -> Any: @@ -341,7 +341,7 @@ def flatten(xs): yield x -def expand_refs(spec_fragment: StrDict, defs: StrDict) -> StrDict | list[StrDict]: +def expand_refs(spec_fragment: StrDict, defs: StrDict) -> Union[StrDict, list[StrDict]]: "Expand all references (ref) with definitions (defs)" if spec_fragment == {}: @@ -364,7 +364,7 @@ def expand_for(spec: list[StrDict]) -> list[StrDict]: out = [] def replace_val( - item: str | float | dict[str, Any], replace: dict[str, Any] + item: Union[str, float, dict[str, Any]], replace: dict[str, Any] ) -> dict[str, Any]: block = {} if isinstance(item, str): @@ -521,7 +521,7 @@ class Parser: def __init__( self, - spec: str | Path | StrDict, + spec: Union[str, Path, StrDict], include_defs: list[str] = [], quiet: bool = False, ): diff --git a/tests/test_parser.py b/tests/test_parser.py index 6cd4407..047e8e9 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import collections import contextlib import io diff --git a/tests/test_python_interface.py b/tests/test_python_interface.py index b7e526b..415aa77 100644 --- a/tests/test_python_interface.py +++ b/tests/test_python_interface.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from pathlib import Path import adtl diff --git a/tests/test_transformations.py b/tests/test_transformations.py index 1b767a8..1dc23c0 100644 --- a/tests/test_transformations.py +++ b/tests/test_transformations.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from datetime import datetime import pytest