Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 33.9k
gh-104683: Argument Clinic: Extract parse_function_names() helper#107964
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
erlend-aasland merged 12 commits into python:main from erlend-aasland:clinic/extract-parse-names-helperAug 16, 2023
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
12 commits Select commit Hold shift + click to select a range
2f53112 gh-104683: Argument Clinic: Extract parse_names() helper
erlend-aasland 76b637a Ensure a C basename is provided after 'as'
erlend-aasland 0243b09 Add test_no_c_basename()
erlend-aasland f2aefff Pull in main
erlend-aasland 06d4f62 Pull in main
erlend-aasland 4620731 Pull in main
erlend-aasland 3f63df9 Adjust test
erlend-aasland 2e68f63 Style
erlend-aasland df8a2cc Pull in main
erlend-aasland a915dc9 Use a named tuple
erlend-aasland 3735c95 Update Tools/clinic/clinic.py
erlend-aasland 2ee0340 Improved function name
erlend-aasland File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1674,18 +1674,8 @@ def render_function( | ||
| full_name = f.full_name | ||
| template_dict ={'full_name': full_name} | ||
| template_dict['name'] = f.displayname | ||
| if f.c_basename: | ||
| c_basename = f.c_basename | ||
| else: | ||
| fields = full_name.split(".") | ||
| if fields[-1] == '__new__': | ||
| fields.pop() | ||
| c_basename = "_".join(fields) | ||
| template_dict['c_basename'] = c_basename | ||
| template_dict['methoddef_name'] = c_basename.upper() + "_METHODDEF" | ||
| template_dict['c_basename'] = f.c_basename | ||
| template_dict['methoddef_name'] = f.c_basename.upper() + "_METHODDEF" | ||
| template_dict['docstring'] = self.docstring_for_c_string(f) | ||
| @@ -2653,7 +2643,7 @@ class Function: | ||
| name: str | ||
| module: Module | Clinic | ||
| cls: Class | None | ||
| c_basename: str | None | ||
| c_basename: str | ||
| full_name: str | ||
| return_converter: CReturnConverter | ||
| kind: FunctionKind | ||
| @@ -4577,6 +4567,11 @@ class ParamState(enum.IntEnum): | ||
| RIGHT_SQUARE_AFTER = 6 | ||
| class FunctionNames(NamedTuple): | ||
| full_name: str | ||
| c_basename: str | ||
| class DSLParser: | ||
| function: Function | None | ||
| state: StateKeeper | ||
| @@ -4840,6 +4835,24 @@ def state_dsl_start(self, line: str) -> None: | ||
| self.next(self.state_modulename_name, line) | ||
| @staticmethod | ||
| def parse_function_names(line: str) -> FunctionNames: | ||
| left, as_, right = line.partition(' as ') | ||
| full_name = left.strip() | ||
| c_basename = right.strip() | ||
| if as_ and not c_basename: | ||
| fail("No C basename provided after 'as' keyword") | ||
| if not c_basename: | ||
| fields = full_name.split(".") | ||
| if fields[-1] == '__new__': | ||
| fields.pop() | ||
| c_basename = "_".join(fields) | ||
| if not is_legal_py_identifier(full_name): | ||
| fail(f"Illegal function name:{full_name!r}") | ||
| if not is_legal_c_identifier(c_basename): | ||
AlexWaygood marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading. Please reload this page. | ||
| fail(f"Illegal C basename:{c_basename!r}") | ||
| return FunctionNames(full_name=full_name, c_basename=c_basename) | ||
| def update_function_kind(self, fullname: str) -> None: | ||
| fields = fullname.split('.') | ||
| name = fields.pop() | ||
| @@ -4877,17 +4890,10 @@ def state_modulename_name(self, line: str) -> None: | ||
| # are we cloning? | ||
| before, equals, existing = line.rpartition('=') | ||
| c_basename: str | None | ||
| if equals: | ||
| full_name, as_, c_basename = before.partition(' as ') | ||
| full_name = full_name.strip() | ||
| c_basename = c_basename.strip() | ||
| if as_ and not c_basename: | ||
| fail("No C basename provided after 'as' keyword") | ||
| full_name, c_basename = self.parse_function_names(before) | ||
| existing = existing.strip() | ||
| if (is_legal_py_identifier(full_name) and | ||
| (not c_basename or is_legal_c_identifier(c_basename)) and | ||
| is_legal_py_identifier(existing)): | ||
| if is_legal_py_identifier(existing): | ||
erlend-aasland marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading. Please reload this page. | ||
| # we're cloning! | ||
| fields = [x.strip() for x in existing.split('.')] | ||
| function_name = fields.pop() | ||
| @@ -4933,16 +4939,7 @@ def state_modulename_name(self, line: str) -> None: | ||
| line, _, returns = line.partition('->') | ||
| returns = returns.strip() | ||
| full_name, as_, c_basename = line.partition(' as ') | ||
| full_name = full_name.strip() | ||
| c_basename = c_basename.strip() or None | ||
| if as_ and not c_basename: | ||
| fail("No C basename provided after 'as' keyword") | ||
| if not is_legal_py_identifier(full_name): | ||
| fail(f"Illegal function name:{full_name!r}") | ||
| if c_basename and not is_legal_c_identifier(c_basename): | ||
| fail(f"Illegal C basename:{c_basename!r}") | ||
| full_name, c_basename = self.parse_function_names(line) | ||
| return_converter = None | ||
| if returns: | ||
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.