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

Method render_function

Tools/clinic/libclinic/clanguage.py:360–535  ·  view source on GitHub ↗
(
        self,
        clinic: Clinic,
        f: Function | None
    )

Source from the content-addressed store, hash-verified

358 template_dict['option_group_parsing'] = libclinic.format_escape("".join(out))
359
360 def render_function(
361 self,
362 clinic: Clinic,
363 f: Function | None
364 ) -> str:
365 if f is None:
366 return ""
367
368 codegen = clinic.codegen
369 data = CRenderData()
370
371 assert f.parameters, "We should always have a 'self' at this point!"
372 parameters = f.render_parameters
373 converters = [p.converter for p in parameters]
374
375 templates = self.output_templates(f, codegen)
376
377 f_self = parameters[0]
378 selfless = parameters[1:]
379 assert isinstance(f_self.converter, self_converter), "No self parameter in " + repr(f.full_name) + "!"
380
381 if f.critical_section:
382 match len(f.target_critical_section):
383 case 0:
384 lock = 'Py_BEGIN_CRITICAL_SECTION({self_name});'
385 unlock = 'Py_END_CRITICAL_SECTION();'
386 case 1:
387 lock = 'Py_BEGIN_CRITICAL_SECTION({target_critical_section});'
388 unlock = 'Py_END_CRITICAL_SECTION();'
389 case _:
390 lock = 'Py_BEGIN_CRITICAL_SECTION2({target_critical_section});'
391 unlock = 'Py_END_CRITICAL_SECTION2();'
392 data.lock.append(lock)
393 data.unlock.append(unlock)
394
395 last_group = 0
396 first_optional = len(selfless)
397 positional = selfless and selfless[-1].is_positional_only()
398 has_option_groups = False
399
400 # offset i by -1 because first_optional needs to ignore self
401 for i, p in enumerate(parameters, -1):
402 c = p.converter
403
404 if (i != -1) and (p.default is not unspecified):
405 first_optional = min(first_optional, i)
406
407 # insert group variable
408 group = p.group
409 if last_group != group:
410 last_group = group
411 if group:
412 group_name = self.group_to_variable_name(group)
413 data.impl_arguments.append(group_name)
414 data.declarations.append("int " + group_name + " = 0;")
415 data.impl_parameters.append("int " + group_name)
416 has_option_groups = True
417

Callers 1

renderMethod · 0.95

Calls 15

output_templatesMethod · 0.95
CRenderDataClass · 0.90
failFunction · 0.90
enumerateFunction · 0.85
c_idFunction · 0.85
strFunction · 0.85
is_positional_onlyMethod · 0.80
format_mapMethod · 0.80
get_destinationMethod · 0.80
appendMethod · 0.45

Tested by

no test coverage detected