Skip to content

Commit

Permalink
Remove some old python fallbacks
Browse files Browse the repository at this point in the history
ForwardRef needs to explicitly call out recursive_guard in python 3.12.
  • Loading branch information
timj committed Jul 12, 2024
1 parent e63e874 commit 8108c08
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 20 deletions.
16 changes: 3 additions & 13 deletions python/lsst/pex/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down
9 changes: 2 additions & 7 deletions python/lsst/pex/config/dictField.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 8108c08

Please sign in to comment.