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

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

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major - P3
    • Resolution: Fixed
    • 3.11.2
    • 4.0
    • BSON
    • None

    Description

      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()`.

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: