[pylint] why pylint wants only capitals identifiers?

Discussion in 'Python' started by Giacomo Boffi, Apr 19, 2010.

  1. 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_]*)|(__.*__))$)
    [...]

    afaict, [A-Z_][A-Z0-9_]* identifiers should be used for constants, and
    i don't think of fun or k_1 as constants... what's going on?

    tia,
    g
    --
    la lenza penzola
    -- PMF, in IHC
    Giacomo Boffi, Apr 19, 2010
    #1
    1. Advertising

  2. 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_]*)|(__.*__))$)
    > [...]
    >
    > afaict, [A-Z_][A-Z0-9_]* identifiers should be used for constants, and
    > i don't think of fun or k_1 as constants... what's going on?
    >
    > tia,
    > g
    >

    Pylint default rules need some tuning, it's highly configurable for that
    purpose.
    Some ppl like to think 'module variables' are constants thus should be
    upper case. If you disagree with that statement like I do, you can
    simply rewrite the regexp for module variables.

    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 purpose but I bet it has no legitimate
    attribute 'fun'.

    JM
    Jean-Michel Pichavant, Apr 19, 2010
    #2
    1. Advertising

  3. Jean-Michel Pichavant <> 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...

    maybe should i use the

    if __name__ == "__main__":
    main()

    idiom to keep happy my pylint? oh, let's do it... it should be easy
    isn't it?

    thanks,
    g
    --
    I wish we'd come to our senses and see there is no truth
    In those who promote the confusion for this ever changing mood.
    (people get ready people get ready people get ready people get ready)
    Giacomo Boffi, Apr 19, 2010
    #3
  4. Giacomo Boffi <> writes:

    >> 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...
    >
    > maybe should i use the
    >
    > if __name__ == "__main__":
    > main()
    >
    > idiom to keep happy my pylint? oh, let's do it... it should be easy
    > isn't it?


    well, it's not so easy... pylint complains (correctly) about too many
    local variables in main(), and about other things for different
    adjustments i tried

    i think i will put some variable at top level, CAPITALIZED, with the
    intention of making evident that those values are the data of the
    problem, as well as other quantities that are computed once from base
    data, and then use these capitalized global variables inside my main
    function --- tonight, at home

    thank you again,
    g
    --
    l'amore e' un sentimento a senso unico. a volte una via comincia dove
    finisce un'altra e viceversa -- Caldana, in IFQ
    Giacomo Boffi, Apr 19, 2010
    #4
  5. Giacomo Boffi wrote:
    > Jean-Michel Pichavant <> 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
    Jean-Michel Pichavant, Apr 19, 2010
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mr. SweatyFinger

    why why why why why

    Mr. SweatyFinger, Nov 28, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    839
    Mark Rae
    Dec 21, 2006
  2. Mr. SweatyFinger
    Replies:
    2
    Views:
    1,685
    Smokey Grindel
    Dec 2, 2006
  3. Replies:
    1
    Views:
    333
    Roedy Green
    Apr 22, 2008
  4. richard

    what turns off capitals?

    richard, Oct 16, 2008, in forum: HTML
    Replies:
    2
    Views:
    417
    richard
    Oct 17, 2008
  5. Jeremy Banks
    Replies:
    12
    Views:
    424
    Steven D'Aprano
    Apr 24, 2009
Loading...

Share This Page