Skip to content

Commit 70a0abc

Browse files
committed
fix test
Signed-off-by: Manjusaka <[email protected]>
1 parent 295b351 commit 70a0abc

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

Doc/library/annotationlib.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ Functions
398398
decorated with :func:`functools.update_wrapper`), or if it is a
399399
:class:`functools.partial` object, it is unwrapped by following the
400400
``__wrapped__`` attribute or :attr:`~functools.partial.func` attribute
401-
repeatedly until a function with :attr:`~function.__globals__` is found.
401+
repeatedly to find the underlying wrapped function's globals.
402402

403403
Calling :func:`!get_annotations` is best practice for accessing the
404404
annotations dict of any object. See :ref:`annotations-howto` for

Lib/functools.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ def _partial_annotate(partial_obj, format):
540540

541541
# Get the signature to determine which parameters are bound
542542
try:
543-
sig = inspect.signature(partial_obj)
543+
sig = inspect.signature(partial_obj, annotation_format=format)
544544
except (ValueError, TypeError) as e:
545545
# If we can't get signature, we can't reliably determine which
546546
# parameters are bound. Raise an error rather than returning
@@ -590,7 +590,7 @@ def _partialmethod_annotate(partialmethod_obj, format):
590590
# The first parameter (self/cls) should remain, but bound args should be removed
591591
try:
592592
# Get the function signature
593-
func_sig = inspect.signature(func)
593+
func_sig = inspect.signature(func, annotation_format=format)
594594
func_params = list(func_sig.parameters.keys())
595595

596596
if not func_params:

Lib/test/test_annotationlib.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1910,14 +1910,17 @@ def foo(a: int, b: str) -> bool:
19101910

19111911
def test_partial_format_forwardref(self):
19121912
"""Test partial with FORWARDREF format."""
1913-
def foo(a: int, b: str) -> bool:
1913+
def foo(a: UndefinedType1, b: UndefinedType2) -> UndefinedReturnType:
19141914
return True
19151915

19161916
partial_foo = functools.partial(foo, 1)
19171917
result = get_annotations(partial_foo, format=Format.FORWARDREF)
19181918

1919-
# Should resolve to actual types
1920-
expected = {'b': str, 'return': bool}
1919+
# Should return forward references for undefined types
1920+
expected = {
1921+
'b': support.EqualToForwardRef('UndefinedType2', owner=foo),
1922+
'return': support.EqualToForwardRef('UndefinedReturnType', owner=foo)
1923+
}
19211924
self.assertEqual(result, expected)
19221925

19231926
def test_partial_with_placeholder(self):

0 commit comments

Comments
 (0)