I am not aware of a way to do that, if only because it is rarely what you would want ("all classes" could include more than you realize and really intended). However, SWIG does support its own macro system, so you could probably do something like:
%define PY_HASHABLE(TypeName)
%extend TypeName {
bool __eq__(const TypeName &other) { return $self == &other; }
bool __ne__(const TypeName &other) { return $self != &other; }
long __hash__() { return (long) $self; } // hash: just address of C struct
}
%enddef
Then you would do
#if defined(SWIGPYTHON)
PY_HASHABLE(Foo)
PY_HASHABLE(Bar)
#endif
etc. You can have multiple extend clauses for a given class so the above does not interfere with other extensions.