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

change requests timeout codemod semgrep pattern #256

Merged
merged 1 commit into from
Feb 13, 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
20 changes: 10 additions & 10 deletions src/core_codemods/add_requests_timeouts.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,20 @@ def on_result_found(self, original_node, updated_node):
- pattern-inside: |
import requests
...
- pattern: $CALL(...)
- pattern-not: $CALL(..., timeout=$TIMEOUT, ...)
- pattern: requests.$CALL(...)
- pattern-not: requests.$CALL(..., timeout=$TIMEOUT, ...)
- metavariable-pattern:
metavariable: $CALL
patterns:
- pattern-either:
- pattern: requests.get
- pattern: requests.post
- pattern: requests.put
- pattern: requests.delete
- pattern: requests.head
- pattern: requests.options
- pattern: requests.patch
- pattern: requests.request
- pattern: get
- pattern: post
- pattern: put
- pattern: delete
- pattern: head
- pattern: options
- pattern: patch
- pattern: request
"""
),
transformer=LibcstTransformerPipeline(TransformAddRequestsTimeouts),
Expand Down
12 changes: 12 additions & 0 deletions tests/codemods/test_add_requests_timeouts.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,15 @@ def test_not_requests(self, tmpdir):
demands.get("https://example.com")
"""
self.run_and_assert(tmpdir, original, original)

def test_chaining(self, tmpdir):
# See issue https://github.com/pixee/codemodder-python/issues/244
original = """
import requests
requests.get("https://example.com").json()
"""
expected = f"""
import requests
requests.get("https://example.com", timeout={TIMEOUT}).json()
"""
self.run_and_assert(tmpdir, original, expected)
Loading