Skip to content

Commit 7b75382

Browse files
committed
Placate mypy (redux)
Signed-off-by: Elsie Hupp <github@elsiehupp.com>
1 parent 3a50bb7 commit 7b75382

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+889
-629
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ repos:
99
rev: 1.6.0
1010
hooks:
1111
- id: poetry-check
12-
# - id: poetry-lock
12+
- id: poetry-lock
1313
- id: poetry-export
1414
args: ["-f", "requirements.txt", "-o", "requirements.txt"]
1515
- repo: https://github.com/pre-commit/pre-commit-hooks

poetry.lock

Lines changed: 231 additions & 72 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,18 @@ requests = "^2.31.0"
7777
flake8 = "^3.9.2"
7878
pre-commit = "^2.17.0"
7979
pymarkdown = "^0.1.4"
80+
mypy = "^1.5.1"
81+
types-requests = "^2.31.0.2"
82+
# flake8-black may be unnecessary?
83+
flake8-black = "^0.3.6"
8084

8185
[build-system]
8286
requires = ["poetry-core>=1.0.0"]
8387
build-backend = "poetry.core.masonry.api"
8488

8589
[tool.pymarkdown]
8690
disable-rules = "line-length,no-inline-html"
91+
92+
[tool.mypy]
93+
check_untyped_defs = true
94+
ignore_missing_imports = true

requirements.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,9 @@ requests==2.31.0 ; python_version >= "3.8" and python_version < "4.0" \
217217
schema==0.7.5 ; python_version >= "3.8" and python_version < "4.0" \
218218
--hash=sha256:f06717112c61895cabc4707752b88716e8420a8819d71404501e114f91043197 \
219219
--hash=sha256:f3ffdeeada09ec34bf40d7d79996d9f7175db93b7a5065de0faa7f41083c1e6c
220-
setuptools==68.1.2 ; python_version >= "3.8" and python_version < "4.0" \
221-
--hash=sha256:3d4dfa6d95f1b101d695a6160a7626e15583af71a5f52176efa5d39a054d475d \
222-
--hash=sha256:3d8083eed2d13afc9426f227b24fd1659489ec107c0e86cec2ffdde5c92e790b
220+
setuptools==68.2.0 ; python_version >= "3.8" and python_version < "4.0" \
221+
--hash=sha256:00478ca80aeebeecb2f288d3206b0de568df5cd2b8fada1209843cc9a8d88a48 \
222+
--hash=sha256:af3d5949030c3f493f550876b2fd1dd5ec66689c4ee5d5344f009746f71fd5a8
223223
six==1.16.0 ; python_version >= "3.8" and python_version < "4.0" \
224224
--hash=sha256:1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926 \
225225
--hash=sha256:8abb2f1d86890a2dfb989f9a77cfcfd3e47c2a354b01111771326f8aa26e0254

wikiteam3/dumpgenerator/__init__.py

100755100644
Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +0,0 @@
1-
#!/usr/bin/env python3
2-
3-
# DumpGenerator A generator of dumps for wikis
4-
# Copyright (C) 2011-2018 WikiTeam developers
5-
# This program is free software: you can redistribute it and/or modify
6-
# it under the terms of the GNU General Public License as published by
7-
# the Free Software Foundation, either version 3 of the License, or
8-
# (at your option) any later version.
9-
#
10-
# This program is distributed in the hope that it will be useful,
11-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13-
# GNU General Public License for more details.
14-
#
15-
# You should have received a copy of the GNU General Public License
16-
# along with this program. If not, see <http://www.gnu.org/licenses/>.
17-
18-
# To learn more, read the documentation:
19-
# https://github.com/WikiTeam/wikiteam/wiki
20-
21-
22-
from wikiteam3.dumpgenerator.dump import DumpGenerator
23-
24-
25-
def main():
26-
DumpGenerator()

wikiteam3/dumpgenerator/__main__.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,32 @@
1+
#!/usr/bin/env python3
2+
3+
# DumpGenerator A generator of dumps for wikis
4+
# Copyright (C) 2011-2018 WikiTeam developers
5+
# This program is free software: you can redistribute it and/or modify
6+
# it under the terms of the GNU General Public License as published by
7+
# the Free Software Foundation, either version 3 of the License, or
8+
# (at your option) any later version.
9+
#
10+
# This program is distributed in the hope that it will be useful,
11+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
# GNU General Public License for more details.
14+
#
15+
# You should have received a copy of the GNU General Public License
16+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
18+
# To learn more, read the documentation:
19+
# https://github.com/WikiTeam/wikiteam/wiki
20+
21+
22+
from wikiteam3.dumpgenerator.dump import DumpGenerator
23+
24+
25+
def main():
26+
DumpGenerator()
27+
28+
129
if __name__ == "__main__":
230
import sys
331

4-
from .__init__ import main
5-
632
sys.exit(main())

wikiteam3/dumpgenerator/api/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22
from .get_json import getJSON
33
from .handle_status_code import handleStatusCode
44
from .wiki_check import getWikiEngine
5+
6+
__all__ = [checkAPI, checkRetryAPI, mwGetAPIAndIndex, getJSON, handleStatusCode, getWikiEngine] # type: ignore

wikiteam3/dumpgenerator/api/api.py

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import re
2-
import time
3-
from typing import *
4-
from urllib.parse import urljoin, urlparse, urlunparse
2+
from typing import Any, Literal, Optional
3+
from urllib.parse import urljoin, urlparse
54

65
import mwclient
76
import requests
@@ -11,7 +10,8 @@
1110
from .get_json import getJSON
1211

1312

14-
def checkAPI(api="", session: requests.Session = None):
13+
# api="", session: requests.Session = None
14+
def checkAPI(api: str, session: requests.Session):
1515
"""Checking API availability"""
1616
global cj
1717
# handle redirects
@@ -34,29 +34,31 @@ def checkAPI(api="", session: requests.Session = None):
3434
"MediaWiki API URL not found or giving error: HTTP %d" % r.status_code
3535
)
3636
return None
37-
if "MediaWiki API is not enabled for this site." in r.text:
38-
return None
39-
try:
40-
result = getJSON(r)
41-
index = None
42-
if result:
43-
try:
44-
index = (
45-
result["query"]["general"]["server"]
46-
+ result["query"]["general"]["script"]
47-
)
48-
return (True, index, api)
49-
except KeyError:
50-
print("MediaWiki API seems to work but returned no index URL")
51-
return (True, None, api)
52-
except ValueError:
53-
print(repr(r.text))
54-
print("MediaWiki API returned data we could not parse")
55-
return None
37+
if r is not None:
38+
if "MediaWiki API is not enabled for this site." in r.text:
39+
return None
40+
try:
41+
result = getJSON(r)
42+
index = None
43+
if result:
44+
try:
45+
index = (
46+
result["query"]["general"]["server"]
47+
+ result["query"]["general"]["script"]
48+
)
49+
return (True, index, api)
50+
except KeyError:
51+
print("MediaWiki API seems to work but returned no index URL")
52+
return (True, None, api)
53+
except ValueError:
54+
print(repr(r.text))
55+
print("MediaWiki API returned data we could not parse")
56+
return None
5657
return None
5758

5859

59-
def mwGetAPIAndIndex(url="", session: requests.Session = None):
60+
# url=""
61+
def mwGetAPIAndIndex(url: str, session: requests.Session):
6062
"""Returns the MediaWiki API and Index.php"""
6163

6264
api = ""
@@ -108,18 +110,21 @@ def mwGetAPIAndIndex(url="", session: requests.Session = None):
108110
return api, index
109111

110112

111-
def checkRetryAPI(api="", apiclient=False, session: requests.Session = None):
113+
# api="", apiclient=False
114+
def checkRetryAPI(api: str, apiclient: bool, session: requests.Session):
112115
"""Call checkAPI and mwclient if necessary"""
113-
check = None
116+
check: (tuple[Literal[True], Any, str] | tuple[Literal[True], None, str] | None)
114117
try:
115118
check = checkAPI(api, session=session)
116119
except requests.exceptions.ConnectionError as e:
117120
print(f"Connection error: {str(e)}")
121+
check = None
118122

119123
if check and apiclient:
120124
apiurl = urlparse(api)
121125
try:
122-
site = mwclient.Site(
126+
# Returns a value, but we're just checking for an error here
127+
mwclient.Site(
123128
apiurl.netloc,
124129
apiurl.path.replace("api.php", ""),
125130
scheme=apiurl.scheme,
@@ -138,13 +143,14 @@ def checkRetryAPI(api="", apiclient=False, session: requests.Session = None):
138143
)
139144

140145
try:
141-
site = mwclient.Site(
146+
# Returns a value, but we're just checking for an error here
147+
mwclient.Site(
142148
apiurl.netloc,
143149
apiurl.path.replace("api.php", ""),
144150
scheme=newscheme,
145151
pool=session,
146152
)
147153
except KeyError:
148-
check = False
154+
check = False # type: ignore
149155

150-
return check, api
156+
return check, api # type: ignore

wikiteam3/dumpgenerator/api/get_json.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ def getJSON(request: requests.Response):
88
# request.encoding = request.apparent_encoding
99
try:
1010
return request.json()
11-
except:
11+
except Exception:
1212
# Maybe an older API version which did not return correct JSON
1313
return {}

wikiteam3/dumpgenerator/api/index_check.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
import requests
44

55

6-
def checkIndex(index="", cookies="", session: requests.Session = None):
6+
# index="", cookies="", session=None
7+
def checkIndex(index: str, cookies: str, session: requests.Session):
78
"""Checking index.php availability"""
8-
r = session.post(url=index, data={"title": "Special:Version"}, timeout=30)
9+
r = session.post(url=index, data={"title": "Special:Version"}, timeout=30) # type: ignore
910
if r.status_code >= 400:
1011
print(f"ERROR: The wiki returned status code HTTP {r.status_code}")
1112
return False

0 commit comments

Comments
 (0)