check type when assignment
Diez B. Roggisch
deets at nospam.web.de
Wed Jul 12 11:59:19 EDT 2006
pipehappy wrote:
> Hello everyone:
>
> Is there a way to check the type when do assignment?
>
> if I write:
> ab = bc
> and want to make sure the return value of isinstance(bc, klass) is True
> or I will raise
> a exception.
In general, not doable. The assignment operator is not overloadable.
Only if you use assignments of the form
a.foo = bar
you could overwrite the __setattribute__-method to achieve what you want.
Diez
More information about the Python-list
mailing list