From 1c37efcc6dc32453032788287304f1fb40ae881a Mon Sep 17 00:00:00 2001 From: Avi Shinnar Date: Wed, 31 Jan 2024 16:46:24 -0500 Subject: [PATCH] Remove code for Python 3.7 compatibility. Update mypi to use 3.8 Signed-off-by: Avi Shinnar --- lale/datasets/util.py | 8 +------- lale/expressions.py | 3 +-- lale/helpers.py | 7 +------ lale/lib/aif360/util.py | 9 +-------- lale/lib/rasl/datasets.py | 4 ++-- lale/lib/rasl/functions.py | 3 +-- lale/lib/rasl/metrics.py | 4 ++-- lale/lib/rasl/monoid.py | 4 +--- lale/lib/rasl/project.py | 3 +-- lale/lib/rasl/scores.py | 3 +-- lale/operator_wrapper.py | 8 +------- lale/operators.py | 7 +------ lale/util/VisitorMeta.py | 14 +------------- mypy.ini | 2 +- 14 files changed, 16 insertions(+), 63 deletions(-) diff --git a/lale/datasets/util.py b/lale/datasets/util.py index 304c2f40f..dd6b570d8 100644 --- a/lale/datasets/util.py +++ b/lale/datasets/util.py @@ -11,8 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -import sys -from typing import Any, Tuple, overload +from typing import Any, Literal, Tuple, overload import numpy as np import pandas as pd @@ -20,11 +19,6 @@ from lale.datasets.data_schemas import add_table_name, get_table_name -if sys.version_info >= (3, 8): - from typing import Literal # raises a mypy error for <3.8 -else: - from typing_extensions import Literal - try: from pyspark.sql import SparkSession diff --git a/lale/expressions.py b/lale/expressions.py index 15925bdf0..e5768ee9b 100644 --- a/lale/expressions.py +++ b/lale/expressions.py @@ -17,10 +17,9 @@ import typing from copy import deepcopy from io import StringIO -from typing import Any, Dict, Optional, Union, overload +from typing import Any, Dict, Literal, Optional, Union, overload import astunparse -from typing_extensions import Literal AstLits = (ast.Num, ast.Str, ast.List, ast.Tuple, ast.Set, ast.Dict, ast.Constant) AstLit = Union[ast.Num, ast.Str, ast.List, ast.Tuple, ast.Set, ast.Dict, ast.Constant] diff --git a/lale/helpers.py b/lale/helpers.py index dd1ede399..6c15e1175 100644 --- a/lale/helpers.py +++ b/lale/helpers.py @@ -16,7 +16,6 @@ import copy import importlib import logging -import sys import time import traceback from importlib import util @@ -26,6 +25,7 @@ Dict, Iterable, List, + Literal, Mapping, Optional, Set, @@ -46,11 +46,6 @@ import lale.datasets.data_schemas -if sys.version_info >= (3, 8): - from typing import Literal # raises a mypy error for <3.8 -else: - from typing_extensions import Literal - try: import torch diff --git a/lale/lib/aif360/util.py b/lale/lib/aif360/util.py index 91aef65db..f2d5c4645 100644 --- a/lale/lib/aif360/util.py +++ b/lale/lib/aif360/util.py @@ -14,8 +14,7 @@ import functools import logging -import sys -from typing import List, Optional, Tuple, Union, cast +from typing import List, Literal, Optional, Tuple, Union, cast import aif360.algorithms.postprocessing import aif360.datasets @@ -38,12 +37,6 @@ from lale.operators import TrainablePipeline, TrainedOperator from lale.type_checking import JSON_TYPE, validate_schema_directly -if sys.version_info >= (3, 8): - from typing import Literal # raises a mypy error for <3.8 -else: - from typing_extensions import Literal - - logger = logging.getLogger(__name__) logger.setLevel(logging.WARNING) diff --git a/lale/lib/rasl/datasets.py b/lale/lib/rasl/datasets.py index 0ba3ee913..f2967ce51 100644 --- a/lale/lib/rasl/datasets.py +++ b/lale/lib/rasl/datasets.py @@ -12,12 +12,12 @@ # See the License for the specific language governing permissions and # limitations under the License. -from typing import Iterable, Tuple, Union, cast, overload +from typing import Iterable, Literal, Tuple, Union, cast, overload import pandas as pd import sklearn.model_selection import sklearn.tree -from typing_extensions import Literal, TypeAlias +from typing_extensions import TypeAlias import lale.helpers from lale.datasets import pandas2spark diff --git a/lale/lib/rasl/functions.py b/lale/lib/rasl/functions.py index 6309849bc..be1ce3ef5 100644 --- a/lale/lib/rasl/functions.py +++ b/lale/lib/rasl/functions.py @@ -13,10 +13,9 @@ # limitations under the License. import datetime -from typing import Any, Callable, Dict, Generic, List, Optional, TypeVar +from typing import Any, Callable, Dict, Generic, List, Optional, Protocol, TypeVar import numpy as np -from typing_extensions import Protocol from lale.helpers import _is_pandas_df, _is_spark_df diff --git a/lale/lib/rasl/metrics.py b/lale/lib/rasl/metrics.py index b98a8c726..493a01b2b 100644 --- a/lale/lib/rasl/metrics.py +++ b/lale/lib/rasl/metrics.py @@ -14,11 +14,11 @@ import functools from abc import abstractmethod -from typing import Dict, Iterable, Optional, Tuple, TypeVar, Union, cast +from typing import Dict, Iterable, Optional, Protocol, Tuple, TypeVar, Union, cast import numpy as np import pandas as pd -from typing_extensions import Protocol, TypeAlias +from typing_extensions import TypeAlias from lale.expressions import astype, count, it from lale.expressions import sum as lale_sum diff --git a/lale/lib/rasl/monoid.py b/lale/lib/rasl/monoid.py index b83439a91..0d931b818 100644 --- a/lale/lib/rasl/monoid.py +++ b/lale/lib/rasl/monoid.py @@ -13,9 +13,7 @@ # limitations under the License. from abc import ABC, abstractmethod -from typing import Any, Generic, Optional, TypeVar - -from typing_extensions import Protocol, runtime_checkable +from typing import Any, Generic, Optional, Protocol, TypeVar, runtime_checkable _InputType_contra = TypeVar("_InputType_contra", contravariant=True) _OutputType_co = TypeVar("_OutputType_co", covariant=True) diff --git a/lale/lib/rasl/project.py b/lale/lib/rasl/project.py index 521a9baee..e30be0d27 100644 --- a/lale/lib/rasl/project.py +++ b/lale/lib/rasl/project.py @@ -11,10 +11,9 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -from typing import Any, List, Optional +from typing import Any, List, Optional, Protocol import numpy as np -from typing_extensions import Protocol import lale.datasets.data_schemas import lale.docstrings diff --git a/lale/lib/rasl/scores.py b/lale/lib/rasl/scores.py index 3d40c906c..e86cd35bf 100644 --- a/lale/lib/rasl/scores.py +++ b/lale/lib/rasl/scores.py @@ -12,11 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. -from typing import Any, Tuple, TypeVar +from typing import Any, Protocol, Tuple, TypeVar import numpy as np from scipy import special -from typing_extensions import Protocol from lale.expressions import count as agg_count from lale.expressions import it diff --git a/lale/operator_wrapper.py b/lale/operator_wrapper.py index 1b300a2dd..87bc95695 100644 --- a/lale/operator_wrapper.py +++ b/lale/operator_wrapper.py @@ -14,16 +14,10 @@ import inspect import logging -import sys -from typing import List, Optional, Set +from typing import Container, List, Optional, Set from lale.operators import Operator, clone_op, get_op_from_lale_lib -if sys.version_info < (3, 9): - from typing import Container # raises a mypy error for <3.8 -else: - from collections.abc import Container - logger = logging.getLogger(__name__) diff --git a/lale/operators.py b/lale/operators.py index cadf64e81..1caf4ffe9 100644 --- a/lale/operators.py +++ b/lale/operators.py @@ -153,7 +153,6 @@ import itertools import logging import os -import sys import warnings from abc import abstractmethod from types import MappingProxyType @@ -164,6 +163,7 @@ Generic, Iterable, List, + Literal, Mapping, Optional, Set, @@ -230,11 +230,6 @@ sklearn_version = version.parse(getattr(sklearn, "__version__")) -if sys.version_info >= (3, 8): - from typing import Literal # raises a mypy error for <3.8 -else: - from typing_extensions import Literal - try: from sklearn.pipeline import ( # pylint:disable=ungrouped-imports if_delegate_has_method, diff --git a/lale/util/VisitorMeta.py b/lale/util/VisitorMeta.py index fed0addbb..5d28abd38 100644 --- a/lale/util/VisitorMeta.py +++ b/lale/util/VisitorMeta.py @@ -12,11 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -# A shim for compatibility across 3.7. -# pre 3.7, we need to inherit from the GenericMeta class (which inherits from ABCmeta) -# to use Generic (which we want to do) -# post 3.7, GenericMeta no longer exists -import sys from abc import ABCMeta @@ -53,14 +48,7 @@ def __init__(cls, *args, **kwargs): setattr(cls, "_accept", ll["_accept"]) -if sys.version_info < (3, 7, 0): - from typing import GenericMeta # type: ignore -else: - global GenericMeta # pylint:disable=global-at-module-level - GenericMeta = ABCMeta # type: ignore - - -class AbstractVisitorMeta(VisitorMeta, GenericMeta): +class AbstractVisitorMeta(VisitorMeta, ABCMeta): """This meta class adds an _accept method that calls visitCLASSNAME on the visitor. It does not currently support inheritance: you need to define the visitC method for subclasses explicitly. diff --git a/mypy.ini b/mypy.ini index 0de2ac6bb..0e4df7832 100644 --- a/mypy.ini +++ b/mypy.ini @@ -1,5 +1,5 @@ [mypy] -python_version = 3.7 +python_version = 3.8 ignore_missing_imports = True [mypy-pandas]