On Fri, May 15, 2009 at 10:57 AM, Aaron Griffin <[email protected]>wrote:
> On Fri, May 15, 2009 at 1:31 AM, Chris Lasher <[email protected]> > wrote: > > On Tue, Dec 23, 2008 at 4:57 PM, Chris Lasher <[email protected]> > > wrote: > >> > >> On Tue, Dec 23, 2008 at 3:50 PM, Aaron Griffin <[email protected] > > > >> wrote: > >> > On Tue, Dec 23, 2008 at 1:58 PM, Bram Moolenaar <[email protected]> > >> > wrote: > >> >> > >> >> Chris Lasher wrote: > >> >> > >> >>> I sent this email to [email protected], but I am also sending it here so > >> >>> more eyes have a chance to see it. > >> >>> > >> >>> Vim's omni-completion fails for Python any time a file contains an > >> >>> import statement which fails (i.e., any import statement that will > >> >>> raise an ImportError). For example: > >> >>> > >> >>> import notamodule > >> >>> > >> >>> class Foo: > >> >>> def bar(self): > >> >>> pass > >> >>> > >> >>> # try omni-completing Foo here <C-x><C-o> > >> >>> # then comment out the above import statement and try again > >> >>> Fo > >> >>> > >> >>> > >> >>> This bug exists even if the import statement is wrapped within a > try, > >> >>> except clause, e.g.,: > >> >>> > >> >>> try: > >> >>> import notamodule > >> >>> except ImportError: > >> >>> pass > >> >> > >> >> I don't think this can be solved. The completion relies on parsing > the > >> >> file by Python, thus when parsing fails somehow it doesn't know what > to > >> >> complete. > >> >> > >> >> Aaron, is there something that can be done to avoid this problem? > >> > > >> > Hmm, it may be solvable if I step through each import one at a time > >> > and ignore the errors. > >> > I'll stick this in my queue of pythoncomplete issues and maybe try to > >> > get a new version out after Christmas time. Although, if anyone feels > >> > frisky, patches are always welcome :) > >> > >> To add additional information on this omni-completion bug, I > >> discovered that this bug only affects omni-completion when editing the > >> file doing the failed import. For example take these two files: > >> > >> -- > >> > >> #!/usr/bin/env python > >> # foo.py > >> > >> import notamodule > >> > >> class Foo: > >> def bar(self): > >> pass > >> > >> # Can't do an omni-complete against Foo here > >> > >> -- > >> > >> #!/usr/bin/env python > >> # spam.py > >> > >> import foo > >> > >> # You can, however, omni-complete foo.Foo here, even foo.Foo.bar > >> > >> -- > >> > >> I'm not sure if this helps but it seemed worth reporting. > > > > I came across this question on Stack Overflow and was reminded of this > > issue: > > http://stackoverflow.com/questions/199180/ > > > > Any workarounds, yet? I, myself, haven't dug into the code responsible > for > > Python completion, so I'm wondering if anyone else has. > > I'm confident that simply wrapping the imports in try blocks (in > pythoncomplete.vim) should solve this just fine. > > More to the point, however - why are you running into a case like > this? Shouldn't you have a try block around imports that you expect to > fail? > Sure, I do, but as I stated in the original post, wrapping failed imports in try blocks still kills omni-completion, curiously. Chris --~--~---------~--~----~------------~-------~--~----~ You received this message from the "vim_dev" maillist. For more information, visit http://www.vim.org/maillist.php -~----------~----~----~----~------~----~------~--~---
