Status: New
Owner: [email protected]
Labels: Type-Defect Priority-Medium
New issue 653 by [email protected]: Repeated fields in python do not
implement the "index()" function
http://code.google.com/p/protobuf/issues/detail?id=653
What steps will reproduce the problem?
1. Define a protobuf message that uses a repeated field.
2. Compile the protobuf to python code.
3. Attempt to search for a value in the repeated field "list" using
the "index" function.
What is the expected output?
Return the matching value from the repeated field list, or ValueError as
appropriate. (The specified behavior of the "index" function.)
What do you see instead?
AttributeError: 'RepeatedCompositeFieldContainer' object has no
attribute 'index'
What version of the product are you using? On what operating system?
Protoc 2.5 on Windows 7.
Please provide any additional information below.
Repeated fields purport to generally function as python lists, in the duck
typing sense. Not implementing support for something relatively basic like
the "index" function definitely violates the principle of least surprise.
It appears that the solution would be as straightforward as adding the
following method definition to RepeatedScalarFieldContainer in
containers.py:
def index(self, elem):
"""Finds the index of a given item in the list. Similar to
list.index(elem)."""
return self._values.index(elem)
--
You received this message because this project is configured to send all
issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings
--
You received this message because you are subscribed to the Google Groups "Protocol
Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.