diff --git a/python/lsst/pex/config/config.py b/python/lsst/pex/config/config.py index b5c7309..bd50740 100644 --- a/python/lsst/pex/config/config.py +++ b/python/lsst/pex/config/config.py @@ -46,14 +46,9 @@ import tempfile import warnings from collections.abc import Mapping +from types import GenericAlias from typing import Any, ForwardRef, Generic, TypeVar, cast, overload -try: - from types import GenericAlias -except ImportError: - # cover python 3.8 usage - GenericAlias = type(Mapping[int, int]) - # if YAML is not available that's fine and we simply don't register # the yaml representer since we know it won't be used. try: @@ -449,13 +444,8 @@ def _parseTypingArgs( _typ = ForwardRef(unpackedParams) # type ignore below because typeshed seems to be wrong. It # indicates there are only 2 args, as it was in python 3.8, but - # 3.9+ takes 3 args. Attempt in old style and new style to - # work with both. - try: - result = _typ._evaluate(globals(), locals(), set()) # type: ignore - except TypeError: - # python 3.8 path - result = _typ._evaluate(globals(), locals()) + # 3.9+ takes 3 args. + result = _typ._evaluate(globals(), locals(), recursive_guard=set()) # type: ignore if result is None: raise ValueError("Could not deduce type from input") unpackedParams = cast(type, result) diff --git a/python/lsst/pex/config/dictField.py b/python/lsst/pex/config/dictField.py index b34e22d..df30d18 100644 --- a/python/lsst/pex/config/dictField.py +++ b/python/lsst/pex/config/dictField.py @@ -263,13 +263,8 @@ def _parseTypingArgs( _typ = ForwardRef(typ) # type ignore below because typeshed seems to be wrong. It # indicates there are only 2 args, as it was in python 3.8, but - # 3.9+ takes 3 args. Attempt in old style and new style to - # work with both. - try: - result = _typ._evaluate(globals(), locals(), set()) # type: ignore - except TypeError: - # python 3.8 path - result = _typ._evaluate(globals(), locals()) + # 3.9+ takes 3 args. + result = _typ._evaluate(globals(), locals(), recursive_guard=set()) # type: ignore if result is None: raise ValueError("Could not deduce type from input") typ = cast(type, result)