Skip to content

__name__ being lost inside cloudpickled staticmethods? (0.8.0 regression) #251

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

Closed
tjb900 opened this issue Mar 7, 2019 · 2 comments · Fixed by #254
Closed

__name__ being lost inside cloudpickled staticmethods? (0.8.0 regression) #251

tjb900 opened this issue Mar 7, 2019 · 2 comments · Fixed by #254

Comments

@tjb900
Copy link

tjb900 commented Mar 7, 2019

Not sure if this is expected or not? Reproducer below.

Thanks!
Tim


Output with cloudpickle 0.7.0:

(cp7) $ python reproducer.py                                                                                                                                   
<pkg.mymod2.MyClass object at 0x7fbf18b3d828>

cloudpickle 0.8.0:

(cp8) $ python reproducer.py                                                                                                                                   
Traceback (most recent call last):
  File "reproducer.py", line 7, in <module>
    print(f())
  File "/mypath/pkg/mymod.py", line 4, in func
    from .mymod2 import MyClass
KeyError: "'__name__' not in globals"
pkg/
   __init__.py
   mymod.py
   mymod2.py
reproducer.py
# pkg/__init__.py
# blank
# pkg/mymod.py
class Blah(object):
    @staticmethod
    def func():
        from .mymod2 import MyClass
        return MyClass()
# pkg/mymod2.py
class MyClass(object):
    pass
# reproducer.py
from pkg.mymod import Blah
from cloudpickle import dumps
from pickle import loads

f = loads(dumps(Blah.func))

print(f())
@pierreglaser
Copy link
Member

You're correct, its a bug.
In 0.8.0 we reverted functions globals handling to the behavior of 0.5.3, and accidentally reintroduced a bug of 0.5.3 that was never reported before.
It is not related to staticmethod specifically, it is due to the relative import mechanism (the failing line is
from .mymod2 import MyClass)
I'll do a PR to fix this.

@ogrisel
Copy link
Contributor

ogrisel commented Mar 25, 2019

I released 0.8.1 to PyPI this morning to publish this fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants