File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -327,6 +327,25 @@ def check_annotations(self, f):
327
327
f .__annotations__ = {"z" : 43 }
328
328
self .assertIs (f .__annotate__ , None )
329
329
330
+ def test_user_defined_annotate (self ):
331
+ class X :
332
+ a : int
333
+
334
+ def __annotate__ (format ):
335
+ return {"a" : str }
336
+ self .assertEqual (X .__annotate__ (annotationlib .Format .VALUE ), {"a" : str })
337
+ self .assertEqual (annotationlib .get_annotations (X ), {"a" : str })
338
+
339
+ mod = build_module (
340
+ """
341
+ a: int
342
+ def __annotate__(format):
343
+ return {"a": str}
344
+ """
345
+ )
346
+ self .assertEqual (mod .__annotate__ (annotationlib .Format .VALUE ), {"a" : str })
347
+ self .assertEqual (annotationlib .get_annotations (mod ), {"a" : str })
348
+
330
349
331
350
class DeferredEvaluationTests (unittest .TestCase ):
332
351
def test_function (self ):
You can’t perform that action at this time.
0 commit comments