From: Scott Gasch Date: Mon, 7 Feb 2022 00:35:16 +0000 (-0800) Subject: Get mypy to stop with this fucking "has no attribute" shit when X-Git-Url: https://wannabe.guru.org/gitweb/?a=commitdiff_plain;h=334f806094fa220bd6518b8b30b9d0f9d50daee2;p=python_utils.git 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. --- 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