1313import re
1414import time
1515import types
16- from typing import Dict , FrozenSet , TextIO , Tuple
16+ from typing import TextIO
1717
1818import umarshal
1919
@@ -57,8 +57,8 @@ def get_localsplus(code: types.CodeType):
5757
5858
5959def get_localsplus_counts (code : types .CodeType ,
60- names : Tuple [str , ...],
61- kinds : bytes ) -> Tuple [ int , int , int , int ]:
60+ names : tuple [str , ...],
61+ kinds : bytes ) -> tuple [ int , int , int ]:
6262 nlocals = 0
6363 ncellvars = 0
6464 nfreevars = 0
@@ -84,7 +84,7 @@ def get_localsplus_counts(code: types.CodeType,
8484PyUnicode_4BYTE_KIND = 4
8585
8686
87- def analyze_character_width (s : str ) -> Tuple [int , bool ]:
87+ def analyze_character_width (s : str ) -> tuple [int , bool ]:
8888 maxchar = ' '
8989 for c in s :
9090 maxchar = max (maxchar , c )
@@ -109,7 +109,7 @@ class Printer:
109109 def __init__ (self , file : TextIO ) -> None :
110110 self .level = 0
111111 self .file = file
112- self .cache : Dict [tuple [type , object , str ], str ] = {}
112+ self .cache : dict [tuple [type , object , str ], str ] = {}
113113 self .hits , self .misses = 0 , 0
114114 self .finis : list [str ] = []
115115 self .inits : list [str ] = []
@@ -305,7 +305,7 @@ def generate_code(self, name: str, code: types.CodeType) -> str:
305305 self .inits .append (f"_PyStaticCode_Init({ name_as_code } )" )
306306 return f"& { name } .ob_base.ob_base"
307307
308- def generate_tuple (self , name : str , t : Tuple [object , ...]) -> str :
308+ def generate_tuple (self , name : str , t : tuple [object , ...]) -> str :
309309 if len (t ) == 0 :
310310 return f"(PyObject *)& _Py_SINGLETON(tuple_empty)"
311311 items = [self .generate (f"{ name } _{ i } " , it ) for i , it in enumerate (t )]
@@ -379,7 +379,7 @@ def generate_complex(self, name: str, z: complex) -> str:
379379 self .write (f".cval = {{ { z .real } , { z .imag } }}," )
380380 return f"&{ name } .ob_base"
381381
382- def generate_frozenset (self , name : str , fs : FrozenSet [object ]) -> str :
382+ def generate_frozenset (self , name : str , fs : frozenset [object ]) -> str :
383383 try :
384384 fs = sorted (fs )
385385 except TypeError :
@@ -465,7 +465,7 @@ def generate(args: list[str], output: TextIO) -> None:
465465 printer = Printer (output )
466466 for arg in args :
467467 file , modname = arg .rsplit (':' , 1 )
468- with open (file , "r" , encoding = "utf8" ) as fd :
468+ with open (file , encoding = "utf8" ) as fd :
469469 source = fd .read ()
470470 if is_frozen_header (source ):
471471 code = decode_frozen_data (source )
@@ -513,7 +513,7 @@ def main() -> None:
513513 if args .file :
514514 if verbose :
515515 print (f"Reading targets from { args .file } " )
516- with open (args .file , "rt" , encoding = "utf-8-sig" ) as fin :
516+ with open (args .file , encoding = "utf-8-sig" ) as fin :
517517 rules = [x .strip () for x in fin ]
518518 else :
519519 rules = args .args
0 commit comments