Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[flake8-bandit] fix S113 false positive for httpx without timeout argument #12213

Merged
merged 3 commits into from
Jul 6, 2024
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
35 changes: 18 additions & 17 deletions crates/ruff_linter/resources/test/fixtures/flake8_bandit/S113.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,23 @@ async def foo():
async with httpx.AsyncClient(timeout=5) as client:
await client.get('https://gmail.com')

httpx.get('https://gmail.com')
httpx.post('https://gmail.com')
httpx.put('https://gmail.com')
httpx.delete('https://gmail.com')
httpx.patch('https://gmail.com')
httpx.options('https://gmail.com')
httpx.head('https://gmail.com')
httpx.Client()
httpx.AsyncClient()

async def bar():
async with httpx.AsyncClient() as client:
await client.get('https://gmail.com')

with httpx.Client() as client:
client.get('https://gmail.com')

# Errors
requests.get('https://gmail.com')
requests.get('https://gmail.com', timeout=None)
Expand All @@ -41,31 +58,15 @@ async def foo():
requests.head('https://gmail.com')
requests.head('https://gmail.com', timeout=None)

httpx.get('https://gmail.com')
httpx.get('https://gmail.com', timeout=None)
httpx.post('https://gmail.com')
httpx.post('https://gmail.com', timeout=None)
httpx.put('https://gmail.com')
httpx.put('https://gmail.com', timeout=None)
httpx.delete('https://gmail.com')
httpx.delete('https://gmail.com', timeout=None)
httpx.patch('https://gmail.com')
httpx.patch('https://gmail.com', timeout=None)
httpx.options('https://gmail.com')
httpx.options('https://gmail.com', timeout=None)
httpx.head('https://gmail.com')
httpx.head('https://gmail.com', timeout=None)
httpx.Client()
httpx.Client(timeout=None)
httpx.AsyncClient()
httpx.AsyncClient(timeout=None)
with httpx.Client() as client:
client.get('https://gmail.com')

with httpx.Client(timeout=None) as client:
client.get('https://gmail.com')
async def bar():
async with httpx.AsyncClient() as client:
await client.get('https://gmail.com')
async def baz():
async with httpx.AsyncClient(timeout=None) as client:
await client.get('https://gmail.com')
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub(crate) fn request_without_timeout(checker: &mut Checker, call: &ast::ExprCal
keyword.range(),
));
}
} else {
} else if module == "requests" {
checker.diagnostics.push(Diagnostic::new(
RequestWithoutTimeout { implicit: true, module: module.to_string() },
call.func.range(),
Expand Down
Loading
Loading