Two-Dimensional Expression Layout

codewizard at gmail.com codewizard at gmail.com
Fri Aug 19 15:51:56 EDT 2016


For some special cases, I prefer the versions below.


On Friday, August 19, 2016 at 4:56:31 AM UTC-4, Lawrence D’Oliveiro wrote:
> [snip]
> 
> Computing a variable value (using redundant parentheses to avoid backslash-continuations):
> 
>     dest_rect = \
>         (
>             draw_bounds
>         +
>             Vector(col, row) * draw_bounds.dimensions
>         +
>             Vector(0, top_extra)
>         )

    dest_rect = sum([
        draw_bounds,
        (col, row) * draw_bounds.dimensions,
        Vector(0, top_extra),
    ])


> From <https://github.com/ldo/python_pixman/blob/master/pixman.py>, a complex condition (with redundant parentheses again):
> 
>     if (
>             not isinstance(src, Image)
>         or
>             mask != None and not isinstance(mask, Image)
>         or
>             not isinstance(dest, Image)
>     ) :
>         raise TypeError("image args must be Image objects")
>     #end if

    if any([
        not isinstance(src, Image),
        mask != None and not isinstance(mask, Image),
        not isinstance(dest, Image),
    ]):
        raise TypeError("image args must be Image objects")

Or equivalently:

    if not all([
        isinstance(src, Image),
        mask is None or isinstance(mask, Image),
        isinstance(dest, Image),
    ]):
        raise TypeError("image args must be Image objects")



More information about the Python-list mailing list