Skip to content

Decoder with OrderedDict does not work. #119

Closed

Description

@spritetong

The following codes causes that subclasses of "class dict" (such as OrderedDict) do not work:

if (PyDict_Check(current.object))
// If it's a standard dictionary, this is +20% faster
rc = PyDict_SetItem(current.object, key, value);
else
rc = PyObject_SetItem(current.object, key, value);

Decoder.py.txt

Activity

  1. lelit commented on Mar 17, 2019

    @lelit
    Contributor

    Thanks for the report.

    Surprisingly, using PyDict_SetItem() on dict subclass such as OrderedDict results in a incomplete dictionary:

    >>> from collections import OrderedDict
    >>> from rapidjson import Decoder
    >>> class OrderedDecoder(Decoder):
    ...     def start_object(self):
    ...         return OrderedDict()
    ... 
    >>> od = OrderedDecoder()
    >>> a = od('{"foo": "bar"}')
    >>> print(a)
    OrderedDict([])
    >>> a == {"foo": "bar"}
    True
  2. spritetong commented on Mar 17, 2019

    @spritetong
    Author

    Thank you for your reply.
    >>> a == {"foo": "bar"}
    True
    I think because dict.__eq__() method is not overrided by OrderedDict.

  3. lelit commented on May 11, 2019

    @lelit
    Contributor

    Solved in v0.7.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions