Skip to content

parsing module

Utilities for parsing.


ann_args_to_args function

ann_args_to_args(
    ann_args
)

Convert annotated arguments back to positional and keyword arguments.


annotate_args function

annotate_args(
    func,
    args,
    kwargs,
    only_passed=False,
    allow_partial=False,
    attach_annotations=False,
    flatten=False
)

Annotate arguments and keyword arguments using the function's signature.

If allow_partial is True, required arguments that weren't provided won't raise an error. But regardless of allow_partial, arguments that aren't in the signature will still raise an error.


extend_args function

extend_args(
    func,
    args,
    kwargs,
    **with_kwargs
)

Extend arguments and keyword arguments with other arguments.


flat_ann_args_to_args function

flat_ann_args_to_args(
    ann_args
)

Convert flattened annotated arguments back to positional and keyword arguments.


flatten_ann_args function

flatten_ann_args(
    ann_args
)

Flatten annotated arguments.


get_context_vars function

get_context_vars(
    var_names,
    frames_back=0,
    local_dict=None,
    global_dict=None
)

Get variables from the local/global context.


get_expr_var_names function

get_expr_var_names(
    expression
)

Get variable names listed in the expression.


get_func_arg_names function

get_func_arg_names(
    func,
    arg_kind=None,
    req_only=False,
    opt_only=False
)

Get argument names of a function.


get_func_kwargs function

get_func_kwargs(
    func
)

Get keyword arguments with defaults of a function.


hash_args function

hash_args(
    func,
    args,
    kwargs,
    ignore_args=None
)

Get hash of arguments.

Use ignore_args to provide a sequence of queries for arguments that should be ignored.


ignore_flat_ann_args function

ignore_flat_ann_args(
    flat_ann_args,
    ignore_args
)

Ignore flattened annotated arguments.


match_and_set_flat_ann_arg function

match_and_set_flat_ann_arg(
    flat_ann_args,
    query,
    new_value
)

Match an argument from flattened annotated arguments and set it to a new value.

See match_flat_ann_arg() for matching logic.


match_ann_arg function

match_ann_arg(
    ann_args,
    query,
    return_name=False,
    return_index=False
)

Match an argument from annotated arguments.

See match_flat_ann_arg() for matching logic.


match_flat_ann_arg function

match_flat_ann_arg(
    flat_ann_args,
    query,
    return_name=False,
    return_index=False
)

Match an argument from flattened annotated arguments.

A query can be an integer indicating the position of the argument, or a string containing the name of the argument, or a regular expression for matching the name of the argument.

If multiple arguments were matched, returns the first one.

The position can stretch over any variable argument.


suppress_stdout function

suppress_stdout(
    func
)

Suppress output from a function.


unflatten_ann_args function

unflatten_ann_args(
    flat_ann_args,
    partial_ann_args=None
)

Unflatten annotated arguments.


warn_stdout function

warn_stdout(
    func
)

Supress and convert to a warning output from a function.


PrintsSuppressed class

PrintsSuppressed(
    new_target
)

Context manager to ignore print statements.

Superclasses

  • abc.ABC
  • contextlib.AbstractContextManager
  • contextlib._RedirectStream
  • contextlib.redirect_stdout

Regex class

Regex(
    *args,
    **kwargs
)

Class for matching a regular expression.

Superclasses

Inherited members


flags class variable

Flags.


matches method

Regex.matches(
    string
)

Return whether the string matches the regular expression pattern.


pattern class variable

Pattern.


UnhashableArgsError class

UnhashableArgsError(
    *args,
    **kwargs
)

Unhashable arguments error.

Superclasses

  • builtins.BaseException
  • builtins.Exception

WarningsFiltered class

WarningsFiltered(
    entries='ignore',
    **kwargs
)

Context manager to ignore warnings.

Specify whether to record warnings and if an alternative module should be used other than sys.modules['warnings'].

For compatibility with Python 3.0, please consider all arguments to be keyword-only.

Superclasses

  • warnings.catch_warnings

entries property

One or more simple entries to add into the list of warnings filters.