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

SON class should be compatible with Python 3's OrderedDict API

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 4.0
    • Affects Version/s: 3.11.2
    • Component/s: BSON
    • Labels:
      None

      The problem is that in all the cases of the normal `dict` or `OrderedDict` the returned object has a `set` interface, so this code should work for any `dict`:

      ```
      from six import viewkeys
      viewkeys(d) - {'a', 'b'}
      ```

      The above code fails for Python3 with:

      ```
      TypeError: unsupported operand type(s) for -: 'list' and 'set'
      ```

      When using the `six.viewkeys()` it maps it to `viewkeys() for Python2 and `keys()` for Python3.

      In Python2 `dict().viewkeys()` returns `dict_keys([])`.
      In Python3 `dict().keys()` also returns `dict_keys([])`.

      For Python2: `OrderedDict().viewkeys()` returns `KeysView(OrderedDict())`
      For Python3: ``OrderedDict().keys()` returns `odict_keys([])`

      The `SON` class returns `list` for `SON().keys()`.

            Assignee:
            julius.park@mongodb.com Julius Park (Inactive)
            Reporter:
            mabewlun@gmail.com Szymon LipiƄski
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: