8000 gh-94430: Allow parameters named `module` or `self` with custom C names in Argument Clinic by erlend-aasland · Pull Request #94431 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-94430: Allow parameters named module or self with custom C names in Argument Clinic #94431

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 6 commits into from
Jul 7, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
8000
Diff view
Diff view
Prev Previous commit
Next Next commit
Harden fix
  • Loading branch information
erlend-aasland committed Jun 29, 2022
commit 4a45b6fa4acf7e5916ba2bf307e535498e804a3d
8 changes: 6 additions & 2 deletions Tools/clinic/clinic.py
Original file line number Diff line number Diff line change
Expand Up @@ -4710,9 +4710,13 @@ def bad_node(self, node):

p = Parameter(parameter_name, kind, function=self.function, converter=converter, default=value, group=self.group)

if (c_name or parameter_name) in self.function.parameters:
names = [k.name for k in self.function.parameters.values()]
key = f"{parameter_name}_{c_name}" if c_name else parameter_name
if parameter_name in names[1:]:
fail("You can't have two parameters named " + repr(parameter_name) + "!")
self.function.parameters[c_name or parameter_name] = p
elif names and parameter_name == names[0] and c_name is None:
fail("Params named 'module' or 'self' need custom C names")
self.function.parameters[key] = p

def parse_converter(self, annotation):
if (hasattr(ast, 'Constant') and
Expand Down
0