Skip to content

Commit

Permalink
change requests timeout codemod semgrep pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
clavedeluna committed Feb 13, 2024
1 parent 464d9c9 commit 4584840
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
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)

0 comments on commit 4584840

Please sign in to comment.