Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Patches: noerror option to code_assist
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  Messages 26 - 49 of 49 - Collapse all  -  Translate all to Translated (View all originals) < Older 
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Anton Beloglazov  
View profile  
 More options Aug 23 2012, 2:02 am
From: Anton Beloglazov <anton.belogla...@gmail.com>
Date: Wed, 22 Aug 2012 23:02:45 -0700 (PDT)
Local: Thurs, Aug 23 2012 2:02 am
Subject: Re: Patches: noerror option to code_assist

Hi All,

Sorry, I couldn't understand from the discussion how this issue can be
fixed in Emacs. Currently, I'm getting the following kind of errors in the
expanded minibuffer when there are some syntax errors:

ModuleSyntaxError: Syntax error in file <tests/test_collector.py> line
<266>:
Syntax errors in file tests/test_collector.py:
  * line 266: unexpected indent ... fixed
  * line 266: unexpected indent ... fixed
  * line 266: unexpected indent ... fixed
  * line 266: unexpected indent ... fixed
  * line 266: unexpected indent ... fixed
  * line 266: unexpected indent ... fixed
  * line 266: unexpected indent ... fixed
  * line 266: unexpected indent ... fixed
  * line 266: unexpected indent ... fixed
  * line 266: unexpected indent ... raised!

Could you please clarify for me how these errors can be hidden or reduced
to one line in Emacs?

Thanks,
Anton


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ali Gholami Rudi  
View profile   Translate to Translated (View Original)
 More options Aug 23 2012, 9:59 am
From: Ali Gholami Rudi <aligr...@gmail.com>
Date: Thu, 23 Aug 2012 18:29:21 +0430
Local: Thurs, Aug 23 2012 9:59 am
Subject: Re: Patches: noerror option to code_assist
Hi,

Anton Beloglazov <anton.belogla...@gmail.com> wrote:
> Sorry, I couldn't understand from the discussion how this issue can be
> fixed in Emacs. Currently, I'm getting the following kind of errors in the
> expanded minibuffer when there are some syntax errors:

I meant something like this patch for rope.  Not tested, so it
may need to be tweaked to work.

        Ali

--- a/rope/contrib/fixsyntax.py 2012-08-23 18:21:45.510172364 +0430
+++ b/rope/contrib/fixsyntax.py 2012-08-23 18:28:15.150743776 +0430
@@ -15,7 +15,7 @@
     @utils.saveit
     def get_pymodule(self):
         """Get a `PyModule`"""
-        errors = []
+        msg = None
         code = self.code
         tries = 0
         while True:
@@ -27,19 +27,15 @@
                 return self.pycore.get_string_module(
                     code, resource=self.resource, force_errors=True)
             except exceptions.ModuleSyntaxError, e:
+                if msg is None:
+                    msg = "%s:%s %s" % (e.filename, e.lineno, e.message_)
                 if tries < self.maxfixes:
                     tries += 1
                     self.commenter.comment(e.lineno)
                     code = '\n'.join(self.commenter.lines)
-                    errors.append('  * line %s: %s ... fixed' % (e.lineno,
-                                                                 e.message_))
                 else:
-                    errors.append('  * line %s: %s ... raised!' % (e.lineno,
-                                                                   e.message_))
-                    new_message = ('\nSyntax errors in file %s:\n' % e.filename) \
-                                   + '\n'.join(errors)
                     raise exceptions.ModuleSyntaxError(e.filename, e.lineno,
-                                                       new_message)
+                                 'Failed to fix error: %s' % msg)

     @property
     @utils.saveit


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Leo  
View profile  
 More options Aug 23 2012, 7:41 pm
From: Leo <sdl....@gmail.com>
Date: Fri, 24 Aug 2012 07:41:44 +0800
Local: Thurs, Aug 23 2012 7:41 pm
Subject: Re: Patches: noerror option to code_assist
On 2012-08-23 21:59 +0800, Ali Gholami Rudi wrote:

> I meant something like this patch for rope.  Not tested, so it
> may need to be tweaked to work.

Note that Pymacs (0.25 and above) no longer prints the whole backtrace
unless debug-on-error is non-nil.

Leo


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Anton Beloglazov  
View profile  
 More options Aug 23 2012, 10:03 pm
From: Anton Beloglazov <anton.belogla...@gmail.com>
Date: Thu, 23 Aug 2012 19:03:57 -0700 (PDT)
Local: Thurs, Aug 23 2012 10:03 pm
Subject: Re: Patches: noerror option to code_assist

Thanks for your replies! Is there any issue with incorporating this fix
into the main branch of rope?

Thanks,
Anton


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ali Gholami Rudi  
View profile   Translate to Translated (View Original)
 More options Aug 23 2012, 10:09 pm
From: Ali Gholami Rudi <aligr...@gmail.com>
Date: Fri, 24 Aug 2012 06:39:07 +0430
Local: Thurs, Aug 23 2012 10:09 pm
Subject: Re: Patches: noerror option to code_assist

Anton Beloglazov <anton.belogla...@gmail.com> wrote:
> Thanks for your replies! Is there any issue with incorporating this fix
> into the main branch of rope?

I think that's a good idea.  Did you test it?

> On Friday, 24 August 2012 09:41:44 UTC+10, Leo wrote:
> > Note that Pymacs (0.25 and above) no longer prints the whole backtrace
> > unless debug-on-error is non-nil.

I don't think that would help, since we do want the error
message but the message is too long; codeassist syntax
errors have multi-line messages, each line describing an
attempt to fix the error.  The patch in my previous
mail made it less verbose.

        Ali


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Anton Beloglazov  
View profile   Translate to Translated (View Original)
 More options Aug 27 2012, 9:13 am
From: Anton Beloglazov <anton.belogla...@gmail.com>
Date: Mon, 27 Aug 2012 23:13:23 +1000
Local: Mon, Aug 27 2012 9:13 am
Subject: Re: Patches: noerror option to code_assist

Hi Ali,

Sorry for the delay. I've tested your patch: the error message has got
indeed reduced into one line. However, the mini buffer still expands into
multiple lines for some reason. Here is a screenshot:
http://i.imgbox.com/ady0ackX.jpg

Do you know what could be the reason for such behavior?

Thanks,
Anton

On Fri, Aug 24, 2012 at 12:09 PM, Ali Gholami Rudi <aligr...@gmail.com>wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ali Gholami Rudi  
View profile  
 More options Aug 27 2012, 11:05 am
From: Ali Gholami Rudi <aligr...@gmail.com>
Date: Mon, 27 Aug 2012 19:35:22 +0430
Local: Mon, Aug 27 2012 11:05 am
Subject: Re: Patches: noerror option to code_assist
Hi,

Anton Beloglazov <anton.belogla...@gmail.com> wrote:
> Sorry for the delay. I've tested your patch: the error message has got
> indeed reduced into one line. However, the mini buffer still expands into
> multiple lines for some reason. Here is a screenshot:
> http://i.imgbox.com/ady0ackX.jpg

> Do you know what could be the reason for such behavior?

Odd...  Does the included patch make any difference.

        Ali

--- a/rope/contrib/fixsyntax.py 2012-08-27 19:42:30.516015457 +0430
+++ b/rope/contrib/fixsyntax.py 2012-08-27 19:45:00.236235582 +0430
@@ -15,7 +15,7 @@
     @utils.saveit
     def get_pymodule(self):
         """Get a `PyModule`"""
-        errors = []
+        msg = None
         code = self.code
         tries = 0
         while True:
@@ -27,19 +27,14 @@
                 return self.pycore.get_string_module(
                     code, resource=self.resource, force_errors=True)
             except exceptions.ModuleSyntaxError, e:
+                if msg is None:
+                    msg = '%s:%s %s' % (e.filename, e.lineno, e.message_.rstrip())
                 if tries < self.maxfixes:
                     tries += 1
                     self.commenter.comment(e.lineno)
                     code = '\n'.join(self.commenter.lines)
-                    errors.append('  * line %s: %s ... fixed' % (e.lineno,
-                                                                 e.message_))
                 else:
-                    errors.append('  * line %s: %s ... raised!' % (e.lineno,
-                                                                   e.message_))
-                    new_message = ('\nSyntax errors in file %s:\n' % e.filename) \
-                                   + '\n'.join(errors)
-                    raise exceptions.ModuleSyntaxError(e.filename, e.lineno,
-                                                       new_message)
+                    raise exceptions.ModuleSyntaxError(e.filename, e.lineno, msg)

     @property
     @utils.saveit


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Anton Beloglazov  
View profile  
 More options Aug 27 2012, 9:43 pm
From: Anton Beloglazov <anton.belogla...@gmail.com>
Date: Tue, 28 Aug 2012 11:42:26 +1000
Local: Mon, Aug 27 2012 9:42 pm
Subject: Re: Patches: noerror option to code_assist

Thanks, Ali. Unfortunately, this has not fixed the problem. Here is a new
screenshot: http://i.imgbox.com/abvW3Bjc.jpg

Best regards,
Anton

On Tue, Aug 28, 2012 at 1:05 AM, Ali Gholami Rudi <aligr...@gmail.com>wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Anton Beloglazov  
View profile  
 More options Aug 27 2012, 10:26 pm
From: Anton Beloglazov <anton.belogla...@gmail.com>
Date: Tue, 28 Aug 2012 12:26:05 +1000
Local: Mon, Aug 27 2012 10:26 pm
Subject: Re: Patches: noerror option to code_assist

Hi Ali,

I've just found that this message is popped up by eldoc-mode. I'm
using rope-get-calltip as eldoc-documentation-function. Due to syntax
errors, it failed all the time and displayed that message. To fix this,
I've modified the get_calltip function in rope/contrib/codeassist.py. Here
is the patch:

--- codeassist.py 2012-08-28 12:17:06.801540893 +1000
+++ codeassist-patched.py 2012-08-28 12:12:31.444884763 +1000
@@ -90,7 +90,10 @@
     """
     fixer = fixsyntax.FixSyntax(project.pycore, source_code,
                                 resource, maxfixes)
-    pymodule = fixer.get_pymodule()
+    try:
+        pymodule = fixer.get_pymodule()
+    except exceptions.ModuleSyntaxError:
+        return None
     pyname = fixer.pyname_at(offset)
     if pyname is None:
         return None

Now it just displays nothing if there is a syntax error, which I think is
reasonable for this purpose. Otherwise, it continuously shows up error
messages, which is very annoying.

Thanks,
Anton

On Tue, Aug 28, 2012 at 11:42 AM, Anton Beloglazov <


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Anton Beloglazov  
View profile  
 More options Aug 28 2012, 3:27 am
From: Anton Beloglazov <anton.belogla...@gmail.com>
Date: Tue, 28 Aug 2012 17:26:30 +1000
Local: Tues, Aug 28 2012 3:26 am
Subject: Re: Patches: noerror option to code_assist

I had to make a similar fix in the _code_completions function to suppress
the error reporting during auto-completion. The updated patch is below:

--- codeassist.py 2012-08-28 17:20:18.937734789 +1000
+++ codeassist-backup.py 2012-08-28 12:17:06.801540893 +1000
@@ -90,10 +90,7 @@
     """
     fixer = fixsyntax.FixSyntax(project.pycore, source_code,
                                 resource, maxfixes)
-    try:
-        pymodule = fixer.get_pymodule()
-    except exceptions.ModuleSyntaxError:
-        return None
+    pymodule = fixer.get_pymodule()
     pyname = fixer.pyname_at(offset)
     if pyname is None:
         return None
@@ -393,10 +390,7 @@
         lineno = self.code.count('\n', 0, self.offset) + 1
         fixer = fixsyntax.FixSyntax(self.pycore, self.code,
                                     self.resource, self.maxfixes)
-        try:
-            pymodule = fixer.get_pymodule()
-        except exceptions.ModuleSyntaxError:
-            return {}
+        pymodule = fixer.get_pymodule()
         module_scope = pymodule.get_scope()
         code = pymodule.source_code
         lines = code.split('\n')

Thanks,
Anton

On Tue, Aug 28, 2012 at 12:26 PM, Anton Beloglazov <


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ali Gholami Rudi  
View profile  
 More options Aug 28 2012, 9:19 am
From: Ali Gholami Rudi <aligr...@gmail.com>
Date: Tue, 28 Aug 2012 17:49:23 +0430
Local: Tues, Aug 28 2012 9:19 am
Subject: Re: Patches: noerror option to code_assist
Hi Anton,

Anton Beloglazov <anton.belogla...@gmail.com> wrote:
> I had to make a similar fix in the _code_completions function to suppress
> the error reporting during auto-completion. The updated patch is below:

I'm wondering if it is a good idea to make a distinction between
ropemode commands and functions; for instance between rope-show-doc
and rope-get-doc; the former is a command in ropemacs/ropevim, while
the latter is a function that can be used in external commands.  If an
error happens when performing a command, I think the user expects an
error message (my fixsyntax.py patch makes one such error more compact,
so I think it would be still useful).  But functions are invoked from
elisp/vimscript and instead of breaking the call chain by throwing
an exception, I think it is a better idea to return a special value.
This is what your patches did, but I think that could be improved.

At the moment both commands and functions are specified using the
local_command decorator in ropemode/interface.py.  I suggest adding a
local_function decorator in ropemode/decorators.py whose only argument is
the value to return if an interrupt occurs, as in the included untested
patch.  What do you think?  Is the default return value of completions
and extended_completions acceptable?

Thanks,
Ali

diff -u a/ropemode/decorators.py b/ropemode/decorators.py
--- a/ropemode/decorators.py    2012-08-28 18:05:56.132361619 +0430
+++ b/ropemode/decorators.py    2012-08-28 18:14:21.633103214 +0430
@@ -47,13 +47,17 @@
                     exceptions.ModuleSyntaxError,
                     exceptions.BadIdentifierError)

-def _exception_handler(func):
+log_errors = object()
+
+def _exception_handler(func, error_return):
     def newfunc(*args, **kwds):
         try:
             return func(*args, **kwds)
         except exceptions.RopeError, e:
             short = None
             if isinstance(e, input_exceptions):
+                if error_return is not log_errors:
+                    return error_return
                 short = _exception_message(e)
             logger(str(traceback.format_exc()), short)
     newfunc.__name__ = func.__name__
@@ -72,10 +76,10 @@
         return func
     return decorator

-
-def local_command(key=None, prefix=False, shortcut=None, name=None):
+def local_command(key=None, prefix=False, shortcut=None,
+                  name=None, error_return=log_errors):
     def decorator(func, name=name):
-        func = _exception_handler(func)
+        func = _exception_handler(func, error_return)
         func.kind = 'local'
         func.prefix = prefix
         func.local_key = key
@@ -86,10 +90,12 @@
         return func
     return decorator

+def local_function(error_return=None):
+       local_command(error_return=error_return)

 def global_command(key=None, prefix=False):
     def decorator(func):
-        func = _exception_handler(func)
+        func = _exception_handler(func, error_return)
         func.kind = 'global'
         func.prefix = prefix
         func.global_key = key
diff -u ropemode_/interface.py ropemode/interface.py
--- ropemode_/interface.py      2012-08-28 18:05:56.132361619 +0430
+++ ropemode/interface.py       2012-08-28 18:20:43.313655977 +0430
@@ -157,7 +157,7 @@
     def pop_mark(self):
         self.env.pop_mark()

-    @decorators.local_command()
+    @decorators.local_function()
     def definition_location(self):
         definition = self._base_definition_location()
         if definition:
@@ -200,7 +200,7 @@
         else:
             self.env.message('No docs available!')

-    @decorators.local_command()
+    @decorators.local_function()
     def get_doc(self):
         self._check_project()
         return self._base_get_doc(codeassist.get_doc)
@@ -272,11 +272,11 @@
     def auto_import(self):
         _CodeAssist(self, self.env).auto_import()

-    @decorators.local_command()
+    @decorators.local_function([])
     def completions(self):
         return _CodeAssist(self, self.env).completions()

-    @decorators.local_command()
+    @decorators.local_function([])
     def extended_completions(self):
         return _CodeAssist(self, self.env).extended_completions()


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Anton Beloglazov  
View profile  
 More options Aug 28 2012, 8:47 pm
From: Anton Beloglazov <anton.belogla...@gmail.com>
Date: Wed, 29 Aug 2012 10:46:54 +1000
Local: Tues, Aug 28 2012 8:46 pm
Subject: Re: Patches: noerror option to code_assist

Hi Ali,

Nice generalization! I've tested your patch, and with a couple of
modifications it works fine. I've added 'return' in the local_function
definition, and made get_calltip a local_function as well. Here are the
updated patches:

For decorators.py:

--- decorators-backup.py 2012-07-17 10:24:30.611629650 +1000
+++ decorators.py 2012-08-29 10:39:11.867472050 +1000
@@ -47,13 +47,17 @@
                     exceptions.ModuleSyntaxError,
                     exceptions.BadIdentifierError)

-def _exception_handler(func):
+log_errors = object()
+
+def _exception_handler(func, error_return):
     def newfunc(*args, **kwds):
         try:
             return func(*args, **kwds)
         except exceptions.RopeError, e:
             short = None
             if isinstance(e, input_exceptions):
+                if error_return is not log_errors:
+                    return error_return
                 short = _exception_message(e)
             logger(str(traceback.format_exc()), short)
     newfunc.__name__ = func.__name__
@@ -72,10 +76,10 @@
         return func
     return decorator

-
-def local_command(key=None, prefix=False, shortcut=None, name=None):
+def local_command(key=None, prefix=False, shortcut=None,
+                  name=None, error_return=log_errors):
     def decorator(func, name=name):
-        func = _exception_handler(func)
+        func = _exception_handler(func, error_return)
         func.kind = 'local'
         func.prefix = prefix
         func.local_key = key
@@ -86,10 +90,12 @@
         return func
     return decorator

+def local_function(error_return=None):
+       return local_command(error_return=error_return)

-def global_command(key=None, prefix=False):
+def global_command(key=None, prefix=False, error_return=log_errors):
     def decorator(func):
-        func = _exception_handler(func)
+        func = _exception_handler(func, error_return)
         func.kind = 'global'
         func.prefix = prefix
         func.global_key = key

For interface.py:

--- interface-backup.py 2012-07-17 10:24:30.611629650 +1000
+++ interface.py 2012-08-29 10:42:22.736438024 +1000
@@ -157,7 +157,7 @@
     def pop_mark(self):
         self.env.pop_mark()

-    @decorators.local_command()
+    @decorators.local_function()
     def definition_location(self):
         definition = self._base_definition_location()
         if definition:
@@ -182,7 +182,7 @@
         self._check_project()
         self._base_show_doc(prefix, self._base_get_doc(codeassist.get_doc))

-    @decorators.local_command()
+    @decorators.local_function()
     def get_calltip(self):
         self._check_project()
         def _get_doc(project, text, offset, *args, **kwds):
@@ -203,7 +203,7 @@
         else:
             self.env.message('No docs available!')

-    @decorators.local_command()
+    @decorators.local_function()
     def get_doc(self):
         self._check_project()
         return self._base_get_doc(codeassist.get_doc)
@@ -275,11 +275,11 @@
     def auto_import(self):
         _CodeAssist(self, self.env).auto_import()

-    @decorators.local_command()
+    @decorators.local_function([])
     def completions(self):
         return _CodeAssist(self, self.env).completions()

-    @decorators.local_command()
+    @decorators.local_function([])
     def extended_completions(self):
         return _CodeAssist(self, self.env).extended_completions()

Thanks,
Anton

On Tue, Aug 28, 2012 at 11:19 PM, Ali Gholami Rudi <aligr...@gmail.com>wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ali Gholami Rudi  
View profile  
 More options Aug 29 2012, 5:53 am
From: Ali Gholami Rudi <aligr...@gmail.com>
Date: Wed, 29 Aug 2012 14:12:31 +0430
Local: Wed, Aug 29 2012 5:42 am
Subject: Re: Patches: noerror option to code_assist
Hi,

Anton Beloglazov <anton.belogla...@gmail.com> wrote:
> Nice generalization! I've tested your patch, and with a couple of
> modifications it works fine. I've added 'return' in the local_function
> definition, and made get_calltip a local_function as well. Here are the
> updated patches:

> For decorators.py:

> --- decorators-backup.py 2012-07-17 10:24:30.611629650 +1000
> +++ decorators.py 2012-08-29 10:39:11.867472050 +1000

> For interface.py:

> --- interface-backup.py 2012-07-17 10:24:30.611629650 +1000
> +++ interface.py 2012-08-29 10:42:22.736438024 +1000

I've CC'ed Anton Gritsay, the maintainer.  Anton, what do you think?
I think this patch and also my patch to make fixsyntax.py errors terser
(I've included the latter in this mail) look acceptable.

Thanks,
Ali

--- a/rope/contrib/fixsyntax.py 2012-08-27 19:42:30.516015457 +0430
+++ b/rope/contrib/fixsyntax.py 2012-08-27 19:45:00.236235582 +0430
@@ -15,7 +15,7 @@
     @utils.saveit
     def get_pymodule(self):
         """Get a `PyModule`"""
-        errors = []
+        msg = None
         code = self.code
         tries = 0
         while True:
@@ -27,19 +27,14 @@
                 return self.pycore.get_string_module(
                     code, resource=self.resource, force_errors=True)
             except exceptions.ModuleSyntaxError, e:
+                if msg is None:
+                    msg = '%s:%s %s' % (e.filename, e.lineno, e.message_)
                 if tries < self.maxfixes:
                     tries += 1
                     self.commenter.comment(e.lineno)
                     code = '\n'.join(self.commenter.lines)
-                    errors.append('  * line %s: %s ... fixed' % (e.lineno,
-                                                                 e.message_))
                 else:
-                    errors.append('  * line %s: %s ... raised!' % (e.lineno,
-                                                                   e.message_))
-                    new_message = ('\nSyntax errors in file %s:\n' % e.filename) \
-                                   + '\n'.join(errors)
-                    raise exceptions.ModuleSyntaxError(e.filename, e.lineno,
-                                                       new_message)
+                    raise exceptions.ModuleSyntaxError(e.filename, e.lineno, msg)

     @property
     @utils.saveit


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
an...@angri.ru  
View profile  
 More options Aug 29 2012, 7:32 pm
From: an...@angri.ru
Date: Thu, 30 Aug 2012 01:31:53 +0200
Local: Wed, Aug 29 2012 7:31 pm
Subject: Re: Patches: noerror option to code_assist
Hi Ali, Anton,

2012/8/29 Ali Gholami Rudi <aligr...@gmail.com>:

> Hi,

> Anton Beloglazov <anton.belogla...@gmail.com> wrote:
>> Nice generalization! I've tested your patch, and with a couple of
>> modifications it works fine. I've added 'return' in the local_function
>> definition, and made get_calltip a local_function as well. Here are the
>> updated patches:

Anton, could you please explain me the semantic difference between
local function and local command? It is also not clear for me why did
you use singleton object for triggering "return on error" behaviour in
_exception_handler(). Could it not be just boolean function parameter
with default to False?

And one more thing: how do I test if it works as it should? What are
steps to reproduce the problem?

>> For decorators.py:

>> --- decorators-backup.py 2012-07-17 10:24:30.611629650 +1000
>> +++ decorators.py 2012-08-29 10:39:11.867472050 +1000

>> For interface.py:

>> --- interface-backup.py 2012-07-17 10:24:30.611629650 +1000
>> +++ interface.py 2012-08-29 10:42:22.736438024 +1000

> I've CC'ed Anton Gritsay, the maintainer.  Anton, what do you think?
> I think this patch and also my patch to make fixsyntax.py errors terser
> (I've included the latter in this mail) look acceptable.

I've committed this one. Thanks!

--
Anton


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Anton Beloglazov  
View profile  
 More options Aug 29 2012, 9:56 pm
From: Anton Beloglazov <anton.belogla...@gmail.com>
Date: Thu, 30 Aug 2012 11:55:25 +1000
Local: Wed, Aug 29 2012 9:55 pm
Subject: Re: Patches: noerror option to code_assist

Hi Anton,

The separation of local function and local command has been proposed by Ali
in one of the previous emails. The idea is that commands are supposed to be
directly executed by the user expecting to see an error message when
something goes wrong. On the other hand, functions are supposed to be used
programmatically inside other external commands, in which case it's more
convenient to just return a special value (specified as a parameter)
instead of throwing an exception.

An example of the latter case is rope-get-calltip function in Emacs, which
can be directly passed to Eldoc as eldoc-documentation-function. Throwing
an exception in case of a syntax error brakes Eldoc, which just expects to
get nil when there is no information available for displaying. This can be
reproduced as follows:

(turn-on-eldoc-mode)
(set (make-local-variable 'eldoc-documentation-function) 'rope-get-calltip)

Then open a Python file, make a Python syntax error: currently, an
exception is shown in the echo area. After applying the patch, in case of a
syntax error nothing is displayed.

Another example is integration with the auto-complete mode, which I set up
as follows:

;; ropemacs integration with auto-complete
(defun ac-ropemacs-candidates ()
  (mapcar (lambda (completion)
    (concat ac-prefix completion))
  (rope-completions)))

(ac-define-source nropemacs
  '((candidates . ac-ropemacs-candidates)
    (symbol     . "r")))

(ac-define-source nropemacs-dot
  '((candidates . ac-ropemacs-candidates)
    (symbol     . "r")
    (prefix     . c-dot)
    (requires   . 0)))

(add-to-list 'ac-sources 'ac-source-nropemacs)
(add-to-list 'ac-sources 'ac-source-nropemacs-dot)

The test is similar, currently when there is a Python syntax error
auto-complete breaks and displays an exception in the echo area. After the
patch, nothing is displayed in the echo area in case of a Python syntax
error. This is desirable by the user (from my point of view), since such
messages just disturb the user, while there are other special means to
report syntax errors, such as flymake-mode.

Regarding the "return on error" behavior, that is the implementation
proposed by Ali, I've just adopted it. Perhaps, Ali could explain his
choice of a singleton object over a boolean variable. To me, it seems that
a boolean parameter would work just as well.

Thanks,
Anton


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ali Gholami Rudi  
View profile  
 More options Aug 30 2012, 10:23 am
From: Ali Gholami Rudi <aligr...@gmail.com>
Date: Thu, 30 Aug 2012 18:52:19 +0430
Local: Thurs, Aug 30 2012 10:22 am
Subject: Re: Patches: noerror option to code_assist
Hi Anton,

Anton Beloglazov <anton.belogla...@gmail.com> wrote:
> Regarding the "return on error" behavior, that is the implementation
> proposed by Ali, I've just adopted it. Perhaps, Ali could explain his
> choice of a singleton object over a boolean variable. To me, it seems that
> a boolean parameter would work just as well.

Actually the error_return parameter is the value to return on errors.
I added a similar parameter to local_command() mainly for implementing
local_function().  But then to retain the old behavior, I needed
to somehow tell local_command() to re-raise an exception instead of
returning a value.  I could have added a new boolean parameter like
reraise_exceptions, which, when False, forced the value of the new
error_return parameter to be returned.  This would have required adding
two new parameters to local_command(), one of which was dependent
on the other; i.e. error_return would have been meaningful only if
reraise_exceptions was False.

I decided to merge the arguments: when exceptions are caught, the value
passed as error_return should be returned, unless it is log_errors (maybe
reraise_errors is a better name).  I added the log_errors singleton
because I couldn't tell if any other value (like None) is meant to
be returned on errors or is meant to request re-raising exceptions.
I thought this is the common practice in such cases, but maybe I'm among
the few who used to use this technique (or hack, probably).

I suggest either adding comments for this new parameter and the new
global variable or using the double parameter approach.  Unless, of
course, someone has a cleaner solution.

Thanks,
Ali


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Anton Beloglazov  
View profile  
 More options Aug 30 2012, 8:50 pm
From: Anton Beloglazov <anton.belogla...@gmail.com>
Date: Fri, 31 Aug 2012 10:49:20 +1000
Local: Thurs, Aug 30 2012 8:49 pm
Subject: Re: Patches: noerror option to code_assist

Hi Ali,

Thanks for the explanation! In my opinion, the two parameter approach is
easier to understand since it's more explicit and doesn't require any
special values.

Thanks,
Anton

On Fri, Aug 31, 2012 at 12:22 AM, Ali Gholami Rudi <aligr...@gmail.com>wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ali Gholami Rudi  
View profile  
 More options Aug 31 2012, 6:00 am
From: Ali Gholami Rudi <aligr...@gmail.com>
Date: Fri, 31 Aug 2012 14:27:46 +0430
Local: Fri, Aug 31 2012 5:57 am
Subject: Re: Patches: noerror option to code_assist
Hi Anton,

Anton Beloglazov <anton.belogla...@gmail.com> wrote:
> Thanks for the explanation! In my opinion, the two parameter approach is
> easier to understand since it's more explicit and doesn't require any
> special values.

That's OK with me and please update your patch.

Thanks,
Ali


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Anton Beloglazov  
View profile  
 More options Aug 31 2012, 7:24 pm
From: Anton Beloglazov <anton.belogla...@gmail.com>
Date: Sat, 1 Sep 2012 09:24:16 +1000
Local: Fri, Aug 31 2012 7:24 pm
Subject: Re: Patches: noerror option to code_assist

Hi Ali and Anton,

Here are the patches (only decorators.py has been updated: I've added
a raise_exceptions argument):

For decorators.py:

--- decorators-backup.py 2012-08-30 11:27:46.690981338 +1000
+++ decorators.py 2012-09-01 09:18:43.820460019 +1000
@@ -47,13 +47,15 @@
                     exceptions.ModuleSyntaxError,
                     exceptions.BadIdentifierError)

-def _exception_handler(func):
+def _exception_handler(func, raise_exceptions, error_return):
     def newfunc(*args, **kwds):
         try:
             return func(*args, **kwds)
         except exceptions.RopeError, e:
             short = None
             if isinstance(e, input_exceptions):
+                if not raise_exceptions:
+                    return error_return
                 short = _exception_message(e)
             logger(str(traceback.format_exc()), short)
     newfunc.__name__ = func.__name__
@@ -72,10 +74,12 @@
         return func
     return decorator

-
-def local_command(key=None, prefix=False, shortcut=None, name=None):
+def local_command(key=None, prefix=False, shortcut=None,
+                  name=None, raise_exceptions=True,
+                  error_return=None):
     def decorator(func, name=name):
-        func = _exception_handler(func)
+        func = _exception_handler(func, raise_exceptions,
+                                  error_return)
         func.kind = 'local'
         func.prefix = prefix
         func.local_key = key
@@ -86,10 +90,15 @@
         return func
     return decorator

+def local_function(error_return=None):
+       return local_command(raise_exceptions=False,
+                            error_return=error_return)

-def global_command(key=None, prefix=False):
+def global_command(key=None, prefix=False, raise_exceptions=True,
+                   error_return=None):
     def decorator(func):
-        func = _exception_handler(func)
+        func = _exception_handler(func, raise_exceptions,
+                                  error_return)
         func.kind = 'global'
         func.prefix = prefix
         func.global_key = key

For interface.py

--- interface-backup.py 2012-07-17 10:24:30.611629650 +1000
+++ interface.py 2012-08-29 10:42:22.736438024 +1000
@@ -157,7 +157,7 @@
     def pop_mark(self):
         self.env.pop_mark()

-    @decorators.local_command()
+    @decorators.local_function()
     def definition_location(self):
         definition = self._base_definition_location()
         if definition:
@@ -182,7 +182,7 @@
         self._check_project()
         self._base_show_doc(prefix, self._base_get_doc(codeassist.get_doc))

-    @decorators.local_command()
+    @decorators.local_function()
     def get_calltip(self):
         self._check_project()
         def _get_doc(project, text, offset, *args, **kwds):
@@ -203,7 +203,7 @@
         else:
             self.env.message('No docs available!')

-    @decorators.local_command()
+    @decorators.local_function()
     def get_doc(self):
         self._check_project()
         return self._base_get_doc(codeassist.get_doc)
@@ -275,11 +275,11 @@
     def auto_import(self):
         _CodeAssist(self, self.env).auto_import()

-    @decorators.local_command()
+    @decorators.local_function([])
     def completions(self):
         return _CodeAssist(self, self.env).completions()

-    @decorators.local_command()
+    @decorators.local_function([])
     def extended_completions(self):
         return _CodeAssist(self, self.env).extended_completions()

Thanks,
Anton

On Fri, Aug 31, 2012 at 7:57 PM, Ali Gholami Rudi <aligr...@gmail.com>wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Anton Beloglazov  
View profile  
 More options Aug 31 2012, 7:26 pm
From: Anton Beloglazov <anton.belogla...@gmail.com>
Date: Sat, 1 Sep 2012 09:25:45 +1000
Local: Fri, Aug 31 2012 7:25 pm
Subject: Re: Patches: noerror option to code_assist

A side note: I'll be away for the next two weeks. If there are any issues,
I'll only be able to look into them when I come back.

Best regards,
Anton

On Sat, Sep 1, 2012 at 9:24 AM, Anton Beloglazov <anton.belogla...@gmail.com


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Anton Beloglazov  
View profile  
 More options Sep 12 2012, 9:42 pm
From: Anton Beloglazov <anton.belogla...@gmail.com>
Date: Thu, 13 Sep 2012 11:41:32 +1000
Local: Wed, Sep 12 2012 9:41 pm
Subject: Re: Patches: noerror option to code_assist

Hi Ali and Anton,

Is there any problem with accepting the patches?

Thanks,
Anton

On Sat, Sep 1, 2012 at 9:25 AM, Anton Beloglazov <anton.belogla...@gmail.com


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
an...@angri.ru  
View profile  
 More options Sep 13 2012, 1:39 am
From: an...@angri.ru
Date: Thu, 13 Sep 2012 09:38:19 +0400
Local: Thurs, Sep 13 2012 1:38 am
Subject: Re: Patches: noerror option to code_assist
Hi Anton, hi Ali,

I'm sorry for the delay. I'm very short on free time these days, but
I'll definitely take care of the patches until the middle of next
week. Thanks!

--
Anton

2012/9/13 Anton Beloglazov <anton.belogla...@gmail.com>:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
an...@angri.ru  
View profile  
 More options Sep 17 2012, 3:46 pm
From: an...@angri.ru
Date: Mon, 17 Sep 2012 23:46:02 +0400
Local: Mon, Sep 17 2012 3:46 pm
Subject: Re: Patches: noerror option to code_assist
The patch is now in master. Please test and let me know if something
is not quite right.

Thanks, Anton and Ali!

--
Anton

2012/9/13  <an...@angri.ru>:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Anton Beloglazov  
View profile  
 More options Sep 17 2012, 7:42 pm
From: Anton Beloglazov <anton.belogla...@gmail.com>
Date: Tue, 18 Sep 2012 09:42:04 +1000
Local: Mon, Sep 17 2012 7:42 pm
Subject: Re: Patches: noerror option to code_assist

I've just tested it, it works. Thanks, Anton and Ali!

Best regards,
Anton


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages < Older 
« Back to Discussions « Newer topic     Older topic »