Skip to content

Commit 99ac17b

Browse files
🔧 fix wrongful instance variable assignments (#198)
1 parent bcc2189 commit 99ac17b

File tree

8 files changed

+32
-22
lines changed

8 files changed

+32
-22
lines changed

mindee/parsing/custom/list.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class ListFieldValueV1(FieldPositionMixin):
99

1010
content: str
1111
"""The content text"""
12-
confidence: float = 0.0
12+
confidence: float
1313
"""Confidence score"""
1414

1515
def __init__(self, raw_prediction: StringDict) -> None:
@@ -24,7 +24,7 @@ def __str__(self) -> str:
2424
class ListFieldV1:
2525
"""A list of values or words."""
2626

27-
confidence: float = 0.0
27+
confidence: float
2828
"""Confidence score"""
2929
reconstructed: bool
3030
"""Whether the field was reconstructed from other fields."""

mindee/parsing/standard/amount.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
class AmountField(FieldPositionMixin, BaseField):
88
"""A field containing an amount value."""
99

10-
value: Optional[float] = None
10+
value: Optional[float]
1111
"""The amount value as a float."""
1212

1313
def __init__(
@@ -23,6 +23,7 @@ def __init__(
2323
:param reconstructed: Bool for reconstructed object (not extracted in the API)
2424
:param page_id: Page number for multi-page document
2525
"""
26+
self.value = None
2627
super().__init__(
2728
raw_prediction,
2829
value_key="value",

mindee/parsing/standard/base.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,29 +25,31 @@ def _set_position(self, raw_prediction: StringDict):
2525
pass
2626
if self.polygon:
2727
self.bounding_box = get_bounding_box(self.polygon)
28+
else:
29+
self.bounding_box = None
2830

2931

3032
class FieldConfidenceMixin:
3133
"""Mixin class to add a confidence score."""
3234

33-
confidence: float = 0.0
35+
confidence: float
3436
"""The confidence score."""
3537

3638
def _set_confidence(self, raw_prediction: StringDict):
3739
try:
3840
self.confidence = float(raw_prediction["confidence"])
3941
except (KeyError, TypeError):
40-
pass
42+
self.confidence = 0.0
4143

4244

4345
class BaseField(FieldConfidenceMixin):
4446
"""Base class for most fields."""
4547

46-
value: Optional[Any] = None
48+
value: Optional[Any]
4749
"""Raw field value"""
4850
reconstructed: bool
4951
"""Whether the field was reconstructed from other fields."""
50-
page_id: Optional[int] = None
52+
page_id: Optional[int]
5153
"""The document page on which the information was found."""
5254

5355
def __init__(
@@ -57,6 +59,8 @@ def __init__(
5759
reconstructed: bool = False,
5860
page_id: Optional[int] = None,
5961
):
62+
self.value = None
63+
self.confidence = 0.0
6064
"""
6165
Base field object.
6266

mindee/parsing/standard/date.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
class DateField(FieldPositionMixin, BaseField):
1414
"""A field containing a date value."""
1515

16-
date_object: Optional[date] = None
16+
date_object: Optional[date]
1717
"""Date as a standard Python ``datetime.date`` object."""
18-
value: Optional[str] = None
18+
value: Optional[str]
1919
"""The raw field value."""
2020

2121
def __init__(
@@ -49,3 +49,7 @@ def __init__(
4949
except (TypeError, ValueError):
5050
self.date_object = None
5151
self.confidence = 0.0
52+
else:
53+
self.date_object = None
54+
self.confidence = 0.0
55+
self.value = None

mindee/parsing/standard/locale.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
class LocaleField(BaseField):
88
"""The locale detected on the document."""
99

10-
language: Optional[str] = None
10+
language: Optional[str]
1111
"""The ISO 639-1 code of the language."""
12-
country: Optional[str] = None
12+
country: Optional[str]
1313
"""The ISO 3166-1 alpha-2 code of the country."""
14-
currency: Optional[str] = None
14+
currency: Optional[str]
1515
"""The ISO 4217 code of the currency."""
1616

1717
def __init__(

mindee/parsing/standard/payment_details.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
class PaymentDetailsField(FieldPositionMixin, BaseField):
88
"""Information on a single payment."""
99

10-
account_number: Optional[str] = None
10+
account_number: Optional[str]
1111
"""Account number"""
12-
iban: Optional[str] = None
12+
iban: Optional[str]
1313
"""Account IBAN"""
14-
routing_number: Optional[str] = None
14+
routing_number: Optional[str]
1515
"""Account routing number"""
16-
swift: Optional[str] = None
16+
swift: Optional[str]
1717
"""Bank's SWIFT code"""
1818

1919
def __init__(

mindee/parsing/standard/position.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010
class PositionField(BaseField):
1111
"""A field indicating a position or area on the document."""
1212

13-
value: Optional[Polygon] = None
13+
value: Optional[Polygon]
1414
"""Polygon of cropped area, identical to the ``polygon`` property."""
15-
polygon: Optional[Polygon] = None
15+
polygon: Optional[Polygon]
1616
"""Polygon of cropped area"""
17-
quadrangle: Optional[Quadrilateral] = None
17+
quadrangle: Optional[Quadrilateral]
1818
"""Quadrangle of cropped area (does not exceed the canvas)"""
19-
rectangle: Optional[Quadrilateral] = None
19+
rectangle: Optional[Quadrilateral]
2020
"""Oriented rectangle of cropped area (may exceed the canvas)"""
21-
bounding_box: Optional[Quadrilateral] = None
21+
bounding_box: Optional[Quadrilateral]
2222
"""Straight rectangle of cropped area (does not exceed the canvas)"""
2323

2424
def __init__(

mindee/parsing/standard/text.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
class StringField(FieldPositionMixin, BaseField):
88
"""A field containing a text value."""
99

10-
value: Optional[str] = None
10+
value: Optional[str]
1111

1212
def __init__(
1313
self,
@@ -24,6 +24,7 @@ def __init__(
2424
:param reconstructed: Bool for reconstructed object (not extracted in the API)
2525
:param page_id: Page number for multi-page document
2626
"""
27+
self.value = None
2728
super().__init__(
2829
raw_prediction,
2930
value_key=value_key,

0 commit comments

Comments
 (0)