On Wed, Oct 5, 2011 at 11:25 PM, PatrickCD <patrick.do...@gmail.com> wrote:

> Nick,
>
> > It's never 'safe' to mess with the internals of Python like this. As a
> rule,
> > if you're trying to change the class of an existing object, that's a code
> > smell, and you should almost certainly be implementing it differently,
> such
>
> Hi. As a rule, when someone uses the term "code smell", that's a
> "cliche smell".
>

Feel free to reword it any way you wish. Trying to change the class of an
object usually means you're trying to do something that OO wasn't designed
to do. Just because Python makes it possible doesn't mean you should do it.


>
> Google bundles django with AppEngine, and django messes with the
> internals of Python like crazy, so Google hopefully does think it's
> safe in some cases.
>

Bundling doesn't signify endorsement. Also, I'm pretty sure Django doesn't
do anything like modifying a class instance's parents after  it's
instantiated.


> I want to put some data into the datastore. Depending on the value of
> that data, I want it to map to a different class when I get it back.
> Changing the __class__ attribute currently works. I posted this
> question for two reasons:
>
>  - to find out whether or not this approach was likely to break in
> some cases or with future versions of DataStore API.
>

Absolutely no guarantees on this front. You're breaking any number of
invariants by doing this, so things may break without notice at any time.


>  - because changing __class__ feels hackish and I was hoping someone
> might suggest a better approach
>

It _is_ a hack. A better approach would be to use a single class with
appropriate properties, or create a new instance of a new class and discard
the old one at such time as you need to make the change.

-Nick Johnson


>
> --
> You received this message because you are subscribed to the Google Groups
> "Google App Engine" group.
> To post to this group, send email to google-appengine@googlegroups.com.
> To unsubscribe from this group, send email to
> google-appengine+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/google-appengine?hl=en.
>
>


-- 
Nick Johnson, Developer Programs Engineer, App Engine

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to google-appengine@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en.

Reply via email to