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

Fix inefficient use of __slots__ in various classes

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 3.5
    • Affects Version/s: None
    • Component/s: Internal
    • Labels:
      None
    • Fully Compatible

      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.

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

              Created:
              Updated:
              Resolved: