PEP 308: Pep Update

Evan Simpson evan at 4-am.com
Thu Feb 13 14:43:10 EST 2003


Andrew Dalke wrote:
> That is, code which in the small looks like normal Python if/else
> statement is really an if/else expression once you look in the
> larger scope, which may be indefinitely away.
> 
> I don't like that.  I would rather use two temporary names.

So, use two temporary names?  Yes, I know, other people's code.

This is another reason why I keep promoting mandatory parens.  They 
would fix this (among other ambiguities) as long as the initial token is 
required to be '(if'.  In other words, don't allow whitespace or 
comments between the opening paren and the 'if':

   # get the 2-ple of name's value and who owns it
   a = (
     #  The value can be cached or in the database
     (if is_cached:
       self._get_cache[name]
     else:
       self.connection.fetch(name)
     ),  # database already open when getting
source

      # The ownership is stored in the database (if the
      # name starts with "DB") or from the web service
      (if x.startswith("DB")
        self.connection.get_owner(name)
      else:
        self.webservice.get_owner_by_name(name)
      )
   )

Cheers,

Evan @ 4-am







More information about the Python-list mailing list