Skip to content

error

Classes:

CustomInlineExprError

CustomInlineExprError(
    message: SupportsString | None = None,
    func: FuncExcept | None = None,
    reason: Any = None,
    **kwargs: Any
)

Bases: CustomRuntimeError

Thrown when a InlineExpr error occurs.

Instantiate a new exception with pretty printing and more.

Parameters:

  • message

    (SupportsString | None, default: None ) –

    Message of the error.

  • func

    (FuncExcept | None, default: None ) –

    Function this exception was raised from.

  • reason

    (Any, default: None ) –

    Reason of the exception. For example, an optional parameter.

Methods:

  • __call__

    Copy an existing exception with defaults and instantiate a new one.

  • add_stack_infos

    Adds additional information on the expr vars used within the with statement of a InlineExprWrapper.

  • catch

    Create a context manager that catches exceptions of this class type.

Attributes:

Source code in jetpytools/exceptions/base.py
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
def __init__(
    self, message: SupportsString | None = None, func: FuncExcept | None = None, reason: Any = None, **kwargs: Any
) -> None:
    """
    Instantiate a new exception with pretty printing and more.

    Args:
        message: Message of the error.
        func: Function this exception was raised from.
        reason: Reason of the exception. For example, an optional parameter.
    """

    self.message = message
    self.func = func
    self.reason = reason
    self.kwargs = kwargs

    super().__init__(message)

func instance-attribute

func = func

kwargs instance-attribute

kwargs = kwargs

message instance-attribute

message = message

reason instance-attribute

reason = reason

__call__

__call__(
    message: SupportsString | None | MissingT = MISSING,
    func: FuncExcept | None | MissingT = MISSING,
    reason: SupportsString | FuncExcept | None | MissingT = MISSING,
    **kwargs: Any
) -> Self

Copy an existing exception with defaults and instantiate a new one.

Parameters:

Source code in jetpytools/exceptions/base.py
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
def __call__(
    self,
    message: SupportsString | None | MissingT = MISSING,
    func: FuncExcept | None | MissingT = MISSING,
    reason: SupportsString | FuncExcept | None | MissingT = MISSING,
    **kwargs: Any,
) -> Self:
    """
    Copy an existing exception with defaults and instantiate a new one.

    Args:
        message: Message of the error.
        func: Function this exception was raised from.
        reason: Reason of the exception. For example, an optional parameter.
    """
    from copy import deepcopy

    err = deepcopy(self)

    if message is not MISSING:
        err.message = message

    if func is not MISSING:
        err.func = func

    if reason is not MISSING:
        err.reason = reason

    err.kwargs |= kwargs

    return err

add_stack_infos

add_stack_infos(expr_vars: dict[str, Any], ie: InlineExprWrapper) -> None

Adds additional information on the expr vars used within the with statement of a InlineExprWrapper.

Parameters:

  • expr_vars

    (dict[str, Any]) –

    Dictionary containing the current scope's local expr variables.

  • ie

    (InlineExprWrapper) –

    The InlineExprWrapper instance.

Source code in vsexprtools/inline/error.py
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
def add_stack_infos(self, expr_vars: dict[str, Any], ie: InlineExprWrapper) -> None:
    """
    Adds additional information on the expr vars used within the with statement of a InlineExprWrapper.

    Args:
        expr_vars: Dictionary containing the current scope's local expr variables.
        ie: The InlineExprWrapper instance.
    """
    from .helpers import ComputedVar
    from .manager import InlineExprWrapper

    self.add_note(_color_tag("\nInlineExpr stack infos:", "\033[0;33m"))

    def _format_var_per_plane(v: ComputedVar) -> str:
        return ("\n    " + (" " * (len(k) + 2))).join(v.to_str_per_plane(ie._format.num_planes))

    for k, v in sorted(expr_vars.items()):
        if k.startswith("_"):
            continue

        if isinstance(v, InlineExprWrapper):
            k = f"{k}.out"
            v = _format_var_per_plane(v.out)
        elif isinstance(v, ComputedVar):
            v = _format_var_per_plane(v)
        elif v is not None:
            with suppress(TypeError):
                v = str([str(x) for x in iter(v)])

        self.add_note("    " + _color_tag(f"{k}: ", "\033[1;37m") + str(v))

catch classmethod

catch() -> CatchError[Self]

Create a context manager that catches exceptions of this class type.

Returns:

  • CatchError[Self]

    CatchError[Self]: A context manager that will catch and store exceptions of type cls when used in a with block.

Source code in jetpytools/exceptions/base.py
134
135
136
137
138
139
140
141
142
143
@classmethod
def catch(cls) -> CatchError[Self]:
    """
    Create a context manager that catches exceptions of this class type.

    Returns:
        CatchError[Self]: A context manager that will catch and store exceptions of type `cls`
            when used in a `with` block.
    """
    return CatchError(cls)