Skip to content

Commit

Permalink
Merge pull request #321 from c-bata/remove-typing-extensions
Browse files Browse the repository at this point in the history
Remove typing_extensions from the dependencies
  • Loading branch information
c-bata committed Dec 26, 2022
2 parents bd99630 + 73e9d0d commit 81451c6
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 62 deletions.
4 changes: 3 additions & 1 deletion optuna_dashboard/_app.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from datetime import datetime
from datetime import timedelta
import functools
Expand Down Expand Up @@ -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.
"""
Expand Down
2 changes: 2 additions & 0 deletions optuna_dashboard/_cached_extra_study_property.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import copy
import threading
from typing import Dict
Expand Down
7 changes: 4 additions & 3 deletions optuna_dashboard/_cli.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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"
Expand Down
41 changes: 21 additions & 20 deletions optuna_dashboard/_importance.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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:
Expand All @@ -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()
Expand Down
23 changes: 12 additions & 11 deletions optuna_dashboard/_note.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
51 changes: 26 additions & 25 deletions optuna_dashboard/_serializer.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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]:
Expand Down
2 changes: 2 additions & 0 deletions optuna_dashboard/_sql_profiler.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import threading
from time import perf_counter
from typing import Dict
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ dependencies = [
"optuna>=2.4.0",
"packaging",
"scikit-learn",
'typing-extensions; python_version<"3.8"',
]
dynamic = ["version"]

Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# project dependency
optuna>=2.4
bottle
typing-extensions;python_version<'3.8'
scikit-learn

# lint
Expand Down

0 comments on commit 81451c6

Please sign in to comment.