54
54
class Code :
55
55
"""Wrapper around Python code objects."""
56
56
57
+ __slots__ = ("raw" ,)
58
+
57
59
def __init__ (self , rawcode ) -> None :
58
60
if not hasattr (rawcode , "co_filename" ):
59
61
rawcode = getrawcode (rawcode )
60
62
if not isinstance (rawcode , CodeType ):
61
63
raise TypeError (f"not a code object: { rawcode !r} " )
62
- self .filename = rawcode .co_filename
63
- self .firstlineno = rawcode .co_firstlineno - 1
64
- self .name = rawcode .co_name
65
64
self .raw = rawcode
66
65
67
66
def __eq__ (self , other ):
@@ -70,6 +69,14 @@ def __eq__(self, other):
70
69
# Ignore type because of https://github.com/python/mypy/issues/4266.
71
70
__hash__ = None # type: ignore
72
71
72
+ @property
73
+ def firstlineno (self ) -> int :
74
+ return self .raw .co_firstlineno - 1
75
+
76
+ @property
77
+ def name (self ) -> str :
78
+ return self .raw .co_name
79
+
73
80
@property
74
81
def path (self ) -> Union [py .path .local , str ]:
75
82
"""Return a path object pointing to source code, or an ``str`` in
@@ -117,12 +124,26 @@ class Frame:
117
124
"""Wrapper around a Python frame holding f_locals and f_globals
118
125
in which expressions can be evaluated."""
119
126
127
+ __slots__ = ("raw" ,)
128
+
120
129
def __init__ (self , frame : FrameType ) -> None :
121
- self .lineno = frame .f_lineno - 1
122
- self .f_globals = frame .f_globals
123
- self .f_locals = frame .f_locals
124
130
self .raw = frame
125
- self .code = Code (frame .f_code )
131
+
132
+ @property
133
+ def lineno (self ) -> int :
134
+ return self .raw .f_lineno - 1
135
+
136
+ @property
137
+ def f_globals (self ) -> Dict [str , Any ]:
138
+ return self .raw .f_globals
139
+
140
+ @property
141
+ def f_locals (self ) -> Dict [str , Any ]:
142
+ return self .raw .f_locals
143
+
144
+ @property
145
+ def code (self ) -> Code :
146
+ return Code (self .raw .f_code )
126
147
127
148
@property
128
149
def statement (self ) -> "Source" :
@@ -164,17 +185,20 @@ def getargs(self, var: bool = False):
164
185
class TracebackEntry :
165
186
"""A single entry in a Traceback."""
166
187
167
- _repr_style : Optional ['Literal["short", "long"]' ] = None
168
- exprinfo = None
188
+ __slots__ = ("_rawentry" , "_excinfo" , "_repr_style" )
169
189
170
190
def __init__ (
171
191
self ,
172
192
rawentry : TracebackType ,
173
193
excinfo : Optional ["ReferenceType[ExceptionInfo[BaseException]]" ] = None ,
174
194
) -> None :
175
- self ._excinfo = excinfo
176
195
self ._rawentry = rawentry
177
- self .lineno = rawentry .tb_lineno - 1
196
+ self ._excinfo = excinfo
197
+ self ._repr_style : Optional ['Literal["short", "long"]' ] = None
198
+
199
+ @property
200
+ def lineno (self ) -> int :
201
+ return self ._rawentry .tb_lineno - 1
178
202
179
203
def set_repr_style (self , mode : "Literal['short', 'long']" ) -> None :
180
204
assert mode in ("short" , "long" )
0 commit comments