Skip to content

Commit 4defb58

Browse files
Add "annotate" SET_FUNCTION_ATTRIBUTE bit to dis. (python#124566)
1 parent 4e829c0 commit 4defb58

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

Lib/dis.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
CONVERT_VALUE = opmap['CONVERT_VALUE']
3333

3434
SET_FUNCTION_ATTRIBUTE = opmap['SET_FUNCTION_ATTRIBUTE']
35-
FUNCTION_ATTR_FLAGS = ('defaults', 'kwdefaults', 'annotations', 'closure')
35+
FUNCTION_ATTR_FLAGS = ('defaults', 'kwdefaults', 'annotations', 'closure', 'annotate')
3636

3737
ENTER_EXECUTOR = opmap['ENTER_EXECUTOR']
3838
LOAD_CONST = opmap['LOAD_CONST']

Lib/test/test_dis.py

+18
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,23 @@ def wrap_func_w_kwargs():
380380
RETURN_CONST 3 (None)
381381
"""
382382

383+
fn_with_annotate_str = """
384+
def foo(a: int, b: str) -> str:
385+
return a * b
386+
"""
387+
388+
dis_fn_with_annotate_str = """\
389+
0 RESUME 0
390+
391+
2 LOAD_CONST 0 (<code object __annotate__ at 0x..., file "<dis>", line 2>)
392+
MAKE_FUNCTION
393+
LOAD_CONST 1 (<code object foo at 0x..., file "<dis>", line 2>)
394+
MAKE_FUNCTION
395+
SET_FUNCTION_ATTRIBUTE 16 (annotate)
396+
STORE_NAME 0 (foo)
397+
RETURN_CONST 2 (None)
398+
"""
399+
383400
compound_stmt_str = """\
384401
x = 0
385402
while 1:
@@ -1098,6 +1115,7 @@ def test_disassemble_str(self):
10981115
self.do_disassembly_test(expr_str, dis_expr_str)
10991116
self.do_disassembly_test(simple_stmt_str, dis_simple_stmt_str)
11001117
self.do_disassembly_test(annot_stmt_str, dis_annot_stmt_str)
1118+
self.do_disassembly_test(fn_with_annotate_str, dis_fn_with_annotate_str)
11011119
self.do_disassembly_test(compound_stmt_str, dis_compound_stmt_str)
11021120

11031121
def test_disassemble_bytes(self):

0 commit comments

Comments
 (0)