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

calling mock object in IPython 2.0.0 under Python 3.4.0 raises AttributeError #5817

Closed
ghost opened this issue May 8, 2014 · 1 comment · Fixed by #5818
Closed

calling mock object in IPython 2.0.0 under Python 3.4.0 raises AttributeError #5817

ghost opened this issue May 8, 2014 · 1 comment · Fixed by #5818
Milestone

Comments

@ghost
Copy link

ghost commented May 8, 2014

Calling a mock object in IPython 2.0.0 under Python 3.4.0 raises an AttributeError.

$ ipython
Python 3.4.0 |Continuum Analytics, Inc.| (default, Mar 17 2014, 16:13:08) 
Type "copyright", "credits" or "license" for more information.

IPython 2.0.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: from unittest import mock

In [2]: m = mock.Mock()

In [3]: m()
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-3-7e5925b669a0> in <module>()
----> 1 m()

/home/nick/anaconda/envs/test2/lib/python3.4/site-packages/IPython/core/displayhook.py in __call__(self, result)
    241         if result is not None and not self.quiet():
    242             # If _ipython_display_ is defined, use that to display this object.
--> 243             display_method = _safe_get_formatter_method(result, '_ipython_display_')
    244             if display_method is not None:
    245                 try:

/home/nick/anaconda/envs/test2/lib/python3.4/site-packages/IPython/core/formatters.py in _safe_get_formatter_method(obj, name)
     87     method = pretty._safe_getattr(obj, name, None)
     88     # formatter methods must be bound
---> 89     if _valid_formatter(method):
     90         return method
     91 

/home/nick/anaconda/envs/test2/lib/python3.4/site-packages/IPython/core/formatters.py in _valid_formatter(f)
     76         # anything that works with zero args should be okay
     77         try:
---> 78             inspect.getcallargs(f)
     79         except TypeError:
     80             return False

/home/nick/anaconda/envs/test2/lib/python3.4/inspect.py in getcallargs(*func_and_positional, **named)
   1165     spec = getfullargspec(func)
   1166     args, varargs, varkw, defaults, kwonlyargs, kwonlydefaults, ann = spec
-> 1167     f_name = func.__name__
   1168     arg2value = {}
   1169 

/home/nick/anaconda/envs/test2/lib/python3.4/unittest/mock.py in __getattr__(self, name)
    557                 raise AttributeError("Mock object has no attribute %r" % name)
    558         elif _is_magic(name):
--> 559             raise AttributeError(name)
    560 
    561         result = self._mock_children.get(name)

AttributeError: __name__

This behavior is not seen under Python 3.3:

$ ipython
Python 3.3.5 |Continuum Analytics, Inc.| (default, Mar 10 2014, 11:19:39) 
Type "copyright", "credits" or "license" for more information.

IPython 2.0.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: from unittest import mock

In [2]: m = mock.Mock()

In [3]: m()
Out[3]: <Mock name='mock()' id='3049469612'>
@ghost ghost closed this as completed May 8, 2014
@ghost ghost reopened this May 8, 2014
@ghost ghost changed the title calling mock object in IPython 2.0.0 under Python 3.4.0 raises AttributeError calling mock object in IPython 2.0.0 under Python 3.4.0 raises AttributeError May 8, 2014
@minrk minrk added this to the 2.1 milestone May 8, 2014
@minrk
Copy link
Member

minrk commented May 8, 2014

Should be fixed by #5818

minrk added a commit that referenced this issue May 8, 2014
…able

some object (mock) lie to callable

closes #5817
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.

1 participant