Skip to content
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

Setting __module__ to None breaks pretty printing #3376

Closed
asmeurer opened this issue May 29, 2013 · 1 comment · Fixed by #3377
Closed

Setting __module__ to None breaks pretty printing #3376

asmeurer opened this issue May 29, 2013 · 1 comment · Fixed by #3377
Labels
Milestone

Comments

@asmeurer
Copy link
Contributor

In [1]: class Test: pass

In [2]: Test.__module__ = None

In [4]: Test
Out[4]: ---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-4-2205e48de5f9> in <module>()
----> 1 Test

/Users/aaronmeurer/Documents/ipython/IPython/core/displayhook.pyc in __call__(self, result)
    236             self.start_displayhook()
    237             self.write_output_prompt()
--> 238             format_dict = self.compute_format_data(result)
    239             self.write_format_data(format_dict)
    240             self.update_user_ns(result)

/Users/aaronmeurer/Documents/ipython/IPython/core/displayhook.pyc in compute_format_data(self, result)
    148             MIME type representation of the object.
    149         """
--> 150         return self.shell.display_formatter.format(result)
    151
    152     def write_format_data(self, format_dict):

/Users/aaronmeurer/Documents/ipython/IPython/core/formatters.pyc in format(self, obj, include, exclude)
    124                     continue
    125             try:
--> 126                 data = formatter(obj)
    127             except:
    128                 # FIXME: log the exception

/Users/aaronmeurer/Documents/ipython/IPython/core/formatters.pyc in __call__(self, obj)
    445                 type_pprinters=self.type_printers,
    446                 deferred_pprinters=self.deferred_printers)
--> 447             printer.pretty(obj)
    448             printer.flush()
    449             return stream.getvalue()

/Users/aaronmeurer/Documents/ipython/IPython/lib/pretty.pyc in pretty(self, obj)
    343                 if cls in self.type_pprinters:
    344                     # printer registered in self.type_pprinters
--> 345                     return self.type_pprinters[cls](obj, self, cycle)
    346                 else:
    347                     # deferred printer

/Users/aaronmeurer/Documents/ipython/IPython/lib/pretty.pyc in _type_pprint(obj, p, cycle)
    612         name = obj.__name__
    613     else:
--> 614         name = mod + '.' + obj.__name__
    615     p.text(name)
    616

TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'

Setting __module__ to None is a way to make pickling work for dynamically defined classes in certain cases (see for example https://code.google.com/p/sympy/issues/detail?id=1198). The whichmodule function in the pickling module does a custom search for the module if __module__ is set to None.

minrk added a commit to minrk/ipython that referenced this issue May 29, 2013
@minrk
Copy link
Member

minrk commented May 29, 2013

try PR #3377

mattvonrocketstein pushed a commit to mattvonrocketstein/ipython that referenced this issue Nov 3, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants