Box icon indicating copy to clipboard operation
Box copied to clipboard

Add support for accessing nested items in BoxList using numpy-style tuple indexing.

Open Bit0r opened this issue 10 months ago • 6 comments

Allow BoxList to use numpy-style tuple indexing, similar to l[0,1,2,3], which is equivalent to l[0][1][2][3].

Bit0r avatar Apr 18 '24 15:04 Bit0r

@cdgriffith Could you approve the workflow review, please?

Bit0r avatar Apr 21 '24 08:04 Bit0r

This would need a new feature flag if added. As tuples are supported dictionary characters themselves.

Consider:


from box import Box
bx = Box({0: {1: {2: {3: 3}}}, (0, 1, 2, 3): 4})
print(bx[0,1,2,3])
# 4 

cdgriffith avatar Apr 26 '24 15:04 cdgriffith

I have implemented this feature only in the BoxList class, whereas Box is a different class and will still output normally. Using the following code in the unit tests is not a problem:

bx = Box({0: {1: {2: {3: 3}}}, (0, 1, 2, 3): 4})
assert bx[0, 1, 2, 3] == 4

But I will add some error messages to make it more user-friendly.

Bit0r avatar Apr 28 '24 16:04 Bit0r

My code only works for list and its subclasses. The first layer must be BoxList, and dict and its subclasses cannot appear in the middle.

Bit0r avatar Apr 28 '24 16:04 Bit0r

@cdgriffith Do you think there are any other problems with the code?

Bit0r avatar Apr 30 '24 09:04 Bit0r

I don't know how to program with PyPy, and I can't provide an equivalent version of it.

Bit0r avatar May 10 '24 13:05 Bit0r

Sorry for delay, I like the addition!

The pypy things is failing even on master as of now, need to sort that out so no something with this code.

cdgriffith avatar Jun 12 '24 02:06 cdgriffith