From 5d29d1336afc90d3575a0379a9e9d9bdac8d1856 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Wed, 3 Nov 2021 13:57:18 -0700 Subject: typing: relatively simple type check fixes These mostly add new variable names so that existing variables aren't overwritten with a new type; delay coercing '{}' or '[]' to 'None' until the last minute; adding is-not-None checks to conditional clauses; and similar small changes. --- python/fatcat_tools/importers/jalc.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'python/fatcat_tools/importers/jalc.py') diff --git a/python/fatcat_tools/importers/jalc.py b/python/fatcat_tools/importers/jalc.py index f540c264..2f10e533 100644 --- a/python/fatcat_tools/importers/jalc.py +++ b/python/fatcat_tools/importers/jalc.py @@ -193,6 +193,9 @@ class JalcImporter(EntityImporter): doi = None if record.doi: doi = clean_doi(record.doi.string.strip().lower()) + # TODO: following code is redundant with clean_doi() + if not doi: + return None if doi.startswith("http://dx.doi.org/"): doi = doi.replace("http://dx.doi.org/", "") elif doi.startswith("https://dx.doi.org/"): @@ -220,11 +223,11 @@ class JalcImporter(EntityImporter): if date: date = date.string if len(date) == 10: - release_date = datetime.datetime.strptime( + release_date_date = datetime.datetime.strptime( date["completed-date"], DATE_FMT ).date() - release_year = release_date.year - release_date = release_date.isoformat() + release_year = release_date_date.year + release_date = release_date_date.isoformat() elif len(date) == 4 and date.isdigit(): release_year = int(date) @@ -252,7 +255,10 @@ class JalcImporter(EntityImporter): # if we wanted the other ISSNs, would also need to uniq the list. # But we only need one to lookup ISSN-L/container issn = issn_list[0].string - issnl = self.issn2issnl(issn) + if issn: + issnl = self.issn2issnl(issn) + else: + issnl = None container_id = None if issnl: container_id = self.lookup_issnl(issnl) -- cgit v1.2.3