[pylint] why pylint wants only capitals identifiers?

Jean-Michel Pichavant jeanmichel at sequans.com
Mon Apr 19 12:30:39 EDT 2010


Giacomo Boffi wrote:
> Jean-Michel Pichavant <jeanmichel at sequans.com> writes:
>
>   
>> Giacomo Boffi wrote:
>>     
>>> i have this code
>>>
>>> def example(a):
>>>     return lambda b: a+b+1
>>>
>>> fun = example(10)
>>> k_1 = fun(7)
>>> ...
>>>
>>> and pylint tells me
>>>
>>> [...]
>>> C:  4: Invalid name "fun" (should match (([A-Z_][A-Z0-9_]*)|(__.*__))$)
>>> C:  5: Invalid name "k_1" (should match (([A-Z_][A-Z0-9_]*)|(__.*__))$)
>>> [...]
>>>                                                                 g
>>>
>>>       
>> Pylint default rules need some tuning
>>     
>
> ok, but maybe it's not my specific problem (see below)
>
>   
>> However, given you example, you should not insert code execution at
>> you module level, unless it's required only at the module import. I
>> dont know what is your module
>>     
>
> module? this was not well specified in my OP, but i'd rather speak of
> a "script" instead of a module...
>   

If by "script" you mean quick-and-dirty, then why bother running pylint 
on it ? Sounds out of topic to me.

But if you still care about how correctly structured you script should 
be, then it should be written almost like a module.

- do not write executable code at the module level
- if a function needs an information, it should ask for it as a 
parameter, not using a de-scoped variable (aka global variables)
- if a function ask for too many parameters, then it may ask for few 
objects instead (e.g. plot(x,y,z) => plot(point), poor example though, 3 
paramaters are acceptable)
- it's better if your script can be imported in a separate file and 
tested there

the list could contain many more items, and the more item you implement 
the closer to a module you get.

JM





More information about the Python-list mailing list