8000 fix: Resolve some bug risks and code quality issues (#497) · twilio/twilio-python@d647789 · GitHub
[go: up one dir, main page]

Skip to content

Commit d647789

Browse files
sanketsauravchildish-sambino
authored andcommitted
fix: Resolve some bug risks and code quality issues (#497)
Changes: - Fix dangerous default argument in `twilio/base/serialize.py` (PYL-W0102) - Classmethods should have `cls` as the first arg. in `twilio/jwt/validation/__init__.py` and `twilio/base/page.py` (PYL-C0202) - Removed unused imports in `tests/unit/http/test_validation_client.py` and `tests/unit/http/test_http_client.py` (PYL-W0611) - Fix `len()` used as condition in `twilio/request_validator.py` (PYL-C1801) Also added `.deepsource.toml` configuration file to run continuous static analysis on the repository with DeepSource.
1 parent af20c9e commit d647789

File tree

7 files changed

+40
-11
lines changed

7 files changed

+40
-11
lines changed

.deepsource.toml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
version = 1
2+
3+
exclude_patterns = [
4+
'examples/**',
5+
6+
# auto-generated files
7+
'twilio/rest/**',
8+
'twilio/twiml/**',
9+
'tests/integration/**',
10+
11+
# compat files
12+
'twilio/compat.py',
13+
]
14+
15+
test_patterns = [
16+
'tests/**'
17+
]
18+
19+
[[analyzers]]
20+
name = "python"
21+
enabled = true
22+
23+
[analyzers.meta]
24+
max_line_length = 100
25+
skip_doc_coverage = ["module", "magic", "class"]

tests/unit/http/test_http_client.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
# -*- coding: utf-8 -*-
2-
import six
3-
42
import unittest
53

64
from mock import patch, Mock
7-
from requests import Request, Session
5+
from requests import Session
86

97
from twilio.http.http_client import TwilioHttpClient
108
from twilio.http.response import Response

tests/unit/http/test_validation_client.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import unittest
44

5-
import mock
65
from mock import patch, Mock
76
from requests import Request
87
from requests import Session

twilio/base/page.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def next(self):
4848
return self.get_instance(next(self._records))
4949

5050
@classmethod
51-
def process_response(self, response):
51+
def process_response(cls, response):
5252
"""
5353
Load a JSON response.
5454

twilio/base/serialize.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,14 @@ def prefixed_collapsible_map(m, prefix):
3939
if m == values.unset:
4040
return {}
4141

42-
def flatten_dict(d, result={}, prv_keys=[]):
42+
def flatten_dict(d, result=None, prv_keys=None):
43+
44+
if result is None:
45+
result = {}
46+
47+
if prv_keys is None:
48+
prv_keys = []
49+
4350
for k, v in d.items():
4451
if isinstance(v, dict):
4552
flatten_dict(v, result, prv_keys + [k])

twilio/jwt/validation/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,13 @@ def _generate_payload(self):
7272
}
7373

7474
@classmethod
75-
def _sort_and_join(self, values, joiner):
75+
def _sort_and_join(cls, values, joiner):
7676
if isinstance(values, string_types):
7777
return values
7878
return joiner.join(sorted(values))
7979

8080
@classmethod
81< 6D40 span class="diff-text-marker">-
def _hash(self, input_str):
81+
def _hash(cls, input_str):
8282
if not input_str:
8383
return input_str
8484

twilio/request_validator.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def add_port(uri):
5252
"""
5353
if uri.port:
5454
return uri.geturl()
55-
55+
5656
port = 443 if uri.scheme == "https" else 80
5757
new_netloc = uri.netloc + ":" + str(port)
5858
new_uri = uri._replace(netloc=new_netloc)
@@ -75,7 +75,7 @@ def compute_signature(self, uri, params, utf=PY3):
7575
:returns: The computed signature
7676
"""
7777
s = uri
78-
if len(params) > 0:
78+
if params:
7979
for k, v in sorted(params.items()):
8080
s += k + v
8181

@@ -117,7 +117,7 @@ def validate(self, uri, params, signature):
117117
valid_body_hash = compare(self.compute_hash(params), query["bodySHA256"][0])
118118
params = {}
119119

120-
# check signature of uri with and without port,
120+
# check signature of uri with and without port,
121121
# since sig generation on back end is inconsistent
122122
valid_signature = compare(self.compute_signature(uri_without_port, params), signature)
123123
valid_signature_with_port = compare(self.compute_signature(uri_with_port, params), signature)

0 commit comments

Comments
 (0)
0