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

Method infer

Tools/clinic/libclinic/dsl_parser.py:195–225  ·  view source on GitHub ↗

Infer what is now the current margin based on this line. Returns: 1 if we have indented (or this is the first margin) 0 if the margin has not changed -N if we have dedented N times

(self, line: str)

Source from the content-addressed store, hash-verified

193 return len(line) - len(stripped)
194
195 def infer(self, line: str) -> int:
196 """
197 Infer what is now the current margin based on this line.
198 Returns:
199 1 if we have indented (or this is the first margin)
200 0 if the margin has not changed
201 -N if we have dedented N times
202 """
203 indent = self.measure(line)
204 margin = ' ' * indent
205 if not self.indents:
206 self.indents.append(indent)
207 self.margin = margin
208 return 1
209 current = self.indents[-1]
210 if indent == current:
211 return 0
212 if indent > current:
213 self.indents.append(indent)
214 self.margin = margin
215 return 1
216 # indent < current
217 if indent not in self.indents:
218 fail("Illegal outdent.")
219 outdent_count = 0
220 while indent != current:
221 self.indents.pop()
222 current = self.indents[-1]
223 outdent_count -= 1
224 self.margin = margin
225 return outdent_count
226
227 @property
228 def depth(self) -> int:

Callers 4

state_modulename_nameMethod · 0.80
state_parameterMethod · 0.80

Calls 4

measureMethod · 0.95
failFunction · 0.90
appendMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected