Skip to content

Commit 5b192c4

Browse files
author
rocky
committed
Populate code.version_triple more often
1 parent e384013 commit 5b192c4

File tree

4 files changed

+13
-10
lines changed

4 files changed

+13
-10
lines changed

xdis/codetype/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ def codeType2Portable(code, version_triple=PYTHON_VERSION_TRIPLE):
8585
co_name=code.co_name,
8686
co_firstlineno=code.co_firstlineno,
8787
co_lnotab=line_table,
88+
version_triple=version_triple,
8889
)
8990
elif version_triple[:2] == (3, 10) or IS_PYPY and version_triple[:2] == (3, 11):
9091
return Code310(
@@ -104,6 +105,7 @@ def codeType2Portable(code, version_triple=PYTHON_VERSION_TRIPLE):
104105
co_name=code.co_name,
105106
co_firstlineno=code.co_firstlineno,
106107
co_linetable=line_table,
108+
version_triple=version_triple,
107109
)
108110
elif version_triple[:2] >= (3, 11):
109111
return Code311(
@@ -125,6 +127,7 @@ def codeType2Portable(code, version_triple=PYTHON_VERSION_TRIPLE):
125127
co_firstlineno=code.co_firstlineno,
126128
co_linetable=line_table,
127129
co_exceptiontable=code.co_exceptiontable,
130+
version_triple=version_triple,
128131
)
129132
elif version_triple > (2, 0):
130133
# 2.0 .. 2.7
@@ -148,6 +151,7 @@ def codeType2Portable(code, version_triple=PYTHON_VERSION_TRIPLE):
148151
# type, should we try to extract it?
149152
collection_order=code.collection_order if hasattr(code, "collection_order") else {},
150153
reference_objects=code.reference_objects if hasattr(code, "reference_objects") else set(),
154+
version_triple=version_triple,
151155

152156
)
153157
else:

xdis/codetype/code311.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,8 +430,8 @@ def __init__(
430430
co_linetable=co_linetable,
431431
co_freevars=co_freevars,
432432
co_cellvars=co_cellvars,
433-
reference_objects = set(),
434-
version_triple = (0, 0, 0),
433+
reference_objects = reference_objects,
434+
version_triple = version_triple,
435435
)
436436
self.co_qualname = co_qualname
437437
self.co_exceptiontable = co_exceptiontable

xdis/codetype/code38.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ def __init__(
107107
co_freevars=co_freevars,
108108
co_cellvars=co_cellvars,
109109
collection_order = collection_order,
110-
reference_objects = set(),
111-
version_triple = (0, 0, 0),
110+
reference_objects = reference_objects,
111+
version_triple = version_triple,
112112
)
113113
self.co_posonlyargcount = co_posonlyargcount
114114
self.fieldtypes = Code38FieldTypes

xdis/unmarshal.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,29 +173,28 @@ def __init__(self, fp, magic_int, bytes_for_s, code_objects={}) -> None:
173173
self.collection_order: Dict[Union[set, frozenset, dict], Tuple[Any]] = {}
174174

175175
self.bytes_for_s = bytes_for_s
176-
version = magic_int2tuple(self.magic_int)
177-
if version >= (3, 4):
176+
self.version_triple = magic_int2tuple(self.magic_int)
177+
if self.version_triple >= (3, 4):
178178
if self.magic_int in (3250, 3260, 3270):
179179
self.marshal_version = 3
180180
else:
181181
self.marshal_version = 4
182-
elif (3, 4) > version >= (2, 5):
182+
elif (3, 4) > self.version_triple >= (2, 5):
183183
self.marshal_version = 2
184-
elif (2, 5) > version >= (2, 4):
184+
elif (2, 5) > self.version_triple >= (2, 4):
185185
self.marshal_version = 1
186186
else:
187187
self.marshal_version = 0
188188

189189
self.intern_strings = []
190190
self.intern_objects = []
191-
self.version_triple = tuple()
192191
self.is_graal = magic_int in GRAAL3_MAGICS
193192
self.is_pypy = magic_int in PYPY3_MAGICS
194193
self.is_rust = magic_int in RUSTPYTHON_MAGICS
195194

196195
if magic_int in RUSTPYTHON_MAGICS:
197196
raise NotImplementedError(
198-
f"RustPython {version_tuple_to_str(version)} is not supported yet."
197+
f"RustPython {version_tuple_to_str(self.version_triple)} is not supported yet."
199198
)
200199

201200
def load(self):

0 commit comments

Comments
 (0)