]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Add "annotate" SET_FUNCTION_ATTRIBUTE bit to dis. (#124566)
authorlarryhastings <larry@hastings.org>
Thu, 26 Sep 2024 00:01:45 +0000 (17:01 -0700)
committerGitHub <noreply@github.com>
Thu, 26 Sep 2024 00:01:45 +0000 (17:01 -0700)
Lib/dis.py
Lib/test/test_dis.py

index f8832b30497822009ae6100b8c345fda23f63e72..e87e6a78469ab0bfd4aeb8fc91aaf8c7c4525735 100644 (file)
@@ -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']
index bccd2182412577d57546c4791068bef4bff1be95..1ee0fbe98914be18b434b7d2ae75eb0b314def8a 100644 (file)
@@ -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):