From 73e9d0d9b6c7edce75b6fcb71ffb632324dbda43 Mon Sep 17 00:00:00 2001 From: c-bata Date: Mon, 26 Dec 2022 16:09:23 +0900 Subject: [PATCH] Remove typing_extensions from the dependencies --- optuna_dashboard/_app.py | 4 +- .../_cached_extra_study_property.py | 2 + optuna_dashboard/_cli.py | 7 +-- optuna_dashboard/_importance.py | 41 +++++++-------- optuna_dashboard/_note.py | 23 +++++---- optuna_dashboard/_serializer.py | 51 ++++++++++--------- optuna_dashboard/_sql_profiler.py | 2 + pyproject.toml | 1 - requirements.txt | 1 - 9 files changed, 70 insertions(+), 62 deletions(-) diff --git a/optuna_dashboard/_app.py b/optuna_dashboard/_app.py index 97be52214..84642d9a8 100644 --- a/optuna_dashboard/_app.py +++ b/optuna_dashboard/_app.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from datetime import datetime from datetime import timedelta import functools @@ -425,7 +427,7 @@ def run_server( run(app, host=host, port=port) -def wsgi(storage: Union[str, BaseStorage]) -> "WSGIApplication": +def wsgi(storage: Union[str, BaseStorage]) -> WSGIApplication: """This function exposes WSGI interface for people who want to run on the production-class WSGI servers like Gunicorn or uWSGI. """ diff --git a/optuna_dashboard/_cached_extra_study_property.py b/optuna_dashboard/_cached_extra_study_property.py index 90e925d2b..765e78334 100644 --- a/optuna_dashboard/_cached_extra_study_property.py +++ b/optuna_dashboard/_cached_extra_study_property.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import copy import threading from typing import Dict diff --git a/optuna_dashboard/_cli.py b/optuna_dashboard/_cli.py index b4bfb6fd1..2d8cfbf1f 100644 --- a/optuna_dashboard/_cli.py +++ b/optuna_dashboard/_cli.py @@ -1,7 +1,10 @@ +from __future__ import annotations + import argparse import os from socketserver import ThreadingMixIn import sys +from typing import TYPE_CHECKING from wsgiref.simple_server import make_server from wsgiref.simple_server import WSGIServer @@ -16,10 +19,8 @@ from ._sql_profiler import register_profiler_view -try: +if TYPE_CHECKING: from typing import Literal -except ImportError: - from typing_extensions import Literal # type: ignore DEBUG = os.environ.get("OPTUNA_DASHBOARD_DEBUG") == "1" diff --git a/optuna_dashboard/_importance.py b/optuna_dashboard/_importance.py index 32dc92377..94bbd51b3 100644 --- a/optuna_dashboard/_importance.py +++ b/optuna_dashboard/_importance.py @@ -1,7 +1,10 @@ +from __future__ import annotations + import threading from typing import Dict from typing import List from typing import Tuple +from typing import TYPE_CHECKING import warnings from optuna.importance import BaseImportanceEvaluator @@ -13,11 +16,6 @@ from optuna.trial import TrialState -try: - from typing import TypedDict -except ImportError: - from typing_extensions import TypedDict - try: from optuna_fast_fanova import FanovaImportanceEvaluator as FastFanovaImportanceEvaluator except ModuleNotFoundError: @@ -27,21 +25,24 @@ FastFanovaImportanceEvaluator = None # type: ignore -ImportanceItemType = TypedDict( - "ImportanceItemType", - { - "name": str, - "importance": float, - "distribution": str, - }, -) -ImportanceType = TypedDict( - "ImportanceType", - { - "target_name": str, - "param_importances": List[ImportanceItemType], - }, -) +if TYPE_CHECKING: + from typing import TypedDict + + ImportanceItemType = TypedDict( + "ImportanceItemType", + { + "name": str, + "importance": float, + "distribution": str, + }, + ) + ImportanceType = TypedDict( + "ImportanceType", + { + "target_name": str, + "param_importances": List[ImportanceItemType], + }, + ) target_name = "Objective Value" param_importance_cache_lock = threading.Lock() diff --git a/optuna_dashboard/_note.py b/optuna_dashboard/_note.py index 15f5f3ffa..8b52e1392 100644 --- a/optuna_dashboard/_note.py +++ b/optuna_dashboard/_note.py @@ -1,27 +1,28 @@ +from __future__ import annotations + import math from typing import Any from typing import Dict +from typing import TYPE_CHECKING from optuna.storages import BaseStorage -try: +if TYPE_CHECKING: from typing import TypedDict -except ImportError: - from typing_extensions import TypedDict + + NoteType = TypedDict( + "NoteType", + { + "version": int, + "body": str, + }, + ) SYSTEM_ATTR_MAX_LENGTH = 2045 NOTE_VER_KEY = "dashboard:note_ver" NOTE_STR_KEY_PREFIX = "dashboard:note_str:" -NoteType = TypedDict( - "NoteType", - { - "version": int, - "body": str, - }, -) - def get_note_from_system_attrs(system_attrs: Dict[str, Any]) -> NoteType: if NOTE_VER_KEY not in system_attrs: diff --git a/optuna_dashboard/_serializer.py b/optuna_dashboard/_serializer.py index 720357053..703848e5a 100644 --- a/optuna_dashboard/_serializer.py +++ b/optuna_dashboard/_serializer.py @@ -1,8 +1,11 @@ +from __future__ import annotations + import json from typing import Any from typing import Dict from typing import List from typing import Tuple +from typing import TYPE_CHECKING from typing import Union import numpy as np @@ -13,36 +16,34 @@ from . import _note as note -try: +if TYPE_CHECKING: from typing import Literal from typing import TypedDict -except ImportError: - from typing_extensions import Literal # type: ignore - from typing_extensions import TypedDict + + Attribute = TypedDict( + "Attribute", + { + "key": str, + "value": str, + }, + ) + AttributeSpec = TypedDict( + "AttributeSpec", + { + "key": str, + "sortable": bool, + }, + ) + IntermediateValue = TypedDict( + "IntermediateValue", + { + "step": int, + "value": Union[float, Literal["inf", "-inf", "nan"]], + }, + ) MAX_ATTR_LENGTH = 1024 -Attribute = TypedDict( - "Attribute", - { - "key": str, - "value": str, - }, -) -AttributeSpec = TypedDict( - "AttributeSpec", - { - "key": str, - "sortable": bool, - }, -) -IntermediateValue = TypedDict( - "IntermediateValue", - { - "step": int, - "value": Union[float, Literal["inf", "-inf", "nan"]], - }, -) def serialize_attrs(attrs: Dict[str, Any]) -> List[Attribute]: diff --git a/optuna_dashboard/_sql_profiler.py b/optuna_dashboard/_sql_profiler.py index de37eb66c..3435dd228 100644 --- a/optuna_dashboard/_sql_profiler.py +++ b/optuna_dashboard/_sql_profiler.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import threading from time import perf_counter from typing import Dict diff --git a/pyproject.toml b/pyproject.toml index 51283cb02..96d29c75a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -30,7 +30,6 @@ dependencies = [ "optuna>=2.4.0", "packaging", "scikit-learn", - 'typing-extensions; python_version<"3.8"', ] dynamic = ["version"] diff --git a/requirements.txt b/requirements.txt index 6d49d55a5..7545e1a93 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,6 @@ # project dependency optuna>=2.4 bottle -typing-extensions;python_version<'3.8' scikit-learn # lint