Skip to content

Commit dbb5ee6

Browse files
committed
Remove prop_type denormalisation
1 parent a47a94f commit dbb5ee6

2 files changed

Lines changed: 8 additions & 7 deletions

File tree

followthemoney/statement/statement.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,14 @@
1010
from followthemoney.statement.util import get_prop_type, BASE_ID
1111

1212
if TYPE_CHECKING:
13-
from followthemoney.statement.entity import SE
13+
from followthemoney.statement.entity import StatementEntity
1414

1515

1616
class StatementDict(TypedDict):
1717
id: Optional[str]
1818
entity_id: str
1919
canonical_id: str
2020
prop: str
21-
prop_type: str
2221
schema: str
2322
value: str
2423
dataset: str
@@ -47,7 +46,6 @@ class Statement(object):
4746
"entity_id",
4847
"canonical_id",
4948
"prop",
50-
"prop_type",
5149
"schema",
5250
"value",
5351
"dataset",
@@ -76,7 +74,6 @@ def __init__(
7674
self.entity_id = entity_id
7775
self.canonical_id = canonical_id or entity_id
7876
self.prop = prop
79-
self.prop_type = get_prop_type(schema, prop)
8077
self.schema = schema
8178
self.value = value
8279
self.dataset = dataset
@@ -89,12 +86,16 @@ def __init__(
8986
id = self.generate_key()
9087
self.id = id
9188

89+
@property
90+
def prop_type(self) -> str:
91+
"""The type of the property, e.g. 'string', 'number', 'url'."""
92+
return get_prop_type(self.schema, self.prop)
93+
9294
def to_dict(self) -> StatementDict:
9395
return {
9496
"canonical_id": self.canonical_id,
9597
"entity_id": self.entity_id,
9698
"prop": self.prop,
97-
"prop_type": self.prop_type,
9899
"schema": self.schema,
99100
"value": self.value,
100101
"dataset": self.dataset,
@@ -109,6 +110,7 @@ def to_dict(self) -> StatementDict:
109110
def to_csv_row(self) -> Dict[str, Optional[str]]:
110111
data = cast(Dict[str, Optional[str]], self.to_dict())
111112
data["external"] = bool_text(self.external)
113+
data["prop_type"] = self.prop_type
112114
return data
113115

114116
def to_db_row(self) -> Dict[str, Any]:
@@ -206,7 +208,7 @@ def from_db_row(cls, row: Row) -> "Statement":
206208
@classmethod
207209
def from_entity(
208210
cls,
209-
entity: "SE",
211+
entity: StatementEntity,
210212
dataset: str,
211213
first_seen: Optional[str] = None,
212214
last_seen: Optional[str] = None,

followthemoney/statement/util.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from typing import Tuple
33

44
from followthemoney.model import Model
5-
from followthemoney.util import sanitize_text
65

76
BASE_ID = "id"
87

0 commit comments

Comments
 (0)