diff options
author | larryhastings <larry@hastings.org> | 2024-09-26 00:01:45 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-26 00:01:45 (GMT) |
commit | 4defb58d3812a80d556410077e3391bb81a1c0b7 (patch) | |
tree | 34a01f4f3baeff7dcdbba38c65ec7c183e8c793c | |
parent | 4e829c0e6fbd47818451660c234eacc42a0b4a08 (diff) | |
download | cpython-4defb58d3812a80d556410077e3391bb81a1c0b7.zip cpython-4defb58d3812a80d556410077e3391bb81a1c0b7.tar.gz cpython-4defb58d3812a80d556410077e3391bb81a1c0b7.tar.bz2 |
Add "annotate" SET_FUNCTION_ATTRIBUTE bit to dis. (#124566)
-rw-r--r-- | Lib/dis.py | 2 | ||||
-rw-r--r-- | Lib/test/test_dis.py | 18 |
2 files changed, 19 insertions, 1 deletions
@@ -32,7 +32,7 @@ _have_code = (types.MethodType, types.FunctionType, types.CodeType, CONVERT_VALUE = opmap['CONVERT_VALUE'] SET_FUNCTION_ATTRIBUTE = opmap['SET_FUNCTION_ATTRIBUTE'] -FUNCTION_ATTR_FLAGS = ('defaults', 'kwdefaults', 'annotations', 'closure') +FUNCTION_ATTR_FLAGS = ('defaults', 'kwdefaults', 'annotations', 'closure', 'annotate') ENTER_EXECUTOR = opmap['ENTER_EXECUTOR'] LOAD_CONST = opmap['LOAD_CONST'] diff --git a/Lib/test/test_dis.py b/Lib/test/test_dis.py index bccd218..1ee0fbe 100644 --- a/Lib/test/test_dis.py +++ b/Lib/test/test_dis.py @@ -380,6 +380,23 @@ dis_annot_stmt_str = """\ RETURN_CONST 3 (None) """ +fn_with_annotate_str = """ +def foo(a: int, b: str) -> str: + return a * b +""" + +dis_fn_with_annotate_str = """\ + 0 RESUME 0 + + 2 LOAD_CONST 0 (<code object __annotate__ at 0x..., file "<dis>", line 2>) + MAKE_FUNCTION + LOAD_CONST 1 (<code object foo at 0x..., file "<dis>", line 2>) + MAKE_FUNCTION + SET_FUNCTION_ATTRIBUTE 16 (annotate) + STORE_NAME 0 (foo) + RETURN_CONST 2 (None) +""" + compound_stmt_str = """\ x = 0 while 1: @@ -1098,6 +1115,7 @@ class DisTests(DisTestBase): self.do_disassembly_test(expr_str, dis_expr_str) self.do_disassembly_test(simple_stmt_str, dis_simple_stmt_str) self.do_disassembly_test(annot_stmt_str, dis_annot_stmt_str) + self.do_disassembly_test(fn_with_annotate_str, dis_fn_with_annotate_str) self.do_disassembly_test(compound_stmt_str, dis_compound_stmt_str) def test_disassemble_bytes(self): |