dell / libsmbios

library for interacting with Dell SMBIOS tables
Other
192 stars 39 forks source link

Fix the TokenTable iterator implementation #100

Open troygraben opened 3 years ago

troygraben commented 3 years ago

The __iter__ function must perform initialization and return the iterator object itself. The __next__ function must return the next item or raise StopIteration when no more elements are available.

This fixes the StopIteration exception being uncaught by the for loop when the iterator reaches the end of the collection. This could be encountered when calling smbios-token-ctl --dump-tokens.

superm1 commented 3 years ago

Cc @srinivasgowda and @goperry

Celelibi commented 3 years ago

This is actually the cause of issue #86 (which has been closed for some reason). The issue arise because of PEP 0479. Since python 3.7 raising a StopIteration exception explicitely inside a generator is deprecated and now raises a RuntimeException.

I think a much simpler fix for this could be to turn the raise StopIteration into a return. In its current state, this PR would disallow concurrent iterations of the TokenTable. (Moreover, calling __next__ on a iterator that already eached the end would call still token_table_get_next, which seems pretty surprising.)

troygraben commented 3 years ago

@Celelibi Your approach sounds much more sensible to me. It seems that many docs online still reference using StopIteration even though this PEP 0479 is has been in place for many years.

superm1 commented 3 years ago

Cc @dell-client-linux

kalvdans commented 1 year ago

This change fixes the problem for me as well. Please merge :)

4oijq342 commented 1 year ago

Hi, still experiencing this issue.