PEP 255: Simple Generators, Revised Posting
Tim Peters
tim.one at home.com
Sat Jun 23 17:27:45 EDT 2001
[Jeremy Hylton]
> Actually, they are in the parse tree.
Yikes! That's what I get for reading the code instead of typing what I
thought was the case <wink>.
> The compiler ignores "if 0" blocks by explicitly calling
> is_constant_false() in com_if_stmt and in the if_stmt case of
> symtable_node(). So it's easy enough to examine that part of the tree.
> ...
> This would be easy to fix in the case of yield for generators, except
> that I'm not sure it's easy to fix for names in general. There are
> lots of other strange possibilities:
>
> def f():
> if 0:
> exec foo
> def g(y):
> return x + y
>
> Should this get a SyntaxError about the bare exec making resolution
> of free variable x ambiguous?
Yes.
> def g(x):
> if 0:
> global x
>
> Should this get a SyntaxError about an argument being declared global?
Yes.
The answers can only be "no" if you think of "if 0:" as a C "#if 0"
preprocessor gimmick. The specific value after a Python "if" should have no
effect on statically-determined properties of Python code.
> I'm inclined not to worry about them, because they'd be a PITA to
> deal with and the "right" choice is far from obvious
Agreed it's a PITA, but disagree the right outcomes are unclear: change "0"
to "42" or "hmm" and the answers are obvious, yes?
> -- unless Guido wants to offer some pronouncements on just what
> the heck they mean.
I may not be able to read our code, but I can still channel Guido <wink>.
More information about the Python-list
mailing list