app.utils

Utils used throughout the whole application.

Module Contents

app.utils.opt_call(func: collections.abc.Callable[[TParam], TReturn], arg: TParam | None) TReturn | None

Optional chaining for function calls.

Parameters:
  • func (collections.abc.Callable[[TParam], TReturn]) – Function to call if arg is not None

  • arg (TParam | None) – Argument to pass to func

Returns:

Result of func or None

Return type:

TReturn | None

app.utils.not_none(value: not_none.T | None, error_msg: str) not_none.T

Returns value if not none or raises exception.

Parameters:
  • value (not_none.T | None) – Value to check.

  • error_msg (str) – Message to throw.

Returns:

The none-none value.

Return type:

not_none.T

app.utils.not_none_or(value: not_none_or.T | None, default_value: not_none_or.T) not_none_or.T

Nullish coalescence - ?? operator. Returns value if not None. Else, returns default_value.

Parameters:
  • value (not_none_or.T | None)

  • default_value (not_none_or.T)

Return type:

not_none_or.T

app.utils.duplicates(list: duplicates.list[duplicates.T]) set[duplicates.T]

Returns set of duplicate items.

Parameters:

list (duplicates.list[duplicates.T])

Return type:

set[duplicates.T]

app.utils.safe_generate_implementation_node(node_id: str, impl: openqasm3.ast.Program | str) app.model.CompileRequest.ImplementationNode

Generate an ImplementationNode without raising an error.

This is used when an error occurred to get the implementation during failure. :param node_id: the id used in the frontend :param impl: the implementation to use

Parameters:
Return type:

app.model.CompileRequest.ImplementationNode

async app.utils.add_status_response_to_db(engine: sqlalchemy.ext.asyncio.AsyncEngine, status: app.model.StatusResponse.StatusResponse) None

Add the StatusResponse to the database

Parameters:
  • engine (sqlalchemy.ext.asyncio.AsyncEngine) – Database to insert the StatusResponse in

  • status (app.model.StatusResponse.StatusResponse) – The StatusResponse to add to the database

Return type:

None

async app.utils.update_status_response_in_db(engine: sqlalchemy.ext.asyncio.AsyncEngine, new_state: app.model.StatusResponse.StatusResponse) None

Update the StatusResponse in the database by replacing the row.

Parameters:
  • engine (sqlalchemy.ext.asyncio.AsyncEngine)

  • new_state (app.model.StatusResponse.StatusResponse)

Return type:

None

async app.utils.get_status_response_from_db(engine: sqlalchemy.ext.asyncio.AsyncEngine, uuid: uuid.UUID) app.model.StatusResponse.StatusResponse | None

Get the instance of StatusResponse with the given uuid from the database

Parameters:
  • engine (sqlalchemy.ext.asyncio.AsyncEngine) – Database engine to get the StatusResponse from

  • uuid (uuid.UUID) – UUID of the StatusResponse to retrieve

Returns:

The StatusResponse if found, otherwise None

Return type:

app.model.StatusResponse.StatusResponse | None

async app.utils.add_result_to_db(engine: sqlalchemy.ext.asyncio.AsyncEngine, uuid: uuid.UUID, results: str | list[app.model.CompileRequest.ImplementationNode]) None

Add a result to the database for the given uuid

Parameters:
Return type:

None