Reference Guide  2.5.0
psyclone.errors.LazyString Class Reference

Public Member Functions

def __init__ (self, func)
 
def __str__ (self)
 

Detailed Description

Utility that defers any computation associated with computing a
string until the string is required. This is particularly useful
for exceptions, where the string will typically not need to be
computed unless the program is about to stop.

:param function func: a function that computes a string.

:raises TypeError: if the func argument is not a function.

Definition at line 42 of file errors.py.

Member Function Documentation

◆ __str__()

def psyclone.errors.LazyString.__str__ (   self)
:raises TypeError: if the function stored in self._func does \
    not return a string.

Definition at line 60 of file errors.py.

60  def __str__(self):
61  '''
62  :raises TypeError: if the function stored in self._func does \
63  not return a string.
64  '''
65  result = self._func()
66  if not isinstance(result, str):
67  raise TypeError(
68  f"The function supplied to the LazyString class should return "
69  f"a string, but found '{type(result).__name__}'.")
70  return result
71 
72 

References psyclone.errors.LazyString._func.


The documentation for this class was generated from the following file: