Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions Lib/test/test_annotationlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -1713,6 +1713,37 @@ def annotate(format, /):
with self.assertRaises(DemoException):
annotationlib.call_annotate_function(annotate, format=fmt)

def test_generated_annotate_non_bool_compare_result(self):
class NonBool:
def __gt__(self, other):
return None

# Function __annotate__
def func(x: int):
pass

self.assertEqual(
func.__annotate__(NonBool()),
Comment thread
BHUVANSH855 marked this conversation as resolved.
{"x": int},
)

# Class __annotate__
class C:
y: int

self.assertEqual(
C.__annotate__(NonBool()),
{"y": int},
)

# Module __annotate__
ns = {}
exec("z: int", ns)

self.assertEqual(
ns["__annotate__"](NonBool()),
{"z": int},
)

class MetaclassTests(unittest.TestCase):
def test_annotated_meta(self):
Expand Down
1 change: 1 addition & 0 deletions Python/codegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,7 @@ codegen_setup_annotations_scope(compiler *c, location loc,
ADDOP_I(c, loc, LOAD_FAST, 0);
ADDOP_LOAD_CONST_NEW(c, loc, value_with_fake_globals);
ADDOP_I(c, loc, COMPARE_OP, (Py_GT << 5) | compare_masks[Py_GT]);
ADDOP(c, loc, TO_BOOL);
NEW_JUMP_TARGET_LABEL(c, body);
ADDOP_JUMP(c, loc, POP_JUMP_IF_FALSE, body);
ADDOP_I(c, loc, LOAD_COMMON_CONSTANT, CONSTANT_NOTIMPLEMENTEDERROR);
Expand Down
Loading