Paul Rubin wrote: > 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.
OK. The Python compiler would check that the name is declared but it would not check that it is defined before use? So this would be acceptable: def foo(): local x return x >>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. Problems: 1. your type checking system is optional and xml.dom does not use it 1a. even if xml.dom did declare the type, what if the type were declared conditionally e.g. try: unicode except NameError: XML_NAMESPACE<str> = "..." else: XML_NAMESPACE<unicode> = u"..." 2. the compiler does not have access to the names in other modules anyway >>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. How would you find the class definition for the Node object at compile-time? And by "slots" do you mean the existing Python slots concept or something new? > If the Node class doesn't > declare fixed slots, then they're dynamic and are looked up at runtime > in the usual way. So only pre-defined slotted attributes would be accessable (if the object uses slots). So the following would not work: foo = Foo() # slots defined foo.my_attribute = 'bar' print foo.my_attribute Cheers, Brian -- http://mail.python.org/mailman/listinfo/python-list