Why no warnings when re-assigning builtin names?
nospam at torek.net
Wed Aug 31 23:30:12 CEST 2011
(I realize this thread is old. I have been away for a few weeks.
I read through the whole thread, though, and did not see anyone
bring up this one particular point: there is already a linting
script that handles this.)
>On Mon, Aug 15, 2011 at 10:52 PM, Gerrat Rickert
><grickert at coldstorage.com> wrote:
>> With surprising regularity, I see program postings (eg. on StackOverflow)
>> from inexperienced Python users accidentally re-assigning built-in names.
>> For example, they'll innocently call some variable, `list', and assign a
>> list of items to it.
In article <mailman.22.1313446504.27778.python-list at python.org>
Chris Angelico <rosuav at gmail.com> wrote:
>It's actually masking, not reassigning. That may make it easier or
>harder to resolve the issue.
>If you want a future directive that deals with it, I'd do it the other
>way - from __future__ import mask_builtin_warning or something - so
>the default remains as it currently is. But this may be a better job
>for a linting script.
The pylint program already does this:
$ cat shado.py
$ pylint shado.py
************* Module shado
W0622: 2:func: Redefining built-in 'list'
Your code has been rated at 6.67/10
If your shadowing is done on purpose, you can put in a pylint
comment directive to suppress the warning.
Pylint is the American Express Card of Python coding: "don't leave
$HOME without it!" :-)
In-Real-Life: Chris Torek, Wind River Systems
Intel require I note that my opinions are not those of WRS or Intel
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: gmail (figure it out) http://web.torek.net/torek/index.html
More information about the Python-list