Debian Codegraph @

Lib/test/test_ast/utils.py

raw
1 def 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)