Language question

Gordon McMillan gmcm at hypernet.com
Tue Oct 19 19:04:03 EDT 1999


Brian Kelley writes:

> This question actually comes up due to accident (bug?)  Here is
> the scenario
> 
> class foo:
>       """insert foo here"""
> 
> def bar(foo):
>       """this should really be class bar(foo):  Insert bar
>       here"""
> 
> As far as python is concerned, this is prefectly legal except
> that the user of bar will probably get None for their troubles. 
> That is foobar = bar() is the same thing as foobar = None.

As will

def bar():
  #some long & painful calculation, but no return statement
 
> My question is, is there any real reason to allow this?  I.e.
> something cool and clever that I am not seeing?  Can I exploit
> this feature for nefarious deeds?  Inquiring minds want to know.

What's to disallow? There was a thread not long ago 
requesting differentiation of procedures and functions (yuck), 
and discussion of runtime checks of assigning the results of a 
function that has no results. That got a warmer reception, but 
not one I'd characterize as "excited".

Or are you talking about empty classes / functions? The 
former are very useful (giving attribute syntax to a dictionary); 
the latter might be used as a placeholder that is assigned to 
later.

- Gordon




More information about the Python-list mailing list