Pychecker

A

Anthony Greene

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?
 
R

Rick Zantow

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?

I think you're asking a lot from pychecker.

kop = 1
koi = 2

if True:
koo = 3

What would you like pychecker to report?
 
M

Matt Good

Anthony said:
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?

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.
 
S

skip

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
 
A

Anthony Greene

Anthony said:
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?

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.

Thanks guys, exactly what was needed.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,796
Messages
2,569,645
Members
45,369
Latest member
Carmen32T6

Latest Threads

Top