PEP 255: Simple Generators
Tim Peters
tim.one at home.com
Tue Jun 19 19:54:13 EDT 2001
[Russell E. Owen]
> In my opinion, "use the documentation", "if you are modifying it then
> you'd better know what it does", "it'll be clear from context" are all
> red flags. That sort of thinking leads to confusing write-only code.
Then you must have terrible problems reading Python functions today, yes?
"def" doesn't tell you *anything* about their behavior, and, e.g., whether a
function adds 1 to an input and returns that, or returns nothing at all, or
sends email to Afghanistan and returns a tuple of time.time() values, are
all mysteries.
> Since a generator is very different than a function, why not mark it as
> such right up front?
>From my POV, because there's no practical benefit. BTW, they are very much
functions: they happen to return a generator-iterator, though. This
function *may* also return a generator-iterator in 2.2:
def fgh(i):
return xyz(i)
Ditto:
def xyz(i):
return external.table[i]
Do you want to call those "gen" too? If you want to know what a function
returns, docstrings and comments are the only ways Python supports now.
Static typing is the way out of that one, not a profusion of new synonyms
for "def".
More information about the Python-list
mailing list