Skip to content

Commit 370dfd9

Browse files
committed
gh-138729: Cover inspect.formatannotationrelativeto with tests
1 parent 04c7f36 commit 370dfd9

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

Lib/test/test_inspect/test_inspect.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1786,6 +1786,33 @@ def test_forwardref(self):
17861786
fwdref = ForwardRef('fwdref')
17871787
self.assertEqual(inspect.formatannotation(fwdref), 'fwdref')
17881788

1789+
def test_formatannotationrelativeto(self):
1790+
import typing
1791+
from test.typinganndata.ann_module9 import A
1792+
1793+
class B: ...
1794+
1795+
self.assertEqual(
1796+
inspect.formatannotationrelativeto(None)(A),
1797+
'testModule.typing.A',
1798+
)
1799+
self.assertEqual(
1800+
inspect.formatannotationrelativeto(inspect)(A),
1801+
'testModule.typing.A',
1802+
)
1803+
self.assertEqual(
1804+
inspect.formatannotationrelativeto(typing.Literal)(A),
1805+
'testModule.typing.A',
1806+
)
1807+
self.assertEqual(
1808+
inspect.formatannotationrelativeto(B)(A),
1809+
'testModule.typing.A',
1810+
)
1811+
self.assertEqual(
1812+
inspect.formatannotationrelativeto(A)(A),
1813+
'A',
1814+
)
1815+
17891816

17901817
class TestIsMethodDescriptor(unittest.TestCase):
17911818

0 commit comments

Comments
 (0)