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

gh-145754: Update signature retrieval in unittest.mock to use forwardref annotation format#145756

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
mschoettle wants to merge5 commits intopython:main
base:main
Choose a base branch
Loading
frommschoettle:patch-1
Open
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletionsLib/test/test_unittest/testmock/testmock.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1743,6 +1743,17 @@ def static_method(): pass
mock_method.assert_called_once_with()
self.assertRaises(TypeError,mock_method,'extra_arg')

#Issue145754
deftest_create_autospec_type_hints_typechecking(self):
fromtypingimportTYPE_CHECKING
ifTYPE_CHECKING:
fromtypingimportTuple

deffoo(x:Tuple[int, ...])->None:
pass

mock.create_autospec(foo)

#Issue21238
deftest_mock_unsafe(self):
m=Mock()
Expand Down
3 changes: 2 additions & 1 deletionLib/unittest/mock.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -34,6 +34,7 @@
import pkgutil
from inspect import iscoroutinefunction
import threading
from annotationlib import Format
from dataclasses import fields, is_dataclass
from types import CodeType, ModuleType, MethodType
from unittest.util import safe_repr
Expand DownExpand Up@@ -119,7 +120,7 @@ def _get_signature_object(func, as_instance, eat_self):
else:
sig_func = func
try:
return func, inspect.signature(sig_func)
return func, inspect.signature(sig_func, annotation_format=Format.FORWARDREF)
except ValueError:
# Certain callable types are not supported by inspect.signature()
return None
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
Request signature during mock autospec with ``FORWARDREF`` annotation format.
This prevents runtime errors when a type referred in a type hint is
imported within a ``TYPE_CHECKING`` block.
Loading

[8]ページ先頭

©2009-2026 Movatter.jp