gh-104504: Run mypy on cases_generator in CI (and blacken the code) (… · python/cpython@28cab71

GitHub

@@ -16,12 +16,11 @@ class InstructionFlags:

1616HAS_FREE_FLAG: bool

1717HAS_LOCAL_FLAG: bool

181819-def__post_init__(self):

19+def__post_init__(self)->None:

2020self.bitmask= {name: (1<<i) fori, nameinenumerate(self.names())}

21212222@staticmethod

23-deffromInstruction(instr: parsing.Node):

24-23+deffromInstruction(instr: parsing.Node) ->"InstructionFlags":

2524has_free= (

2625variable_used(instr, "PyCell_New")

2726orvariable_used(instr, "PyCell_GET")

@@ -41,15 +40,15 @@ def fromInstruction(instr: parsing.Node):

4140 )

42414342@staticmethod

44-defnewEmpty():

43+defnewEmpty()->"InstructionFlags":

4544returnInstructionFlags(False, False, False, False, False, False)

46454746defadd(self, other: "InstructionFlags") ->None:

4847forname, valueindataclasses.asdict(other).items():

4948ifvalue:

5049setattr(self, name, value)

515052-defnames(self, value=None) ->list[str]:

51+defnames(self, value: bool|None=None) ->list[str]:

5352ifvalueisNone:

5453returnlist(dataclasses.asdict(self).keys())

5554return [nforn, vindataclasses.asdict(self).items() ifv==value]

@@ -62,7 +61,7 @@ def bitmap(self) -> int:

6261returnflags

63626463@classmethod

65-defemit_macros(cls, out: Formatter):

64+defemit_macros(cls, out: Formatter)->None:

6665flags=cls.newEmpty()

6766forname, valueinflags.bitmask.items():

6867out.emit(f"#define {name} ({value})")

@@ -90,9 +89,9 @@ def variable_used_unspecialized(node: parsing.Node, name: str) -> bool:

9089text="".join(token.text.split())

9190# TODO: Handle nested #if

9291iftext=="#if":

93-if (

94-i+1<len(node.tokens)

95-andnode.tokens[i+1].textin ("ENABLE_SPECIALIZATION", "TIER_ONE")

92+ifi+1<len(node.tokens) andnode.tokens[i+1].textin(

93+"ENABLE_SPECIALIZATION",

94+"TIER_ONE",

9695 ):

9796skipping=True

9897eliftextin ("#else", "#endif"):