lint for Python?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Pat

    lint for Python?

    I've been searching for a good multi-module lint checker for Python and
    I haven't found one yet.

    Pylint does a decent job at checking for errors only within a single module.

    Here's one of my problems. I have two modules.

    In module one, I have a function:

    def foo( host, userid, password ):
    pass

    In module two, I call that function:

    foo( userid, password)

    lint doesn't find that error and it won't be caught until it's called
    while the program is running. I don't want that error found at 3AM.

    I've never used a language that didn't catch that type of error. I'm
    quite surprised that Python is being used by a number of major
    companies. How you catch these types of errors?

    I've spoken to tech support at Wing and they weren't aware of a
    multi-module lint but they're considering putting their own lint into
    their IDE.

    Thank you
  • Chris Rebert

    #2
    Re: lint for Python?

    On Fri, Oct 3, 2008 at 2:38 PM, Pat <Pat@tanker.net wrote:
    I've been searching for a good multi-module lint checker for Python and I
    haven't found one yet.
    >
    Pylint does a decent job at checking for errors only within a single module.
    >
    Here's one of my problems. I have two modules.
    >
    In module one, I have a function:
    >
    def foo( host, userid, password ):
    pass
    >
    In module two, I call that function:
    >
    foo( userid, password)
    >
    lint doesn't find that error and it won't be caught until it's called while
    the program is running. I don't want that error found at 3AM.
    >
    I've never used a language that didn't catch that type of error. I'm quite
    surprised that Python is being used by a number of major companies. How you
    catch these types of errors?
    In a word (or phrase rather): unit testing. Lots of unit testing,
    which catches both silly errors like this and more complicated logic
    errors.
    Check out the 'unittest' module
    [http://docs.python.org/library/unittest.html] and any of the many
    writings on the subject for more information. And I'm sure some other
    posters will respond with more thorough explanations.

    Cheers,
    Chris
    --
    Follow the path of the Iguana...

    >
    I've spoken to tech support at Wing and they weren't aware of a multi-module
    lint but they're considering putting their own lint into their IDE.
    >
    Thank you
    --

    >

    Comment

    • Lawrence D'Oliveiro

      #3
      Re: lint for Python?

      In message <gc63c7$gi2$1@a ioe.org>, Pat wrote:
      In module one, I have a function:
      >
      def foo( host, userid, password ):
      pass
      >
      In module two, I call that function:
      >
      foo( userid, password)
      >
      lint doesn't find that error and it won't be caught until it's called
      while the program is running. I don't want that error found at 3AM.
      >
      I've never used a language that didn't catch that type of error.
      Because in Python, it's not necessarily an error. Every name you define in
      Python is just a variable, and can have its value changed at any time: the
      compiler can't tell that foo won't have a different value put into it
      between the definition of the function and the actual call.

      Comment

      • Marc 'BlackJack' Rintsch

        #4
        Re: lint for Python?

        On Fri, 03 Oct 2008 17:38:13 -0400, Pat wrote:
        Pylint does a decent job at checking for errors only within a single
        module.
        >
        Here's one of my problems. I have two modules.
        >
        In module one, I have a function:
        >
        def foo( host, userid, password ):
        pass
        >
        In module two, I call that function:
        >
        foo( userid, password)
        >
        lint doesn't find that error and it won't be caught until it's called
        while the program is running. I don't want that error found at 3AM.
        Then don't run the unit tests that late at night (or early in the
        morning). ;-)

        Besides the `unittest` module from the standard library you might look
        into `py.test` and `nose`.

        Ciao,
        Marc 'BlackJack' Rintsch

        Comment

        • bearophileHUGS@lycos.com

          #5
          Re: lint for Python?

          Pat:

          I know about 3 different lints for Python, there's PyFlake too. But I
          don't know if it does what you want.

          I've never used a language that didn't catch that type of error.
          What dynamic languages have you used in the past?

          I'm quite surprised that Python is being used by a number of major
          companies. How you catch these types of errors?
          Writing tests. You must adapt your coding style to the language you
          use.
          In Java/C++ your static type system catches those bugs for you, in
          dynamic languages you have to catch them with testing (or lints, if
          they are present). Languages like Haskell with a type system much
          stronger than Java/C++ ones help you catch even more bugs/problems at
          compile time, so you need more time to have a clean compilation, but
          you have less bugs later (but tests are useful in Haskell too, see
          QuickCheck, that has inspired lot of similar tools for other
          languages, Python included).

          Bye,
          bearophile

          Comment

          • Alex_Gaynor

            #6
            Re: lint for Python?

            On Oct 3, 5:38 pm, Pat <P...@tanker.ne twrote:
            I've been searching for a good multi-module lint checker for Python and
            I haven't found one yet.
            >
            Pylint does a decent job at checking for errors only within a single module.
            >
            Here's one of my problems.  I have two modules.
            >
            In module one, I have a function:
            >
            def foo( host, userid, password ):
                 pass
            >
            In module two, I call that function:
            >
            foo( userid, password)
            >
            lint doesn't find that error and it won't be caught until it's called
            while the program is running.  I don't want that error found at 3AM.
            >
            I've never used a language that didn't catch that type of error.  I'm
            quite surprised that Python is being used by a number of major
            companies.  How you catch these types of errors?
            >
            I've spoken to tech support at Wing and they weren't aware of a
            multi-module lint but they're considering putting their own lint into
            their IDE.
            >
            Thank you
            I doubt you will find a tool that can find that kind of error(at least
            not reliably), python is a highly dynamic language, and so foo() can
            easily be reassigned at any point in the execution.

            Comment

            • Benjamin

              #7
              Re: lint for Python?

              On Oct 3, 4:38 pm, Pat <P...@tanker.ne twrote:
              I've been searching for a good multi-module lint checker for Python and
              I haven't found one yet.
              >
              Pylint does a decent job at checking for errors only within a single module.
              >
              Here's one of my problems.  I have two modules.
              >
              In module one, I have a function:
              >
              def foo( host, userid, password ):
                   pass
              >
              In module two, I call that function:
              >
              foo( userid, password)
              >
              lint doesn't find that error and it won't be caught until it's called
              while the program is running.  I don't want that error found at 3AM.
              >
              I've never used a language that didn't catch that type of error.  I'm
              quite surprised that Python is being used by a number of major
              companies.  How you catch these types of errors?
              You have to write extensive tests for your code. Not only does this
              catch trivial errors like the above, but it finds logic errors in your
              implementation.
              >
              I've spoken to tech support at Wing and they weren't aware of a
              multi-module lint but they're considering putting their own lint into
              their IDE.
              >
              Thank you

              Comment

              • Miki

                #8
                Re: lint for Python?

                Hello,
                In module one, I have a function:
                >
                def foo( host, userid, password ):
                     pass
                >
                In module two, I call that function:
                >
                foo( userid, password)
                >
                lint doesn't find that error and it won't be caught until it's called
                while the program is running.
                pychecker does find these kind of errors.
                I've never used a language that didn't catch that type of error.  I'm
                quite surprised that Python is being used by a number of major
                companies.  How you catch these types of errors?
                By running a large test suite, I highly recommend "nose".

                HTH,
                --
                Miki <miki.tebeka@gm ail.com>
                If it won't be simple, it simply won't be. [Hire me, source code]

                Comment

                • Pat

                  #9
                  Re: lint for Python?

                  Miki wrote:
                  Hello,
                  >
                  >In module one, I have a function:
                  >>
                  >def foo( host, userid, password ):
                  > pass
                  >>
                  >In module two, I call that function:
                  >>
                  >foo( userid, password)
                  >>
                  >lint doesn't find that error and it won't be caught until it's called
                  >while the program is running.
                  pychecker does find these kind of errors.
                  Before posting my original question, I tried pychecker and it didn't
                  catch that error.
                  >
                  >I've never used a language that didn't catch that type of error. I'm
                  >quite surprised that Python is being used by a number of major
                  >companies. How you catch these types of errors?
                  By running a large test suite, I highly recommend "nose".
                  That's something I'll look into after I'm more proficient in Python.
                  Currently, I'm learning my way around Python.

                  Thank you.
                  >
                  HTH,
                  --
                  Miki <miki.tebeka@gm ail.com>
                  http://pythonwise.blogspot.com

                  Comment

                  • Aaron \Castironpi\ Brady

                    #10
                    Re: lint for Python?

                    Pat wrote:
                    I've been searching for a good multi-module lint checker for Python and
                    I haven't found one yet.
                    >
                    Pylint does a decent job at checking for errors only within a single
                    module.
                    >
                    Here's one of my problems. I have two modules.
                    >
                    In module one, I have a function:
                    >
                    def foo( host, userid, password ):
                    pass
                    >
                    In module two, I call that function:
                    >
                    foo( userid, password)
                    >
                    lint doesn't find that error and it won't be caught until it's called
                    while the program is running. I don't want that error found at 3AM.
                    >
                    I've never used a language that didn't catch that type of error. I'm
                    quite surprised that Python is being used by a number of major
                    companies. How you catch these types of errors?
                    >
                    I've spoken to tech support at Wing and they weren't aware of a
                    multi-module lint but they're considering putting their own lint into
                    their IDE.
                    >
                    Thank you
                    --

                    >
                    The example you gave is specific. You could catch that one by hand.
                    But, would it hurt, perhaps by causing neglect of other errors; and
                    would it be worth the effort? And, if you're using any dynamics at all,
                    catching that one's even in question.

                    from mod import foo
                    bar= foo
                    bar( arg1, arg2 )

                    It would add difficulty to catching by hand. Same with variable
                    argument lists.

                    from mod import foo
                    args= ( arg1, arg2 )
                    foo( *args )

                    If you could knock off an error and ignore the false positives, that
                    might be worth an afternoon.



                    Comment

                    • Aaron \Castironpi\ Brady

                      #11
                      Re: lint for Python?

                      Pat wrote:
                      I've been searching for a good multi-module lint checker for Python and
                      I haven't found one yet.
                      >
                      Pylint does a decent job at checking for errors only within a single
                      module.
                      >
                      Here's one of my problems. I have two modules.
                      >
                      In module one, I have a function:
                      >
                      def foo( host, userid, password ):
                      pass
                      >
                      In module two, I call that function:
                      >
                      foo( userid, password)
                      >
                      lint doesn't find that error and it won't be caught until it's called
                      while the program is running. I don't want that error found at 3AM.
                      >
                      I've never used a language that didn't catch that type of error. I'm
                      quite surprised that Python is being used by a number of major
                      companies. How you catch these types of errors?
                      >
                      I've spoken to tech support at Wing and they weren't aware of a
                      multi-module lint but they're considering putting their own lint into
                      their IDE.
                      >
                      Thank you
                      --

                      >
                      The example you gave is specific. You could catch that one by hand.
                      But, would it hurt, perhaps by causing neglect of other errors; and
                      would it be worth the effort? And, if you're using any dynamics at all,
                      catching that one's even in question.

                      from mod import foo
                      bar= foo
                      bar( arg1, arg2 )

                      It would add difficulty to catching by hand. Same with variable
                      argument lists.

                      from mod import foo
                      args= ( arg1, arg2 )
                      foo( *args )

                      If you could knock off an error and ignore the false positives, that
                      might be worth an afternoon.




                      Comment

                      • Aaron \Castironpi\ Brady

                        #12
                        Re: lint for Python?

                        Pat wrote:
                        I've been searching for a good multi-module lint checker for Python and
                        I haven't found one yet.
                        >
                        Pylint does a decent job at checking for errors only within a single
                        module.
                        >
                        Here's one of my problems. I have two modules.
                        >
                        In module one, I have a function:
                        >
                        def foo( host, userid, password ):
                        pass
                        >
                        In module two, I call that function:
                        >
                        foo( userid, password)
                        >
                        lint doesn't find that error and it won't be caught until it's called
                        while the program is running. I don't want that error found at 3AM.
                        >
                        I've never used a language that didn't catch that type of error. I'm
                        quite surprised that Python is being used by a number of major
                        companies. How you catch these types of errors?
                        >
                        I've spoken to tech support at Wing and they weren't aware of a
                        multi-module lint but they're considering putting their own lint into
                        their IDE.
                        >
                        Thank you
                        --

                        >
                        The example you gave is specific. You could catch that one by hand.
                        But, would it hurt, perhaps by causing neglect of other errors; and
                        would it be worth the effort? And, if you're using any dynamics at all,
                        catching that one's even in question.

                        from mod import foo
                        bar= foo
                        bar( arg1, arg2 )

                        It would add difficulty to catching by hand. Same with variable
                        argument lists.

                        from mod import foo
                        args= ( arg1, arg2 )
                        foo( *args )

                        If you could knock off an error and ignore the false positives, that
                        might be worth an afternoon.




                        Comment

                        • Aaron \Castironpi\ Brady

                          #13
                          Re: lint for Python?

                          On Oct 5, 8:53 am, Pat <P...@junk.netw rote:
                          Miki wrote:
                          Hello,
                          >
                          In module one, I have a function:
                          >
                          def foo( host, userid, password ):
                               pass
                          >
                          In module two, I call that function:
                          >
                          foo( userid, password)
                          >
                          lint doesn't find that error and it won't be caught until it's called
                          while the program is running.
                          pychecker does find these kind of errors.
                          >
                          Before posting my original question, I tried pychecker and it didn't
                          catch that error.
                          Sorry for the multiple posting earlier (you heard me right, not 2 but
                          3 identical). The basic checker of walking a parse tree, doing
                          imports by hand, and checking call signatures isn't awful. 60 lines.

                          /File:

                          from ng23mod1 import foo as foo
                          userid, password= 'abc', '123'
                          import random
                          foo( 'localhost', userid, password)
                          if random.uniform( 0, 1 )< .01: # 1 out of 100 times
                          foo( userid, password)

                          /Checker output:

                          foo ['Str', 'Name', 'Name'] found 3 expected
                          random ['Num', 'Num'] found 2 expected
                          foo ['Name', 'Name'] found 3 expected

                          But it's extremely delicate and at 60 lines only checks fixed-length
                          call signatures and functions, not even methods. If you have a
                          statement:

                          x= y.z()

                          Then 'y' has to be defined somewhere, so you could make some educated
                          guesses that way.

                          Comment

                          • Wolfgang Grafen

                            #14
                            Re: lint for Python?

                            No need to develop another lint tool. Just give the creator of pylint an
                            improvement proposal. This can be at least reported as a warning.

                            Even in a highly dynamic language like Python it is good to follow some
                            style guides. I try to avoid the same names if possible for different
                            functionality. This makes the code much more manageable and maintainable
                            and understandable for larger projects.

                            Pat schrieb:
                            I've been searching for a good multi-module lint checker for Python and
                            I haven't found one yet.
                            >
                            Pylint does a decent job at checking for errors only within a single
                            module.
                            >
                            Here's one of my problems. I have two modules.
                            >
                            In module one, I have a function:
                            >
                            def foo( host, userid, password ):
                            pass
                            >
                            In module two, I call that function:
                            >
                            foo( userid, password)
                            >
                            lint doesn't find that error and it won't be caught until it's called
                            while the program is running. I don't want that error found at 3AM.
                            >
                            I've never used a language that didn't catch that type of error. I'm
                            quite surprised that Python is being used by a number of major
                            companies. How you catch these types of errors?
                            >
                            I've spoken to tech support at Wing and they weren't aware of a
                            multi-module lint but they're considering putting their own lint into
                            their IDE.
                            >
                            Thank you

                            Comment

                            • Pat

                              #15
                              Re: lint for Python?

                              Bruno Desthuilliers wrote:
                              Pat a écrit :
                              >I've been searching for a good multi-module lint checker for Python
                              >and I haven't found one yet.
                              >>
                              >Pylint does a decent job at checking for errors only within a single
                              >module.
                              >>
                              >Here's one of my problems. I have two modules.
                              >>
                              >In module one, I have a function:
                              >>
                              >def foo( host, userid, password ):
                              > pass
                              >>
                              >In module two, I call that function:
                              >>
                              >foo( userid, password)
                              >>
                              >lint doesn't find that error
                              >
                              Nope, but even the most simple manual test should find it pretty quick.
                              >
                              >and it won't be caught until it's called while the program is
                              >running. I don't want that error found at 3AM.
                              >
                              Don't you ever test your code ???
                              >
                              >I've never used a language that didn't catch that type of error.
                              >
                              It does. Just try to run your code, and you'll have a nice traceback.
                              Unless of course 'foo' is rebound in module two to another callable
                              expecting only two parameters...
                              >
                              > I'm quite surprised that Python is being used by a number of major
                              >companies.
                              >
                              Perhaps do they rely more on testing and less on the compiler ? FWIW,
                              I've seen my share of bugs in declarativly statically typed languages,
                              and most of them were way nastier (and way less obvious) than the above
                              one.
                              >
                              > How you catch these types of errors?
                              >
                              Just like any other type of errors : testing, testing, and then add some
                              more tests.
                              >
                              I haven't gotten into unittesting. I've just started learning Python.

                              It also dawned on me why my original question is a bit lame. Python
                              supports default arguments; something that is new to me. How could lint
                              possibly know the correct number of arguments passed to it? Unless, of
                              course, lint knew which functions had default arguments or not.

                              I'll come back with more intelligent questions after I've actually
                              learned some Python.

                              Comment

                              Working...