mirror of
https://github.com/python/cpython.git
synced 2025-08-03 00:23:06 +00:00
gh-132064: Make annotationlib use __annotate__ if only it is present (#132195)
This commit is contained in:
parent
a1cd4ca7f4
commit
4d3ad0467e
5 changed files with 126 additions and 22 deletions
|
@ -1,4 +1,5 @@
|
|||
import abc
|
||||
from annotationlib import Format, get_annotations
|
||||
import builtins
|
||||
import collections
|
||||
import collections.abc
|
||||
|
@ -22,6 +23,7 @@ from inspect import Signature
|
|||
|
||||
from test.support import import_helper
|
||||
from test.support import threading_helper
|
||||
from test.support import EqualToForwardRef
|
||||
|
||||
import functools
|
||||
|
||||
|
@ -2075,6 +2077,34 @@ class TestLRU:
|
|||
self.assertEqual(str(Signature.from_callable(lru.cache_info)), '()')
|
||||
self.assertEqual(str(Signature.from_callable(lru.cache_clear)), '()')
|
||||
|
||||
def test_get_annotations(self):
|
||||
def orig(a: int) -> str: ...
|
||||
lru = self.module.lru_cache(1)(orig)
|
||||
|
||||
self.assertEqual(
|
||||
get_annotations(orig), {"a": int, "return": str},
|
||||
)
|
||||
self.assertEqual(
|
||||
get_annotations(lru), {"a": int, "return": str},
|
||||
)
|
||||
|
||||
def test_get_annotations_with_forwardref(self):
|
||||
def orig(a: int) -> nonexistent: ...
|
||||
lru = self.module.lru_cache(1)(orig)
|
||||
|
||||
self.assertEqual(
|
||||
get_annotations(orig, format=Format.FORWARDREF),
|
||||
{"a": int, "return": EqualToForwardRef('nonexistent', owner=orig)},
|
||||
)
|
||||
self.assertEqual(
|
||||
get_annotations(lru, format=Format.FORWARDREF),
|
||||
{"a": int, "return": EqualToForwardRef('nonexistent', owner=lru)},
|
||||
)
|
||||
with self.assertRaises(NameError):
|
||||
get_annotations(orig, format=Format.VALUE)
|
||||
with self.assertRaises(NameError):
|
||||
get_annotations(lru, format=Format.VALUE)
|
||||
|
||||
@support.skip_on_s390x
|
||||
@unittest.skipIf(support.is_wasi, "WASI has limited C stack")
|
||||
@support.skip_if_sanitizer("requires deep stack", ub=True, thread=True)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue