Skip to content

Commit e9cd973

Browse files
committed
Fix various ruff/pylint warnings
1 parent 2d8a007 commit e9cd973

File tree

4 files changed

+21
-25
lines changed

4 files changed

+21
-25
lines changed

setup.py

100644100755
File mode changed.

snallygaster

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,17 @@ urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) # noqa: DUO
4949

5050

5151
def DEFAULT(f):
52-
setattr(f, "_is_default_test", True)
52+
f._is_default_test = True
5353
return f
5454

5555

5656
def INFO(f):
57-
setattr(f, "_is_info_test", True)
57+
f._is_info_test = True
5858
return f
5959

6060

6161
def HOSTNAME(f):
62-
setattr(f, "_is_hostname_test", True)
62+
f._is_hostname_test = True
6363
return f
6464

6565

@@ -78,11 +78,10 @@ def pout(cause, url, misc="", noisymsg=False):
7878
duplicate_preventer.append(dup_check)
7979
if args.json:
8080
json_out.append({"cause": cause, "url": url, "misc": misc})
81+
elif misc:
82+
print(f"[{cause}] {url} {misc}")
8183
else:
82-
if misc:
83-
print(f"[{cause}] {url} {misc}")
84-
else:
85-
print(f"[{cause}] {url}")
84+
print(f"[{cause}] {url}")
8685

8786

8887
def randstring():
@@ -100,8 +99,7 @@ def fetcher(fullurl, binary=False, getredir=False, geterrpage=False):
10099
r = pool.request("GET", fullurl, retries=False, redirect=False)
101100
if getredir:
102101
headers = {k.lower(): v for k, v in r.headers.items()}
103-
if "location" in headers:
104-
redir = headers["location"]
102+
redir = headers.get("location", "")
105103
elif (r.status != 200 and not geterrpage):
106104
data = ""
107105
elif binary:
@@ -192,10 +190,7 @@ def getmainpage(url):
192190
else:
193191
data = ""
194192
headers = {k.lower(): v for k, v in r.headers.items()}
195-
if "location" in headers:
196-
redir = headers["location"]
197-
else:
198-
redir = ""
193+
redir = headers.get("location", "")
199194
except (urllib3.exceptions.HTTPError, UnicodeError,
200195
ConnectionRefusedError):
201196
mainpage_cache[url] = {}
@@ -813,8 +808,8 @@ def test_axfr(qhost):
813808
ConnectionResetError, ConnectionRefusedError,
814809
EOFError, socket.gaierror, TimeoutError, OSError):
815810
return
816-
for r in ns.rrset:
817-
r = str(r)
811+
for rr in ns.rrset:
812+
r = str(rr)
818813
ipv4 = []
819814
ipv6 = []
820815
try:
@@ -1039,7 +1034,7 @@ if not args.nowww:
10391034
hosts.append("www." + h)
10401035

10411036
for i, h in enumerate(hosts):
1042-
if h.startswith("http://") or h.startswith("https://"):
1037+
if h.startswith(("http://", "https://")):
10431038
print("ERROR: Please run snallygaster with a hostname, not a URL.")
10441039
sys.exit(1)
10451040
try:

tests/test_codingstyle.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,16 @@
66
class TestCodingstyle(unittest.TestCase):
77
@staticmethod
88
def test_codingstyle():
9-
pyfiles = ["snallygaster", "setup.py"] + glob.glob("tests/*.py")
10-
subprocess.run(["pycodestyle", "--ignore=W503", "--max-line-length=100"]
11-
+ pyfiles, check=True)
12-
subprocess.run(["pyflakes"] + pyfiles, check=True)
9+
pyfiles = ["snallygaster", "setup.py", *glob.glob("tests/*.py")]
10+
subprocess.run(["pycodestyle", "--ignore=W503", "--max-line-length=100",
11+
*pyfiles], check=True)
12+
subprocess.run(["pyflakes", *pyfiles], check=True)
1313
subprocess.run(["pylint", "--disable=missing-docstring,invalid-name,"
14-
"consider-using-with,too-many-lines"]
15-
+ pyfiles, check=True)
16-
subprocess.run(["flake8", "--select=DUO"] + pyfiles, check=True)
17-
subprocess.run(["pyupgrade", "--py311-plus"] + pyfiles, check=True)
14+
"consider-using-with,too-many-lines,"
15+
"protected-access", *pyfiles],
16+
check=True)
17+
subprocess.run(["flake8", "--select=DUO", *pyfiles], check=True)
18+
subprocess.run(["pyupgrade", "--py311-plus", *pyfiles], check=True)
1819

1920

2021
if __name__ == "__main__":

tests/test_docs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def test_docs(self):
1212
fd = open("TESTS.md", encoding="utf-8")
1313
docs = []
1414
ol = ""
15-
for line in fd.readlines():
15+
for line in fd:
1616
if line.startswith("---"):
1717
docs.append(ol.rstrip())
1818
ol = line

0 commit comments

Comments
 (0)