Skip to content

Commit

Permalink
Fix MYPY for python 3.8
Browse files Browse the repository at this point in the history
  • Loading branch information
Andi Kleen committed Nov 20, 2023
1 parent 8f07953 commit 4402a75
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
7 changes: 4 additions & 3 deletions tl_cpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
import glob
import sys
if sys.version_info.major == 3:
from typing import Set, List, Dict # noqa
import typing # noqa
from typing import Set, List, Dict, Tuple # noqa

modelid_map = {
(0x8e, ): "KBLR",
Expand Down Expand Up @@ -106,8 +107,8 @@ def __init__(self, known_cpus=(), nocheck=False, env=Env()):
self.threads = 0
forced_cpu = self.force_cpu(known_cpus)
forced_ht = self.force_ht()
cores = Counter() # type: Counter[tuple[int,int]]
sockets = Counter() # type: Counter[int]
cores = Counter() # type: typing.Counter[Tuple[int,int]]
sockets = Counter() # type: typing.Counter[int]
self.coreids = defaultdict(list)
self.cputocore = {}
self.cputothread = {}
Expand Down
3 changes: 2 additions & 1 deletion tl_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from tl_uval import UVal, combine_uval
from tl_io import flex_open_w
if sys.version_info.major == 3:
import typing # noqa
from typing import DefaultDict, Dict, Any # noqa

def output_name(name, typ):
Expand Down Expand Up @@ -462,7 +463,7 @@ def __init__(self, logfile, sep, args, version, cpu):
Output.__init__(self, logfile, version, cpu, args)
self.nodes = defaultdict(dict) # type: DefaultDict[str, Dict[str, Any]]
self.headers = OrderedDict()
self.count = Counter() # type: Counter[str]
self.count = Counter() # type: typing.Counter[str]
self.no_header = args.no_json_header
self.no_footer = args.no_json_footer
self.num = 0
Expand Down
21 changes: 11 additions & 10 deletions toplev.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@
obj_debug_print, debug_print, warn_no_assert, \
set_args as io_set_args
if sys.version_info.major == 3:
from typing import Set, List, Dict, Any, Tuple # noqa
import typing # noqa
from typing import Set, List, Dict, Any, Tuple, DefaultDict # noqa

known_cpus = (
("snb", (42, )),
Expand Down Expand Up @@ -1468,7 +1469,7 @@ def setup_perf(evstr, rest):
class Stat(object):
def __init__(self):
self.total = 0
self.errors = Counter() # type: Counter[str]
self.errors = Counter() # type: typing.Counter[str]

def print_not(a, count, msg, j):
print(("%s %s %s %.2f%% in %d measurements"
Expand All @@ -1479,7 +1480,7 @@ def print_not(a, count, msg, j):

# XXX need to get real ratios from perf
def print_account(ad):
total = Counter() # type: Counter[str]
total = Counter() # type: typing.Counter[str]
for j in ad:
a = ad[j]
for e in a.errors:
Expand Down Expand Up @@ -1947,7 +1948,7 @@ def execute_no_multiplex(runner_list, out, rest, summary):
outg = []
n = 0
ctx = SaveContext()
resoff = Counter() # type: Counter[str]
resoff = Counter() # type: typing.Counter[str]
RES, REV, INTERVAL, VALSTATS, ENV = range(5)
ret = 0
# runs could be further reduced by tweaking
Expand Down Expand Up @@ -2022,7 +2023,7 @@ def runner_split(runner_list, res, rev):
end = off + len(r.sched.evnum)
yield r, { "": res[""][off:end]}, { "": rev[""][off:end] }
elif r.cpu_list:
d = defaultdict(list) # type: defaultdict[str,list]
d = defaultdict(list) # type: DefaultDict[str,list]
d.update({ "%d" % k: res["%d" % k] for k in r.cpu_list })
yield r, d, rev
else:
Expand Down Expand Up @@ -2172,11 +2173,11 @@ def check_event(rlist, event, off, title, prev_interval, l, revnum, linenum, las
return r, False, event

def do_execute(rlist, summary, evstr, flat_rmap, out, rest, resoff, revnum):
res = defaultdict(list) # type: defaultdict[str,List[float]]
rev = defaultdict(list) # type: defaultdict[str, List[str]]
valstats = defaultdict(list) # type: defaultdict[str,List[ValStat]]
res = defaultdict(list) # type: DefaultDict[str,List[float]]
rev = defaultdict(list) # type: DefaultDict[str, List[str]]
valstats = defaultdict(list) # type: DefaultDict[str,List[ValStat]]
env = {} # type: Dict[str,str]
account = defaultdict(Stat) # type: defaultdict[str,Stat]
account = defaultdict(Stat) # type: DefaultDict[str,Stat]
inf, prun = setup_perf(evstr, rest)
prev_interval = 0.0
interval = None
Expand Down Expand Up @@ -2855,7 +2856,7 @@ class Summary(object):
def __init__(self):
self.res = defaultdict(list)
self.rev = defaultdict(list)
self.env = Counter() # type: Counter[str]
self.env = Counter() # type: typing.Counter[str]
self.valstats = defaultdict(list)
self.summary_perf = OrderedDict()

Expand Down

0 comments on commit 4402a75

Please sign in to comment.