Pychecker

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

    #1

    Pychecker

    Howdy, I had the impression that pychecker caught and reported such
    dynamic syntactical errors.

    #!/usr/bin/env python


    def add(i):
    i += 10

    status = 3

    if 1 == 1:
    statuss = 15

    add(status)

    =============== ========

    exalted sysfault$ pychecker foo.py
    Processing foo...

    Warnings...

    None

    =============== ========

    Hence the mispelling of status (statuss), which was done purposely to test
    if pychecker will acknowledge and report the error. Do i need to enable
    some type of pychecker option in order for it to pick up the error? I know
    that it is syntactically correct in python, however it's likely that
    'status' is meant. Am i wishing that pychecker will replace a statically
    typed language mechanism?

    --
    A wise man knows he knows nothing.

  • Rick Zantow

    #2
    Re: Pychecker

    Anthony Greene <sysfault@zetaf unc.net> wrote in
    news:pan.2006.0 6.09.18.10.58.7 46134@zetafunc. net:
    [color=blue]
    > Howdy, I had the impression that pychecker caught and reported such
    > dynamic syntactical errors.
    >
    > #!/usr/bin/env python
    >
    >
    > def add(i):
    > i += 10
    >
    > status = 3
    >
    > if 1 == 1:
    > statuss = 15
    >
    > add(status)
    >
    > =============== ========
    >
    > exalted sysfault$ pychecker foo.py
    > Processing foo...
    >
    > Warnings...
    >
    > None
    >
    > =============== ========
    >
    > Hence the mispelling of status (statuss), which was done purposely to
    > test if pychecker will acknowledge and report the error. Do i need to
    > enable some type of pychecker option in order for it to pick up the
    > error? I know that it is syntactically correct in python, however it's
    > likely that 'status' is meant. Am i wishing that pychecker will
    > replace a statically typed language mechanism?
    >[/color]

    I think you're asking a lot from pychecker.

    kop = 1
    koi = 2

    if True:
    koo = 3

    What would you like pychecker to report?


    --
    rzed

    Comment

    • Matt Good

      #3
      Re: Pychecker

      Anthony Greene wrote:[color=blue]
      > Howdy, I had the impression that pychecker caught and reported such
      > dynamic syntactical errors.
      >
      > #!/usr/bin/env python
      >
      >
      > def add(i):
      > i += 10
      >
      > status = 3
      >
      > if 1 == 1:
      > statuss = 15
      >
      > add(status)
      >
      > =============== ========
      >
      > exalted sysfault$ pychecker foo.py
      > Processing foo...
      >
      > Warnings...
      >
      > None
      >
      > =============== ========
      >
      > Hence the mispelling of status (statuss), which was done purposely to test
      > if pychecker will acknowledge and report the error. Do i need to enable
      > some type of pychecker option in order for it to pick up the error? I know
      > that it is syntactically correct in python, however it's likely that
      > 'status' is meant. Am i wishing that pychecker will replace a statically
      > typed language mechanism?[/color]

      That's a functional error, not a syntactical one. Analyzing the
      spelling of variables for similarity would lead to a lot of incorrect
      warnings since pychecker has no way to tell this apart from intentional
      similar spellings such as:

      values = [1, 2, 3]
      value = values[0]

      However, when the misspelling is made inside a local scope, rather than
      at the module level a warning is reported "test.py:8: Local variable
      (statuss) not used":

      def add(i):
      i += 10

      def test():
      status = 3
      if 1 == 1:
      statuss = 15
      add(status)


      This is why tools like pychecker (or pyflakes, pylint, or even a static
      code compiler) aren't a substitute for unit tests. They can definitely
      help catch common mistakes, but they can't ensure your code does what
      you intended.

      --
      Matt Good

      Comment

      • skip@pobox.com

        #4
        Re: Pychecker


        Rick> I think you're asking a lot from pychecker.

        Rick> kop = 1
        Rick> koi = 2

        Rick> if True:
        Rick> koo = 3

        Rick> What would you like pychecker to report?

        I thing the OP was hoping for a "not used" error, but it can only reasonably
        do that within a function, which it does do:

        pyc.py:2: Local variable (kop) not used
        pyc.py:3: Local variable (koi) not used
        pyc.py:6: Local variable (koo) not used

        At the module level it doesn't know that the suspect object isn't accessed
        from another module.

        Skip

        Comment

        • Anthony Greene

          #5
          Re: Pychecker

          On Fri, 09 Jun 2006 11:46:59 -0700, Matt Good wrote:
          [color=blue]
          > Anthony Greene wrote:[color=green]
          >> Howdy, I had the impression that pychecker caught and reported such
          >> dynamic syntactical errors.
          >>
          >> #!/usr/bin/env python
          >>
          >>
          >> def add(i):
          >> i += 10
          >>
          >> status = 3
          >>
          >> if 1 == 1:
          >> statuss = 15
          >>
          >> add(status)
          >>
          >> =============== ========
          >>
          >> exalted sysfault$ pychecker foo.py
          >> Processing foo...
          >>
          >> Warnings...
          >>
          >> None
          >>
          >> =============== ========
          >>
          >> Hence the mispelling of status (statuss), which was done purposely to test
          >> if pychecker will acknowledge and report the error. Do i need to enable
          >> some type of pychecker option in order for it to pick up the error? I know
          >> that it is syntactically correct in python, however it's likely that
          >> 'status' is meant. Am i wishing that pychecker will replace a statically
          >> typed language mechanism?[/color]
          >
          > That's a functional error, not a syntactical one. Analyzing the
          > spelling of variables for similarity would lead to a lot of incorrect
          > warnings since pychecker has no way to tell this apart from intentional
          > similar spellings such as:
          >
          > values = [1, 2, 3]
          > value = values[0]
          >
          > However, when the misspelling is made inside a local scope, rather than
          > at the module level a warning is reported "test.py:8: Local variable
          > (statuss) not used":
          >
          > def add(i):
          > i += 10
          >
          > def test():
          > status = 3
          > if 1 == 1:
          > statuss = 15
          > add(status)
          >
          >
          > This is why tools like pychecker (or pyflakes, pylint, or even a static
          > code compiler) aren't a substitute for unit tests. They can definitely
          > help catch common mistakes, but they can't ensure your code does what
          > you intended.[/color]

          Thanks guys, exactly what was needed.
          --
          A wise man knows he knows nothing.



          Comment

          Working...