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

commented self.custom_completers = None #9897

Closed
wants to merge 1 commit into from
Closed

commented self.custom_completers = None #9897

wants to merge 1 commit into from

Conversation

ghost
Copy link

@ghost ghost commented Aug 23, 2016

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

I have commented the intialization of null value in the __init__ of IPCompleter object, since it is subclass of Completer.py where custom_completers is being created.

@Carreau
Copy link
Member

Carreau commented Aug 23, 2016

Hi !

Thanks a lot for that; that does not seem to do it for me I still get a different error;

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

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

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

/Users/bussonniermatthias/dev/ipython/IPython/core/completer.py in comp(*args, **kwargs)
     82     @wraps(complete)
     83     def comp(*args, **kwargs):
---> 84         text, matches =  complete(*args, **kwargs)
     85         if len(matches) == 1:
     86             return text, [matches[0].rstrip()]

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

/Users/bussonniermatthias/dev/ipython/IPython/core/completer.py in dispatch_custom_completer(self, text)
   1088
   1089     def dispatch_custom_completer(self, text):
-> 1090         if not self.custom_completers:
   1091             return
   1092

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

Did you committed all your changes ?

@ghost
Copy link
Author

ghost commented Aug 24, 2016

i am very sorry sir, i think i may have done something wrong. I will try to fix it. Thank you

@Carreau
Copy link
Member

Carreau commented Aug 24, 2016

i am very sorry sir, i think i may have done something wrong. I will try to fix it. Thank you

Don't worry; it might be me that have a wrong setup.

Thanks a lot for wanting to contribute !

@ghost
Copy link
Author

ghost commented Aug 25, 2016

sir, i have removed any previous installs of ipython and python and installed python 3.5.2 and running windows 10 and using git i cloned the repo and ran python -m IPython it gave the following messages.

C:\Users\rkchi\Desktop\repos\ipython>python -m IPython
Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:01:18) [MSC v.1900 32 bit (Intel)]
Type "copyright", "credits" or "license" for more information.

IPython 6.0.0.dev -- 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 IPython.core.completer import IPCompleter

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

In [3]: c.complete('foo')
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
C:\Users\rkchi\Desktop\repos\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

C:\Users\rkchi\Desktop\repos\ipython\IPython\core\completer.py in python_matches(self, text)
    800                 matches = []
    801         else:
--> 802             matches = self.global_matches(text)
    803         return matches
    804

C:\Users\rkchi\Desktop\repos\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', [])

@Carreau
Copy link
Member

Carreau commented Aug 30, 2016

Thanks, sorry I was away for a few day I can get back on that and look at what's happening.

@Carreau
Copy link
Member

Carreau commented Aug 30, 2016

Ok, so let's have look at what's happening, you indeed get the error message AttributeError: 'IPCompleter' object has no attribute 'namespace', so this piece of code assume there is a namespace attribute to self which definitively is not there.

We have 2 choices here:

  1. Handle the case where namespace does not exists if it make sens to not have namespace.
    • Likely with hasattr(self, 'namespace') or getattr(self, 'namespace'). I'll assume you know what these 2 are doing, or know how to find what they are doing feel free to ask if you need more info.
  2. Make sure namespace is set on the class (figure out why it is not)

Let's go with 2.
After some digging which take som practice:

  • namespace is set (or not) here on the IPcompleter superclass.
  • You can see that it's accessed/updated here when calling Completer.complete and inparticular if it was not passed to __init__ it uses __main__
  • Though if you look at the superclass IPCompleter, the overridden method complete does not handle this case.
  • IPCompleter__init__ does not handle this case either (it could have), also in particular it calls Completer.__init__ instead of super(IPcompleter, self).__init__ because this is reallllly old code.

My take on that (it's not the only solution) would be to add around this position a snippet like:

if self.use_main_ns:
            self.namespace = __main__.__dict__

A cleaner fix would be to change in __init__ the self.namespace to self._namespace and make self.namespace a @property that return the right thing (maybe add a setter as well).

Does that make some sens ?

Carreau added a commit to Carreau/ipython that referenced this pull request Sep 18, 2016
added

```
if self.use_main_ns:
           self.namespace = __main__.__dict__
```
in IPcompelter.py as suggested by Carreau sir,  in ipython#9897
@Carreau
Copy link
Member

Carreau commented Sep 19, 2016

Closing this as you fixed it in #9936. Thanks !

@Carreau Carreau closed this Sep 19, 2016
@Carreau Carreau added this to the no action milestone Sep 19, 2016
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 this pull request may close these issues.

None yet

1 participant