Let us walk on the 3-isogeny graph
Loading...
Searching...
No Matches
pip._vendor.rich.traceback Namespace Reference

Data Structures

class  _SyntaxError
 
class  Frame
 
class  PathHighlighter
 
class  Stack
 
class  Trace
 
class  Traceback
 

Functions

Callable[[Type[BaseException], BaseException, Optional[TracebackType]], Any] install (*Optional[Console] console=None, Optional[int] width=100, int extra_lines=3, Optional[str] theme=None, bool word_wrap=False, bool show_locals=False, int locals_max_length=LOCALS_MAX_LENGTH, int locals_max_string=LOCALS_MAX_STRING, bool locals_hide_dunder=True, Optional[bool] locals_hide_sunder=None, bool indent_guides=True, Iterable[Union[str, ModuleType]] suppress=(), int max_frames=100)
 
None bar (Any a)
 
None foo (Any a)
 
None error ()
 

Variables

str WINDOWS = "Windows"
 
int LOCALS_MAX_LENGTH = 10
 
int LOCALS_MAX_STRING = 80
 
 console = Console()
 

Function Documentation

◆ bar()

None bar ( Any  a)

Definition at line 729 of file traceback.py.

729 def bar(a: Any) -> None: # 这是对亚洲语言支持的测试。面对模棱两可的想法,拒绝猜测的诱惑
730 one = 1
731 print(one / a)
732

◆ error()

None error ( )

Definition at line 746 of file traceback.py.

746 def error() -> None:
747
748 try:
749 try:
750 foo(0)
751 except:
752 slfkjsldkfj # type: ignore[name-defined]
753 except:
754 console.print_exception(show_locals=True)
755
for i

References pip._vendor.rich.traceback.error(), pip._vendor.rich.traceback.foo(), and i.

Referenced by pip._vendor.rich.traceback.error().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ foo()

None foo ( Any  a)

Definition at line 733 of file traceback.py.

733 def foo(a: Any) -> None:
734 _rich_traceback_guard = True
735 zed = {
736 "characters": {
737 "Paul Atreides",
738 "Vladimir Harkonnen",
739 "Thufir Hawat",
740 "Duncan Idaho",
741 },
742 "atomic_types": (None, False, True),
743 }
744 bar(a)
745

Referenced by pip._vendor.rich.traceback.error().

Here is the caller graph for this function:

◆ install()

Callable[[Type[BaseException], BaseException, Optional[TracebackType]], Any] install ( *Optional[Console]   console = None,
Optional[int]   width = 100,
int   extra_lines = 3,
Optional[str]   theme = None,
bool   word_wrap = False,
bool   show_locals = False,
int   locals_max_length = LOCALS_MAX_LENGTH,
int   locals_max_string = LOCALS_MAX_STRING,
bool   locals_hide_dunder = True,
Optional[bool]   locals_hide_sunder = None,
bool   indent_guides = True,
Iterable[Union[str, ModuleType]]   suppress = (),
int   max_frames = 100 
)
Install a rich traceback handler.

Once installed, any tracebacks will be printed with syntax highlighting and rich formatting.


Args:
    console (Optional[Console], optional): Console to write exception to. Default uses internal Console instance.
    width (Optional[int], optional): Width (in characters) of traceback. Defaults to 100.
    extra_lines (int, optional): Extra lines of code. Defaults to 3.
    theme (Optional[str], optional): Pygments theme to use in traceback. Defaults to ``None`` which will pick
        a theme appropriate for the platform.
    word_wrap (bool, optional): Enable word wrapping of long lines. Defaults to False.
    show_locals (bool, optional): Enable display of local variables. Defaults to False.
    locals_max_length (int, optional): Maximum length of containers before abbreviating, or None for no abbreviation.
        Defaults to 10.
    locals_max_string (int, optional): Maximum length of string before truncating, or None to disable. Defaults to 80.
    locals_hide_dunder (bool, optional): Hide locals prefixed with double underscore. Defaults to True.
    locals_hide_sunder (bool, optional): Hide locals prefixed with single underscore. Defaults to False.
    indent_guides (bool, optional): Enable indent guides in code and locals. Defaults to True.
    suppress (Sequence[Union[str, ModuleType]]): Optional sequence of modules or paths to exclude from traceback.

Returns:
    Callable: The previous exception handler that was replaced.

Definition at line 48 of file traceback.py.

63) -> Callable[[Type[BaseException], BaseException, Optional[TracebackType]], Any]:
64 """Install a rich traceback handler.
65
66 Once installed, any tracebacks will be printed with syntax highlighting and rich formatting.
67
68
69 Args:
70 console (Optional[Console], optional): Console to write exception to. Default uses internal Console instance.
71 width (Optional[int], optional): Width (in characters) of traceback. Defaults to 100.
72 extra_lines (int, optional): Extra lines of code. Defaults to 3.
73 theme (Optional[str], optional): Pygments theme to use in traceback. Defaults to ``None`` which will pick
74 a theme appropriate for the platform.
75 word_wrap (bool, optional): Enable word wrapping of long lines. Defaults to False.
76 show_locals (bool, optional): Enable display of local variables. Defaults to False.
77 locals_max_length (int, optional): Maximum length of containers before abbreviating, or None for no abbreviation.
78 Defaults to 10.
79 locals_max_string (int, optional): Maximum length of string before truncating, or None to disable. Defaults to 80.
80 locals_hide_dunder (bool, optional): Hide locals prefixed with double underscore. Defaults to True.
81 locals_hide_sunder (bool, optional): Hide locals prefixed with single underscore. Defaults to False.
82 indent_guides (bool, optional): Enable indent guides in code and locals. Defaults to True.
83 suppress (Sequence[Union[str, ModuleType]]): Optional sequence of modules or paths to exclude from traceback.
84
85 Returns:
86 Callable: The previous exception handler that was replaced.
87
88 """
89 traceback_console = Console(stderr=True) if console is None else console
90
91 locals_hide_sunder = (
92 True
93 if (traceback_console.is_jupyter and locals_hide_sunder is None)
94 else locals_hide_sunder
95 )
96
97 def excepthook(
98 type_: Type[BaseException],
99 value: BaseException,
100 traceback: Optional[TracebackType],
101 ) -> None:
104 type_,
105 value,
106 traceback,
107 width=width,
108 extra_lines=extra_lines,
109 theme=theme,
110 word_wrap=word_wrap,
111 show_locals=show_locals,
112 locals_max_length=locals_max_length,
113 locals_max_string=locals_max_string,
114 locals_hide_dunder=locals_hide_dunder,
115 locals_hide_sunder=bool(locals_hide_sunder),
116 indent_guides=indent_guides,
117 suppress=suppress,
118 max_frames=max_frames,
119 )
120 )
121
122 def ipy_excepthook_closure(ip: Any) -> None: # pragma: no cover
123 tb_data = {} # store information about showtraceback call
124 default_showtraceback = ip.showtraceback # keep reference of default traceback
125
126 def ipy_show_traceback(*args: Any, **kwargs: Any) -> None:
127 """wrap the default ip.showtraceback to store info for ip._showtraceback"""
128 nonlocal tb_data
129 tb_data = kwargs
130 default_showtraceback(*args, **kwargs)
131
133 *args: Any, is_syntax: bool = False, **kwargs: Any
134 ) -> None:
135 """Internally called traceback from ip._showtraceback"""
136 nonlocal tb_data
137 exc_tuple = ip._get_exc_info()
138
139 # do not display trace on syntax error
140 tb: Optional[TracebackType] = None if is_syntax else exc_tuple[2]
141
142 # determine correct tb_offset
143 compiled = tb_data.get("running_compiled_code", False)
144 tb_offset = tb_data.get("tb_offset", 1 if compiled else 0)
145 # remove ipython internal frames from trace with tb_offset
146 for _ in range(tb_offset):
147 if tb is None:
148 break
149 tb = tb.tb_next
150
151 excepthook(exc_tuple[0], exc_tuple[1], tb)
152 tb_data = {} # clear data upon usage
153
154 # replace _showtraceback instead of showtraceback to allow ipython features such as debugging to work
155 # this is also what the ipython docs recommends to modify when subclassing InteractiveShell
156 ip._showtraceback = ipy_display_traceback
157 # add wrapper to capture tb_data
158 ip.showtraceback = ipy_show_traceback
159 ip.showsyntaxerror = lambda *args, **kwargs: ipy_display_traceback(
160 *args, is_syntax=True, **kwargs
161 )
162
163 try: # pragma: no cover
164 # if within ipython, use customized traceback
165 ip = get_ipython() # type: ignore[name-defined]
167 return sys.excepthook
168 except Exception:
169 # otherwise use default system hook
170 old_excepthook = sys.excepthook
171 sys.excepthook = excepthook
172 return old_excepthook
173
174
175@dataclass

References i.

Variable Documentation

◆ console

console = Console()

Definition at line 726 of file traceback.py.

◆ LOCALS_MAX_LENGTH

int LOCALS_MAX_LENGTH = 10

Definition at line 44 of file traceback.py.

◆ LOCALS_MAX_STRING

int LOCALS_MAX_STRING = 80

Definition at line 45 of file traceback.py.

◆ WINDOWS

str WINDOWS = "Windows"

Definition at line 42 of file traceback.py.