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

AttributeError: 'IPCompleter' object has no attribute 'custom_completers' #9395

Closed
Carreau opened this issue Apr 13, 2016 · 7 comments
Closed
Milestone

Comments

@Carreau
Copy link
Member

Carreau commented Apr 13, 2016

We seem to set it in interactiveshell.py, but it shoudl likely handle the case when it does not exists,
and should be wrapped in setters/getters.

In [1]: from IPython.core.completer import IPCompleter

In [2]: c = IPCompleter(get_ipython())

In [3]: c.complete('foo')
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-3-1faa54daaabd> in <module>()
----> 1 c.complete('foo')

/Users/bussonniermatthias/dev/ipython/IPython/core/completer.py in complete(self, text, line_buffer, cursor_pos)
   1182         # Start with a clean slate of completions
   1183         self.matches[:] = []
-> 1184         custom_res = self.dispatch_custom_completer(text)
   1185         if custom_res is not None:
   1186             # did custom completers produce something?

/Users/bussonniermatthias/dev/ipython/IPython/core/completer.py in dispatch_custom_completer(self, text)
   1094         # for foo etc, try also to find completer for %foo
   1095         if not cmd.startswith(self.magic_escape):
-> 1096             try_magic = self.custom_completers.s_matches(
   1097                 self.magic_escape + cmd)
   1098         else:

AttributeError: 'IPCompleter' object has no attribute 'custom_completers'
@minrk
Copy link
Member

minrk commented Apr 15, 2016

It should probably be declared on the class so it's always defined

@Carreau
Copy link
Member Author

Carreau commented Apr 15, 2016

It should probably be declared on the class so it's always defined

Yes, I just leave an easy open bug that does not bother anyone for a new contributor !

@Carreau Carreau added this to the wishlist milestone Apr 30, 2016
@ghost
Copy link

ghost commented Aug 21, 2016

@Carreau sir, i tried something, is this valid, i commented the line in __init__ of IPCompleter object i.e.,
self.custom_completers = None
and it gave the following result.

In [1]: from IPython.core.completer import IPCompleter

In [2]: c = IPCompleter(get_ipython())

In [3]: c.complete('foo')

In [4]:

the error disappeared, i thought that custom_completers object is being instantiated in the parent class of Completer,because in interactiveshell.py ,


  # Add custom completers to the basic ones built into IPCompleter
        sdisp = self.strdispatchers.get('complete_command', StrDispatch())
        self.strdispatchers['complete_command'] = sdisp
        self.Completer.custom_completers = sdisp

here custom_completers object is being instantiated. I am assuming that Interactiveshell.py will run first. I am a beginner , please review and help me with this, thank you.

@Carreau
Copy link
Member Author

Carreau commented Aug 24, 2016

Note, this has (partially been already fixed by #9487) but it now raises the following:

In [1]: from IPython.core.completer import IPCompleter

In [2]: c = IPCompleter(get_ipython())

In [3]: c.complete('foo')
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
/Users/bussonniermatthias/dev/ipython/IPython/core/completer.py in complete(self, text, line_buffer, cursor_pos)
   1203                 for matcher in self.matchers:
   1204                     try:
-> 1205                         self.matches.extend(matcher(text))
   1206                     except:
   1207                         # Show the ugly traceback if the matcher causes an

/Users/bussonniermatthias/dev/ipython/IPython/core/completer.py in python_matches(self, text)
    800                 matches = []
    801         else:
--> 802             matches = self.global_matches(text)
    803         return matches
    804

/Users/bussonniermatthias/dev/ipython/IPython/core/completer.py in global_matches(self, text)
    356         for lst in [keyword.kwlist,
    357                     builtin_mod.__dict__.keys(),
--> 358                     self.namespace.keys(),
    359                     self.global_namespace.keys()]:
    360             for word in lst:

AttributeError: 'IPCompleter' object has no attribute 'namespace'
Out[3]: ('foo', [])

That might be the reason why @thesageinpilani does not see the same error.

Can you check that when you are on master you see the above error ?

@ghost
Copy link

ghost commented Aug 25, 2016

yes sir, i see the same error

@srinivasreddy
Copy link
Contributor

srinivasreddy commented Dec 22, 2016

@Carreau
Looks like this has been fixed. Let's close this.
on master,

In [1]: from IPython.core.completer import IPCompleter

In [2]: c = IPCompleter(get_ipython())

In [3]: c.complete('foo')
Out[3]: ('foo', [])

In [4]: 

@takluyver
Copy link
Member

Thanks

@minrk minrk modified the milestones: 6.0, wishlist Jan 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants