From 334f806094fa220bd6518b8b30b9d0f9d50daee2 Mon Sep 17 00:00:00 2001 From: Scott Gasch Date: Sun, 6 Feb 2022 16:35:16 -0800 Subject: [PATCH] Get mypy to stop with this fucking "has no attribute" shit when importing a submodule. I am probably doing something wrong here but I have no idea what. --- string_utils.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/string_utils.py b/string_utils.py index ec662d2..3c97ff7 100644 --- a/string_utils.py +++ b/string_utils.py @@ -1075,13 +1075,13 @@ def to_date(in_str: str) -> Optional[datetime.date]: """ Parses a date string. See DateParser docs for details. """ - import dateparse.dateparse_utils as dp + import dateparse.dateparse_utils as du try: - d = dp.DateParser() + d = du.DateParser() # type: ignore d.parse(in_str) return d.get_date() - except dp.ParseException: + except du.ParseException: # type: ignore msg = f'Unable to parse date {in_str}.' logger.warning(msg) return None @@ -1091,13 +1091,14 @@ def valid_date(in_str: str) -> bool: """ True if the string represents a valid date. """ + import dateparse import dateparse.dateparse_utils as dp try: - d = dp.DateParser() + d = dp.DateParser() # type: ignore _ = d.parse(in_str) return True - except dp.ParseException: + except dp.ParseException: # type: ignore msg = f'Unable to parse date {in_str}.' logger.warning(msg) return False @@ -1110,7 +1111,7 @@ def to_datetime(in_str: str) -> Optional[datetime.datetime]: import dateparse.dateparse_utils as dp try: - d = dp.DateParser() + d = dp.DateParser() # type: ignore dt = d.parse(in_str) if type(dt) == datetime.datetime: return dt -- 2.47.1