Skip to content

Commit 6044598

Browse files
committed
remove code312 type and organize
1 parent 2582fd3 commit 6044598

File tree

3 files changed

+33
-153
lines changed

3 files changed

+33
-153
lines changed

xdis/codetype/__init__.py

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
from xdis.codetype.code38 import Code38
2929
from xdis.codetype.code310 import Code310
3030
from xdis.codetype.code311 import Code311, Code311FieldNames
31-
from xdis.codetype.code312 import Code312
3231
from xdis.version_info import PYTHON_VERSION_TRIPLE
3332

3433

@@ -101,7 +100,7 @@ def codeType2Portable(code, version_tuple=PYTHON_VERSION_TRIPLE):
101100
co_firstlineno=code.co_firstlineno,
102101
co_linetable=line_table,
103102
)
104-
elif version_tuple[:2] == (3,11):
103+
elif version_tuple[:2] >= (3,11):
105104
return Code311(
106105
co_argcount=code.co_argcount,
107106
co_posonlyargcount=code.co_posonlyargcount,
@@ -122,27 +121,6 @@ def codeType2Portable(code, version_tuple=PYTHON_VERSION_TRIPLE):
122121
co_linetable=line_table,
123122
co_exceptiontable=code.co_exceptiontable,
124123
)
125-
elif version_tuple[:2] >= (3,12):
126-
return Code312(
127-
co_argcount=code.co_argcount,
128-
co_posonlyargcount=code.co_posonlyargcount,
129-
co_kwonlyargcount=code.co_kwonlyargcount,
130-
co_nlocals=code.co_nlocals,
131-
co_stacksize=code.co_stacksize,
132-
co_flags=code.co_flags,
133-
co_consts=code.co_consts,
134-
co_code=code.co_code,
135-
co_names=code.co_names,
136-
co_varnames=code.co_varnames,
137-
co_freevars=code.co_freevars,
138-
co_cellvars=code.co_cellvars,
139-
co_filename=code.co_filename,
140-
co_name=code.co_name,
141-
co_qualname=code.co_qualname,
142-
co_firstlineno=code.co_firstlineno,
143-
co_linetable=line_table,
144-
co_exceptiontable=code.co_exceptiontable,
145-
)
146124
elif version_tuple > (2, 0):
147125
# 2.0 .. 2.7
148126
return Code2(
@@ -209,11 +187,9 @@ def portableCodeType(version_tuple=PYTHON_VERSION_TRIPLE):
209187
elif version_tuple[:2] == (3, 10):
210188
# 3.10
211189
return Code310
212-
elif version_tuple[:2] == (3,11):
190+
elif version_tuple[:2] >= (3,11):
213191
# 3.11 ...
214192
return Code311
215-
elif version_tuple[:2] >= (3,12):
216-
return Code312
217193
elif version_tuple > (2, 0):
218194
# 2.0 .. 2.7
219195
return Code2

xdis/codetype/code311.py

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,37 @@
2323
from xdis.version_info import PYTHON_VERSION_TRIPLE, version_tuple_to_str
2424

2525

26+
# Note: order is the positional order given in the Python docs for
27+
# 3.11 types.Codetype.
28+
# "posonlyargcount" is not used, but it is in other Python versions, so it
29+
# has to be included since this structure is used as the Union type
30+
# for all code types.
31+
Code311FieldNames = """
32+
co_argcount
33+
co_posonlyargcount
34+
co_kwonlyargcount
35+
co_nlocals
36+
co_stacksize
37+
co_flags
38+
co_consts
39+
co_code
40+
co_names
41+
co_varnames
42+
co_freevars
43+
co_cellvars
44+
co_filename
45+
co_name
46+
co_qualname
47+
co_firstlineno
48+
co_linetable
49+
co_exceptiontable
50+
"""
51+
52+
Code311FieldTypes = deepcopy(Code310FieldTypes)
53+
Code311FieldTypes.update({"co_qualname": str, "co_exceptiontable": bytes})
54+
55+
56+
##### Parse location table #####
2657
def parse_location_entries(location_bytes, first_line):
2758
"""
2859
Parses the locations table described in: https://github.com/python/cpython/blob/3.11/Objects/locations.md
@@ -131,36 +162,6 @@ def decode_signed_varint(s):
131162
return entries
132163

133164

134-
# Note: order is the positional order given in the Python docs for
135-
# 3.11 types.Codetype.
136-
# "posonlyargcount" is not used, but it is in other Python versions, so it
137-
# has to be included since this structure is used as the Union type
138-
# for all code types.
139-
Code311FieldNames = """
140-
co_argcount
141-
co_posonlyargcount
142-
co_kwonlyargcount
143-
co_nlocals
144-
co_stacksize
145-
co_flags
146-
co_consts
147-
co_code
148-
co_names
149-
co_varnames
150-
co_freevars
151-
co_cellvars
152-
co_filename
153-
co_name
154-
co_qualname
155-
co_firstlineno
156-
co_linetable
157-
co_exceptiontable
158-
"""
159-
160-
Code311FieldTypes = deepcopy(Code310FieldTypes)
161-
Code311FieldTypes.update({"co_qualname": str, "co_exceptiontable": bytes})
162-
163-
164165
##### NEW "OPAQUE" LINE TABLE PARSING #####
165166
# See: https://github.com/python/cpython/blob/aaed91cabcedc16c089c4b1c9abb1114659a83d3/Objects/codeobject.c#L1245C1-L1245C17
166167
PY_CODE_LOCATION_INFO_SHORT0 = 0

xdis/codetype/code312.py

Lines changed: 0 additions & 97 deletions
This file was deleted.

0 commit comments

Comments
 (0)