A.T.Hofkamp wrote:
> Skip Montanaro wrote:
>> Pylint doesn't catch that I have shadowed the argument msg.  Since
>> that shadowing happened in an except clause it went unexecuted (and
>> thus undetected) for a long time.
> 
>> It seems to me that formal function parameters are about as important
>> as globals.  Any chance of coaxing pylint into warning about shadowing
>> parameters?
> 
> When do you shadow a formal parameter?
> 
> My first intuition would be when you assign a new value to it.
> 
> However, that means that you get three warnings in the code below:
> 
> def f(x = None):
>   if x is None:
>     x = []
> 
>   x = x + x
> 
>   y = x
>   x = y + y
> 
>   return x
> 

reporting shadowing could be a command line option.

I think there are (at least) two philosophies about handling function
arguments.

The first one saying any parameter passed to a function should never be
assigned to.
Some adherents of this philosophy apply even different naming styles to
local vars and parameters in order to visually separate them.


The second is, that a parameter is just a special case of a local
variable with a preasigned value and that they can be modified any time.


Following the second philsophy I don't care about such warnings, but it
might be a good idea to highlight them with a pylint option.
If an entire team decides for 'philosophy 1' it would be good to have a
way of checking it.










_______________________________________________
Python-Projects mailing list
[email protected]
http://lists.logilab.org/mailman/listinfo/python-projects

Reply via email to