From 4d30ae540d6d6e49cc3bbb74bd5826c98f196456 Mon Sep 17 00:00:00 2001 From: Robert McArthur Date: Wed, 1 May 2024 16:57:33 +1000 Subject: [PATCH] DEV: resolve import error on 3.9 --- src/cogent3/app/typing.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/cogent3/app/typing.py b/src/cogent3/app/typing.py index 7836e83f5..803e5ff0f 100644 --- a/src/cogent3/app/typing.py +++ b/src/cogent3/app/typing.py @@ -4,13 +4,20 @@ import inspect import re +import sys from typing import ForwardRef, TypeVar, Union -from types import UnionType from typing_extensions import get_args, get_origin +if sys.version_info.minor >= 10: + from types import UnionType + + NESTED_HINTS = (Union, UnionType, list, tuple, set) +else: + NESTED_HINTS = (Union, list, tuple, set) + AlignedSeqsType = TypeVar("AlignedSeqsType", "Alignment", "ArrayAlignment") UnalignedSeqsType = TypeVar("UnalignedSeqsType", bound="SequenceCollection") SeqsCollectionType = Union[AlignedSeqsType, UnalignedSeqsType] @@ -76,7 +83,7 @@ def get_constraint_names(*hints) -> set[str | type]: all_hints.update(hint.__constraints__) continue - if get_origin(hint) in (Union, UnionType, list, tuple, set): + if get_origin(hint) in NESTED_HINTS: all_hints.update(get_constraint_names(*get_args(hint))) if type(hint) == type: