Skip to content

Commit fae922c

Browse files
authored
chg: ✨ add mypy and pylint to CI; 🚨 basic lint fixes (#40)
1 parent 01b99ec commit fae922c

File tree

14 files changed

+59
-24
lines changed

14 files changed

+59
-24
lines changed

.github/workflows/linting.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,9 @@ jobs:
2323
- name: Analysing the code with Black
2424
run: |
2525
black --check .
26+
- name: Analysing the code with mypy
27+
run: |
28+
mypy --install-types --non-interactive ./mindee
29+
- name: Analysing the code with pylint
30+
run: |
31+
pylint ./mindee

mindee/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
}
2020

2121

22-
class Client(object):
22+
class Client:
2323
def __init__(
2424
self,
2525
expense_receipt_token=None,
@@ -231,7 +231,7 @@ def parse_financial_document(
231231
return self._wrap_response(input_file, response, "financial_document")
232232

233233

234-
class Response(object):
234+
class Response:
235235
def __init__(
236236
self, http_response=None, pages=None, document=None, document_type=None
237237
):
@@ -311,7 +311,7 @@ def format_response(json_response, document_type, input_file):
311311
raise Exception("Document type not supported.")
312312

313313
# Create page level objects
314-
for page_n, page_prediction in enumerate(
314+
for _, page_prediction in enumerate(
315315
json_response["document"]["inference"]["pages"]
316316
):
317317
pages.append(

mindee/documents/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
class Document(object):
1+
class Document:
22
def __init__(self, input_file=None):
33
self.filepath = None
44
self.filename = None
@@ -11,6 +11,7 @@ def __init__(self, input_file=None):
1111
self.checklist = {}
1212

1313
def request(self, *args):
14+
"""Make request to the product endpoint"""
1415
raise NotImplementedError()
1516

1617
def _checklist(self, *args):
@@ -20,4 +21,5 @@ def _reconstruct(self, *args):
2021
pass
2122

2223
def all_checks(self):
24+
"""Return all checks"""
2325
return all(self.checklist)

mindee/documents/car_plate.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from mindee.documents import Document
22
from mindee.fields import Field
33
from mindee.http import make_api_request, make_predict_url
4-
import os
54

65

76
class CarPlate(Document):
@@ -46,7 +45,7 @@ def build_from_api_prediction(self, api_prediction, page_n=0):
4645
for license_plate in api_prediction["license_plates"]
4746
]
4847

49-
def __str__(self):
48+
def __str__(self) -> str:
5049
return (
5150
"-----Car plate data-----\n"
5251
"Filename: %s\n"

mindee/documents/financial_document.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from mindee.http import make_api_request, make_predict_url
99
from mindee.documents.invoice import Invoice
1010
from mindee.documents.receipt import Receipt
11-
import os
1211

1312

1413
class FinancialDocument(Document):
@@ -159,7 +158,7 @@ def build_from_api_prediction(self, api_prediction, input_file, page_n=0):
159158
self.payment_details = []
160159
self.company_number = []
161160

162-
def __str__(self):
161+
def __str__(self) -> str:
163162
return (
164163
"-----Financial Document data-----\n"
165164
"Filename: %s \n"

mindee/documents/invoice.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from mindee.fields.payment_details import PaymentDetails
88
from mindee.fields.tax import Tax
99
from mindee.http import make_api_request, make_predict_url
10-
import os
1110

1211

1312
class Invoice(Document):
@@ -153,7 +152,7 @@ def build_from_api_prediction(self, api_prediction, page_n=0):
153152
{"value": None, "probability": 0.0}, value_key="value", page_n=page_n
154153
)
155154

156-
def __str__(self):
155+
def __str__(self) -> str:
157156
return (
158157
"-----Invoice data-----\n"
159158
"Filename: %s \n"

mindee/documents/passport.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1+
from datetime import datetime
12
from mindee.documents import Document
23
from mindee.fields import Field
34
from mindee.fields.date import Date
4-
from datetime import datetime
55
from mindee.http import make_api_request, make_predict_url
6-
import os
76

87

98
class Passport(Document):
@@ -127,7 +126,7 @@ def build_from_api_prediction(self, api_prediction, page_n=0):
127126
self.mrz = Field({"value": None, "probability": 0.0}, page_n=page_n)
128127
self.full_name = Field({"value": None, "probability": 0.0}, page_n=page_n)
129128

130-
def __str__(self):
129+
def __str__(self) -> str:
131130
return (
132131
"-----Passport data-----\n"
133132
"Filename: %s \n"

mindee/documents/receipt.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from mindee.fields.orientation import Orientation
77
from mindee.fields.tax import Tax
88
from mindee.http import make_api_request, make_predict_url
9-
import os
109

1110

1211
class Receipt(Document):
@@ -95,7 +94,7 @@ def __init__(
9594
# Reconstruct extra fields
9695
self._reconstruct()
9796

98-
def __str__(self):
97+
def __str__(self) -> str:
9998
return (
10099
"-----Receipt data-----\n"
101100
"Filename: %s\n"

mindee/fields/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
class Field(object):
1+
class Field:
22
def __init__(
33
self,
44
abstract_prediction,

mindee/http.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
MINDEE_API_URL = "https://api.mindee.net/v1"
55

6-
platform = get_platform()
6+
PLATFORM = get_platform()
77

88

99
def make_predict_url(product: str, version: str, owner: str = "mindee") -> str:
@@ -30,7 +30,7 @@ def make_api_request(url: str, input_file, token: str, include_words: bool = Fal
3030
files = {"document": (input_file.filename, input_file.file_object.read())}
3131
headers = {
3232
"Authorization": f"Token {token}",
33-
"User-Agent": f"mindee-api-python@v{__version__} python-v{python_version} {platform}",
33+
"User-Agent": f"mindee-api-python@v{__version__} python-v{python_version} {PLATFORM}",
3434
}
3535

3636
params = {}

0 commit comments

Comments
 (0)