[Python-projects] pylint: -r/--reports option doesn't work

Maarten ter Huurne maarten.ter.huurne at philips.com
Mon Sep 15 19:08:32 CEST 2008


> pylint: -r/--reports option doesn't work. The following command still
> outputs reports:
>
>   % pylint --reports=no module
>
> versions and environment:
>
>   % uname -a
>   Darwin macbook3.local 9.4.0 Darwin Kernel Version 9.4.0: Mon Jun  9
> 19:30:53 PDT 2008; root:xnu-1228.5.20~1/RELEASE_I386 i386
>   % python --version
>   Python 2.5.1
>   % pylint --version
>   No config file found, using default configuration
>   pylint 0.15.0,
>   astng 0.17.3, common 0.35.0
>   Python 2.5.1 (r251:54863, Apr 15 2008, 22:57:26)
>   [GCC 4.0.1 (Apple Inc. build 5465)]
>
> on Mac OS X 10.5.4.

I encounter the same problem on Linux:
pylint 0.15.0,
astng 0.17.3, common 0.35.0
Python 2.5.1 (r251:54863, Mar  7 2008, 03:41:45)
[GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)]

I opened a ticket for it:
http://www.logilab.org/ticket/6006

> I gave a quick look at the pylint source code. Removing optparse
> 'default' option fixes this problem (see attachment), but I don't know
> why.

I did some debugging and the problem seems to be that if you pass "-rn",
the "reports" option is briefly set to False like it should, but is
overwritten by the default value (True) soon after.

In logilab/common/configuration.py, method
load_command_line_configuration() there is the following line:

(options, args) = self._optik_parser.parse_args(args=args)

During parse_args, the option callbacks are run, causing set_option() to
store the right value (False). However, this value is not updated in the
"values" object that the parser keeps, so when the parser returns,
"options" will still contain the default value (True) for "reports" and
load_command_line_configuration() will then proceed to store that value.

I am not sure what the proper general way is to fix this, but the following
change at least fixes the problem with pylint, so it can be a starting
point:

diff -ru logilab-common-0.35.0.org/configuration.py logilab-common-0.35.0
/configuration.py
--- logilab-common-0.35.0.org/configuration.py  2008-09-15
18:39:27.000000000 +0200
+++ logilab-common-0.35.0/configuration.py      2008-09-15
18:13:37.000000000 +0200
@@ -429,6 +429,7 @@
         if value is None:
             value = 1
         self.global_set_option(opt_name, value)
+        setattr(parser.values, opt_name, value)

     def global_set_option(self, opt_name, value):
         """set option on the correct option provider"""

Bye,
            Maarten
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.logilab.org/pipermail/python-projects/attachments/20080915/f78cf976/attachment.htm 


More information about the Python-Projects mailing list