Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit345fdce

Browse files
gh-133037: Add test for shadowing __annotate__ (#133084)
1 parent245cd6c commit345fdce

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

‎Lib/test/test_type_annotations.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,25 @@ def check_annotations(self, f):
327327
f.__annotations__= {"z":43}
328328
self.assertIs(f.__annotate__,None)
329329

330+
deftest_user_defined_annotate(self):
331+
classX:
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+
330349

331350
classDeferredEvaluationTests(unittest.TestCase):
332351
deftest_function(self):

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp