Python

Python

Made by DeepSource

Found yield statement inside a comprehension PTC-W0025

Bug risk
Major

Do not use yield inside a comprehension as it will return a generator object. Use a generator expression instead.

Note: Use of yield inside a comprehension was allowed till Python 3.7 but is a syntax error from Python 3.8 onwards.

Bad practice

number_generator = [(yield num) for num in range(1,1000)]

Recommended

number_generator = (num for num in range(1,1000))