Skip to content

Commit

Permalink
Put more constants into libclinic
Browse files Browse the repository at this point in the history
Also make them final.
  • Loading branch information
erlend-aasland committed Dec 20, 2023
1 parent bc7f169 commit e64f7e3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 20 deletions.
24 changes: 4 additions & 20 deletions Tools/clinic/clinic.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,6 @@

version = '1'

CLINIC_PREFIX = "__clinic_"
CLINIC_PREFIXED_ARGS = {
"_keywords",
"_parser",
"args",
"argsbuf",
"fastargs",
"kwargs",
"kwnames",
"nargs",
"noptargs",
"return_value",
}

# match '#define Py_LIMITED_API'
LIMITED_CAPI_REGEX = re.compile(r'#define +Py_LIMITED_API')

Expand All @@ -106,8 +92,6 @@ def __repr__(self) -> str:

NULL = Null()

sig_end_marker = '--'

TemplateDict = dict[str, str]


Expand Down Expand Up @@ -1886,7 +1870,7 @@ def render_function(
template_dict['c_basename'] = f.c_basename

template_dict['docstring'] = libclinic.docstring_for_c_string(f.docstring,
sig_end_marker)
libclinic.SIG_END_MARKER)

template_dict['self_name'] = template_dict['self_type'] = template_dict['self_type_check'] = ''
template_dict['target_critical_section'] = ', '.join(f.target_critical_section)
Expand Down Expand Up @@ -3578,8 +3562,8 @@ def set_template_dict(self, template_dict: TemplateDict) -> None:

@property
def parser_name(self) -> str:
if self.name in CLINIC_PREFIXED_ARGS: # bpo-39741
return CLINIC_PREFIX + self.name
if self.name in libclinic.CLINIC_PREFIXED_ARGS: # bpo-39741
return libclinic.CLINIC_PREFIX + self.name
else:
return self.name

Expand Down Expand Up @@ -6314,7 +6298,7 @@ def add_parameter(text: str) -> None:
# add(f.return_converter.py_default)

if not f.docstring_only:
add("\n" + sig_end_marker + "\n")
add("\n" + libclinic.SIG_END_MARKER + "\n")

signature_line = output()

Expand Down
19 changes: 19 additions & 0 deletions Tools/clinic/libclinic/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Final

from .accumulators import (
_TextAccumulator,
_text_accumulator,
Expand All @@ -13,6 +15,23 @@
)


CLINIC_PREFIX: Final[str] = "__clinic_"
CLINIC_PREFIXED_ARGS: Final[set[str]] = {
"_keywords",
"_parser",
"args",
"argsbuf",
"fastargs",
"kwargs",
"kwnames",
"nargs",
"noptargs",
"return_value",
}

SIG_END_MARKER: Final[str] = '--'


__all__ = [
# Accumulators
"_TextAccumulator",
Expand Down

0 comments on commit e64f7e3

Please sign in to comment.