Make Store.namespaces an empty generator #1432
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
90f6fe5 changed
to
This resulted in
Store.namespaces
no longer being an emtpy generatorby default (see https://stackoverflow.com/q/13243766).
The reason it was removed is because it is unreachable code, however I
did not consider that it would make the function an empty generator.
The reason why
if False: yield None
made it an empty generator isbecause the presence of the yield keyword informs CPython that a
function is a generator:
https://www.python.org/dev/peps/pep-0255/#why-a-new-keyword-for-yield-why-not-a-builtin-function-instead
There are several ways of making an empty generator:
if False: yield
return
andyield
yield from ()
Both
if False: yield
andreturn
;yield
results in same bytecodehowever, which is that of an empty function, and they are both equally
confusing I would say.
yield from ()
is somewhat clearer, but the bytecode of the funcitonlooks very different from an empty function (see https://stackoverflow.com/a/61496399)
So the best option I see is to just put back what was there and add a
comment and a test to prevent the issue from re-occuring.
Fixes #1431