"no variable or argument declarations are necessary."

Paul Rubin http
Wed Oct 5 08:31:28 EDT 2005


Brian Quinlan <brian at sweetapp.com> writes:
> Aren't you looking for some of compile-time checking that ensures that
> only declared variables are actually used? If so, how does global help?

You'd have to declare any variable global, or declare it local, or it
could be a function name (defined with def) or a function arg (in the
function scope), or maybe you could also declare things like loop
indices.  If it wasn't one of the above, the compiler would flag it.

> >>Your making this feature "optional" contradicts the subject of this
> >> thread i.e. declarations being necessary.
> > They're necessary if you enable the option.
> 
> OK. Would it work on a per-module basis or globally?

Whatever perl does.  I think that means per-module where the option is
given as "use strict" inside the module.

> > def do_add(x->str, y->str):
> >       return '%s://%s' % (x, y)
> > def do_something(node->Node):
> >       if node.namespace == XML_NAMESPACE:
> >           return do_add('http://', node.namespace)
> >       elif node.namespace == ...
> 
> Wouldn't an error be generated because XML_NAMESPACE is not declared?

XML_NAMESPACE would be declared in the xml.dom module and the type
info would carry over through the import.

> And I notice that you are not doing any checking that "namespace" is a
> valid attribute of the node object. Aren't the typos class of error
> that you are looking to catch just as likely to occur for attributes
> as variables?

The node object is declared to be a Node instance and if the Node
class definition declares a fixed list of slots, then the compiler
would know the slot names and check them.  If the Node class doesn't
declare fixed slots, then they're dynamic and are looked up at runtime
in the usual way.



More information about the Python-list mailing list