Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Write union types as X | Y #731

Merged
merged 2 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions docs/gen_ref_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from pathlib import Path
from textwrap import fill
from typing import Any
from typing import Optional

import mkdocs_gen_files # type: ignore[import]
from mkdocs_gen_files import Nav
Expand All @@ -17,7 +16,7 @@
def to_markdown(
data: dict[str, Any],
level: int,
parent_cmd: Optional[str] = None,
parent_cmd: str | None = None,
) -> str:
"""
Given a `data` object with keys `name`, `description` and `usage`, produce
Expand Down
3 changes: 1 addition & 2 deletions fractal_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from sys import argv
from typing import List
from typing import Tuple
from typing import Union

from httpx import Client
from httpx import ConnectError
Expand All @@ -34,7 +33,7 @@ class MissingCredentialsError(RuntimeError):


def _check_credentials(
*, username: Union[str, None], password: Union[str, None]
*, username: str | None, password: str | None
) -> Tuple[str, str]:
"""
Check that username and password are defined
Expand Down
7 changes: 3 additions & 4 deletions fractal_client/cmd/_aux_task_caching.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import json
from pathlib import Path
from typing import Any
from typing import Optional

import packaging.version

Expand Down Expand Up @@ -92,7 +91,7 @@ def _get_matching_tasks(
task_list: _TaskList,
*,
name: str,
version: Optional[str] = None,
version: str | None = None,
) -> _TaskList:
"""
Given a task list, extract all the tasks matching some conditions.
Expand Down Expand Up @@ -128,7 +127,7 @@ def _search_in_task_list(
*,
task_list: _TaskList,
name: str,
version: Optional[str] = None,
version: str | None = None,
) -> int:
"""
Search for a single task in `task_list` based on the provided `name`
Expand Down Expand Up @@ -194,7 +193,7 @@ def _search_in_task_list(


def get_task_id_from_cache(
client: AuthClient, task_name: str, version: Optional[str] = None
client: AuthClient, task_name: str, version: str | None = None
) -> int:
"""
Retrieve the `id` of a task from the cache based on the provided
Expand Down
7 changes: 3 additions & 4 deletions fractal_client/cmd/_dataset.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import json
from typing import Optional

from ..authclient import AuthClient
from ..config import settings
Expand All @@ -13,7 +12,7 @@ def post_dataset(
project_id: int,
dataset_name: str,
zarr_dir: str,
filters: Optional[str] = None,
filters: str | None = None,
batch: bool = False,
) -> Interface:
"""
Expand Down Expand Up @@ -48,8 +47,8 @@ def patch_dataset(
*,
project_id: int,
dataset_id: int,
new_name: Optional[str] = None,
filters: Optional[str] = None,
new_name: str | None = None,
filters: str | None = None,
) -> Interface:
# Prepare payload
dataset_update = {}
Expand Down
8 changes: 3 additions & 5 deletions fractal_client/cmd/_group.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import Optional

from ..authclient import AuthClient
from ..config import settings
from ..interface import Interface
Expand Down Expand Up @@ -30,7 +28,7 @@ def group_new(
client: AuthClient,
*,
name: str,
viewer_paths: Optional[list[str]] = None,
viewer_paths: list[str] | None = None,
batch: bool = False,
):
request_body = dict(name=name)
Expand All @@ -52,8 +50,8 @@ def group_update(
client: AuthClient,
*,
group_id: int,
new_user_ids: Optional[list[int]] = None,
new_viewer_paths: Optional[list[str]] = None,
new_user_ids: list[int] | None = None,
new_viewer_paths: list[str] | None = None,
):

request_body = dict()
Expand Down
7 changes: 3 additions & 4 deletions fractal_client/cmd/_job.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import logging
import os
from pathlib import Path
from typing import Optional
from zipfile import ZipFile

from ..authclient import AuthClient
Expand Down Expand Up @@ -129,9 +128,9 @@ def job_submit(
project_id: int,
workflow_id: int,
dataset_id: int,
first_task_index: Optional[int] = None,
last_task_index: Optional[int] = None,
worker_init: Optional[str] = None,
first_task_index: int | None = None,
last_task_index: int | None = None,
worker_init: str | None = None,
batch: bool = False,
) -> Interface:

Expand Down
4 changes: 1 addition & 3 deletions fractal_client/cmd/_project.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import Optional

from ..authclient import AuthClient
from ..config import settings
from ..interface import Interface
Expand Down Expand Up @@ -47,7 +45,7 @@ def patch_project(
client: AuthClient,
*,
project_id: int,
new_name: Optional[str] = None,
new_name: str | None = None,
) -> Interface:
project_update = {}
if new_name:
Expand Down
45 changes: 22 additions & 23 deletions fractal_client/cmd/_task.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import json
import logging
import sys
from typing import Optional

from ..authclient import AuthClient
from ..config import settings
Expand All @@ -21,10 +20,10 @@ def task_collect_pip(
client: AuthClient,
*,
package: str,
package_version: Optional[str] = None,
python_version: Optional[str] = None,
package_extras: Optional[str] = None,
pinned_dependency: Optional[list[str]] = None,
package_version: str | None = None,
python_version: str | None = None,
package_extras: str | None = None,
pinned_dependency: list[str] | None = None,
private: bool = False,
batch: bool = False,
) -> Interface:
Expand Down Expand Up @@ -70,9 +69,9 @@ def task_collect_custom(
label: str,
python_interpreter: str,
manifest: str,
version: Optional[str] = None,
package_name: Optional[str] = None,
package_root: Optional[str] = None,
version: str | None = None,
package_name: str | None = None,
package_root: str | None = None,
private: bool = False,
batch: bool = False,
) -> Interface:
Expand Down Expand Up @@ -139,14 +138,14 @@ def post_task(
*,
name: str,
batch: bool = False,
command_non_parallel: Optional[str] = None,
command_parallel: Optional[str] = None,
version: Optional[str] = None,
meta_non_parallel: Optional[str] = None,
meta_parallel: Optional[str] = None,
args_schema_non_parallel: Optional[str] = None,
args_schema_parallel: Optional[str] = None,
args_schema_version: Optional[str] = None,
command_non_parallel: str | None = None,
command_parallel: str | None = None,
version: str | None = None,
meta_non_parallel: str | None = None,
meta_parallel: str | None = None,
args_schema_non_parallel: str | None = None,
args_schema_parallel: str | None = None,
args_schema_version: str | None = None,
private: bool = False,
) -> Interface:
task = dict(name=name)
Expand Down Expand Up @@ -184,13 +183,13 @@ def post_task(
def patch_task(
client: AuthClient,
*,
id: Optional[int] = None,
name: Optional[str] = None,
version: Optional[str] = None,
command_non_parallel: Optional[str] = None,
command_parallel: Optional[str] = None,
input_types: Optional[str] = None,
output_types: Optional[str] = None,
id: int | None = None,
name: str | None = None,
version: str | None = None,
command_non_parallel: str | None = None,
command_parallel: str | None = None,
input_types: str | None = None,
output_types: str | None = None,
) -> Interface:

if id:
Expand Down
21 changes: 10 additions & 11 deletions fractal_client/cmd/_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import sys
from json.decoder import JSONDecodeError
from pathlib import Path
from typing import Optional

from ..authclient import AuthClient
from ..config import settings
Expand Down Expand Up @@ -44,10 +43,10 @@ def user_register(
*,
new_email: str,
new_password: str,
slurm_user: Optional[str] = None,
cache_dir: Optional[str] = None,
username: Optional[str] = None,
ssh_settings_json: Optional[str] = None,
slurm_user: str | None = None,
cache_dir: str | None = None,
username: str | None = None,
ssh_settings_json: str | None = None,
superuser: bool = False,
verified: bool = True, # TODO: this is not currently exposed in the CLI
batch: bool = False,
Expand Down Expand Up @@ -124,12 +123,12 @@ def user_edit(
client: AuthClient,
*,
user_id: str,
new_email: Optional[str] = None,
new_password: Optional[str] = None,
new_username: Optional[str] = None,
new_slurm_user: Optional[str] = None,
new_cache_dir: Optional[str] = None,
new_ssh_settings_json: Optional[str] = None,
new_email: str | None = None,
new_password: str | None = None,
new_username: str | None = None,
new_slurm_user: str | None = None,
new_cache_dir: str | None = None,
new_ssh_settings_json: str | None = None,
make_superuser: bool = False,
remove_superuser: bool = False,
make_verified: bool = False,
Expand Down
31 changes: 15 additions & 16 deletions fractal_client/cmd/_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import logging
import sys
from pathlib import Path
from typing import Optional

from ..authclient import AuthClient
from ..config import settings
Expand Down Expand Up @@ -63,16 +62,16 @@ def post_workflowtask(
*,
project_id: int,
workflow_id: int,
input_filters: Optional[str] = None,
args_non_parallel: Optional[str] = None,
args_parallel: Optional[str] = None,
meta_non_parallel: Optional[str] = None,
meta_parallel: Optional[str] = None,
task_id: Optional[int] = None,
task_name: Optional[str] = None,
task_version: Optional[str] = None,
input_filters: str | None = None,
args_non_parallel: str | None = None,
args_parallel: str | None = None,
meta_non_parallel: str | None = None,
meta_parallel: str | None = None,
task_id: int | None = None,
task_name: str | None = None,
task_version: str | None = None,
batch: bool = False,
order: Optional[int] = None,
order: int | None = None,
) -> Interface:

if task_id:
Expand Down Expand Up @@ -143,11 +142,11 @@ def patch_workflowtask(
project_id: int,
workflow_id: int,
workflow_task_id: int,
input_filters: Optional[str] = None,
args_non_parallel: Optional[str] = None,
args_parallel: Optional[str] = None,
meta_non_parallel: Optional[str] = None,
meta_parallel: Optional[str] = None,
input_filters: str | None = None,
args_non_parallel: str | None = None,
args_parallel: str | None = None,
meta_non_parallel: str | None = None,
meta_parallel: str | None = None,
) -> Interface:

payload = {}
Expand Down Expand Up @@ -227,7 +226,7 @@ def workflow_import(
*,
project_id: int,
json_file: str,
workflow_name: Optional[str] = None,
workflow_name: str | None = None,
batch: bool = False,
) -> Interface:
with Path(json_file).open("r") as f:
Expand Down
5 changes: 2 additions & 3 deletions fractal_client/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"""
from os import getenv
from pathlib import Path
from typing import Optional

from dotenv import load_dotenv

Expand All @@ -23,8 +22,8 @@
class Settings:
def __init__(self):

self.FRACTAL_USER: Optional[str] = getenv("FRACTAL_USER")
self.FRACTAL_PASSWORD: Optional[str] = getenv("FRACTAL_PASSWORD")
self.FRACTAL_USER: str | None = getenv("FRACTAL_USER")
self.FRACTAL_PASSWORD: str | None = getenv("FRACTAL_PASSWORD")

self.FRACTAL_SERVER: str = getenv(
"FRACTAL_SERVER", "http://localhost:8000"
Expand Down
5 changes: 2 additions & 3 deletions fractal_client/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import sys
from json.decoder import JSONDecodeError
from typing import Any
from typing import Union

from httpx import Response

Expand All @@ -12,9 +11,9 @@

def check_response(
res: Response,
expected_status_code: Union[int, list[int]] = 200,
expected_status_code: int | list[int] = 200,
redact_long_payload: bool = False,
) -> Union[list[Any], dict[str, Any], str, int, float, bool]:
) -> list[Any] | dict[str, Any] | str | int | float | bool:
"""
Check the validity of the http response from fractal server

Expand Down
Loading
Loading