mirror of
https://github.com/wassname/optuna-dashboard.git
synced 2026-09-12 12:40:33 +08:00
Make typing_extensions optional again
This commit is contained in:
@@ -29,7 +29,6 @@ from optuna.version import __version__ as optuna_ver
|
||||
from packaging import version
|
||||
|
||||
from . import _note as note
|
||||
from . import artifact
|
||||
from ._bottle_util import BottleViewReturn
|
||||
from ._bottle_util import json_api_view
|
||||
from ._cached_extra_study_property import get_cached_extra_study_property
|
||||
@@ -43,6 +42,7 @@ from .artifact._backend import register_artifact_route
|
||||
|
||||
if typing.TYPE_CHECKING:
|
||||
from _typeshed.wsgi import WSGIApplication
|
||||
from optuna_dashboard.artifact.protocol import ArtifactBackend
|
||||
|
||||
try:
|
||||
from optuna.study._frozen import FrozenStudy
|
||||
@@ -182,7 +182,7 @@ def get_trials(storage: BaseStorage, study_id: int, ttl_seconds: int = 10) -> li
|
||||
|
||||
def create_app(
|
||||
storage: BaseStorage,
|
||||
artifact_backend: Optional[artifact.ArtifactBackend] = None,
|
||||
artifact_backend: Optional[ArtifactBackend] = None,
|
||||
debug: bool = False,
|
||||
) -> Bottle:
|
||||
app = Bottle()
|
||||
|
||||
@@ -1,2 +1 @@
|
||||
from ._backend import ArtifactBackend # noqa
|
||||
from ._backend import upload_artifact # noqa
|
||||
|
||||
@@ -15,20 +15,15 @@ from .._bottle_util import json_api_view
|
||||
from .._bottle_util import parse_data_uri
|
||||
|
||||
|
||||
try:
|
||||
from typing import Protocol
|
||||
except ImportError:
|
||||
from typing_extensions import Protocol # type: ignore
|
||||
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from typing import Any
|
||||
from typing import BinaryIO
|
||||
from typing import Optional
|
||||
from typing import TypedDict
|
||||
|
||||
from optuna.storages import BaseStorage
|
||||
|
||||
from .protocol import ArtifactBackend
|
||||
|
||||
ArtifactMeta = TypedDict(
|
||||
"ArtifactMeta",
|
||||
{
|
||||
@@ -44,17 +39,6 @@ ARTIFACTS_ATTR_PREFIX = "dashboard:artifacts:"
|
||||
DEFAULT_MIME_TYPE = "application/octet-stream"
|
||||
|
||||
|
||||
class ArtifactBackend(Protocol):
|
||||
def open(self, artifact_id: str) -> BinaryIO:
|
||||
...
|
||||
|
||||
def write(self, artifact_id: str, content_body: BinaryIO) -> None:
|
||||
...
|
||||
|
||||
def remove(self, artifact_id: str) -> None:
|
||||
...
|
||||
|
||||
|
||||
def register_artifact_route(
|
||||
app: Bottle, storage: BaseStorage, artifact_backend: Optional[ArtifactBackend]
|
||||
) -> None:
|
||||
|
||||
@@ -51,6 +51,6 @@ class Boto3Backend:
|
||||
if TYPE_CHECKING:
|
||||
# A mypy-runtime assertion to ensure that Boto3Backend
|
||||
# implements all abstract methods in ArtifactBackendProtocol.
|
||||
from ._backend import ArtifactBackend
|
||||
from .protocol import ArtifactBackend
|
||||
|
||||
_: ArtifactBackend = Boto3Backend("")
|
||||
|
||||
@@ -26,6 +26,6 @@ class FileSystemBackend:
|
||||
if TYPE_CHECKING:
|
||||
# A mypy-runtime assertion to ensure that LocalArtifactBackend
|
||||
# implements all abstract methods in ArtifactBackendProtocol.
|
||||
from ._backend import ArtifactBackend
|
||||
from .protocol import ArtifactBackend
|
||||
|
||||
_: ArtifactBackend = FileSystemBackend("")
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
from typing import BinaryIO
|
||||
from typing import Protocol
|
||||
|
||||
|
||||
class ArtifactBackend(Protocol):
|
||||
def open(self, artifact_id: str) -> BinaryIO:
|
||||
...
|
||||
|
||||
def write(self, artifact_id: str, content_body: BinaryIO) -> None:
|
||||
...
|
||||
|
||||
def remove(self, artifact_id: str) -> None:
|
||||
...
|
||||
@@ -30,7 +30,6 @@ dependencies = [
|
||||
"optuna>=2.4.0",
|
||||
"packaging",
|
||||
"scikit-learn",
|
||||
'typing-extensions; python_version<"3.8"',
|
||||
]
|
||||
dynamic = ["version"]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user