Rhodri James wrote:
On Sat, 21 Feb 2009 01:12:01 -0000, Darren Dale <dsdal...@gmail.com> wrote:
I would like to assert that a method accepts certain types....
from functools import wraps
def accepts(*types):
def check_accepts(f): ...
class Test(object):
@accepts(int)
def check(self, obj):
print obj
but now I want Test.check to accept an instance of Test as well....
An icky but relatively clear way to get around this is to gratuitously
subclass Test:
class AcceptableTest(object):
pass
class Test(AcceptableTest):
@accepts(int, AcceptableTest)
def check(self, obj):
print obj
To Increase the ick, but lowering the name pollution
(while making the _source_ read more clearly):
class Test(<Test base classes>):
pass # Just a placeholder for type checking
class Test(Test):
@accepts(int, Test)
def check(self, obj):
print obj
--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list