id
int64
1
6.07M
name
stringlengths
1
295
code
stringlengths
12
426k
language
stringclasses
1 value
source_file
stringlengths
5
202
start_line
int64
1
158k
end_line
int64
1
158k
repo
dict
9,901
parse_argument
def parse_argument(self, args: list[str]) -> None: assert not (self.converter and self.encoding) if self.format_unit == 'O&': assert self.converter args.append(self.converter) if self.encoding: args.append(libclinic.c_repr(self.encoding)) elif self.su...
python
Tools/clinic/libclinic/converter.py
320
335
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,902
simple_declaration
def simple_declaration( self, by_reference: bool = False, *, in_parser: bool = False ) -> str: """ Computes the basic declaration of the variable. Used in computing the prototype declaration and the variable declaration. """ ...
python
Tools/clinic/libclinic/converter.py
341
365
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,903
declaration
def declaration(self, *, in_parser: bool = False) -> str: """ The C statement to declare this variable. """ declaration = [self.simple_declaration(in_parser=True)] default = self.c_default if not default and self.parameter.group: default = self.c_ignored_defau...
python
Tools/clinic/libclinic/converter.py
367
382
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,904
initialize
def initialize(self) -> str: """ The C statements required to set up this variable before parsing. Returns a string containing this code indented at column 0. If no initialization is necessary, returns an empty string. """ return ""
python
Tools/clinic/libclinic/converter.py
384
390
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,905
modify
def modify(self) -> str: """ The C statements required to modify this variable after parsing. Returns a string containing this code indented at column 0. If no modification is necessary, returns an empty string. """ return ""
python
Tools/clinic/libclinic/converter.py
392
398
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,906
post_parsing
def post_parsing(self) -> str: """ The C statements required to do some operations after the end of parsing but before cleaning up. Return a string containing this code indented at column 0. If no operation is necessary, return an empty string. """ return ""
python
Tools/clinic/libclinic/converter.py
400
406
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,907
cleanup
def cleanup(self) -> str: """ The C statements required to clean up after this variable. Returns a string containing this code indented at column 0. If no cleanup is necessary, returns an empty string. """ return ""
python
Tools/clinic/libclinic/converter.py
408
414
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,908
pre_render
def pre_render(self) -> None: """ A second initialization function, like converter_init, called just before rendering. You are permitted to examine self.function here. """ pass
python
Tools/clinic/libclinic/converter.py
416
422
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,909
bad_argument
def bad_argument(self, displayname: str, expected: str, *, limited_capi: bool, expected_literal: bool = True) -> str: assert '"' not in expected if limited_capi: if expected_literal: return (f'PyErr_Format(PyExc_TypeError, ' f'"{{{{name}}}}() {displayn...
python
Tools/clinic/libclinic/converter.py
424
439
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,910
format_code
def format_code(self, fmt: str, *, argname: str, bad_argument: str | None = None, bad_argument2: str | None = None, **kwargs: Any) -> str: if '{bad_argument}' in fmt: if not bad_argument: raise TypeError(...
python
Tools/clinic/libclinic/converter.py
441
454
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,911
use_converter
def use_converter(self) -> None: """Method called when self.converter is used to parse an argument.""" pass
python
Tools/clinic/libclinic/converter.py
456
458
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,912
parse_arg
def parse_arg(self, argname: str, displayname: str, *, limited_capi: bool) -> str | None: if self.format_unit == 'O&': self.use_converter() return self.format_code(""" if (!{converter}({argname}, &{paramname})) {{{{ goto exit; }}}} ...
python
Tools/clinic/libclinic/converter.py
460
501
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,913
set_template_dict
def set_template_dict(self, template_dict: TemplateDict) -> None: pass
python
Tools/clinic/libclinic/converter.py
503
504
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,914
parser_name
def parser_name(self) -> str: if self.name in libclinic.CLINIC_PREFIXED_ARGS: # bpo-39741 return libclinic.CLINIC_PREFIX + self.name else: return self.name
python
Tools/clinic/libclinic/converter.py
507
511
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,915
add_include
def add_include(self, name: str, reason: str, *, condition: str | None = None) -> None: include = Include(name, reason, condition) self._includes.append(include)
python
Tools/clinic/libclinic/converter.py
513
516
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,916
get_includes
def get_includes(self) -> list[Include]: return self._includes
python
Tools/clinic/libclinic/converter.py
518
519
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,917
add_legacy_c_converter
def add_legacy_c_converter( format_unit: str, **kwargs: Any ) -> Callable[[CConverterClassT], CConverterClassT]: def closure(f: CConverterClassT) -> CConverterClassT: added_f: Callable[..., CConverter] if not kwargs: added_f = f else: added_f = functools.parti...
python
Tools/clinic/libclinic/converter.py
539
552
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,918
closure
def closure(f: CConverterClassT) -> CConverterClassT: added_f: Callable[..., CConverter] if not kwargs: added_f = f else: added_f = functools.partial(f, **kwargs) if format_unit: legacy_converters[format_unit] = added_f return f
python
Tools/clinic/libclinic/converter.py
543
551
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,919
docstring_for_c_string
def docstring_for_c_string(docstring: str) -> str: lines = [] # Turn docstring into a properly quoted C string. for line in docstring.split("\n"): lines.append('"') lines.append(_quoted_for_c_string(line)) lines.append('\\n"\n') if lines[-2] == SIG_END_MARKER: # If we on...
python
Tools/clinic/libclinic/formatting.py
13
28
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,920
_quoted_for_c_string
def _quoted_for_c_string(text: str) -> str: """Helper for docstring_for_c_string().""" for old, new in ( ("\\", "\\\\"), # must be first! ('"', '\\"'), ("'", "\\'"), ): text = text.replace(old, new) return text
python
Tools/clinic/libclinic/formatting.py
31
39
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,921
c_repr
def c_repr(text: str) -> str: return '"' + text + '"'
python
Tools/clinic/libclinic/formatting.py
42
43
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,922
wrapped_c_string_literal
def wrapped_c_string_literal( text: str, *, width: int = 72, suffix: str = "", initial_indent: int = 0, subsequent_indent: int = 4 ) -> str: wrapped = textwrap.wrap( text, width=width, replace_whitespace=False, drop_whitespace=False, break_on_hyphens=F...
python
Tools/clinic/libclinic/formatting.py
46
62
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,923
_add_prefix_and_suffix
def _add_prefix_and_suffix(text: str, *, prefix: str = "", suffix: str = "") -> str: """Return 'text' with 'prefix' prepended and 'suffix' appended to all lines. If the last line is empty, it remains unchanged. If text is blank, return text unchanged. (textwrap.indent only adds to non-blank lines.) ...
python
Tools/clinic/libclinic/formatting.py
65
77
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,924
indent_all_lines
def indent_all_lines(text: str, prefix: str) -> str: return _add_prefix_and_suffix(text, prefix=prefix)
python
Tools/clinic/libclinic/formatting.py
80
81
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,925
suffix_all_lines
def suffix_all_lines(text: str, suffix: str) -> str: return _add_prefix_and_suffix(text, suffix=suffix)
python
Tools/clinic/libclinic/formatting.py
84
85
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,926
pprint_words
def pprint_words(items: list[str]) -> str: if len(items) <= 2: return " and ".join(items) return ", ".join(items[:-1]) + " and " + items[-1]
python
Tools/clinic/libclinic/formatting.py
88
91
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,927
_strip_leading_and_trailing_blank_lines
def _strip_leading_and_trailing_blank_lines(text: str) -> str: lines = text.rstrip().split("\n") while lines: line = lines[0] if line.strip(): break del lines[0] return "\n".join(lines)
python
Tools/clinic/libclinic/formatting.py
94
101
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,928
normalize_snippet
def normalize_snippet(text: str, *, indent: int = 0) -> str: """ Reformats 'text': * removes leading and trailing blank lines * ensures that it does not end with a newline * dedents so the first nonwhite character on any line is at column "indent" """ text = _strip_leading_and_tr...
python
Tools/clinic/libclinic/formatting.py
105
116
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,929
format_escape
def format_escape(text: str) -> str: # double up curly-braces, this string will be used # as part of a format_map() template later text = text.replace("{", "{{") text = text.replace("}", "}}") return text
python
Tools/clinic/libclinic/formatting.py
119
124
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,930
wrap_declarations
def wrap_declarations(text: str, length: int = 78) -> str: """ A simple-minded text wrapper for C function declarations. It views a declaration line as looking like this: xxxxxxxx(xxxxxxxxx,xxxxxxxxx) If called with length=30, it would wrap that line into xxxxxxxx(xxxxxxxxx, ...
python
Tools/clinic/libclinic/formatting.py
127
175
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,931
linear_format
def linear_format(text: str, **kwargs: str) -> str: """ Perform str.format-like substitution, except: * The strings substituted must be on lines by themselves. (This line is the "source line".) * If the substitution text is empty, the source line is removed in the output. * If...
python
Tools/clinic/libclinic/formatting.py
178
223
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,932
negate
def negate(condition: str) -> str: """ Returns a CPP conditional that is the opposite of the conditional passed in. """ if condition.startswith('!'): return condition[1:] return "!" + condition
python
Tools/clinic/libclinic/cpp.py
15
21
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,933
__post_init__
def __post_init__(self) -> None: self.stack: TokenStack = [] self.in_comment = False self.continuation: str | None = None self.line_number = 0
python
Tools/clinic/libclinic/cpp.py
44
48
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,934
__repr__
def __repr__(self) -> str: parts = ( str(id(self)), f"line={self.line_number}", f"condition={self.condition()!r}" ) return f"<clinic.Monitor {' '.join(parts)}>"
python
Tools/clinic/libclinic/cpp.py
50
56
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,935
status
def status(self) -> str: return str(self.line_number).rjust(4) + ": " + self.condition()
python
Tools/clinic/libclinic/cpp.py
58
59
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,936
condition
def condition(self) -> str: """ Returns the current preprocessor state, as a single #if condition. """ return " && ".join(condition for token, condition in self.stack)
python
Tools/clinic/libclinic/cpp.py
61
65
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,937
fail
def fail(self, msg: str) -> NoReturn: raise ParseError(msg, filename=self.filename, lineno=self.line_number)
python
Tools/clinic/libclinic/cpp.py
67
68
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,938
writeline
def writeline(self, line: str) -> None: self.line_number += 1 line = line.strip() def pop_stack() -> TokenAndCondition: if not self.stack: self.fail(f"#{token} without matching #if / #ifdef / #ifndef!") return self.stack.pop() if self.continuatio...
python
Tools/clinic/libclinic/cpp.py
70
179
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,939
pop_stack
def pop_stack() -> TokenAndCondition: if not self.stack: self.fail(f"#{token} without matching #if / #ifdef / #ifndef!") return self.stack.pop()
python
Tools/clinic/libclinic/cpp.py
74
77
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,940
_main
def _main(filenames: list[str] | None = None) -> None: filenames = filenames or sys.argv[1:] for filename in filenames: with open(filename) as f: cpp = Monitor(filename, verbose=True) print() print(filename) for line in f: cpp.writeline(lin...
python
Tools/clinic/libclinic/cpp.py
182
190
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,941
__init__
def __init__(self, clinic: Clinic) -> None: ...
python
Tools/clinic/libclinic/parser.py
18
18
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,942
parse
def parse(self, block: Block) -> None: ...
python
Tools/clinic/libclinic/parser.py
19
19
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,943
_create_parser_base_namespace
def _create_parser_base_namespace() -> dict[str, Any]: ns = dict( CConverter=CConverter, CReturnConverter=CReturnConverter, buffer=buffer, robuffer=robuffer, rwbuffer=rwbuffer, unspecified=unspecified, NoneType=NoneType, ) for name, converter in conver...
python
Tools/clinic/libclinic/parser.py
23
37
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,944
create_parser_namespace
def create_parser_namespace() -> dict[str, Any]: base_namespace = _create_parser_base_namespace() return base_namespace.copy()
python
Tools/clinic/libclinic/parser.py
40
42
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,945
__init__
def __init__(self, clinic: Clinic) -> None: pass
python
Tools/clinic/libclinic/parser.py
46
47
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,946
parse
def parse(self, block: Block) -> None: namespace = create_parser_namespace() with contextlib.redirect_stdout(io.StringIO()) as s: exec(block.input, namespace) block.output = s.getvalue()
python
Tools/clinic/libclinic/parser.py
49
53
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,947
__init__
def __init__(self, filename: str) -> None: super().__init__(filename) self.cpp = libclinic.cpp.Monitor(filename)
python
Tools/clinic/libclinic/clanguage.py
55
57
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,948
parse_line
def parse_line(self, line: str) -> None: self.cpp.writeline(line)
python
Tools/clinic/libclinic/clanguage.py
59
60
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,949
render
def render( self, clinic: Clinic, signatures: Iterable[Module | Class | Function] ) -> str: function = None for o in signatures: if isinstance(o, Function): if function: fail("You may specify at most one function per block.\nFou...
python
Tools/clinic/libclinic/clanguage.py
62
73
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,950
compiler_deprecated_warning
def compiler_deprecated_warning( self, func: Function, parameters: list[Parameter], ) -> str | None: minversion: VersionTuple | None = None for p in parameters: for version in p.deprecated_positional, p.deprecated_keyword: if version and (not minve...
python
Tools/clinic/libclinic/clanguage.py
75
96
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,951
deprecate_positional_use
def deprecate_positional_use( self, func: Function, params: dict[int, Parameter], ) -> str: assert len(params) > 0 first_pos = next(iter(params)) last_pos = next(reversed(params)) # Format the deprecation message. if len(params) == 1: cond...
python
Tools/clinic/libclinic/clanguage.py
98
147
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,952
deprecate_keyword_use
def deprecate_keyword_use( self, func: Function, params: dict[int, Parameter], argname_fmt: str | None = None, *, fastcall: bool, codegen: CodeGen, ) -> str: assert len(params) > 0 last_param = next(reversed(params.values())) limited_ca...
python
Tools/clinic/libclinic/clanguage.py
149
230
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,953
output_templates
def output_templates( self, f: Function, codegen: CodeGen, ) -> dict[str, str]: args = ParseArgsCodeGen(f, codegen) return args.parse_args(self)
python
Tools/clinic/libclinic/clanguage.py
232
238
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,954
group_to_variable_name
def group_to_variable_name(group: int) -> str: adjective = "left_" if group < 0 else "right_" return "group_" + adjective + str(abs(group))
python
Tools/clinic/libclinic/clanguage.py
241
243
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,955
render_option_group_parsing
def render_option_group_parsing( self, f: Function, template_dict: TemplateDict, limited_capi: bool, ) -> None: # positional only, grouped, optional arguments! # can be optional on the left or right. # here's an example: # # [ [ [ A1 A2 ] B1 B2...
python
Tools/clinic/libclinic/clanguage.py
245
348
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,956
render_function
def render_function( self, clinic: Clinic, f: Function | None ) -> str: if f is None: return "" codegen = clinic.codegen data = CRenderData() assert f.parameters, "We should always have a 'self' at this point!" parameters = f.render_param...
python
Tools/clinic/libclinic/clanguage.py
350
527
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,957
parse_file
def parse_file( filename: str, *, limited_capi: bool, output: str | None = None, verify: bool = True, ) -> None: if not output: output = filename extension = os.path.splitext(filename)[1][1:] if not extension: raise ClinicError(f"Can't extract file ty...
python
Tools/clinic/libclinic/cli.py
49
86
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,958
create_cli
def create_cli() -> argparse.ArgumentParser: cmdline = argparse.ArgumentParser( prog="clinic.py", description="""Preprocessor for CPython C files. The purpose of the Argument Clinic is automating all the boilerplate involved with writing argument parsing code for builtins and providing introspectio...
python
Tools/clinic/libclinic/cli.py
89
119
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,959
run_clinic
def run_clinic(parser: argparse.ArgumentParser, ns: argparse.Namespace) -> None: if ns.converters: if ns.filename: parser.error( "can't specify --converters and a filename at the same time" ) AnyConverterType = ConverterType | ReturnConverterType conve...
python
Tools/clinic/libclinic/cli.py
122
219
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,960
main
def main(argv: list[str] | None = None) -> NoReturn: parser = create_cli() args = parser.parse_args(argv) try: run_clinic(parser, args) except ClinicError as exc: sys.stderr.write(exc.report()) sys.exit(1) else: sys.exit(0)
python
Tools/clinic/libclinic/cli.py
222
231
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,961
write_file
def write_file(filename: str, new_contents: str) -> None: """Write new content to file, iff the content changed.""" try: with open(filename, encoding="utf-8") as fp: old_contents = fp.read() if old_contents == new_contents: # no change: avoid modifying the file modificat...
python
Tools/clinic/libclinic/utils.py
10
29
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,962
compute_checksum
def compute_checksum(input_: str, length: int | None = None) -> str: checksum = hashlib.sha1(input_.encode("utf-8")).hexdigest() if length: checksum = checksum[:length] return checksum
python
Tools/clinic/libclinic/utils.py
32
36
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,963
create_regex
def create_regex( before: str, after: str, word: bool = True, whole_line: bool = True ) -> re.Pattern[str]: """Create a regex object for matching marker lines.""" group_re = r"\w+" if word else ".+" before = re.escape(before) after = re.escape(after) pattern = rf"{before}({group_re}){after}" ...
python
Tools/clinic/libclinic/utils.py
39
49
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,964
__init__
def __init__(self) -> None: self.counts = collections.Counter[str]()
python
Tools/clinic/libclinic/utils.py
62
63
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,965
get_value
def get_value( self, key: str, args: object, kwargs: object # type: ignore[override] ) -> Literal[""]: self.counts[key] += 1 return ""
python
Tools/clinic/libclinic/utils.py
65
69
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,966
__repr__
def __repr__(self) -> str: return f"<{self.value.capitalize()}>"
python
Tools/clinic/libclinic/utils.py
79
80
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,967
__repr__
def __repr__(self) -> str: return '<Null>'
python
Tools/clinic/libclinic/utils.py
89
90
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,968
declare_parser
def declare_parser( f: Function, *, hasformat: bool = False, codegen: CodeGen, ) -> str: """ Generates the code template for a static local PyArg_Parser variable, with an initializer. For core code (incl. builtin modules) the kwtuple field is also statically initialized. Otherwise ...
python
Tools/clinic/libclinic/parse_args.py
17
87
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,969
__init__
def __init__(self, func: Function, codegen: CodeGen) -> None: self.func = func self.codegen = codegen self.parameters = list(self.func.parameters.values()) first_param = self.parameters.pop(0) if not isinstance(first_param.converter, self_converter): raise ValueError...
python
Tools/clinic/libclinic/parse_args.py
228
267
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,970
is_new_or_init
def is_new_or_init(self) -> bool: return self.func.kind.new_or_init
python
Tools/clinic/libclinic/parse_args.py
269
270
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,971
has_option_groups
def has_option_groups(self) -> bool: return (bool(self.parameters and (self.parameters[0].group or self.parameters[-1].group)))
python
Tools/clinic/libclinic/parse_args.py
272
274
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,972
use_meth_o
def use_meth_o(self) -> bool: return (len(self.parameters) == 1 and self.parameters[0].is_positional_only() and not self.converters[0].is_optional() and not self.requires_defining_class and not self.is_new_or_init())
python
Tools/clinic/libclinic/parse_args.py
276
281
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,973
use_simple_return
def use_simple_return(self) -> bool: return (self.func.return_converter.type == 'PyObject *' and not self.func.critical_section)
python
Tools/clinic/libclinic/parse_args.py
283
285
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,974
select_prototypes
def select_prototypes(self) -> None: self.docstring_prototype = '' self.docstring_definition = '' self.methoddef_define = METHODDEF_PROTOTYPE_DEFINE self.return_value_declaration = "PyObject *return_value = NULL;" if self.is_new_or_init() and not self.func.docstring: ...
python
Tools/clinic/libclinic/parse_args.py
287
306
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,975
init_limited_capi
def init_limited_capi(self) -> None: self.limited_capi = self.codegen.limited_capi if self.limited_capi and (self.pseudo_args or (any(p.is_optional() for p in self.parameters) and any(p.is_keyword_only() and not p.is_optional() for p in self.parameters)) or ...
python
Tools/clinic/libclinic/parse_args.py
308
315
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,976
parser_body
def parser_body( self, *fields: str, declarations: str = '' ) -> None: lines = [self.parser_prototype] self.parser_body_fields = fields preamble = libclinic.normalize_snippet(""" {{ {return_value_declaration} {parser_declar...
python
Tools/clinic/libclinic/parse_args.py
317
349
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,977
parse_no_args
def parse_no_args(self) -> None: parser_code: list[str] | None simple_return = self.use_simple_return() if self.func.kind is GETTER: self.parser_prototype = PARSER_PROTOTYPE_GETTER parser_code = [] elif self.func.kind is SETTER: self.parser_prototype =...
python
Tools/clinic/libclinic/parse_args.py
351
387
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,978
parse_one_arg
def parse_one_arg(self) -> None: self.flags = "METH_O" if (isinstance(self.converters[0], object_converter) and self.converters[0].format_unit == 'O'): meth_o_prototype = METH_O_PROTOTYPE if self.use_simple_return(): # maps perfectly to METH_O, doesn...
python
Tools/clinic/libclinic/parse_args.py
389
430
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,979
parse_option_groups
def parse_option_groups(self) -> None: # positional parameters with option groups # (we have to generate lots of PyArg_ParseTuple calls # in a big switch statement) self.flags = "METH_VARARGS" self.parser_prototype = PARSER_PROTOTYPE_VARARGS parser_code = ' {option_g...
python
Tools/clinic/libclinic/parse_args.py
432
440
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,980
parse_pos_only
def parse_pos_only(self) -> None: if self.fastcall: # positional-only, but no option groups # we only need one call to _PyArg_ParseStack self.flags = "METH_FASTCALL" self.parser_prototype = PARSER_PROTOTYPE_FASTCALL nargs = 'nargs' argname...
python
Tools/clinic/libclinic/parse_args.py
442
583
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,981
parse_general
def parse_general(self, clang: CLanguage) -> None: parsearg: str | None deprecated_positionals: dict[int, Parameter] = {} deprecated_keywords: dict[int, Parameter] = {} for i, p in enumerate(self.parameters): if p.deprecated_positional: deprecated_positionals[...
python
Tools/clinic/libclinic/parse_args.py
585
784
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,982
copy_includes
def copy_includes(self) -> None: # Copy includes from parameters to Clinic after parse_arg() # has been called above. for converter in self.converters: for include in converter.get_includes(): self.codegen.add_include( include.filename, ...
python
Tools/clinic/libclinic/parse_args.py
786
794
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,983
handle_new_or_init
def handle_new_or_init(self) -> None: self.methoddef_define = '' if self.func.kind is METHOD_NEW: self.parser_prototype = PARSER_PROTOTYPE_KEYWORD else: self.return_value_declaration = "int return_value = -1;" self.parser_prototype = PARSER_PROTOTYPE_KEYWORD_...
python
Tools/clinic/libclinic/parse_args.py
796
832
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,984
process_methoddef
def process_methoddef(self, clang: CLanguage) -> None: methoddef_cast_end = "" if self.flags in ('METH_NOARGS', 'METH_O', 'METH_VARARGS'): methoddef_cast = "(PyCFunction)" elif self.func.kind is GETTER: methoddef_cast = "" # This should end up unused elif self.lim...
python
Tools/clinic/libclinic/parse_args.py
834
862
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,985
finalize
def finalize(self, clang: CLanguage) -> None: # add ';' to the end of self.parser_prototype and self.impl_prototype # (they mustn't be None, but they could be an empty string.) assert self.parser_prototype is not None if self.parser_prototype: assert not self.parser_prototype...
python
Tools/clinic/libclinic/parse_args.py
864
881
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,986
create_template_dict
def create_template_dict(self) -> dict[str, str]: d = { "docstring_prototype" : self.docstring_prototype, "docstring_definition" : self.docstring_definition, "impl_prototype" : self.impl_prototype, "methoddef_define" : self.methoddef_define, "parser_pr...
python
Tools/clinic/libclinic/parse_args.py
883
905
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,987
parse_args
def parse_args(self, clang: CLanguage) -> dict[str, str]: self.select_prototypes() self.init_limited_capi() self.flags = "" self.declarations = "" self.parser_prototype = "" self.parser_definition = "" self.impl_prototype = None self.impl_definition = IMP...
python
Tools/clinic/libclinic/parse_args.py
907
940
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,988
__init__
def __init__(self, filename: str) -> None: self.filename = filename
python
Tools/clinic/libclinic/language.py
24
25
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,989
render
def render( self, clinic: Clinic, signatures: Iterable[Module | Class | Function] ) -> str: ...
python
Tools/clinic/libclinic/language.py
28
33
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,990
parse_line
def parse_line(self, line: str) -> None: ...
python
Tools/clinic/libclinic/language.py
35
36
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,991
validate
def validate(self) -> None: def assert_only_one( attr: str, *additional_fields: str ) -> None: """ Ensures that the string found at getattr(self, attr) contains exactly one formatter replacement string for each valid field. ...
python
Tools/clinic/libclinic/language.py
38
94
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,992
assert_only_one
def assert_only_one( attr: str, *additional_fields: str ) -> None: """ Ensures that the string found at getattr(self, attr) contains exactly one formatter replacement string for each valid field. The list of valid fields is ...
python
Tools/clinic/libclinic/language.py
39
88
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,993
local_fail
def local_fail(should_be_there_but_isnt: bool) -> None: if should_be_there_but_isnt: fail("{} {} must contain {{{}}} exactly once!".format( self.__class__.__name__, attr, name)) else: fail("{} {} must not contain {{{}}}!".fo...
python
Tools/clinic/libclinic/language.py
72
78
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,994
__repr__
def __repr__(self) -> str: dsl_name = self.dsl_name or "text" def summarize(s: object) -> str: s = repr(s) if len(s) > 30: return s[:26] + "..." + s[0] return s parts = ( repr(dsl_name), f"input={summarize(self.input)}",...
python
Tools/clinic/libclinic/block_parser.py
71
83
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,995
summarize
def summarize(s: object) -> str: s = repr(s) if len(s) > 30: return s[:26] + "..." + s[0] return s
python
Tools/clinic/libclinic/block_parser.py
73
77
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,996
__init__
def __init__( self, input: str, language: Language, *, verify: bool = True ) -> None: """ "input" should be a str object with embedded \n characters. "language" should be a Language object. """ language.vali...
python
Tools/clinic/libclinic/block_parser.py
92
120
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,997
__iter__
def __iter__(self) -> BlockParser: return self
python
Tools/clinic/libclinic/block_parser.py
122
123
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,998
__next__
def __next__(self) -> Block: while True: if not self.input: raise StopIteration if self.dsl_name: try: return_value = self.parse_clinic_block(self.dsl_name) except ClinicError as exc: exc.filename = ...
python
Tools/clinic/libclinic/block_parser.py
125
144
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
9,999
is_start_line
def is_start_line(self, line: str) -> str | None: match = self.start_re.match(line.lstrip()) return match.group(1) if match else None
python
Tools/clinic/libclinic/block_parser.py
147
149
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }
10,000
_line
def _line(self, lookahead: bool = False) -> str: self.line_number += 1 line = self.input.pop() if not lookahead: self.language.parse_line(line) return line
python
Tools/clinic/libclinic/block_parser.py
151
156
{ "name": "PublicHealthInformationTechnology/cpython", "url": "https://github.com/PublicHealthInformationTechnology/cpython.git", "license": "NOASSERTION", "stars": 0, "forks": 0 }