"no variable or argument declarations are necessary."

Brian Quinlan brian at sweetapp.com
Thu Oct 6 04:55:19 EDT 2005


Paul Rubin wrote:
> Brian Quinlan <brian at sweetapp.com> writes:
> 
>>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
> 
> 
> Come on, you are asking silly questions.  Any reasonable C compiler
> would flag something like that and Python (with the flag set) should
> do the same.  If you want to ask substantive questions, that's fine,
> but stop wasting our time with silly stuff.

I'm not trying to be silly. I am trying to get a handle on the semantics 
that you are proposing. So we now have two requirements for the new 
declaration syntax (please let me know if I'm wrong):

o the variable must be declared
o the variable must be assigned

I would assume that you would make it so that assignment and delaration 
happen as part of the same statement?

> If type checking is implemented then the stdlib should be updated to
> add declarations for public symbols.  If not, the compiler would flag
> the undeclared symbol.  You could always declare it to be of type 'object'.

Fair enough.

> 
>>     try:
>>          unicode
>>     except NameError:
>>          XML_NAMESPACE<str> = "..."
>>     else:
>>          XML_NAMESPACE<unicode> = u"..."
> 
> 
> This wouldn't be allowed.

OK, that sucks.

> 
>>2. the compiler does not have access to the names in other modules anyway
> 
> 
> You're being silly again.  The compiler would examine the other module
> when it processes the import statement, just like it does now.

Right now, the compiler DOES NOT examine the contents of the other 
modules. All it does is generate an IMPORT_NAME instruction which is 
evaluation during runtime. So are you proposing that the compiler now 
scan other modules during compilation?

>>How would you find the class definition for the Node object at
>>compile-time? 
> 
> 
> By processing the xml.dom module when it's imported.

Import happens at runtime (see above). But you seem to want compile-time 
type checking.

Cheers,
Brian



More information about the Python-list mailing list