Skip to content

Commit dff834d

Browse files
committed
Make einfo compatible with inspect (fixes #176)
1 parent 69c2f29 commit dff834d

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

billiard/einfo.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import sys
22
import traceback
3+
import types
34

45
__all__ = ['ExceptionInfo', 'Traceback']
56

@@ -26,6 +27,10 @@ def __init__(self, code):
2627
self.co_qualname = code.co_qualname
2728
self._co_positions = list(code.co_positions())
2829

30+
@property
31+
def __class__(self):
32+
return types.CodeType
33+
2934
if sys.version_info >= (3, 11):
3035
@property
3136
def co_positions(self):
@@ -58,6 +63,10 @@ def __init__(self, frame):
5863
# don't want to hit https://bugs.python.org/issue21967
5964
self.f_restricted = False
6065

66+
@property
67+
def __class__(self):
68+
return types.FrameType
69+
6170
if sys.version_info >= (3, 11):
6271
@property
6372
def co_positions(self):
@@ -100,6 +109,10 @@ def __init__(self):
100109
self.tb_next = None
101110
self.tb_lasti = 0
102111

112+
@property
113+
def __class__(self):
114+
return types.TracebackType
115+
103116
if sys.version_info >= (3, 11):
104117
@property
105118
def co_positions(self):
@@ -120,6 +133,10 @@ def __init__(self, tb, max_frames=DEFAULT_MAX_FRAMES, depth=0):
120133
else:
121134
self.tb_next = _Truncated()
122135

136+
@property
137+
def __class__(self):
138+
return types.TracebackType
139+
123140

124141
class RemoteTraceback(Exception):
125142
def __init__(self, tb):

t/unit/test_einfo.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import inspect
12
import logging
23
import pickle
34
import sys
5+
import types
46

57
from billiard.einfo import _Code # noqa
68
from billiard.einfo import _Frame # noqa
@@ -116,3 +118,34 @@ def test_truncated_co_positions():
116118
assert list(iter(truncated.co_positions())) == list(
117119
iter(truncated.tb_frame.co_positions())
118120
)
121+
def make_python_tb():
122+
tb = None
123+
depth = 0
124+
while True:
125+
try:
126+
frame = sys._getframe(depth)
127+
except ValueError:
128+
break
129+
else:
130+
depth += 1
131+
132+
tb = types.TracebackType(tb, frame, frame.f_lasti, frame.f_lineno)
133+
134+
return tb
135+
136+
137+
class test_inspect:
138+
def test_istraceback(self):
139+
assert inspect.istraceback(Traceback(tb=make_python_tb()))
140+
141+
def test_isframe(self):
142+
assert inspect.isframe(_Frame(make_python_tb().tb_frame))
143+
144+
def test_iscode(self):
145+
assert inspect.iscode(_Code(make_python_tb().tb_frame.f_code))
146+
147+
def test_getframeinfo(self):
148+
assert inspect.getframeinfo(Traceback(tb=make_python_tb()))
149+
150+
def test_getinnerframes(self):
151+
assert inspect.getinnerframes(Traceback(tb=make_python_tb()))

0 commit comments

Comments
 (0)