@decorators

Mark 'Kamikaze' Hughes kamikaze at kuoi.asui.uidaho.edu
Sun Aug 8 20:48:44 EDT 2004


Mark Bottjer <mark_bottjer at hotmail.com>
wrote on Fri, 06 Aug 2004 16:10:37 -0400:
> John Roth wrote:
>> All of the existing packages (at least to my knowledge) use
>> descriptors to wrap the necessary functions. They could be
>> very easily reimplemented in terms of the decorator syntax.
>> However, the decorator syntax brings no new functionality
>> to the table; it's simply syntactic sugar for already existing
>> functionality.
> Exactly. What's more, I don't think that decorators are really the ideal 
> way to express DBC, either. For one thing, pre and post conditions often 
> want access to at least the argument list, and often to the internal 
> variables of the definition. I don't think that this will be possible 
> with the decorators as proposed, since they are outside the scope of the 
> function.

  You can already do pre- and post-conditions without new syntax:

import types
def intdiv(a, b):
    # preconditions
    assert type(a) == types.IntType
    assert type(b) == types.IntType
    assert b != 0
    rc = None
    try:
        # body
        rc = a // b; return rc
    finally:
        # postconditions
        assert type(rc) == types.IntType

  If assignment was an expression, that return would be a little nicer,
but it's acceptable.

-- 
 <a href="http://kuoi.asui.uidaho.edu/~kamikaze/"> Mark Hughes </a>
"Virtues foster one another; so too, vices.
 Bad English kills trees, consumes energy, and befouls the Earth.
 Good English renews it." -The Underground Grammarian, v1n2



More information about the Python-list mailing list