Uploaded image for project: 'Python Driver'
  1. Python Driver
  2. PYTHON-1335

Fix inefficient use of __slots__ in various classes

    XMLWordPrintable

Details

    • Improvement
    • Status: Closed
    • Major - P3
    • Resolution: Fixed
    • None
    • 3.5
    • Internal
    • None
    • Fully Compatible

    Description

      While investigating PYTHON-1317 I realized that our _WriteOp subclasses do not define __slots__. This means these classes will automatically include __dict__. From the Python docs:

      The action of a _slots_ declaration is limited to the class where it is defined. As a result, subclasses will have a _dict_ unless they also define _slots_ (which must only contain names of any additional slots).

      https://docs.python.org/2/reference/datamodel.html#__slots__

      >>> from pymongo.operations import InsertOne
      >>> i = InsertOne({})
      >>> i.__dict__
      {}
      

      This same problem is present in a number of other class hierarchies, including _WriteResult, _ServerMode, _ServerHeartbeatEvent, and TopologyEvent. We should fix up our usage of slots so that it does what we intend.

      Attachments

        Issue Links

          Activity

            People

              shane.harvey@mongodb.com Shane Harvey
              shane.harvey@mongodb.com Shane Harvey
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: