Skip to content

Commit

Permalink
Added while-used message example (#6562)
Browse files Browse the repository at this point in the history
  • Loading branch information
matusvalo committed May 9, 2022
1 parent 63a9124 commit 737f5bd
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
12 changes: 12 additions & 0 deletions doc/data/messages/w/while-used/bad.py
@@ -0,0 +1,12 @@
import requests


def fetch_data():
i = 1
while i < 6: # [while-used]
print(f'Attempt {i}...')
try:
return requests.get('https://example.com/data')
except requests.exceptions.RequestException:
pass
i += 1
10 changes: 10 additions & 0 deletions doc/data/messages/w/while-used/good.py
@@ -0,0 +1,10 @@
import requests


def fetch_data():
for i in range(1, 6):
print(f'Attempt {i}...')
try:
return requests.get('https://example.com/data')
except requests.exceptions.RequestException:
pass
2 changes: 2 additions & 0 deletions doc/data/messages/w/while-used/pylintrc
@@ -0,0 +1,2 @@
[master]
load-plugins=pylint.extensions.while_used
1 change: 1 addition & 0 deletions doc/data/messages/w/while-used/related.rst
@@ -0,0 +1 @@
- `Stackoverflow discussion <https://stackoverflow.com/questions/920645/when-to-use-while-or-for-in-python>`_

0 comments on commit 737f5bd

Please sign in to comment.