Skip to content

Commit 85fb1f4

Browse files
author
Philip Guo
committed
fix for python 3
1 parent a909c46 commit 85fb1f4

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

‎PyTutorGAE/pg_logger.py‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@
3636
import traceback
3737
import types
3838

39-
if sys.version_info[0] == 3:
39+
is_python3 = (sys.version_info[0] == 3)
40+
41+
if is_python3:
4042
import io as cStringIO
4143
else:
4244
import cStringIO
@@ -378,8 +380,9 @@ def create_encoded_stack_entry(cur_frame):
378380
v not in self.closures and \
379381
v not in self.globally_defined_funcs):
380382

381-
# Look for the presence of v.func_code (code object) in
382-
# the constant pool (f_code.co_consts) of an enclosing
383+
# Look for the presence of the code object (v.func_code
384+
# for Python 2 or v.__code__ for Python 3) in the
385+
# constant pool (f_code.co_consts) of an enclosing
383386
# stack frame, and set that frame as your parent.
384387
#
385388
# This technique properly handles lambdas passed as
@@ -396,7 +399,7 @@ def create_encoded_stack_entry(cur_frame):
396399
break
397400

398401
for frame_const in my_frame.f_code.co_consts:
399-
if frame_const is v.func_code:
402+
if frame_const is (v.__code__ if is_python3 else v.func_code):
400403
chosen_parent_frame = my_frame
401404
break
402405

0 commit comments

Comments
 (0)