Down casting Python objects
anfedorov at gmail.com
Wed Mar 10 14:31:14 CET 2010
On Wed, Mar 10, 2010 at 12:24 AM, Rami Chowdhury <rami.chowdhury at gmail.com>
> Could you tell us *why* you need to down-cast x? Explicit type-casting is
> usually unnecessary in Python...
Sure! It's related to the longer question I unwisely asked during PyCon 
(when no one had time to read it, I suppose).
I have a couple of different flavors of request objects which I'd like to
make conform to a single interface. So Request `x' come in, I determine
which kind of request I'm dealing with, and would like to "down-cast" it to
ARequest or BRequest, classes which will provide appropriate accessor
properties for the rest of the code to use.
An option clearly in line with Python's docs might be for `x' to be an
attribute of an ARequest instance, but that would complicate the code of
ARequest. What I'm looking for is a way of adding mix-in's at runtime, if
that makes sense.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-list