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

Annotate types as optional #180

Closed
wants to merge 1 commit into from
Closed
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
10 changes: 5 additions & 5 deletions src/prefect_server/api/agents.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import List
from typing import List, Optional

import pendulum

Expand All @@ -11,9 +11,9 @@
async def register_agent(
tenant_id: str,
labels: List[str],
agent_config_id: str = None,
name: str = None,
type: str = None,
agent_config_id: Optional[str] = None,
name: Optional[str] = None,
type: Optional[str] = None,
) -> str:
"""
Register a new agent
Expand Down Expand Up @@ -142,7 +142,7 @@ async def delete_agent_config(agent_config_id: str) -> bool:

@register_api("agents.update_agent_config")
async def update_agent_config(
agent_config_id: str, name: str = None, settings: dict = None
agent_config_id: str, name: Optional[str] = None, settings: Optional[dict] = None
) -> str:
"""
Update an agent config
Expand Down
4 changes: 3 additions & 1 deletion src/prefect_server/api/artifacts.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Optional

from prefect import models
from prefect.utilities.plugins import register_api

Expand All @@ -7,7 +9,7 @@ async def create_task_run_artifact(
task_run_id: str,
kind: str,
data: dict,
tenant_id: str = None,
tenant_id: Optional[str] = None,
) -> str:
"""
Create a task run artifact.
Expand Down
10 changes: 5 additions & 5 deletions src/prefect_server/api/cloud_hooks.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import asyncio
import json
import uuid
from typing import List
from typing import List, Optional

import httpx
from box import Box
Expand Down Expand Up @@ -31,8 +31,8 @@ async def create_cloud_hook(
tenant_id: str,
type: str,
states: List[str],
config: dict = None,
version_group_id: str = None,
config: Optional[dict] = None,
version_group_id: Optional[str] = None,
name=None,
) -> str:
"""
Expand Down Expand Up @@ -372,8 +372,8 @@ async def _call_prefect_message(event: events.FlowRunStateChange):
@register_api("cloud_hooks.test_cloud_hook")
async def test_cloud_hook(
cloud_hook_id: str,
flow_run_id: str = None,
state: prefect.engine.state.State = None,
flow_run_id: Optional[str] = None,
state: Optional[prefect.engine.state.State] = None,
):
"""
Sends a test payload to a hook
Expand Down
6 changes: 3 additions & 3 deletions src/prefect_server/api/flow_groups.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pendulum
from typing import List, Dict, Any
from typing import List, Dict, Any, Optional

from prefect import api, models
from prefect.serialization.schedule import ClockSchema
Expand Down Expand Up @@ -69,7 +69,7 @@ async def set_flow_group_default_parameters(

@register_api("flow_groups.set_flow_group_schedule")
async def set_flow_group_schedule(
flow_group_id: str, clocks: List[dict], timezone: str = None
flow_group_id: str, clocks: List[dict], timezone: Optional[str] = None
) -> bool:
"""
Sets a schedule for a flow group
Expand Down Expand Up @@ -175,7 +175,7 @@ async def set_flow_group_labels(flow_group_id: str, labels: List[str] = None) ->

@register_api("flow_groups.set_flow_group_description")
async def set_flow_group_description(
flow_group_id: str, description: str = None
flow_group_id: str, description: Optional[str] = None
) -> bool:
"""
Sets description for a flow group.
Expand Down
34 changes: 17 additions & 17 deletions src/prefect_server/api/flows.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import hashlib
import json
import uuid
from typing import Any, Dict, List
from typing import Any, Dict, List, Optional

import pendulum
from packaging import version as module_version
Expand Down Expand Up @@ -40,15 +40,15 @@ class ScheduleSchema(Model):

class TaskSchema(Model):
id: str = Field(default_factory=lambda: str(uuid.uuid4()))
name: str = None
name: Optional[str] = None
slug: str
type: str = None
type: Optional[str] = None
auto_generated: bool = False
tags: List[str] = Field(default_factory=list)
max_retries: int = 0
retry_delay: datetime.timedelta = None
cache_key: str = None
trigger: str = None
retry_delay: Optional[datetime.timedelta] = None
cache_key: Optional[str] = None
trigger: Optional[str] = None
mapped: bool = False
is_reference_task: bool = False
is_root_task: bool = False
Expand All @@ -66,7 +66,7 @@ class EdgeSchema(Model):
upstream_task: str
downstream_task: str
mapped: bool = False
key: str = None
key: Optional[str] = None

@validator("upstream_task", pre=True)
def _validate_upstream_task(cls, v):
Expand All @@ -84,22 +84,22 @@ def _validate_downstream_task(cls, v):


class ParameterSchema(Model):
name: str = None
name: Optional[str] = None
slug: str
required: bool = False
default: Any = None


class FlowSchema(Model):
name: str = None
name: Optional[str] = None
tasks: List[TaskSchema] = Field(default_factory=list)
edges: List[EdgeSchema] = Field(default_factory=list)
parameters: List[ParameterSchema] = Field(default_factory=list)
environment: Dict[str, Any] = None
run_config: Dict[str, Any] = None
__version__: str = None
storage: Dict[str, Any] = None
schedule: ScheduleSchema = None
environment: Optional[Dict[str, Any]] = None
run_config: Optional[Dict[str, Any]] = None
__version__: Optional[str] = None
storage: Optional[Dict[str, Any]] = None
schedule: Optional[ScheduleSchema] = None
reference_tasks: List[str] = Field(default_factory=list)

@validator("reference_tasks", pre=True)
Expand All @@ -117,10 +117,10 @@ def _validate_reference_tasks(cls, v):
async def create_flow(
serialized_flow: dict,
project_id: str,
version_group_id: str = None,
version_group_id: Optional[str] = None,
set_schedule_active: bool = True,
description: str = None,
idempotency_key: str = None,
description: Optional[str] = None,
idempotency_key: Optional[str] = None,
) -> str:
"""
Add a flow to the database.
Expand Down
4 changes: 3 additions & 1 deletion src/prefect_server/api/messages.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Optional

from prefect import models
from prefect.utilities.plugins import register_api

Expand All @@ -6,7 +8,7 @@

@register_api("messages.create_message")
async def create_message(
type: str, content: dict, tenant_id: str, text: str = None
type: str, content: dict, tenant_id: str, text: Optional[str] = None
) -> str:
if type not in PREFECT_MESSAGE_TYPES:
raise ValueError("Invalid message type.")
Expand Down
6 changes: 5 additions & 1 deletion src/prefect_server/api/projects.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
from typing import Optional

from prefect import models
from prefect.utilities.plugins import register_api


@register_api("projects.create_project")
async def create_project(tenant_id: str, name: str, description: str = None) -> str:
async def create_project(
tenant_id: str, name: str, description: Optional[str] = None
) -> str:
"""
Creates a project, returning its id

Expand Down
30 changes: 15 additions & 15 deletions src/prefect_server/api/runs.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import datetime
from typing import Any, Iterable, List
from typing import Any, Iterable, List, Optional

import pendulum

Expand All @@ -20,15 +20,15 @@

@register_api("runs.create_flow_run")
async def create_flow_run(
flow_id: str = None,
parameters: dict = None,
context: dict = None,
flow_id: Optional[str] = None,
parameters: Optional[dict] = None,
context: Optional[dict] = None,
scheduled_start_time: datetime.datetime = None,
flow_run_name: str = None,
version_group_id: str = None,
idempotency_key: str = None,
flow_run_name: Optional[str] = None,
version_group_id: Optional[str] = None,
idempotency_key: Optional[str] = None,
labels: List[str] = None,
run_config: dict = None,
run_config: Optional[dict] = None,
) -> Any:
"""
Creates a new flow run for an existing flow.
Expand Down Expand Up @@ -116,14 +116,14 @@ async def set_task_run_name(task_run_id: str, name: str) -> bool:

@register_api("runs._create_flow_run")
async def _create_flow_run(
flow_id: str = None,
parameters: dict = None,
context: dict = None,
flow_id: Optional[str] = None,
parameters: Optional[dict] = None,
context: Optional[dict] = None,
scheduled_start_time: datetime.datetime = None,
flow_run_name: str = None,
version_group_id: str = None,
flow_run_name: Optional[str] = None,
version_group_id: Optional[str] = None,
labels: List[str] = None,
run_config: dict = None,
run_config: Optional[dict] = None,
) -> Any:
"""
Creates a new flow run for an existing flow.
Expand Down Expand Up @@ -451,7 +451,7 @@ async def get_runs_in_queue(
tenant_id: str,
before: datetime = None,
labels: Iterable[str] = None,
agent_id: str = None,
agent_id: Optional[str] = None,
) -> List[str]:

if tenant_id is None:
Expand Down
4 changes: 3 additions & 1 deletion src/prefect_server/api/states.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import asyncio
import uuid

from typing import Optional

import pendulum

import prefect
Expand All @@ -20,7 +22,7 @@

@register_api("states.set_flow_run_state")
async def set_flow_run_state(
flow_run_id: str, state: State, version: int = None, agent_id: str = None
flow_run_id: str, state: State, version: int = None, agent_id: Optional[str] = None
) -> models.FlowRunState:
"""
Updates a flow run state.
Expand Down
4 changes: 3 additions & 1 deletion src/prefect_server/api/tenants.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import slugify

from typing import Optional

from prefect import models
from prefect.utilities.plugins import register_api

Expand All @@ -10,7 +12,7 @@ def verify_slug(slug: str) -> None:


@register_api("tenants.create_tenant")
async def create_tenant(name: str, slug: str = None) -> str:
async def create_tenant(name: str, slug: Optional[str] = None) -> str:
"""
Create a new tenant.

Expand Down
36 changes: 18 additions & 18 deletions src/prefect_server/database/hasura.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import asyncio
from typing import Any, Dict, Iterable, List, Union
from typing import Any, Dict, Iterable, List, Optional, Union

from box import Box

Expand Down Expand Up @@ -46,14 +46,14 @@ def get_value(self) -> dict:


class HasuraClient(GraphQLClient):
def __init__(self, url: str = None, headers=None) -> None:
def __init__(self, url: Optional[str] = None, headers=None) -> None:
super().__init__(url=url or config.hasura.graphql_url, headers=headers)

async def execute(
self,
query: Union[str, Dict[str, Any]],
variables: Dict[str, Any] = None,
headers: dict = None,
variables: Optional[Dict[str, Any]] = None,
headers: Optional[dict] = None,
raise_on_error: bool = True,
as_box: bool = True,
) -> dict:
Expand Down Expand Up @@ -119,7 +119,7 @@ async def execute(
async def execute_mutations_in_transaction(
self,
mutations: List[dict],
headers: dict = None,
headers: Optional[dict] = None,
raise_on_error: bool = True,
as_box: bool = True,
) -> Box:
Expand Down Expand Up @@ -171,11 +171,11 @@ async def insert(
self,
graphql_type: str,
objects: List[dict],
on_conflict: dict = None,
alias: str = None,
on_conflict: Optional[dict] = None,
alias: Optional[str] = None,
selection_set: GQLObjectTypes = "affected_rows",
run_mutation: bool = True,
insert_mutation_name: str = None,
insert_mutation_name: Optional[str] = None,
) -> Box:
"""
Runs an `insert` mutation against the provided Hasura type, evaluating the provided
Expand Down Expand Up @@ -243,11 +243,11 @@ async def delete(
self,
graphql_type: str,
where: GQLObjectTypes = None,
id: str = None,
alias: str = None,
id: Optional[str] = None,
alias: Optional[str] = None,
selection_set: GQLObjectTypes = "affected_rows",
run_mutation: bool = True,
delete_mutation_name: str = None,
delete_mutation_name: Optional[str] = None,
) -> Box:
"""
Runs an `delete` mutation against the provided Hasura type and `where` clause,
Expand Down Expand Up @@ -305,17 +305,17 @@ async def update(
self,
graphql_type: str,
where: GQLObjectTypes = None,
id: str = None,
id: Optional[str] = None,
set: GQLObjectTypes = None,
increment: GQLObjectTypes = None,
append: dict = None,
prepend: dict = None,
delete_key: dict = None,
delete_elem: dict = None,
append: Optional[dict] = None,
prepend: Optional[dict] = None,
delete_key: Optional[dict] = None,
delete_elem: Optional[dict] = None,
selection_set: GQLObjectTypes = "affected_rows",
alias: str = None,
alias: Optional[str] = None,
run_mutation: bool = True,
update_mutation_name: str = None,
update_mutation_name: Optional[str] = None,
) -> Box:
"""
Runs an `update` mutation against the provided Hasura type and `where` clause, applying
Expand Down
Loading