Sorry, I wrote my last e-mail too fast (my example is totally wrong).
My objective is to define a class where some attributes can be optionnal.
If an optionnal attribute is defined then it should be a String for example.
I would like to have something like :
String = IsOneOf(str, unicode, NoneType)
class MyClass(object):
@accept(String, String)
def __init__(a, b=None):
blabla ...
but None cannot be used with the operator IsOneOf, etc.
Does it mean that with typecheck, a method or function looses its ability
to have optionnal argument ?
Thx,
Marc.
2009/1/11 shi dingan <shi...@gm...>
> Hi,
>
> I would like to define a class where an
> attribute can be None.
> For instance :
> @accept(String, String)
> class MyClass(a, b=None):
> if b:
> return b
> else:
> return a
> I didn't find a way to use typecheck on this kind
> of class. I tried to define String with
> String = IsOneOf(str, unicode, NoneType) but it does
> not work. It seems that 'None' can not
> be checked. Have you any idea ?
>
> Regards,
> Marc.
>
>
|