demessaging.backend.utils module

Utitlity functions for the backend framework.

Classes:

AsyncIoThread(func, args, kwargs)

A thread that runs an async function.

ImportMixin()

Mixin class for isort.identify.Import.

Functions:

camelize(w)

Camelize a word by making the first letter upper case.

get_desc(docstring)

Get the description of an object.

get_fields(name, sig, docstring, config)

Get the model fields from a function signature.

get_kws(sig, obj)

Get keywords from a signature and a base model.

get_module_imports(mod)

Get all the imports from a module

run_async(func, *args, **kwargs)

Run an async function and wait for the result.

snake_to_camel(*words)

Transform a list of words into its camelized version.

class demessaging.backend.utils.AsyncIoThread(func: Callable, args: Tuple, kwargs: Dict)[source]

Bases: Thread

A thread that runs an async function.

See: func: run_async for the implementation.

Methods:

run()

Method representing the thread's activity.

run()[source]

Method representing the thread’s activity.

You may override this method in a subclass. The standard run() method invokes the callable object passed to the object’s constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.

class demessaging.backend.utils.ImportMixin[source]

Bases: object

Mixin class for isort.identify.Import.

A response to https://github.com/PyCQA/isort/issues/1641.

Methods:

statement()

statement() str[source]
demessaging.backend.utils.camelize(w: str) str[source]

Camelize a word by making the first letter upper case.

demessaging.backend.utils.get_desc(docstring: docstring_parser.Docstring) str[source]

Get the description of an object.

Parameters:

docstring (docstring_parser.Docstring) – The parser that analyzed the docstring.

Returns:

The description of the callable.

Return type:

str

demessaging.backend.utils.get_fields(name: str, sig: inspect.Signature, docstring: docstring_parser.Docstring, config: FunctionConfig | ClassConfig) Dict[str, Tuple[Any, Any]][source]

Get the model fields from a function signature.

Parameters:
  • name (str) – The name of the function or class

  • sig (inspect.Signature) – The signature of the callable

  • docstring (docstring_parser.Docstring) – The parser that analyzed the docstring

  • config (FunctionConfig or ClassConfig) – The configuration for the callable

Returns:

A mapping from field name to field parameters to be used in pydantic.create_model().

Return type:

dict

demessaging.backend.utils.get_kws(sig, obj) Dict[str, Any][source]

Get keywords from a signature and a base model.

demessaging.backend.utils.get_module_imports(mod: Any) str[source]

Get all the imports from a module

Parameters:

mod (module) – The module to use

demessaging.backend.utils.run_async(func: Callable, *args: Any, **kwargs: Any) Any[source]

Run an async function and wait for the result.

This function works within standard python scripts, and during a running jupyter session.

demessaging.backend.utils.snake_to_camel(*words: str) str[source]

Transform a list of words into its camelized version.