mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
gh-132493: Avoid eager evaluation of annotations in @reprlib.recursive_repr()
(#133411)
This commit is contained in:
parent
b936ccdb6f
commit
dbee142a01
3 changed files with 19 additions and 2 deletions
|
@ -3,6 +3,7 @@
|
|||
Nick Mathewson
|
||||
"""
|
||||
|
||||
import annotationlib
|
||||
import sys
|
||||
import os
|
||||
import shutil
|
||||
|
@ -11,7 +12,7 @@ import importlib.util
|
|||
import unittest
|
||||
import textwrap
|
||||
|
||||
from test.support import verbose
|
||||
from test.support import verbose, EqualToForwardRef
|
||||
from test.support.os_helper import create_empty_file
|
||||
from reprlib import repr as r # Don't shadow builtin repr
|
||||
from reprlib import Repr
|
||||
|
@ -829,5 +830,19 @@ class TestRecursiveRepr(unittest.TestCase):
|
|||
self.assertEqual(type_params[0].__name__, 'T')
|
||||
self.assertEqual(type_params[0].__bound__, str)
|
||||
|
||||
def test_annotations(self):
|
||||
class My:
|
||||
@recursive_repr()
|
||||
def __repr__(self, default: undefined = ...):
|
||||
return default
|
||||
|
||||
annotations = annotationlib.get_annotations(
|
||||
My.__repr__, format=annotationlib.Format.FORWARDREF
|
||||
)
|
||||
self.assertEqual(
|
||||
annotations,
|
||||
{'default': EqualToForwardRef("undefined", owner=My.__repr__)}
|
||||
)
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue