how to assert that method accepts specific types
Aahz
aahz at pythoncraft.com
Thu Mar 12 11:47:25 EDT 2009
In article <3f26a2f1-94cf-4083-9bda-7076959ad784 at k19g2000yqg.googlegroups.com>,
Darren Dale <dsdale24 at gmail.com> wrote:
>
>class Test(object):
> @accepts(int)
> def check(self, obj):
> print obj
>
>t = Test()
>t.check(1)
>
>but now I want Test.check to accept an instance of Test as well. Does
>anyone know how this can be accomplished? The following class
>definition for Test raises a NameError:
>
>class Test(object):
> @accepts(int, Test)
> def check(self, obj):
> print obj
Are you using Python 2.6 or later? You could probably write a tricky
class decorator that re-wraps all wrapped methods....
--
Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/
"All problems in computer science can be solved by another level of
indirection." --Butler Lampson
More information about the Python-list
mailing list