Skip to content

Commit

Permalink
gh-104050: Argument clinic: annotate post_parsing() and cleanup() (
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexWaygood authored Jul 25, 2023
1 parent 70dc009 commit 33838fe
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions Tools/clinic/clinic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3664,10 +3664,12 @@ 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:
if self.encoding:
name = self.name
return f"PyMem_FREE({name});\n"
else:
return ""

def parse_arg(self, argname: str, displayname: str) -> str:
if self.format_unit == 's':
Expand Down Expand Up @@ -3845,8 +3847,10 @@ def converter_init(
fail("Py_UNICODE_converter: illegal 'accept' argument " + repr(accept))
self.c_default = "NULL"

def cleanup(self):
if not self.length:
def cleanup(self) -> str:
if self.length:
return ""
else:
return """\
PyMem_Free((void *){name});
""".format(name=self.name)
Expand Down

0 comments on commit 33838fe

Please sign in to comment.