Skip to content

Commit 776099a

Browse files
authored
🐛 should never use mutable defaults in class definitions (#96)
1 parent 1119ba8 commit 776099a

File tree

6 files changed

+16
-12
lines changed

6 files changed

+16
-12
lines changed

mindee/documents/bank_check.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class BankCheck(Document):
1313
"""Date the check was issued"""
1414
amount: Amount
1515
"""Total including taxes"""
16-
payees: List[Field] = []
16+
payees: List[Field]
1717
"""List of payees (full name or company name)"""
1818
check_number: Field
1919
"""Check number"""
@@ -23,7 +23,7 @@ class BankCheck(Document):
2323
"""Payer's bank account number"""
2424
check_position: Field
2525
"""Check's position in the image"""
26-
signatures_positions: List[Field] = []
26+
signatures_positions: List[Field]
2727
"""Signatures' positions in the image"""
2828
# orientation is only present on page-level, not document-level
2929
orientation: Optional[Orientation] = None

mindee/documents/custom_document.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55

66
class CustomDocument(Document):
7-
fields: Dict[str, dict] = {}
7+
fields: Dict[str, dict]
88
"""Dictionary of all fields in the document"""
99

1010
def __init__(
@@ -38,6 +38,7 @@ def _build_from_api_prediction(
3838
:param api_prediction: Raw prediction from HTTP response
3939
:param page_n: Page number for multi pages pdf input
4040
"""
41+
self.fields = {}
4142
for field_name in api_prediction:
4243
field = api_prediction[field_name]
4344
field["page_n"] = page_n

mindee/documents/financial_document.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class FinancialDocument(Document):
2828
"""Invoice number"""
2929
due_date: Date
3030
"""Date the invoice is due"""
31-
taxes: List[Tax] = []
31+
taxes: List[Tax]
3232
"""List of all taxes"""
3333
merchant_name: Field
3434
"""Merchant/Supplier's name"""
@@ -38,11 +38,11 @@ class FinancialDocument(Document):
3838
"""Customer's name"""
3939
customer_address: Field
4040
"""Customer's address"""
41-
customer_company_registration: List[TypedField] = []
41+
customer_company_registration: List[TypedField]
4242
"""Customer company registration numbers"""
43-
payment_details: List[PaymentDetails] = []
43+
payment_details: List[PaymentDetails]
4444
"""Payment details"""
45-
company_number: List[TypedField] = []
45+
company_number: List[TypedField]
4646
"""Company numbers"""
4747
total_tax: Amount
4848
"""Sum total of all taxes"""
@@ -115,6 +115,9 @@ def _build_from_api_prediction(
115115
self.merchant_name = receipt.merchant_name
116116
self.time = receipt.time
117117
self.total_tax = receipt.total_tax
118+
self.customer_company_registration = []
119+
self.company_number = []
120+
self.payment_details = []
118121
self.invoice_number = Field({"value": None, "confidence": 0.0})
119122
self.supplier_address = Field({"value": None, "confidence": 0.0})
120123
self.customer_name = Field({"value": None, "confidence": 0.0})

mindee/documents/invoice.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ class Invoice(Document):
3535
"""Customer's name"""
3636
customer_address: Field
3737
"""Customer's address"""
38-
customer_company_registration: List[TypedField] = []
38+
customer_company_registration: List[TypedField]
3939
"""Customer company registration numbers"""
40-
payment_details: List[PaymentDetails] = []
40+
payment_details: List[PaymentDetails]
4141
"""Payment details"""
42-
company_number: List[TypedField] = []
42+
company_number: List[TypedField]
4343
"""Company numbers"""
4444
# orientation is only present on page-level, not document-level
4545
orientation: Optional[Orientation] = None

mindee/documents/passport.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Passport(Document):
1717
"""Date the passport was issued"""
1818
surname: Field
1919
"""Holder's last name (surname)"""
20-
given_names: List[Field] = []
20+
given_names: List[Field]
2121
"""Holder's list of first (given) names"""
2222
full_name: Field
2323
"""

mindee/documents/receipt.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class Receipt(Document):
2222
"""Service category"""
2323
merchant_name: Field
2424
"""Merchant's name"""
25-
taxes: List[Tax] = []
25+
taxes: List[Tax]
2626
"""List of all taxes"""
2727
total_tax: Amount
2828
"""Sum total of all taxes"""

0 commit comments

Comments
 (0)