[
https://issues.apache.org/jira/browse/PROTON-1835?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16452494#comment-16452494
]
Kim van der Riet commented on PROTON-1835:
------------------------------------------
This can be solved by defining {{__eq__()}} functions for each of the derived
classes. This is illustrated here with a similar test class {{mybin}}:
{noformat}
>>> import proton
>>> proton.decimal128(b'123') == b'123'
True
>>>
>>> class mybin(bytes):
... def __repr__(self):
... return 'mybin(%s)' % bytes.__repr__(self)
... def __eq__(self, other):
... if type(self) == type(other):
... return self == other
... else:
... return False
>>> mybin(b'123') == b'123'
False
>>> {mybin(b'123'): 'hello', b'123': 'world'}
{'123': 'world', mybin('123'): 'hello'}{noformat}
> [Python binding] Use of Python dict for AMQP maps does not allow derived or
> related keys of the same value
> ----------------------------------------------------------------------------------------------------------
>
> Key: PROTON-1835
> URL: https://issues.apache.org/jira/browse/PROTON-1835
> Project: Qpid Proton
> Issue Type: Bug
> Components: python-binding
> Reporter: Kim van der Riet
> Priority: Major
>
> The AMQP map (expressed as a list) {{[binary(123), "hello", decimal128(123),
> "world"]}} cannot be implemented in Python using the {{dict}} type. This
> happens because {{proton.decimal}} is derived from {{bytes}}, and the
> dictionary treats the keys as the same value and causes the first value to be
> overwritten by the second:
> {noformat}
> >>> import proton
> >>> {b'123': 'hello', proton.decimal128(b'123'): 'world'}
> {'123': 'world'}
> {noformat}
> Using the {{[]}} operator to add the values one at a time to an empty
> {{dict}} results in the same outcome. Even using related classes (ie both
> derived from a common parent) don't work:
> {noformat}
> >>> import proton
> >>> class mybin(bytes):
> ... def __repr__(self):
> ... return 'mybin(%s)' % bytes.__repr__(self)
> ...
> >>> {mybin(b'123'): 'hello', proton.decimal128(b'123'): 'world'}
> {mybin('123'): 'world'}
> {noformat}
> This issue highlights that the Python {{dict}} type is not suitable for
> representing AMQP maps. In addition, dicts do not guarantee ordering of the
> elements (although other Python classes such as {{collections.OrderedDict}}
> do). Solving this issue will probably require re-implementing the way AMQP
> maps are represented.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]