Skip to content

kamihi.bot.utils ⚓︎

Utilities and constants for the bot module.

License

MIT

Attributes:

Name Type Description
COMMAND_REGEX Pattern

Regular expression pattern for validating command names.

Functions:

Name Description
parse_annotation

Parse an annotation, extracting base type and metadata.

parse_annotation ⚓︎

parse_annotation(ann: Any) -> tuple[type, Any]

Parse an annotation, extracting base type and metadata.

Parameters:

Name Type Description Default

ann ⚓︎

Any

The annotation to parse.

required

Returns:

Name Type Description
tuple tuple[type, Any]

A tuple containing the base type and metadata.

Source code in src/kamihi/bot/utils.py
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
def parse_annotation(ann: Any) -> tuple[type, Any]:  # noqa: ANN401
    """
    Parse an annotation, extracting base type and metadata.

    Args:
        ann (Any): The annotation to parse.

    Returns:
        tuple: A tuple containing the base type and metadata.

    """
    origin = get_origin(ann)
    if origin is Annotated:
        args = get_args(ann)
        base_type = args[0]
        metadata = args[1]
        return base_type, metadata
    return ann, None