allowing braces around suites

Jacek Generowicz jacek.generowicz at cern.ch
Fri Aug 27 10:35:42 EDT 2004


Kjetil Torgrim Homme <kjetilho at yksi.ifi.uio.no> writes:

> often when re-factoring code, I need to change the indent level of
> some chunk of code.  due to the lack of an end marker, my Emacs has
> to use heuristics when re-indenting,

You've lost me here.

When you want to change the indent level of some chunk of Python code
in Emacs, you highlight the chunk of code and hit C-c > or C-c <.

I don't see any scope for heuristics here.

>     def appraise_insurance(rental_cars):
>         assert isinstance(rental_cars, (list, tuple))
>     
>         for car in rental_cars:
>         {
>             if car.make == "Lamborghini":
>                 car.insurance = 1000.00
>             elif car.make == "Lada":
>                 car.insurance = 50.00
>             else:
>                 car.insurance = 100.00
>         }
>         logger.debug("Insurance values updated")

> the single pair of braces is enough.  there is now no risk of Emacs
> including the debug line into the else branch unnoticed.

How about

    for car in rental_cars:
        if car.make == "Lamborghini":
            car.insurance = 1000.00
        elif car.make == "Lada":
            car.insurance = 50.00
        else:
            car.insurance = 100.00
            pass
        pass
    logger.debug("Insurance values updated")

?

Hmm ... not pretty, but at least it doesn't PERLize the language.

> what do you think?  should I write a PEP?

Yes please write a PEP. It will be formally rejected, thereby forming
an excellent reference to which we might direct people who come up
with similar ideas.



More information about the Python-list mailing list