[Python-3000] why interfaces shouldn't be trusted
Nick Coghlan
ncoghlan at gmail.com
Thu May 11 14:24:03 CEST 2006
Marcin 'Qrczak' Kowalczyk wrote:
> "tomer filiba" <tomerfiliba at gmail.com> writes:
>
>> one thing that worries me with generic methods is, they would
>> dispatch based on types... which means my proxies would all break.
>> please, think of the proxies! ;)
>
> OTOH proxies generated by my Python<->Kogut bridge would break if
> hasattr was used to determine interfaces. For example if obj is a
> Kogut object wrapped in a Python object, then obj.__iter__ always
> succeeds, but calling the resulting function fails if the underlying
> object doesn't actually support iteration.
>
> (Types aren't currently reflected either, so type-based interface
> discovery would fail too, but I plan to change that.)
When you change type-based checks to work, you can make the rest of the slots
work properly too by generating wrapper types on the fly (i.e., generator a
type proxy as well as an instance proxy - you can use a type proxy cache do
avoid creating new ones all the time).
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
---------------------------------------------------------------
http://www.boredomandlaziness.org
More information about the Python-3000
mailing list