Down casting Python objects

Andrey Fedorov anfedorov at
Wed Mar 10 14:31:14 CET 2010

On Wed, Mar 10, 2010 at 12:24 AM, Rami Chowdhury <rami.chowdhury at>

> 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 [1]
(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...
URL: <>

More information about the Python-list mailing list