Skip to content
Open
Changes from all 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
10 changes: 9 additions & 1 deletion Lib/test/test_inspect/test_inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import os
import dis
from os.path import normcase
import _pickle
import pickle
import shutil
import stat
Expand All @@ -29,6 +28,12 @@
import warnings
import weakref

try:
import _pickle
MISSING_C_PICKLE = False
except ImportError:
MISSING_C_PICKLE = True
Comment on lines +31 to +35
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
try:
import _pickle
MISSING_C_PICKLE = False
except ImportError:
MISSING_C_PICKLE = True
try:
import _pickle
except ImportError:
_pickle = None

This pattern is used more often in tests, as shown in the line below, it removes the need for a variable and makes the codebase more consistent.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this, use @unittest.skipUnless(_pickle, "requires _pickle module") as the test decorator.

Or to pick a different pattern in use in this module, use _pickle = import_helper.import_module('_pickle') in the test (see some examples that use _testcapi).

As another option, is there a particular reason to use _pickle? Can/should something from _testcapi be used instead?



try:
from concurrent.futures import ThreadPoolExecutor
Expand Down Expand Up @@ -1410,6 +1415,7 @@ def test(): pass

@unittest.skipIf(MISSING_C_DOCSTRINGS,
"Signature information for builtins requires docstrings")
@unittest.skipIf(MISSING_C_PICKLE, "requires _pickle")
def test_getfullargspec_builtin_methods(self):
self.assertFullArgSpecEquals(_pickle.Pickler.dump, ['self', 'obj'])

Expand Down Expand Up @@ -4635,6 +4641,7 @@ class D(C): pass

@unittest.skipIf(MISSING_C_DOCSTRINGS,
"Signature information for builtins requires docstrings")
@unittest.skipIf(MISSING_C_PICKLE, "requires _pickle")
def test_signature_on_builtin_class(self):
expected = ('(file, protocol=None, fix_imports=True, '
'buffer_callback=None)')
Expand Down Expand Up @@ -5176,6 +5183,7 @@ class foo: pass

@unittest.skipIf(MISSING_C_DOCSTRINGS,
"Signature information for builtins requires docstrings")
@unittest.skipIf(MISSING_C_PICKLE, "requires _pickle")
def test_signature_from_callable_builtin_obj(self):
class MySignature(inspect.Signature): pass
sig = MySignature.from_callable(_pickle.Pickler)
Expand Down
Loading