fix possible use of deallocated python object

 __dealloc__ method might be called when the object is partially deleted, so
e.g. its methods must not be called. Fix this by copying the code of the
methods which require no python object internals.

Closes gh-458.
Merge pull request #460 from juliantaylor/dealloc-fix

fix possible use of deallocated python object