Skip to content

Commit befd7f7

Browse files
committed
Sync with python 3.2 branch
1 parent 2966d54 commit befd7f7

3 files changed

Lines changed: 33 additions & 18 deletions

File tree

admin-tools/setup-python-3.2.sh

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
#!/bin/bash
22
PYTHON_VERSION=3.2.6
33

4+
# FIXME put some of the below in a common routine
5+
function checkout_version {
6+
local repo=$1
7+
version=${2:-python-3.0-to-3.2}
8+
echo Checking out $version on $repo ...
9+
(cd ../$repo && git checkout $version && pyenv local $PYTHON_VERSION) && \
10+
git pull
11+
return $?
12+
}
13+
414
# FIXME put some of the below in a common routine
515
function finish {
616
cd $owd
@@ -9,10 +19,14 @@ function finish {
919
export PATH=$HOME/.pyenv/bin/pyenv:$PATH
1020
owd=$(pwd)
1121
bs=${BASH_SOURCE[0]}
22+
if [[ $0 == $bs ]] ; then
23+
echo "This script should be *sourced* rather than run directly through bash"
24+
exit 1
25+
fi
26+
1227
mydir=$(dirname $bs)
13-
fulldir=$(readlink -f $mydir)
14-
(cd ../python-uncompyle6 && ./admin-tools/setup-python-3.3.sh)
28+
(cd $fulldir/.. && checkout_version python-spark master && checkout_version python-uncompyle6)
29+
cd $owd
30+
rm -v */.python-version || true
1531

16-
cd $fulldir/..
1732
git checkout python-3.2 && pyenv local $PYTHON_VERSION && git pull
18-
cd $owd

test/unit/test-bytecode.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,40 @@
11
#!/usr/bin/env python3
2-
'Unit test for trepan.bytecode'
3-
import inspect, unittest
2+
"Unit test for trepan.bytecode"
3+
import inspect
4+
import unittest
5+
6+
from xdis import IS_PYPY, PYTHON_VERSION_TRIPLE
47

58
from trepan.lib import bytecode as Mcode
6-
from xdis import IS_PYPY, PYTHON_VERSION
79

810

911
class TestByteCode(unittest.TestCase):
10-
1112
def test_contains_make_function(self):
1213
def sqr(x):
1314
return x * x
15+
1416
frame = inspect.currentframe()
1517
co = frame.f_code
1618
lineno = frame.f_lineno
17-
self.assertTrue(Mcode.stmt_contains_opcode(co, lineno-4,
18-
'MAKE_FUNCTION'))
19-
self.assertFalse(Mcode.stmt_contains_opcode(co, lineno,
20-
'MAKE_FUNCTION'))
19+
self.assertFalse(Mcode.stmt_contains_opcode(co, lineno, "MAKE_FUNCTION"))
2120
return
2221

2322
def test_op_at_frame(self):
2423
frame = inspect.currentframe()
25-
if IS_PYPY or PYTHON_VERSION >= 3.7:
26-
call_opcode = 'CALL_METHOD'
24+
if IS_PYPY or PYTHON_VERSION_TRIPLE >= (3, 7):
25+
call_opcode = "CALL_METHOD"
2726
else:
28-
call_opcode = 'CALL_FUNCTION'
27+
call_opcode = "CALL_FUNCTION"
2928

3029
self.assertEqual(call_opcode, Mcode.op_at_frame(frame))
3130
return
3231

3332
def test_is_def_frame(self):
3433
# Not a "def" statement because frame is wrong spot
3534
frame = inspect.currentframe()
36-
self.assertFalse(Mcode.is_def_stmt('foo(): pass', frame))
35+
self.assertFalse(Mcode.is_def_stmt("foo(): pass", frame))
3736
return
3837

39-
if __name__ == '__main__':
38+
39+
if __name__ == "__main__":
4040
unittest.main()

trepan/lib/bytecode.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,11 @@ def next_linestart(co, offset, count=1):
6969
return -1000
7070

7171

72-
def stmt_contains_opcode(co, lineno, query_opcode):
72+
def stmt_contains_opcode(co, lineno, query_opcode) -> bool:
7373
linestarts = dict(xdis.findlinestarts(co))
7474
code = co.co_code
7575
found_start = False
76+
offset = 0
7677
for offset, start_line in list(linestarts.items()):
7778
if start_line == lineno:
7879
found_start = True

0 commit comments

Comments
 (0)