From b23c5a83dc7e72a227a26cc2b3cd763dfb696683 Mon Sep 17 00:00:00 2001 From: lojack5 <1458329+lojack5@users.noreply.github.com> Date: Wed, 18 Oct 2023 13:10:24 -0600 Subject: [PATCH] Python <3.9 typing compat: tuples Subscripting builtins.tuple was added in Python 3.9, so use `typing.Tuple` where applicable. --- etgtools/extractors.py | 2 +- etgtools/pi_generator.py | 2 +- etgtools/tweaker_tools.py | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/etgtools/extractors.py b/etgtools/extractors.py index a534f05e..071cf484 100644 --- a/etgtools/extractors.py +++ b/etgtools/extractors.py @@ -540,7 +540,7 @@ class FunctionDef(BaseDef, FixWxPrefix): elif len(returns) == 1: self.pyArgsString = f'{self.pyArgsString} -> {returns[0]}' elif len(returns) > 1: - self.pyArgsString = f"{self.pyArgsString} -> tuple[{', '.join(returns)}]" + self.pyArgsString = f"{self.pyArgsString} -> Tuple[{', '.join(returns)}]" def collectPySignatures(self): diff --git a/etgtools/pi_generator.py b/etgtools/pi_generator.py index b1507d0a..6aad3ce4 100644 --- a/etgtools/pi_generator.py +++ b/etgtools/pi_generator.py @@ -82,7 +82,7 @@ typing_imports = """\ from __future__ import annotations from collections.abc import Callable from enum import IntEnum, IntFlag, auto -from typing import Any, overload, TypeAlias, TypeVar, ParamSpec, Generic, Union, Optional, List +from typing import Any, overload, TypeAlias, TypeVar, ParamSpec, Generic, Union, Optional, List, Tuple """ diff --git a/etgtools/tweaker_tools.py b/etgtools/tweaker_tools.py index 2235426d..dc8eec28 100644 --- a/etgtools/tweaker_tools.py +++ b/etgtools/tweaker_tools.py @@ -19,7 +19,7 @@ import re import sys, os import copy import textwrap -from typing import Union +from typing import Union, Tuple PY3 = sys.version_info[0] == 3 @@ -222,7 +222,7 @@ class FixWxPrefix(object): return 'list' return type_map.get(type_name, type_name) - def parseNameAndType(self, name_string: str, type_string: Union[str, None]) -> tuple[str, str | None]: + def parseNameAndType(self, name_string: str, type_string: Union[str, None]) -> Tuple[str, str | None]: """Given an identifier name and an optional type annotation, process these per cleanName and cleanType. Further performs transforms on the identifier name that may be required due to the type annotation.