You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Obviously (actually not) the end-user code breaks.
Desired solution
I propose considering as error all cases where a generator implicitly interpreted as boolean. It will always return True even if a generator is exhausted, so this is useless. Error text should contain "to check if value is None use is not None".
The text was updated successfully, but these errors were encountered:
Pierre-Sassoulas
changed the title
Consider if some_generator as a mistake
Raise a warning using-constant-test when casting a generator to a boolean as they are always truthey
Jun 10, 2022
If not, then it's because the name can't be inferred by astroid as a nodes.GeneratorExp. Could you open an issue there? Another way of putting it: if n.test.inferred()[0] below was a nodes.GeneratorExp, this would already work (I think).
>>>code="""... def get_generator():... return (x for x in range(0))... x = get_generator()... if x: #@... pass... """>>>n=astroid.extract_node(code)
>>>n<Ifl.5at0x102732470>>>>n.test<Name.xl.5at0x10279c0d0>>>>n.test.inferred()
[Uninferable]
Current problem
Suppose library code:
and code that use the function:
At some point, authors decide to change signature in this way:
Obviously (actually not) the end-user code breaks.
Desired solution
I propose considering as error all cases where a generator implicitly interpreted as boolean. It will always return
True
even if a generator is exhausted, so this is useless. Error text should contain "to check if value is None useis not None
".The text was updated successfully, but these errors were encountered: