From 7bc211d30c62e45ad839bb94d15ddaa4d842c78f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Jankowski?= Date: Tue, 5 Dec 2023 13:43:05 +0100 Subject: [PATCH] Use literals instead of str for Mode typing and `typing-extensions` added as a direct requirement (#1586) --- CHANGELOG.md | 9 +++++++++ pyproject.toml | 1 + src/neptune/metadata_containers/model.py | 6 ++++-- src/neptune/metadata_containers/model_version.py | 6 ++++-- src/neptune/metadata_containers/project.py | 6 ++++-- src/neptune/metadata_containers/run.py | 4 +++- 6 files changed, 25 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b1b64c027..2c0e7c52f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +## [UNRELEASED] 1.8.7 + +### Fixes +- Add direct requirement of `typing-extensions` ([#1586](https://github.com/neptune-ai/neptune-client/pull/1586)) + +### Changes +- Use literals instead of str for Mode typing ([#1586](https://github.com/neptune-ai/neptune-client/pull/1586)) + + ## 1.8.6 ### Fixes diff --git a/pyproject.toml b/pyproject.toml index 3c67ddb8b..6812cf986 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,6 +13,7 @@ python = "^3.7" # Python lack of functionalities from future versions importlib-metadata = { version = "*", python = "<3.8" } +typing-extensions = ">=3.10.0" # Missing compatibility layer between Python 2 and Python 3 six = ">=1.12.0" diff --git a/src/neptune/metadata_containers/model.py b/src/neptune/metadata_containers/model.py index d62e1cbe3..b028d045e 100644 --- a/src/neptune/metadata_containers/model.py +++ b/src/neptune/metadata_containers/model.py @@ -23,6 +23,8 @@ Optional, ) +from typing_extensions import Literal + from neptune.attributes.constants import SYSTEM_NAME_ATTRIBUTE_PATH from neptune.common.exceptions import NeptuneException from neptune.envs import CONNECTION_MODE @@ -90,7 +92,7 @@ class Model(MetadataContainer): mode: Connection mode in which the tracking will work. If `None` (default), the value of the NEPTUNE_MODE environment variable is used. If no value was set for the environment variable, "async" is used by default. - Possible values are `async`, `sync`, `offline`, `read-only`, and `debug`. + Possible values are `async`, `sync`, `read-only`, and `debug`. flush_period: In the asynchronous (default) connection mode, how often disk flushing is triggered (in seconds). proxies: Argument passed to HTTP calls made via the Requests library, as dictionary of strings. @@ -166,7 +168,7 @@ def __init__( key: Optional[str] = None, project: Optional[str] = None, api_token: Optional[str] = None, - mode: Optional[str] = None, + mode: Optional[Literal["async", "sync", "read-only", "debug"]] = None, flush_period: float = DEFAULT_FLUSH_PERIOD, proxies: Optional[dict] = None, async_lag_callback: Optional[NeptuneObjectCallback] = None, diff --git a/src/neptune/metadata_containers/model_version.py b/src/neptune/metadata_containers/model_version.py index 0915f265b..9159e459a 100644 --- a/src/neptune/metadata_containers/model_version.py +++ b/src/neptune/metadata_containers/model_version.py @@ -22,6 +22,8 @@ Optional, ) +from typing_extensions import Literal + from neptune.attributes.constants import ( SYSTEM_NAME_ATTRIBUTE_PATH, SYSTEM_STAGE_ATTRIBUTE_PATH, @@ -87,7 +89,7 @@ class ModelVersion(MetadataContainer): mode: Connection mode in which the tracking will work. If None (default), the value of the NEPTUNE_MODE environment variable is used. If no value was set for the environment variable, "async" is used by default. - Possible values are `async`, `sync`, `offline`, `read-only`, and `debug`. + Possible values are `async`, `sync`, `read-only`, and `debug`. flush_period: In the asynchronous (default) connection mode, how often disk flushing is triggered (in seconds). proxies: Argument passed to HTTP calls made via the Requests library, as dictionary of strings. @@ -166,7 +168,7 @@ def __init__( model: Optional[str] = None, project: Optional[str] = None, api_token: Optional[str] = None, - mode: Optional[str] = None, + mode: Optional[Literal["async", "sync", "read-only", "debug"]] = None, flush_period: float = DEFAULT_FLUSH_PERIOD, proxies: Optional[dict] = None, async_lag_callback: Optional[NeptuneObjectCallback] = None, diff --git a/src/neptune/metadata_containers/project.py b/src/neptune/metadata_containers/project.py index 319014444..bb12af11b 100644 --- a/src/neptune/metadata_containers/project.py +++ b/src/neptune/metadata_containers/project.py @@ -22,6 +22,8 @@ Union, ) +from typing_extensions import Literal + from neptune.common.exceptions import NeptuneException from neptune.envs import CONNECTION_MODE from neptune.exceptions import InactiveProjectException @@ -72,7 +74,7 @@ class Project(MetadataContainer): mode: Connection mode in which the tracking will work. If left empty, the value of the NEPTUNE_MODE environment variable is used. If no value was set for the environment variable, "async" is used by default. - Possible values are `async`, `sync`, `offline`, `read-only`, and `debug`. + Possible values are `async`, `sync`, `read-only`, and `debug`. flush_period: In the asynchronous (default) connection mode, how often disk flushing is triggered. Defaults to 5 (every 5 seconds). proxies: Argument passed to HTTP calls made via the Requests library, as dictionary of strings. @@ -136,7 +138,7 @@ def __init__( project: Optional[str] = None, *, api_token: Optional[str] = None, - mode: Optional[str] = None, + mode: Optional[Literal["async", "sync", "read-only", "debug"]] = None, flush_period: float = DEFAULT_FLUSH_PERIOD, proxies: Optional[dict] = None, async_lag_callback: Optional[NeptuneObjectCallback] = None, diff --git a/src/neptune/metadata_containers/run.py b/src/neptune/metadata_containers/run.py index 22c2d8e84..6ff38dd82 100644 --- a/src/neptune/metadata_containers/run.py +++ b/src/neptune/metadata_containers/run.py @@ -26,6 +26,8 @@ Union, ) +from typing_extensions import Literal + from neptune.attributes.constants import ( SYSTEM_DESCRIPTION_ATTRIBUTE_PATH, SYSTEM_FAILED_ATTRIBUTE_PATH, @@ -309,7 +311,7 @@ def __init__( project: Optional[str] = None, api_token: Optional[str] = None, custom_run_id: Optional[str] = None, - mode: Optional[str] = None, + mode: Optional[Literal["async", "sync", "offline", "read-only", "debug"]] = None, name: Optional[str] = None, description: Optional[str] = None, tags: Optional[Union[List[str], str]] = None,