diff options
author | Adam Turner <9087854+AA-Turner@users.noreply.github.com> | 2023-08-28 21:31:45 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-28 21:31:45 (GMT) |
commit | 0bd2ba553d1cbf4137295dad21fc06e7745ab858 (patch) | |
tree | 5e7e913efdfd3a085cd9804de76b040c3c2fc9c0 | |
parent | cf7ba83eb274df8389cb9ebdf8601132c47de48a (diff) | |
download | cpython-0bd2ba553d1cbf4137295dad21fc06e7745ab858.zip cpython-0bd2ba553d1cbf4137295dad21fc06e7745ab858.tar.gz cpython-0bd2ba553d1cbf4137295dad21fc06e7745ab858.tar.bz2 |
GH-107603: Clinic: Pass specific attributes to ``print_block()`` (#108581)
-rw-r--r-- | Lib/test/test_clinic.py | 2 | ||||
-rwxr-xr-x | Tools/clinic/clinic.py | 28 |
2 files changed, 18 insertions, 12 deletions
diff --git a/Lib/test/test_clinic.py b/Lib/test/test_clinic.py index 0592c2e..b29f2ea 100644 --- a/Lib/test/test_clinic.py +++ b/Lib/test/test_clinic.py @@ -834,7 +834,7 @@ class ClinicBlockParserTest(TestCase): writer = clinic.BlockPrinter(language) c = _make_clinic() for block in blocks: - writer.print_block(block, clinic=c) + writer.print_block(block, limited_capi=c.limited_capi, header_includes=c.includes) output = writer.f.getvalue() assert output == input, "output != input!\n\noutput " + repr(output) + "\n\n input " + repr(input) diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py index 39a776f..2b01668 100755 --- a/Tools/clinic/clinic.py +++ b/Tools/clinic/clinic.py @@ -2172,8 +2172,9 @@ class BlockPrinter: self, block: Block, *, - clinic: Clinic, core_includes: bool = False, + limited_capi: bool, + header_includes: dict[str, str], ) -> None: input = block.input output = block.output @@ -2203,7 +2204,7 @@ class BlockPrinter: output = '' if core_includes: - if not clinic.limited_capi: + if not limited_capi: output += textwrap.dedent(""" #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) # include "pycore_gc.h" // PyGC_Head @@ -2212,12 +2213,10 @@ class BlockPrinter: """) - if clinic is not None: - # Emit optional includes - for include, reason in sorted(clinic.includes.items()): - line = f'#include "{include}"' - line = line.ljust(35) + f'// {reason}\n' - output += line + # Emit optional "#include" directives for C headers + for include, reason in sorted(header_includes.items()): + line = f'#include "{include}"'.ljust(35) + f'// {reason}\n' + output += line input = ''.join(block.input) output += ''.join(block.output) @@ -2531,7 +2530,9 @@ impl_definition block self.parsers[dsl_name] = parsers[dsl_name](self) parser = self.parsers[dsl_name] parser.parse(block) - printer.print_block(block, clinic=self) + printer.print_block(block, + limited_capi=self.limited_capi, + header_includes=self.includes) # these are destinations not buffers for name, destination in self.destinations.items(): @@ -2546,7 +2547,9 @@ impl_definition block block.input = "dump " + name + "\n" warn("Destination buffer " + repr(name) + " not empty at end of file, emptying.") printer.write("\n") - printer.print_block(block, clinic=self) + printer.print_block(block, + limited_capi=self.limited_capi, + header_includes=self.includes) continue if destination.type == 'file': @@ -2571,7 +2574,10 @@ impl_definition block block.input = 'preserve\n' printer_2 = BlockPrinter(self.language) - printer_2.print_block(block, core_includes=True, clinic=self) + printer_2.print_block(block, + core_includes=True, + limited_capi=self.limited_capi, + header_includes=self.includes) write_file(destination.filename, printer_2.f.getvalue()) continue |