Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-104683: Argument clinic: cleanupstate_modulename_name()#107340

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
AlexWaygood merged 3 commits intopython:mainfromAlexWaygood:clinic-modulename-name
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from1 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
Diff view
Diff view
PrevPrevious commit
Add some tests
  • Loading branch information
@AlexWaygood
AlexWaygood committedJul 27, 2023
commit37865cae64c283999449536aa45f1e5dc1fa9748
26 changes: 26 additions & 0 deletionsLib/test/test_clinic.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -679,6 +679,32 @@ def test_return_converter(self):
""")
self.assertIsInstance(function.return_converter, clinic.int_return_converter)

def test_return_converter_invalid_syntax(self):
stdout = self.parse_function_should_fail("""
module os
os.stat -> invalid syntax
""")
expected_error = "Badly formed annotation for os.stat: 'invalid syntax'"
self.assertIn(expected_error, stdout)

def test_legacy_converter_disallowed_in_return_annotation(self):
stdout = self.parse_function_should_fail("""
module os
os.stat -> "s"
""")
expected_error = "Legacy converter 's' not allowed as a return converter"
self.assertIn(expected_error, stdout)

def test_unknown_return_converter(self):
stdout = self.parse_function_should_fail("""
module os
os.stat -> foooooooooooooooooooooooo
""")
expected_error = (
"No available return converter called 'foooooooooooooooooooooooo'"
)
self.assertIn(expected_error, stdout)

def test_star(self):
function = self.parse_function("""
module os
Expand Down
5 changes: 3 additions & 2 deletionsTools/clinic/clinic.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -4730,6 +4730,7 @@ def state_modulename_name(self, line: str | None) -> None:
return

line, _, returns = line.partition('->')
returns = returns.strip()

full_name, _, c_basename = line.partition(' as ')
full_name = full_name.strip()
Expand All@@ -4746,7 +4747,7 @@ def state_modulename_name(self, line: str | None) -> None:
try:
module_node = ast.parse(ast_input)
except SyntaxError:
fail(f"Badly-formed annotation for {full_name}: {returns}")
fail(f"Badlyformed annotation for {full_name}: {returns!r}")
function_node = module_node.body[0]
assert isinstance(function_node, ast.FunctionDef)
try:
Expand All@@ -4757,7 +4758,7 @@ def state_modulename_name(self, line: str | None) -> None:
fail(f"No available return converter called {name!r}")
return_converter = return_converters[name](**kwargs)
except ValueError:
fail(f"Badly-formed annotation for {full_name}: {returns}")
fail(f"Badlyformed annotation for {full_name}: {returns!r}")

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

[8]ページ先頭

©2009-2025 Movatter.jp