Skip to content

Commit

Permalink
astcompat: support up to Python 3.12
Browse files Browse the repository at this point in the history
  • Loading branch information
Technologicat committed Sep 27, 2024
1 parent 0a7ca96 commit 4084a29
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions unpythonic/syntax/astcompat.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"""Conditionally import AST node types only supported by recent enough Python versions."""

__all__ = ["NamedExpr",
"Match", "match_case", "MatchValue", "MatchSingleton", "MatchSequence", "MatchStar", "MatchMapping", "MatchClass", "MatchAs", "MatchOr",
"TryStar",
"TypeAlias", "TypeVar", "ParamSpec", "TypeVarTuple",
"Num", "Str", "Bytes", "NameConstant", "Ellipsis",
"Index", "ExtSlice",
"getconstant"]
Expand All @@ -25,9 +28,23 @@
NamedExpr = _NoSuchNodeType

# No new AST node types in Python 3.9.
# No new AST node types in Python 3.10.
# TODO: Any new AST node types in Python 3.11?
# TODO: Any new AST node types in Python 3.12?

try: # Python 3.10+
from ast import (Match, match_case,
MatchValue, MatchSingleton, MatchSequence, MatchStar,
MatchMapping, MatchClass, MatchAs, MatchOr) # `match`/`case`
except ImportError: # pragma: no cover
Match = match_case = MatchValue = MatchSingleton = MatchSequence = MatchStar = MatchMapping = MatchClass = MatchAs = MatchOr = _NoSuchNodeType

try: # Python 3.11+
from ast import TryStar # `try`/`except*` (exception groups)
except ImportError: # pragma: no cover
TryStar = _NoSuchNodeType

try: # Python 3.12+
from ast import TypeAlias, TypeVar, ParamSpec, TypeVarTuple # `type` statement (type alias)
except ImportError: # pragma: no cover
TypeAlias = TypeVar = ParamSpec = TypeVarTuple = _NoSuchNodeType

# --------------------------------------------------------------------------------
# Deprecated AST node types
Expand Down

0 comments on commit 4084a29

Please sign in to comment.