Skip to content
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

gh-106368: Argument clinic: Fix minor bug in state_modulename_name #107387

Merged
merged 2 commits into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
Diff view
Diff view
17 changes: 17 additions & 0 deletions Lib/test/test_clinic.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def __init__(self):
('parser_definition', d('block')),
('impl_definition', d('block')),
))
self.functions = []

def get_destination(self, name):
d = self.destinations.get(name)
Expand All @@ -104,6 +105,9 @@ def directive(self, name, args):

_module_and_class = clinic.Clinic._module_and_class

def __repr__(self):
return "<FakeClinic object>"


class ClinicWholeFileTest(_ParserBase):
def setUp(self):
Expand Down Expand Up @@ -672,6 +676,19 @@ def test_c_name(self):
""")
self.assertEqual("os_stat_fn", function.c_basename)

def test_cloning_nonexistent_function_correctly_fails(self):
stdout = self.parse_function_should_fail("""
cloned = fooooooooooooooooooooooo
This is trying to clone a nonexistent function!!
""")
expected_error = """\
cls=None, module=<FakeClinic object>, existing='fooooooooooooooooooooooo'
(cls or module).functions=[]
Error on line 0:
Couldn't find existing function 'fooooooooooooooooooooooo'!
"""
self.assertEqual(expected_error, stdout)

def test_return_converter(self):
function = self.parse_function("""
module os
Expand Down
8 changes: 3 additions & 5 deletions Tools/clinic/clinic.py
Original file line number Diff line number Diff line change
Expand Up @@ -4707,11 +4707,9 @@ def state_modulename_name(self, line: str | None) -> None:
if existing_function.name == function_name:
break
else:
existing_function = None
if not existing_function:
print("class", cls, "module", module, "existing", existing)
print("cls. functions", cls.functions)
fail("Couldn't find existing function " + repr(existing) + "!")
print(f"{cls=}, {module=}, {existing=}")
print(f"{(cls or module).functions=}")
fail(f"Couldn't find existing function {existing!r}!")

fields = [x.strip() for x in full_name.split('.')]
function_name = fields.pop()
Expand Down