Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions doc/data/messages/u/use-a-generator/bad.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from random import randint

all([randint(-5, 5) > 0 for _ in range(10)]) # [use-a-generator]
any([randint(-5, 5) > 0 for _ in range(10)]) # [use-a-generator]
3 changes: 3 additions & 0 deletions doc/data/messages/u/use-a-generator/details.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
By using a generator you can cut the execution tree and exit directly at the first element that is ``False`` for ``all`` or ``True`` for ``any`` instead of
calculating all the elements. Except in the worst possible case where you still need to evaluate everything (all values
are True for ``all`` or all values are false for ``any``) performance will be better.
4 changes: 4 additions & 0 deletions doc/data/messages/u/use-a-generator/good.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from random import randint

all(randint(-5, 5) > 0 for _ in range(10))
any(randint(-5, 5) > 0 for _ in range(10))
2 changes: 2 additions & 0 deletions doc/data/messages/u/use-a-generator/related.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- `PEP 289 โ€“ Generator Expressions <https://peps.python.org/pep-0289/>`_
- `Benchmark and discussion during initial implementation <https://github.com/PyCQA/pylint/pull/3309#discussion_r576683109>`_
โšก