8000 gh-114258: Refactor Argument Clinic function name parser by erlend-aasland · Pull Request #114930 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-114258: Refactor Argument Clinic function name parser #114930

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Feb 15, 2024
Prev Previous commit
Next Next commit
Also refactor out 'add function'
  • Loading branch information
erlend-aasland committed Feb 2, 2024
commit 8850002ff05b559f2571b24d553b1656baa17350
33 changes: 20 additions & 13 deletions Tools/clinic/clinic.py
Original file line number Diff line number Diff line change
Expand Up @@ -5272,7 +5272,7 @@ def state_modulename_name(self, line: str) -> None:
function_name = fields.pop()
module, cls = self.clinic._module_and_class(fields)

self.function = Function(
func = Function(
name=function_name,
full_name=full_name,
module=module,
Expand All @@ -5284,21 +5284,28 @@ def state_modulename_name(self, line: str) -> None:
critical_section=self.critical_section,
target_critical_section=self.target_critical_section
)
self.block.signatures.append(self.function)
self.add_function(func)

# insert a self converter automatically
type, name = correct_name_for_self(self.function)
kwargs = {}
if cls and type == "PyObject *":
kwargs['type'] = cls.typedef
sc = self.function.self_converter = self_converter(name, name, self.function, **kwargs)
p_self = Parameter(name, inspect.Parameter.POSITIONAL_ONLY,
function=self.function, converter=sc)
self.function.parameters[name] = p_self

(cls or module).functions.append(self.function)
self.next(self.state_parameters_start)

def add_function(self, func: Function) -> None:
# Insert a self converter automatically.
tp, name = correct_name_for_self(func)
kwargs = {}
if func.cls and tp == "PyObject *":
kwargs['type'] = func.cls.typedef
6042 func.self_converter = self_converter(name, name, func, **kwargs)
func.parameters[name] = Parameter(
name,
inspect.Parameter.POSITIONAL_ONLY,
function=func,
converter=func.self_converter
)

self.block.signatures.append(func)
self.function = func
(func.cls or func.module).functions.append(func)

# Now entering the parameters section. The rules, formally stated:
#
# * All lines must be indented with spaces only.
Expand Down
0