From dd6eb71fdd586fc7e04acf0b3e8892fb933c7117 Mon Sep 17 00:00:00 2001 From: Philipp Moritz Date: Mon, 16 Oct 2023 18:23:07 -0700 Subject: [PATCH] [Dependencies] Remove typing_extensions (#40336) Now that we drop Python 3.7 support for Ray 2.8, we can remove the `typing_extensions` dependency. --- doc/source/ray-overview/pip_freeze_ray-ml-py39-cpu.txt | 1 - doc/source/ray-overview/pip_freeze_ray-py39-cpu.txt | 1 - python/ray/_private/worker.py | 5 +---- python/ray/data/block.py | 8 ++------ python/ray/data/dataset.py | 7 +------ python/ray/data/datasource/file_based_datasource.py | 6 +----- python/ray/data/datasource/parquet_datasource.py | 8 +------- python/ray/data/preprocessors/batch_mapper.py | 8 +------- python/ray/data/read_api.py | 7 +------ python/ray/train/_internal/data_config.py | 8 +------- python/ray/util/state/custom_types.py | 7 +------ python/requirements.txt | 1 - python/setup.py | 3 --- release/nightly_tests/dataset/iter_batches_benchmark.py | 6 +----- release/nightly_tests/dataset/map_batches_benchmark.py | 6 +----- release/ray_release/configs/global_config.py | 2 +- 16 files changed, 13 insertions(+), 71 deletions(-) diff --git a/doc/source/ray-overview/pip_freeze_ray-ml-py39-cpu.txt b/doc/source/ray-overview/pip_freeze_ray-ml-py39-cpu.txt index 98a2639438153..fb91fcbff3dec 100644 --- a/doc/source/ray-overview/pip_freeze_ray-ml-py39-cpu.txt +++ b/doc/source/ray-overview/pip_freeze_ray-ml-py39-cpu.txt @@ -446,7 +446,6 @@ triton==2.0.0 tune-sklearn @ git+https://github.com/ray-project/tune-sklearn@6e813e18fb43156d32f0958794881c7c12d14f17 typeguard==2.13.3 typer==0.9.0 -typing_extensions==4.5.0 tzdata==2023.3 uri-template==1.3.0 uritemplate==3.0.1 diff --git a/doc/source/ray-overview/pip_freeze_ray-py39-cpu.txt b/doc/source/ray-overview/pip_freeze_ray-py39-cpu.txt index 600ecef9ce84c..29aff27c82bd2 100644 --- a/doc/source/ray-overview/pip_freeze_ray-py39-cpu.txt +++ b/doc/source/ray-overview/pip_freeze_ray-py39-cpu.txt @@ -149,7 +149,6 @@ tensorboardX==2.6 tifffile==2023.7.10 tqdm @ file:///croot/tqdm_1679561862951/work typer==0.9.0 -typing_extensions==4.5.0 tzdata==2023.3 uritemplate==3.0.1 urllib3 @ file:///croot/urllib3_1686163155763/work diff --git a/python/ray/_private/worker.py b/python/ray/_private/worker.py index 985860dab95c9..05c57102a0193 100644 --- a/python/ray/_private/worker.py +++ b/python/ray/_private/worker.py @@ -37,10 +37,7 @@ import colorama import setproctitle -if sys.version_info >= (3, 8): - from typing import Literal, Protocol -else: - from typing_extensions import Literal, Protocol +from typing import Literal, Protocol import ray import ray._private.node diff --git a/python/ray/data/block.py b/python/ray/data/block.py index ea5937ace8933..35bfcf1f971b3 100644 --- a/python/ray/data/block.py +++ b/python/ray/data/block.py @@ -1,6 +1,5 @@ import collections import os -import sys import time from dataclasses import dataclass from typing import ( @@ -9,7 +8,9 @@ Dict, Iterator, List, + Literal, Optional, + Protocol, Tuple, TypeVar, Union, @@ -30,11 +31,6 @@ except ImportError: resource = None -if sys.version_info >= (3, 8): - from typing import Literal, Protocol -else: - from typing_extensions import Literal, Protocol - if TYPE_CHECKING: import pandas import pyarrow diff --git a/python/ray/data/dataset.py b/python/ray/data/dataset.py index e3b41fced9cbe..1e77ff2878f27 100644 --- a/python/ray/data/dataset.py +++ b/python/ray/data/dataset.py @@ -3,7 +3,6 @@ import html import itertools import logging -import sys import time from typing import ( TYPE_CHECKING, @@ -14,6 +13,7 @@ Iterable, Iterator, List, + Literal, Mapping, Optional, Tuple, @@ -131,11 +131,6 @@ from ray.widgets import Template from ray.widgets.util import repr_with_fallback -if sys.version_info >= (3, 8): - from typing import Literal -else: - from typing_extensions import Literal - if TYPE_CHECKING: import dask import mars diff --git a/python/ray/data/datasource/file_based_datasource.py b/python/ray/data/datasource/file_based_datasource.py index 5bd67749c0671..b1654e03d6dde 100644 --- a/python/ray/data/datasource/file_based_datasource.py +++ b/python/ray/data/datasource/file_based_datasource.py @@ -12,6 +12,7 @@ Iterable, Iterator, List, + Literal, Optional, Tuple, TypeVar, @@ -45,11 +46,6 @@ ) from ray.util.annotations import DeveloperAPI, PublicAPI -if sys.version_info >= (3, 8): - from typing import Literal -else: - from typing_extensions import Literal - if TYPE_CHECKING: import pandas as pd import pyarrow diff --git a/python/ray/data/datasource/parquet_datasource.py b/python/ray/data/datasource/parquet_datasource.py index f9d6ca34c176b..1ff42af88c559 100644 --- a/python/ray/data/datasource/parquet_datasource.py +++ b/python/ray/data/datasource/parquet_datasource.py @@ -1,6 +1,5 @@ import logging -import sys -from typing import TYPE_CHECKING, Callable, Iterator, List, Optional, Union +from typing import TYPE_CHECKING, Callable, Iterator, List, Literal, Optional, Union import numpy as np @@ -23,11 +22,6 @@ from ray.data.datasource.parquet_base_datasource import ParquetBaseDatasource from ray.util.annotations import PublicAPI -if sys.version_info >= (3, 8): - from typing import Literal -else: - from typing_extensions import Literal - if TYPE_CHECKING: import pyarrow from pyarrow.dataset import ParquetFileFragment diff --git a/python/ray/data/preprocessors/batch_mapper.py b/python/ray/data/preprocessors/batch_mapper.py index e85f0af5d2458..a6679b9b7e3a6 100644 --- a/python/ray/data/preprocessors/batch_mapper.py +++ b/python/ray/data/preprocessors/batch_mapper.py @@ -1,6 +1,5 @@ -import sys import warnings -from typing import TYPE_CHECKING, Any, Callable, Dict, Optional, Union +from typing import TYPE_CHECKING, Any, Callable, Dict, Literal, Optional, Union import numpy as np @@ -8,11 +7,6 @@ from ray.data.preprocessor import Preprocessor from ray.util.annotations import Deprecated -if sys.version_info >= (3, 8): - from typing import Literal -else: - from typing_extensions import Literal - if TYPE_CHECKING: import pandas diff --git a/python/ray/data/read_api.py b/python/ray/data/read_api.py index e898025d0364a..6d439caeceb00 100644 --- a/python/ray/data/read_api.py +++ b/python/ray/data/read_api.py @@ -1,13 +1,13 @@ import collections import logging import os -import sys from typing import ( TYPE_CHECKING, Any, Callable, Dict, List, + Literal, Optional, Tuple, TypeVar, @@ -83,11 +83,6 @@ from ray.util.annotations import Deprecated, DeveloperAPI, PublicAPI from ray.util.scheduling_strategies import NodeAffinitySchedulingStrategy -if sys.version_info >= (3, 8): - from typing import Literal -else: - from typing_extensions import Literal - if TYPE_CHECKING: import dask import datasets diff --git a/python/ray/train/_internal/data_config.py b/python/ray/train/_internal/data_config.py index 4d36386e684f9..461a6013547d8 100644 --- a/python/ray/train/_internal/data_config.py +++ b/python/ray/train/_internal/data_config.py @@ -1,5 +1,4 @@ -import sys -from typing import Dict, List, Optional, Union +from typing import Dict, List, Literal, Optional, Union import ray from ray.actor import ActorHandle @@ -10,11 +9,6 @@ from ray.train.constants import TRAIN_DATASET_KEY # noqa from ray.util.annotations import DeveloperAPI, PublicAPI -if sys.version_info >= (3, 8): - from typing import Literal -else: - from typing_extensions import Literal - @PublicAPI(stability="stable") class DataConfig: diff --git a/python/ray/util/state/custom_types.py b/python/ray/util/state/custom_types.py index 5f3535a274468..28c5e67cadf1f 100644 --- a/python/ray/util/state/custom_types.py +++ b/python/ray/util/state/custom_types.py @@ -1,5 +1,3 @@ -import sys - from ray.core.generated.common_pb2 import ( TaskStatus, TaskType, @@ -13,10 +11,7 @@ ) from ray.dashboard.memory_utils import ReferenceType -if sys.version_info >= (3, 8): - from typing import Literal -else: - from typing_extensions import Literal +from typing import Literal ACTOR_STATUS = [ diff --git a/python/requirements.txt b/python/requirements.txt index 91308af2683e9..7ea8f7717e49a 100644 --- a/python/requirements.txt +++ b/python/requirements.txt @@ -25,7 +25,6 @@ grpcio == 1.54.2; sys_platform == "darwin" grpcio >= 1.54.2; sys_platform != "darwin" numpy>=1.16; python_version < '3.9' numpy>=1.19.3; python_version >= '3.9' -typing_extensions; python_version < '3.8' pyarrow >= 6.0.1; platform_system != "Windows" pyarrow >= 6.0.1, < 7.0.0; platform_system == "Windows" diff --git a/python/setup.py b/python/setup.py index cfb60ae77d5e4..06870881c6e91 100644 --- a/python/setup.py +++ b/python/setup.py @@ -359,9 +359,6 @@ def get_packages(self): "aiosignal", "frozenlist", "requests", - # Light weight requirement, can be replaced with "typing" once - # we deprecate Python 3.7 (this will take a while). - "typing_extensions; python_version < '3.8'", ] diff --git a/release/nightly_tests/dataset/iter_batches_benchmark.py b/release/nightly_tests/dataset/iter_batches_benchmark.py index cf9428ff2db9b..c30084b2ff8d4 100644 --- a/release/nightly_tests/dataset/iter_batches_benchmark.py +++ b/release/nightly_tests/dataset/iter_batches_benchmark.py @@ -1,4 +1,3 @@ -import sys from typing import Optional import ray @@ -6,10 +5,7 @@ from benchmark import Benchmark -if sys.version_info >= (3, 8): - from typing import Literal -else: - from typing_extensions import Literal +from typing import Literal def iter_batches( diff --git a/release/nightly_tests/dataset/map_batches_benchmark.py b/release/nightly_tests/dataset/map_batches_benchmark.py index 6f1a7fbc7882c..42792324f4b28 100644 --- a/release/nightly_tests/dataset/map_batches_benchmark.py +++ b/release/nightly_tests/dataset/map_batches_benchmark.py @@ -1,4 +1,3 @@ -import sys from typing import Optional, Union import numpy as np @@ -8,10 +7,7 @@ from benchmark import Benchmark -if sys.version_info >= (3, 8): - from typing import Literal -else: - from typing_extensions import Literal +from typing import Literal def map_batches( diff --git a/release/ray_release/configs/global_config.py b/release/ray_release/configs/global_config.py index 8aea549eac8b9..96b41d509476f 100644 --- a/release/ray_release/configs/global_config.py +++ b/release/ray_release/configs/global_config.py @@ -1,7 +1,7 @@ import os import yaml -from typing_extensions import TypedDict +from typing import TypedDict class GlobalConfig(TypedDict):