Skip to content
Merged
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
19 changes: 19 additions & 0 deletions Lib/test/test_type_annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,25 @@ def check_annotations(self, f):
f.__annotations__ = {"z": 43}
self.assertIs(f.__annotate__, None)

def test_user_defined_annotate(self):
class X:
a: int

def __annotate__(format):
return {"a": str}
self.assertEqual(X.__annotate__(annotationlib.Format.VALUE), {"a": str})
self.assertEqual(annotationlib.get_annotations(X), {"a": str})

mod = build_module(
"""
a: int
def __annotate__(format):
return {"a": str}
"""
)
self.assertEqual(mod.__annotate__(annotationlib.Format.VALUE), {"a": str})
self.assertEqual(annotationlib.get_annotations(mod), {"a": str})


class DeferredEvaluationTests(unittest.TestCase):
def test_function(self):
Expand Down
Loading