Skip to content

Commit bf9466a

Browse files
committed
Fix type annotations
Remove duplicated declaration of "clinic" global variable.
1 parent 743d8ff commit bf9466a

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

Lib/test/test_clinic.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -830,11 +830,10 @@ class ClinicBlockParserTest(TestCase):
830830
def _test(self, input, output):
831831
language = clinic.CLanguage(None)
832832

833-
clinic_arg = None # mock Clinic, not used here
834833
blocks = list(clinic.BlockParser(input, language))
835834
writer = clinic.BlockPrinter(language)
836835
for block in blocks:
837-
writer.print_block(block, clinic_arg)
836+
writer.print_block(block)
838837
output = writer.f.getvalue()
839838
assert output == input, "output != input!\n\noutput " + repr(output) + "\n\n input " + repr(input)
840839

Tools/clinic/clinic.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2115,9 +2115,10 @@ class BlockPrinter:
21152115
def print_block(
21162116
self,
21172117
block: Block,
2118-
clinic: Clinic,
21192118
*,
2120-
core_includes: bool = False
2119+
core_includes: bool = False,
2120+
# needed if core_includes is true
2121+
clinic: Clinic | None = None,
21212122
) -> None:
21222123
input = block.input
21232124
output = block.output
@@ -2146,7 +2147,7 @@ def print_block(
21462147
write("\n")
21472148

21482149
output = ''
2149-
if core_includes:
2150+
if core_includes and clinic:
21502151
output += textwrap.dedent("""
21512152
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
21522153
# include "pycore_gc.h" // PyGC_Head
@@ -2303,7 +2304,7 @@ def __init__(self, clinic: Clinic) -> None: ...
23032304
def parse(self, block: Block) -> None: ...
23042305

23052306

2306-
clinic = None
2307+
clinic : Clinic | None = None
23072308
class Clinic:
23082309

23092310
presets_text = """
@@ -2430,7 +2431,7 @@ def __init__(
24302431
global clinic
24312432
clinic = self
24322433

2433-
def add_include(self, name: str, reason: str):
2434+
def add_include(self, name: str, reason: str) -> None:
24342435
if name in self.includes:
24352436
return
24362437
self.includes[name] = reason
@@ -2470,7 +2471,7 @@ def parse(self, input: str) -> str:
24702471
self.parsers[dsl_name] = parsers[dsl_name](self)
24712472
parser = self.parsers[dsl_name]
24722473
parser.parse(block)
2473-
printer.print_block(block, clinic)
2474+
printer.print_block(block)
24742475

24752476
# these are destinations not buffers
24762477
for name, destination in self.destinations.items():
@@ -2485,7 +2486,7 @@ def parse(self, input: str) -> str:
24852486
block.input = "dump " + name + "\n"
24862487
warn("Destination buffer " + repr(name) + " not empty at end of file, emptying.")
24872488
printer.write("\n")
2488-
printer.print_block(block, clinic)
2489+
printer.print_block(block)
24892490
continue
24902491

24912492
if destination.type == 'file':
@@ -2510,7 +2511,7 @@ def parse(self, input: str) -> str:
25102511

25112512
block.input = 'preserve\n'
25122513
printer_2 = BlockPrinter(self.language)
2513-
printer_2.print_block(block, clinic, core_includes=True)
2514+
printer_2.print_block(block, core_includes=True, clinic=self)
25142515
write_file(destination.filename, printer_2.f.getvalue())
25152516
continue
25162517

@@ -3362,7 +3363,7 @@ def parser_name(self) -> str:
33623363
else:
33633364
return self.name
33643365

3365-
def add_include(self, name, reason):
3366+
def add_include(self, name: str, reason: str) -> None:
33663367
if self.include:
33673368
raise ValueError("a converter only supports a single include")
33683369
self.include = (name, reason)
@@ -5987,9 +5988,6 @@ def do_post_block_processing_cleanup(self, lineno: int) -> None:
59875988
}
59885989

59895990

5990-
clinic = None
5991-
5992-
59935991
def create_cli() -> argparse.ArgumentParser:
59945992
cmdline = argparse.ArgumentParser(
59955993
prog="clinic.py",

0 commit comments

Comments
 (0)