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

Method parse_converter

Tools/clinic/libclinic/dsl_parser.py:1131–1149  ·  view source on GitHub ↗
(
        annotation: ast.expr | None
    )

Source from the content-addressed store, hash-verified

1129
1130 @staticmethod
1131 def parse_converter(
1132 annotation: ast.expr | None
1133 ) -> tuple[str, bool, ConverterArgs]:
1134 match annotation:
1135 case ast.Constant(value=str() as value):
1136 return value, True, {}
1137 case ast.Name(name):
1138 return name, False, {}
1139 case ast.Call(func=ast.Name(name)):
1140 kwargs: ConverterArgs = {}
1141 for node in annotation.keywords:
1142 if not isinstance(node.arg, str):
1143 fail("Cannot use a kwarg splat in a function-call annotation")
1144 kwargs[node.arg] = eval_ast_expr(node.value)
1145 return name, False, kwargs
1146 case _:
1147 fail(
1148 "Annotations must be either a name, a function call, or a string."
1149 )
1150
1151 def parse_version(self, thenceforth: str) -> VersionTuple:
1152 """Parse Python version in `[from ...]` marker."""

Callers 2

parse_parameterMethod · 0.95

Calls 2

failFunction · 0.90
eval_ast_exprFunction · 0.85

Tested by

no test coverage detected