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-104050: Argument clinic: annotatepost_parsing() andcleanup()#107225

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 2 commits intopython:mainfromAlexWaygood:clinic-dodgy-methods
Jul 25, 2023

Conversation

@AlexWaygood
Copy link
Member

@AlexWaygoodAlexWaygood commentedJul 25, 2023
edited
Loading

The docstring forCConverter.post_parsing() is here:

defpost_parsing(self)->str:
"""
The C statements required to do some operations after the end of parsing but before cleaning up.
Return a string containing this code indented at column 0.
If no operation is necessary, return an empty string.
"""

The docstring forCConverter.cleanup() is here:

defcleanup(self)->str:
"""
The C statements required to clean up after this variable.
Returns a string containing this code indented at column 0.
If no cleanup is necessary, returns an empty string.
"""

Both docstrings state that these methods should always return astr, so it's arguably a micro-bug thatstr_converter.post_parsing()Py_UNICODE_converter.cleanup() can both sometimes returnNone currently, sincestr_converter andPy_UNICODE_converter are both subclasses ofCConverter. (The micro-bug doesn't result in any erroneous behaviour currently, however.)

As such, I've slightly changed the implementations of these methods so that they always return astr, like the docstring promises.

erlend-aasland reacted with thumbs up emoji
@AlexWaygood
Copy link
MemberAuthor

AlexWaygood commentedJul 25, 2023
edited
Loading

The alternative way of fixing this problem would be to do this (diff is relative tomain):

Alternative fix
diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.pyindex 8c959ed4d0..e8e2710a18 100755--- a/Tools/clinic/clinic.py+++ b/Tools/clinic/clinic.py@@ -3018,19 +3018,19 @@ def modify(self) -> str:         """         return ""-    def post_parsing(self) -> str:+    def post_parsing(self) -> str | None:         """         The C statements required to do some operations after the end of parsing but before cleaning up.         Return a string containing this code indented at column 0.-        If no operation is necessary, return an empty string.+        If no operation is necessary, return an empty string or None.         """         return ""-    def cleanup(self) -> str:+    def cleanup(self) -> str | None:         """         The C statements required to clean up after this variable.         Returns a string containing this code indented at column 0.-        If no cleanup is necessary, returns an empty string.+        If no cleanup is necessary, returns an empty string or None.         """         return ""@@ -3660,10 +3660,11 @@ def converter_init(         if NoneType in accept and self.c_default == "Py_None":             self.c_default = "NULL"-    def post_parsing(self):+    def post_parsing(self) -> str | None:         if self.encoding:             name = self.name             return f"PyMem_FREE({name});\n"+        return None     def parse_arg(self, argname: str, displayname: str) -> str:         if self.format_unit == 's':@@ -3841,11 +3842,12 @@ def converter_init(                 fail("Py_UNICODE_converter: illegal 'accept' argument " + repr(accept))         self.c_default = "NULL"-    def cleanup(self):+    def cleanup(self) -> str | None:         if not self.length:             return """\ PyMem_Free((void *){name}); """.format(name=self.name)+        return None     def parse_arg(self, argname: str, argnum: str) -> str:         if not self.length:

Copy link
Contributor

@erlend-aaslanderlend-aasland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

LGTM! Thanks

AlexWaygood reacted with heart emoji
@erlend-aasland
Copy link
Contributor

FWIW, I agree that it is better to fix these microbugs instead of taking thestr | None approach.

AlexWaygood reacted with thumbs up emoji

@AlexWaygoodAlexWaygood merged commit33838fe intopython:mainJul 25, 2023
@AlexWaygoodAlexWaygood deleted the clinic-dodgy-methods branchJuly 25, 2023 22:33
jtcave pushed a commit to jtcave/cpython that referenced this pull requestJul 27, 2023
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@erlend-aaslanderlend-aaslanderlend-aasland approved these changes

Assignees

No one assigned

Labels

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@AlexWaygood@erlend-aasland@bedevere-bot

[8]ページ先頭

©2009-2025 Movatter.jp