i answered my own question by writing it out
class A:
def __init__(self):
self.my_indexes = [4, 2, 3, 0, 1] #my_list, sorted
self.my_list = [40, 50, 20, 30, 10]
def list_comprehension(self):
return [self.my_list[i] for i in self.my_indexes]
def list_generator(self):
return (self.my_list[i] for i in self.my_indexes)
def a_scope():
my_a = A()
return my_a.list_comprehension()
def a_scope_two():
my_a = A()
return my_a.list_generator()
def out_scope():
test_arr = a_scope()
test_stream = a_scope_two()
#it makes sense to be able to get this, since list_comprehension allocated all the mem,
#and is able to return it in full even after object destruction:
print(test_arr)
#but if generators are a stream, and this is indexing non-accessible memory, how is it working?
print(test_stream)
#(answer: it's returning a valid generator object type but no it's not usable)
output
>>> import temp_mytest
>>> temp_mytest.out_scope()
[10, 20, 30, 40, 50]
<generator object A.list_generator.<locals>.<genexpr> at 0x7f99542bea40>
>>>