Coverage for src/renaissance/integrations/python/ast/util.py: 86%
14 statements
« prev ^ index » next coverage.py v7.16.1, created at 2026-10-02 13:12 +0000
« prev ^ index » next coverage.py v7.16.1, created at 2026-10-02 13:12 +0000
1"""AI: Utility helpers for converting between source positions and node representations."""
4def convert(lines, line_nr, col):
5 """AI: Convert a (line, column) source position into an absolute character offset."""
6 if line_nr > len(lines):
7 return 0
8 return sum(len(lines[i]) + 1 for i in range(line_nr - 1)) + col
9 # add node to the node list for references
12def to_str(node) -> str:
13 """AI: Return the node's signature if it has one, otherwise its string representation."""
14 if hasattr(node, "signature"):
15 return node.signature
16 return str(node)
19def convert_function(fun):
20 """AI: Return the function's signature rewritten to take a leading 'self' parameter."""
21 signature: str = fun.signature + "\n\n\n"
22 if len(fun.node.args.args) == 0:
23 signature = signature.replace(f"{fun.name}()", f"{fun.name}(self)", 1)
24 else:
25 signature = signature.replace(f"{fun.name}(", f"{fun.name}(self,", 1)
26 return signature