MCPcopy Index your code
hub / github.com/python/cpython / to_tuple

Function to_tuple

Lib/test/test_ast/utils.py:1–15  ·  view source on GitHub ↗
(t)

Source from the content-addressed store, hash-verified

1def to_tuple(t):
2 if t is None or isinstance(t, (str, int, complex, float, bytes, tuple)) or t is Ellipsis:
3 return t
4 elif isinstance(t, list):
5 return [to_tuple(e) for e in t]
6 result = [t.__class__.__name__]
7 if hasattr(t, 'lineno') and hasattr(t, 'col_offset'):
8 result.append((t.lineno, t.col_offset))
9 if hasattr(t, 'end_lineno') and hasattr(t, 'end_col_offset'):
10 result[-1] += (t.end_lineno, t.end_col_offset)
11 if t._fields is None:
12 return tuple(result)
13 for f in t._fields:
14 result.append(to_tuple(getattr(t, f)))
15 return tuple(result)

Callers 4

test_snippetsMethod · 0.90
test_picklingMethod · 0.90
mainFunction · 0.90

Calls 1

appendMethod · 0.45

Tested by 3

test_snippetsMethod · 0.72
test_picklingMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…