tool to check whether formal and actual parameters have similar names

G. S. Hayes sjdevnull at yahoo.com
Tue Aug 10 18:22:11 CEST 2004


"Amir  Michail" <amichail at gmail.com> wrote in message news:<cfa3hb$387 at odak26.prod.google.com>...
> I was wondering if there is a tool that will perform some heuristic
> checking of actual and formal parameters to warn about likely errors.
> 
> Such a tool could check that formal and actual parameters have similar
> names.
> 
> For example:
> 
> def plot(x,y): ...
> 
> plot( x1, y1 ) # ok
> 
> plot( y1, x1 ) # not ok, but this is ok:  plot (x=y1, y=x1)

I'm not sure how generally useful this would be.  There are just too
many circumstances where the name in the definition and the name you
call with are legitimately quite different:

def plot(x, y):
...
plot(square.width, square.height)
for column in range(8):
    for row in range(8):
        move_pawn_to(column, row)
        plot(column, row)
 
for i in range(10):
    for j in range(10):
        plot(i,j)  #along with other stuff using the loop variables

def write_log(string_to_send):    # probably a log.write method in
real life
...
write_log(server.error_message)
write_log(user.username)

def wait_for_connection(socket):
...
wait_for_connection(servers["yahoo"])

It _might_ be somewhat useful to have something that detects ONLY when
you are calling with similar names in a different order.  Even that
isn't necessarily useful, there might be non-trivial cases something
like:

class generic_tree():
    def insert_member(child, parent):
class gui_window_tree(our_tree):
class crypto_algorithms_tree(our_tree):
...
(child, parent) = fork_wrapper()
GUIWindows.insert_member(child, parent)
EncryptionAlgorithms.insert_member(parent, child)

where flip-flopping names made sense.  Though this isn't a
particularly great example, and it might generally be a decent lint
warning.



More information about the Python-list mailing list