In Python 2, objects automatically inherit the __hash__ of their parent
class. In Python 3, objects that override __eq__ do not automatically inherit
__hash__, so these objects were not hashable under Python 3. Additionally,
mutable BSON types and types that overide __eq__ but did not explicitly define
__hash__ had broken __hash__ methods under Python 2. This commit unifies the
hashing behavior between Python versions and fixes the __hash__ methods such
that two BSON objects hash the same only if they are equal.
N.B.: bson.code.Code and bson.regex.Regex are no longer hashable under Python 2
because they are mutable.
When encoding a document in C while running in a python sub interpreter
(e.g. mod_wsgi spawning sub interpreters) PyMongo would often have
to reload its cache of pure python types - ObjectId, Timestamp,
UUID, etc. - raising RuntimeWarning in the process. The reason this was
necessary is described in the mod_wsgi documentation here:
https://code.google.com/p/modwsgi/wiki/ApplicationIssues#Multiple_Python_Sub_Interpreters
With workarounds documented here:
http://api.mongodb.org/python/2.6.2/faq.html#does-pymongo-work-with-mod-wsgi
With this commit PyMongo will no longer use cached pure python types
when running in a sub interpreter. Instead it will look up pure python
types as needed (primarily when decoding BSON). This eliminates the
problem described in the mod_wsgi docs and eliminates the need for the
Runtime warning.
Many of the pymongo modules have been moved into the bson
package. Aliases for those modules have been added to the pymongo
package, without deprecation warnings for now. Application developers
should begin to use the bson namespace, as deprecation of moved
modules will probably begin in the next release.