-
-
Notifications
You must be signed in to change notification settings - Fork 278
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Problem with partial and pickle #925
Comments
@renefritze thanks for your report. Would you mind opening a PR on astroid please? |
Sure thing. |
Reopening because I did not understand that the merge request was only illustrative |
Is there anything more I can do to help that doesn't require in-depth astroid knowledge? |
I have investigated this a little. def test_conditional_definition_partial_pickle(self) -> None:
"""Regression test for a conditional defintion of a partial function wrapping pickle.
Reported in https://github.com/PyCQA/astroid/issues/925
"""
module = resources.build_file(
"data/conditional_pickle_import/conditional_importer.py"
)
dump_nodes = module.lookup("dump")[1]
assert len(dump_nodes) == 2
# Check the function defintion node
func_def_nodes = list(dump_nodes[0].infer())
assert len(func_def_nodes) == 1
assert isinstance(func_def_nodes[0], FunctionDef)
# Check the partial node
partial_node = list(dump_nodes[1].infer())
assert len(partial_node) == 1
assert isinstance(partial_node[0], objects.PartialFunction) This should pass with: # conditional_importer
import pickle
if False:
def dump(obj, file, protocol=None):
pass
else:
from functools import partial
dump = partial(pickle.dump, protocol=0) The problem is that On that line in the We will need a tip for a |
I'm not using astroid directly, but discovered this issue downstream using sphinx-autoapi.
It seems I've run into an edge case with
partial
and thepickle
module. I've added a new test case toastroid
to showcase my problem: master...renefritze:conditional_test_pickleWith the last commit on that branch the test suite succeeds: https://travis-ci.com/github/renefritze/astroid/jobs/487475875
Dropping the last commit, the suite fails: https://travis-ci.com/github/renefritze/astroid/jobs/487452325
The difference being 307f3ac
The text was updated successfully, but these errors were encountered: