Skip to content

Commit

Permalink
try to use ins.get_length() to detect children overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
t-kalinowski committed Nov 13, 2024
1 parent 019a10a commit abe0f37
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions inst/python/rpytools/ark_variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,26 @@

MAX_DISPLAY = 100


def get_keys_and_children(inspector):
# positron frontend only displays the first 100 items, then the count of the rest.
keys, values = [], []
keys_iterator = iter(inspector.get_children())
# positron frontend only displays the first 100 items, then the length of the rest.
try:
for _ in range(MAX_DISPLAY):
key = next(keys_iterator)
keys.append(str(key))
values.append(inspector.get_child(key))
except StopIteration:
return keys, values

n_remaining = 0
for n_remaining, _ in enumerate(keys_iterator, 1):
pass
if n_remaining > 0:
keys.append("[[...]]")
values.append(ChildrenOverflow(n_remaining))
for key in islice(keys_iterator, MAX_DISPLAY):
keys.append(str(key))
values.append(inspector.get_child(key))

if len(keys) == MAX_DISPLAY:
# check if there are more children
n_children = inspector.get_length()
if n_children == 0:
# no len() method, finish iteratoring over keys_iterator to get the true size
for n_children, _ in enumerate(keys_iterator, MAX_DISPLAY + 1):
pass
n_remaining = n_children - MAX_DISPLAY
if n_remaining > 0:
keys.append("[[...]]")
values.append(ChildrenOverflow(n_remaining))

return keys, values

Expand All @@ -28,6 +30,7 @@ def get_child(inspector, index):
key = next(islice(inspector.get_children(), index - 1, None))
return inspector.get_child(key)


class ChildrenOverflow:
def __init__(self, n_remaining):
self.n_remaining = n_remaining

0 comments on commit abe0f37

Please sign in to comment.