Skip to content

Commit

Permalink
Retire python 3.8 and other version checks that are no longer needed
Browse files Browse the repository at this point in the history
Signed-off-by: Rob Ambalu <[email protected]>
  • Loading branch information
robambalu committed Feb 13, 2025
1 parent 0a72f34 commit ae63c74
Show file tree
Hide file tree
Showing 12 changed files with 38 additions and 165 deletions.
1 change: 0 additions & 1 deletion .github/actions/setup-python/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ inputs:
type: choice
description: "Version to install"
options:
- '3.8'
- '3.9'
- '3.10'
- '3.11'
Expand Down
39 changes: 0 additions & 39 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,11 @@ jobs:
- macos-14 # https://github.com/actions/runner-images/blob/main/images/macos/macos-14-arm64-Readme.md
- windows-2019 # https://github.com/actions/runner-images/blob/main/images/windows/Windows2019-Readme.md
python-version:
- "3.8"
- "3.9"
- "3.10"
- "3.11"
- "3.12"
cibuildwheel:
- "cp38"
- "cp39"
- "cp310"
- "cp311"
Expand All @@ -217,40 +215,24 @@ jobs:
############################
# Skip when cibuildwheel != python version
# to avoid duplication
- python-version: "3.8"
cibuildwheel: "cp39"
- python-version: "3.8"
cibuildwheel: "cp310"
- python-version: "3.8"
cibuildwheel: "cp311"
- python-version: "3.8"
cibuildwheel: "cp312"
- python-version: "3.9"
cibuildwheel: "cp38"
- python-version: "3.9"
cibuildwheel: "cp310"
- python-version: "3.9"
cibuildwheel: "cp311"
- python-version: "3.9"
cibuildwheel: "cp312"
- python-version: "3.10"
cibuildwheel: "cp38"
- python-version: "3.10"
cibuildwheel: "cp39"
- python-version: "3.10"
cibuildwheel: "cp311"
- python-version: "3.10"
cibuildwheel: "cp312"
- python-version: "3.11"
cibuildwheel: "cp38"
- python-version: "3.11"
cibuildwheel: "cp39"
- python-version: "3.11"
cibuildwheel: "cp310"
- python-version: "3.11"
cibuildwheel: "cp312"
- python-version: "3.12"
cibuildwheel: "cp38"
- python-version: "3.12"
cibuildwheel: "cp39"
- python-version: "3.12"
Expand All @@ -263,16 +245,10 @@ jobs:
# Things to exclude if not a full matrix run #
##############################################
# mac arm builds support py3.10+
- os: macos-14
python-version: "3.8"
- os: macos-14
python-version: "3.9"

# Avoid extra resources for windows build
- is-full-run: false
os: windows-2019
python-version: "3.8"

- is-full-run: false
os: windows-2019
python-version: "3.9"
Expand All @@ -289,10 +265,6 @@ jobs:
- is-full-run: false
os: macos-13

- is-full-run: false
os: macos-14
python-version: "3.8"

- is-full-run: false
os: macos-14
python-version: "3.9"
Expand Down Expand Up @@ -463,7 +435,6 @@ jobs:
- macos-14
- windows-2019
python-version:
- 3.8
- 3.9
- "3.10"
- 3.11
Expand All @@ -475,16 +446,10 @@ jobs:
# Things to exclude if not a full matrix run #
##############################################
# mac arm builds support py3.10+
- os: macos-14
python-version: "3.8"
- os: macos-14
python-version: "3.9"

# Avoid extra resources for windows build
- is-full-run: false
os: windows-2019
python-version: "3.8"

- is-full-run: false
os: windows-2019
python-version: "3.9"
Expand All @@ -501,10 +466,6 @@ jobs:
- is-full-run: false
os: macos-13

- is-full-run: false
os: macos-14
python-version: "3.8"

- is-full-run: false
os: macos-14
python-version: "3.9"
Expand Down
2 changes: 1 addition & 1 deletion csp/impl/types/container_type_normalizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def normalized_type_to_actual_python_type(cls, typ, level=0):
return [cls.normalized_type_to_actual_python_type(typ.__args__[0], level + 1), True]
if origin is typing.List and level == 0:
return [cls.normalized_type_to_actual_python_type(typ.__args__[0], level + 1)]
if origin in (typing.Literal, typing_extensions.Literal): # Not the same in python 3.8/3.9
if origin is typing.Literal:
# Import here to prevent circular import
from csp.impl.types.instantiation_type_resolver import UpcastRegistry

Expand Down
25 changes: 0 additions & 25 deletions csp/impl/types/pydantic_types.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import collections.abc
import sys
import types
import typing
import typing_extensions
from pydantic import GetCoreSchemaHandler, ValidationInfo, ValidatorFunctionWrapHandler
from pydantic_core import CoreSchema, core_schema
from typing import Any, ForwardRef, Generic, Optional, Type, TypeVar, Union, get_args, get_origin
Expand All @@ -11,24 +9,6 @@
from csp.impl.types.tstype import SnapKeyType, SnapType, isTsDynamicBasket
from csp.impl.types.typing_utils import TsTypeValidator

# Required for py38 compatibility
# In python 3.8, get_origin(List[float]) returns list, but you can't call list[float] to retrieve the annotation
# Furthermore, Annotated is part of typing_Extensions and get_origin(Annotated[str, ...]) returns str rather than Annotated
_IS_PY38 = sys.version_info < (3, 9)
# For a more complete list, see https://github.com/alexmojaki/eval_type_backport/blob/main/eval_type_backport/eval_type_backport.py
_PY38_ORIGIN_MAP = {
tuple: typing.Tuple,
list: typing.List,
dict: typing.Dict,
set: typing.Set,
frozenset: typing.FrozenSet,
collections.abc.Callable: typing.Callable,
collections.abc.Iterable: typing.Iterable,
collections.abc.Mapping: typing.Mapping,
collections.abc.MutableMapping: typing.MutableMapping,
collections.abc.Sequence: typing.Sequence,
}

_K = TypeVar("T", covariant=True)
_T = TypeVar("T", covariant=True)

Expand Down Expand Up @@ -140,11 +120,6 @@ def adjust_annotations(

forced_tvars = forced_tvars or {}
origin = get_origin(annotation)
if _IS_PY38:
if isinstance(annotation, typing_extensions._AnnotatedAlias):
return annotation
else:
origin = _PY38_ORIGIN_MAP.get(origin, origin)
args = get_args(annotation)
if isinstance(annotation, str):
annotation = TypeVar(annotation)
Expand Down
36 changes: 8 additions & 28 deletions csp/impl/types/typing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@ def __init__(self):
raise NotImplementedError("Can not init FastList class")


class CspTypingUtils37:
class CspTypingUtils39:
_ORIGIN_COMPAT_MAP = {list: typing.List, set: typing.Set, dict: typing.Dict, tuple: typing.Tuple}
_ARRAY_ORIGINS = (csp.typing.Numpy1DArray, csp.typing.NumpyNDArray)
_GENERIC_ALIASES = (typing._GenericAlias,)
_GENERIC_ALIASES = (typing._GenericAlias, typing.GenericAlias)

@classmethod
def is_generic_container(cls, typ):
return isinstance(typ, cls._GENERIC_ALIASES) and typ.__origin__ is not typing.Union

@classmethod
def is_type_spec(cls, val):
Expand Down Expand Up @@ -47,14 +51,6 @@ def is_numpy_array_type(cls, typ):
def is_numpy_nd_array_type(cls, typ):
return cls.is_numpy_array_type(typ) and cls.get_origin(typ) is csp.typing.NumpyNDArray

# is typ a standard generic container
@classmethod
def is_generic_container(cls, typ):
# isinstance(typing.Callable, typing._GenericAlias) passses in python 3.8, we don't want that
return (
isinstance(typ, cls._GENERIC_ALIASES) and typ.__origin__ is not typing.Union and typ is not typing.Callable
)

@classmethod
def is_union_type(cls, typ):
return isinstance(typ, typing._GenericAlias) and typ.__origin__ is typing.Union
Expand Down Expand Up @@ -82,19 +78,8 @@ def pretty_typename(cls, typ):
return str(typ)


CspTypingUtils = CspTypingUtils37

if sys.version_info >= (3, 9):

class CspTypingUtils39(CspTypingUtils37):
# To support PEP 585
_GENERIC_ALIASES = (typing._GenericAlias, typing.GenericAlias)

@classmethod
def is_generic_container(cls, typ):
return isinstance(typ, cls._GENERIC_ALIASES) and typ.__origin__ is not typing.Union
CspTypingUtils = CspTypingUtils39

CspTypingUtils = CspTypingUtils39

if sys.version_info >= (3, 10):

Expand Down Expand Up @@ -136,7 +121,6 @@ def __init__(self, source_type: type):
from csp.impl.types.tstype import TsType

self._source_type = source_type
# Use CspTypingUtils for 3.8 compatibility, to map list -> typing.List, so one can call List[float]
self._source_origin = typing.get_origin(source_type)
self._source_is_union = CspTypingUtils.is_union_type(source_type)
self._source_args = typing.get_args(source_type)
Expand Down Expand Up @@ -226,11 +210,7 @@ def validate(self, value_type, info=None):
source_validator.validate(value_arg, info)
for value_arg, source_validator in zip(value_args, self._source_args_validators)
)
if sys.version_info >= (3, 9):
return self._source_origin[new_args]
else:
# Because python 3.8 will return "list" for get_origin(List[float]), but you can't call list[(float,)]
return CspTypingUtils._ORIGIN_COMPAT_MAP.get(self._source_origin, self._source_origin)[new_args]
return self._source_origin[new_args]

raise ValueError(f"{self._error_message(value_type)}.")

Expand Down
16 changes: 1 addition & 15 deletions csp/impl/wiring/ast_utils.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
# For managing AST changes across python versions
import ast
import sys


class ASTUtils38:
@staticmethod
def get_subscript_index(subscript: ast.Subscript):
return subscript.slice.value

@staticmethod
def create_subscript_index(value):
return ast.Index(value=value)


class ASTUtils39:
Expand All @@ -23,7 +12,4 @@ def create_subscript_index(value):
return value


if sys.version_info.major > 3 or sys.version_info.minor >= 9:
ASTUtils = ASTUtils39
else:
ASTUtils = ASTUtils38
ASTUtils = ASTUtils39
8 changes: 2 additions & 6 deletions csp/impl/wiring/base_parser.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import ast
import copy
import inspect
import sys
import textwrap
import typing
from abc import ABCMeta, abstractmethod
Expand Down Expand Up @@ -354,7 +353,7 @@ def parse_func_signature(self, funcdef):
if args.vararg or args.kwarg:
raise CspParseError("*args and **kwargs arguments are not supported in csp nodes")

if (sys.version_info.major > 3 or sys.version_info.minor >= 8) and args.posonlyargs:
if args.posonlyargs:
raise CspParseError("position only arguments are not supported in csp nodes")

inputs = []
Expand Down Expand Up @@ -419,10 +418,7 @@ def get_non_ts_args(self):

@classmethod
def _create_ast_module(cls, body):
if sys.version_info.major > 3 or sys.version_info.minor >= 8:
return ast.Module(body, [])
else:
return ast.Module(body)
return ast.Module(body, [])

def _compile_function(self, newfuncdef):
modast = self._create_ast_module([newfuncdef])
Expand Down
25 changes: 9 additions & 16 deletions csp/impl/wiring/node_parser.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import ast
import copy
import inspect
import sys
import textwrap
from warnings import warn

Expand Down Expand Up @@ -738,21 +737,15 @@ def consume_block(*args, **kwargs):
def _create_ast_args(
cls, posonlyargs=[], args=[], kwonlyargs=[], defaults=[], vararg=None, kwarg=None, kw_defaults=[]
):
# position only args are introducing in 3.8
if sys.version_info.major > 3 or sys.version_info.minor >= 8:
return ast.arguments(
posonlyargs=posonlyargs,
args=args,
kwonlyargs=kwonlyargs,
defaults=defaults,
vararg=vararg,
kwarg=kwarg,
kw_defaults=kw_defaults,
)
else:
return ast.arguments(
args=args, kwonlyargs=kwonlyargs, defaults=defaults, vararg=vararg, kwarg=kwarg, kw_defaults=kw_defaults
)
return ast.arguments(
posonlyargs=posonlyargs,
args=args,
kwonlyargs=kwonlyargs,
defaults=defaults,
vararg=vararg,
kwarg=kwarg,
kw_defaults=kw_defaults,
)

def _is_ts_args_removed_from_signature(self):
return True
Expand Down
10 changes: 4 additions & 6 deletions csp/tests/impl/types/test_pydantic_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,8 @@ def test_tvar_container(self):
self.assertAnnotationsEqual(adjust_annotations(List["T"]), List[CspTypeVar[T]])
self.assertAnnotationsEqual(adjust_annotations(List[T]), List[CspTypeVar[T]])
self.assertAnnotationsEqual(adjust_annotations(List[List["T"]]), List[List[CspTypeVar[T]]])
if sys.version_info >= (3, 9):
self.assertAnnotationsEqual(adjust_annotations(list["T"]), list[CspTypeVar[T]])
self.assertAnnotationsEqual(adjust_annotations(list[T]), list[CspTypeVar[T]])
self.assertAnnotationsEqual(adjust_annotations(list["T"]), list[CspTypeVar[T]])
self.assertAnnotationsEqual(adjust_annotations(list[T]), list[CspTypeVar[T]])

self.assertAnnotationsEqual(adjust_annotations(Dict["K", "T"]), Dict[CspTypeVar[K], CspTypeVar[T]])
self.assertAnnotationsEqual(adjust_annotations(Dict[K, T]), Dict[CspTypeVar[K], CspTypeVar[T]])
Expand All @@ -63,9 +62,8 @@ def test_tvar_ts_of_container(self):
self.assertAnnotationsEqual(adjust_annotations(ts[List["T"]]), ts[List[CspTypeVarType[T]]])
self.assertAnnotationsEqual(adjust_annotations(ts[List[T]]), ts[List[CspTypeVarType[T]]])
self.assertAnnotationsEqual(adjust_annotations(ts[List[List["T"]]]), ts[List[List[CspTypeVarType[T]]]])
if sys.version_info >= (3, 9):
self.assertAnnotationsEqual(adjust_annotations(ts[list["T"]]), ts[list[CspTypeVarType[T]]])
self.assertAnnotationsEqual(adjust_annotations(ts[list[T]]), ts[list[CspTypeVarType[T]]])
self.assertAnnotationsEqual(adjust_annotations(ts[list["T"]]), ts[list[CspTypeVarType[T]]])
self.assertAnnotationsEqual(adjust_annotations(ts[list[T]]), ts[list[CspTypeVarType[T]]])

self.assertAnnotationsEqual(
adjust_annotations(ts[Dict["K", "T"]]), ts[Dict[CspTypeVarType[K], CspTypeVarType[T]]]
Expand Down
12 changes: 5 additions & 7 deletions csp/tests/impl/types/test_tstype.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,10 @@ def test_nested_ts_type(self):
def test_list(self):
ta = TypeAdapter(TsType[List[float]])
ta.validate_python(csp.null_ts(List[float]))
if sys.version_info >= (3, 9):
ta.validate_python(csp.null_ts(list[float]))
ta.validate_python(csp.null_ts(list[np.float64]))
ta.validate_python(csp.null_ts(list[int]))
self.assertRaises(Exception, ta.validate_python, csp.null_ts(list[str]))
ta.validate_python(csp.null_ts(list[float]))
ta.validate_python(csp.null_ts(list[np.float64]))
ta.validate_python(csp.null_ts(list[int]))
self.assertRaises(Exception, ta.validate_python, csp.null_ts(list[str]))

ta = TypeAdapter(TsType[list])
ta.validate_python(csp.null_ts(list))
Expand All @@ -58,8 +57,7 @@ def test_list(self):
def test_nested(self):
ta = TypeAdapter(TsType[Dict[str, List[float]]])
ta.validate_python(csp.null_ts(Dict[str, List[float]]))
if sys.version_info >= (3, 9):
ta.validate_python(csp.null_ts(dict[str, list[float]]))
ta.validate_python(csp.null_ts(dict[str, list[float]]))
ta.validate_python(csp.null_ts(Dict[str, List[np.float64]]))
ta.validate_python(csp.null_ts(Dict[str, List[int]]))
self.assertRaises(Exception, ta.validate_python, csp.null_ts(Dict[int, List[float]]))
Expand Down
Loading

0 comments on commit ae63c74

Please sign in to comment.