NthItemOfAnyList: allow negative index (#1085)

This commit is contained in:
Alexopus
2025-10-09 11:00:26 +09:00
committed by GitHub
parent dc304e2dff
commit 190ca9a6fe
+3 -2
View File
@@ -450,7 +450,7 @@ class NthItemOfAnyList:
def INPUT_TYPES(s):
return {"required": {
"any_list": (any_typ,),
"index": ("INT", {"default": 0, "min": 0, "max": sys.maxsize, "step": 1, "tooltip": "The index of the item you want to select from the list."}),
"index": ("INT", {"default": 0, "min": -sys.maxsize, "max": sys.maxsize, "step": 1, "tooltip": "The index of the item you want to select from the list. Use negative values to select from the end (e.g., -1 for last item, -2 for second to last)."}),
}
}
@@ -464,7 +464,8 @@ class NthItemOfAnyList:
def doit(self, any_list, index):
i = index[0]
if i >= len(any_list):
list_len = len(any_list)
if i >= list_len or i < -list_len:
return (any_list[-1],)
else:
return (any_list[i],)