MCPcopy Index your code
hub / github.com/SourceCode-AI/aura / string_slice

Method string_slice

aura/analyzers/python/rewrite_ast.py:89–127  ·  view source on GitHub ↗
(self, context)

Source from the content-addressed store, hash-verified

87 # TODO cover other cases
88
89 def string_slice(self, context):
90 if not type(context.node) == Subscript:
91 return
92 elif not type(context.node.value) in (String,):
93 return
94
95 value = str(context.node.value)
96
97 if type(context.node.slice) == Number:
98 try:
99 sliced_str = value[int(context.node.slice)]
100 except IndexError: # out of range
101 return
102 elif type(context.node.slice) == dict and context.node.slice.get("_type") == "Slice":
103 step = context.node.slice.get("step")
104 if type(step) == Number:
105 step = int(step)
106 elif step is not None and type(step) != int:
107 return
108
109 lower = context.node.slice.get("lower")
110 if type(lower) == Number:
111 lower = int(lower)
112 elif lower is not None and type(lower) != int:
113 return
114
115 upper = context.node.slice.get("upper")
116 if type(upper) == Number:
117 upper = int(upper)
118 elif upper is not None and type(upper) != int:
119 return
120
121 sliced_str = value[lower:upper:step]
122 else:
123 return # Unknown slice type
124
125 new_node = String(sliced_str)
126 new_node.enrich_from_previous(context.node)
127 context.replace(new_node)
128
129 def resolve_variable(self, context: Context):
130 """

Callers

nothing calls this directly

Calls 3

StringClass · 0.85
getMethod · 0.80
enrich_from_previousMethod · 0.80

Tested by

no test coverage detected