Skip to content

Commit 94b4a1e

Browse files
committed
update to python 3.8+
1 parent 46af0ae commit 94b4a1e

File tree

4 files changed

+29
-9
lines changed

4 files changed

+29
-9
lines changed

pypytools/pypylog/model.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
import itertools
21
from collections import defaultdict
32
import attr
43
import numpy as np
4+
from pypytools.util import PY3
5+
6+
if not PY3:
7+
import itertools
58

69
@attr.s
710
class Event(object):
@@ -46,15 +49,15 @@ def add_event(self, ev):
4649

4750
def print_summary(self):
4851
fmt = '%-28s %6s %8s'
49-
print fmt % ('section', 'n', 'delta')
50-
print '-'*44
52+
print(fmt % ('section', 'n', 'delta'))
53+
print('-'*44)
5154
for name, events in sorted(self.sections.iteritems()):
5255
total = 0
5356
for ev in events:
5457
delta = ev.end - ev.start
5558
assert delta >= 0
5659
total += delta
57-
print fmt % (name, len(events), format(delta, '.4f'))
60+
print(fmt % (name, len(events), format(delta, '.4f')))
5861

5962
class Series(object):
6063

@@ -79,8 +82,12 @@ def __len__(self):
7982
return len(self.X)
8083

8184
def __iter__(self):
82-
for x, y in itertools.izip(self.X, self.Y):
83-
yield x, y
85+
if PY3:
86+
for x, y in zip(self.X, self.Y):
87+
yield x, y
88+
else:
89+
for x, y in itertools.izip(self.X, self.Y):
90+
yield x, y
8491

8592
def __getitem__(self, i):
8693
return self.X[i], self.Y[i]

pypytools/pypylog/parse.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import re
22
import attr
33
from pypytools.pypylog import model
4+
from pypytools.util import PY3
45

56
# stolen from rpython/tool/logparse.py
67
_color = "(?:\x1b.*?m)?"
@@ -35,6 +36,8 @@ def parse_file(f):
3536
#
3637
if log is None:
3738
log = model.PyPyLog()
39+
if PY3:
40+
basestring = str
3841
if isinstance(fname, basestring):
3942
with open(fname) as f:
4043
return parse_file(f)

pypytools/pypylog/testing/test_parse.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
import pytest
22
import textwrap
3-
from cStringIO import StringIO
3+
4+
from pypytools.util import PY3
5+
6+
if PY3:
7+
from io import StringIO
8+
else:
9+
from cStringIO import StringIO
10+
411
from pypytools.pypylog import parse
512
from pypytools.pypylog import model
613
from pypytools.pypylog.model import Event, GcMinor, GcCollectStep
@@ -33,7 +40,7 @@ def test_mismatch(self):
3340
[456] foo}
3441
[0ab] bar}
3542
"""
36-
pytest.raises(parse.ParseError, "self.parse(log)")
43+
pytest.raises(parse.ParseError(self.parse(log)))
3744

3845
def test_nested(self):
3946
log = self.parse("""
@@ -124,4 +131,4 @@ def test_parse_frequency():
124131
assert pf('40 KHz') == 40e3
125132
assert pf('40 MHz') == 40e6
126133
assert pf('40 GHz') == 40e9
127-
pytest.raises(ValueError, "pf('')")
134+
pytest.raises(ValueError(pf('')))

pypytools/util.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from sys import version_info
33

44
PY3 = version_info.major == 3
5+
PY3M = version_info.minor
56

67
def clonefunc(f):
78
"""Deep clone the given function to create a new one.
@@ -22,6 +23,8 @@ def clonefunc(f):
2223
co.co_firstlineno, co.co_lnotab, co.co_freevars, co.co_cellvars]
2324
if PY3:
2425
args.insert(1, co.co_kwonlyargcount)
26+
if PY3 and PY3M >= 8:
27+
args.insert(1, co.co_posonlyargcount)
2528
co2 = types.CodeType(*args)
2629
#
2730
# then, we clone the function itself, using the new co2

0 commit comments

Comments
 (0)