New PEP: The directive statement

Nathan Gray n8gray at caltech.edu.is.my.e-mail.address
Tue Mar 20 22:31:04 EST 2001


Martin von Loewis wrote:

> Please have a look at the PEP below. It is intended to replace the
> __future__ import suggested in PEP 236.

Excellent work, Martin.  As it stands, I would prefer this to __future__
on grounds of clarity alone.  Last time I checked, though, my name wasn't 
Guido, so you can take that for what it's worth.  Thanks for putting your
money where your mouth was.  Or putting your additional keystrokes where 
your original keystrokes were.  Usenet stretches the boundaries of our 
cliches...

I've got a couple of comments about the design, though.

> 
> Syntax
> 
>     A directive_statement is a statement of the form
> 
>         directive_statement: 'directive' NAME [atom] [';'] NEWLINE
> 
>     The name in the directive indicates the kind of the directive; it
>     defines whether the optional atom can be present, and whether
>     there are further syntactical or semantical restrictions to the
>     atom. In addition, depending on the name of the directive, certain
>     additional syntactical or semantical restrictions may be placed on
>     the directive (e.g. placement of the directive in the module may be
>     restricted to the top of the module).

This syntax works but leaves little room for the future (no pun intended).  
Only one directive can be placed on a line, and using whitespace to link NAME
with its possible atom seems inconsistent with the way similar constructs
in Python work. (e.g. import general.lessgeneral.specific)

Would you consider using this sort of syntax instead?

   directive_statement: "directive" directive_ID ("," directive_ID)* 
                            [";"] NEWLINE
   directive_ID:        identifier ("." identifier)*

I understand that there are those who want to keep things as dead-simple as
possible, and there are good reasons for *not* wanting people to put multiple
directives on one line, but at the very least consider changing the syntax to 
NAME ["." atom] to allow for more elegant extension in the future if we 
decide that this functionality is desirable.

My second comment is that you may want to consider adopting a form of the 
__future__ proposal's runtime semantics for directive statements.  Perhaps 

    directive transitional.nested_scopes

could create a "_Feature object" called nested_scopes identical to the one
proposed in "back to the __future__".

    print nested_scopes.getOptionalRelease()   # prints "(2, 1, 0, 'beta', 1)"

Note that not all directive statements would need to have runtime 
semantics.  In the case of "transitional", though, it seems like a 
useful idea.

Well, that's all for now.  Lest it sound like I'm blasting Martin's PEP, 
I should reiterate that I think it's the way to go.  I've just got a 
quibble and a suggestion here and there.

Thanks again, Martin,

-n8

-- 
_.~'^`~._.~'^`~._.~'^`~._.~'^`~._.~'^`~._
               Nathaniel Gray
     California Institute of Technology
      Computation and Neural Systems
       n8gray <at> caltech <dot> edu
_.~'^`~._.~'^`~._.~'^`~._.~'^`~._.~'^`~._




More information about the Python-list mailing list