MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / scanvars

Function scanvars

tools/python-3.11.9-amd64/Lib/cgitb.py:85–104  ·  view source on GitHub ↗

Scan one logical line of Python and look up values of variables used.

(reader, frame, locals)

Source from the content-addressed store, hash-verified

83 return None, __UNDEF__
84
85def scanvars(reader, frame, locals):
86 """Scan one logical line of Python and look up values of variables used."""
87 vars, lasttoken, parent, prefix, value = [], None, None, '', __UNDEF__
88 for ttype, token, start, end, line in tokenize.generate_tokens(reader):
89 if ttype == tokenize.NEWLINE: break
90 if ttype == tokenize.NAME and token not in keyword.kwlist:
91 if lasttoken == '.':
92 if parent is not __UNDEF__:
93 value = getattr(parent, token, __UNDEF__)
94 vars.append((prefix + token, prefix, value))
95 else:
96 where, value = lookup(token, frame, locals)
97 vars.append((token, where, value))
98 elif token == '.':
99 prefix += lasttoken + '.'
100 parent = value
101 else:
102 parent, prefix = None, ''
103 lasttoken = token
104 return vars
105
106def html(einfo, context=5):
107 """Return a nice HTML document describing a given traceback."""

Callers 2

htmlFunction · 0.85
textFunction · 0.85

Calls 2

lookupFunction · 0.70
appendMethod · 0.45

Tested by

no test coverage detected