Skip to content

Commit

Permalink
Specify type when initializing self.mapped_data
Browse files Browse the repository at this point in the history
  • Loading branch information
amywieliczka committed Sep 10, 2024
1 parent 60f6dc6 commit 621f573
Showing 1 changed file with 10 additions and 21 deletions.
31 changes: 10 additions & 21 deletions metadata_mapper/mappers/mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Record(ABC, object):
validator = Validator

def __init__(self, collection_id: int, record: dict[str, Any]):
self.mapped_data = {}
self.mapped_data: dict = {}
self.collection_id: int = collection_id
self.source_metadata: dict = record
# TODO: pre_mapped_data is a stop gap to accomodate
Expand All @@ -58,7 +58,7 @@ def to_UCLDC(self) -> dict[str, Any]:
Returns: dict
"""
supermaps = [
super(c, self).UCLDC_map() # type: ignore
super(c, self).UCLDC_map()
for c in list(reversed(type(self).__mro__))
if hasattr(super(c, self), "UCLDC_map")
]
Expand Down Expand Up @@ -538,25 +538,16 @@ def lookup(self, prop, target, substitution, inverse=[False]):
def enrich_earliest_date(self):
"""
Called 2794 times, never with any arguments
TODO: self.mapped_data is not guaranteed to be a dictionary,
according to pylance. Rather than wrap this in an
if isinstance(self.mapped_data, dict), I've added type: ignore
self.mapped_data is always a dictionary and should always be a
dictionary, so directionally, I'd rather resolve this by
figuring out why pylance thinks it could be otherwise and adding
clarity there.
"""
if "date" not in self.mapped_data:
return self

date_values = self.mapped_data.get('date') # type: ignore
date_values = self.mapped_data.get('date')
converted_dates = convert_dates(date_values)
self.mapped_data['date'] = converted_dates # type: ignore
self.mapped_data['date'] = converted_dates
check_date_format(
self.mapped_data['calisphere-id'], # type: ignore
self.mapped_data['date'] # type: ignore
self.mapped_data['calisphere-id'],
self.mapped_data['date']
)

# uncomment these lines to add dates to test data:
Expand Down Expand Up @@ -584,19 +575,17 @@ def enrich_date(self, prop="sourceResource/temporal"):
- 354: Adams (Peggy H.) papers
- 17210: Pierce (C.C.) Photographic Collection
- 26092: Bartlett (Adelbert) Papers
TODO: see comment in enrich_earliest_date regarding type: ignore
"""
if isinstance(prop, list):
prop = prop[0]
prop = prop.split('/')[-1] # remove sourceResource
date_values = self.mapped_data.get(prop) # type: ignore
date_values = self.mapped_data.get(prop)
converted_dates = convert_dates(date_values)
self.mapped_data[prop] = converted_dates # type: ignore
self.mapped_data[prop] = converted_dates

check_date_format(
self.mapped_data['calisphere-id'], # type: ignore
self.mapped_data[prop] # type: ignore
self.mapped_data['calisphere-id'],
self.mapped_data[prop]
)

# uncomment these lines to add dates to test data:
Expand Down

0 comments on commit 621f573

Please sign in to comment.