From 2163322ef62fa97573ac94298261161fd9721993 Mon Sep 17 00:00:00 2001 From: Yobmod Date: Mon, 2 Aug 2021 14:00:33 +0100 Subject: increase mypy strictness (warn unused ignored) --- git/objects/util.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'git/objects/util.py') diff --git a/git/objects/util.py b/git/objects/util.py index f627211e..d3842cfb 100644 --- a/git/objects/util.py +++ b/git/objects/util.py @@ -346,7 +346,7 @@ class Traversable(Protocol): if not as_edge: out: IterableList[Union['Commit', 'Submodule', 'Tree', 'Blob']] = IterableList(id) - out.extend(self.traverse(as_edge=as_edge, *args, **kwargs)) # type: ignore + out.extend(self.traverse(as_edge=as_edge, *args, **kwargs)) return out # overloads in subclasses (mypy does't allow typing self: subclass) # Union[IterableList['Commit'], IterableList['Submodule'], IterableList[Union['Submodule', 'Tree', 'Blob']]] -- cgit v1.2.1 From 91fce331de16de6039c94cd4d7314184a5763e61 Mon Sep 17 00:00:00 2001 From: Yobmod Date: Mon, 2 Aug 2021 14:56:03 +0100 Subject: increase mypy strictness (warn unused ignored and warn unreachable) --- git/objects/util.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'git/objects/util.py') diff --git a/git/objects/util.py b/git/objects/util.py index d3842cfb..9c9ce773 100644 --- a/git/objects/util.py +++ b/git/objects/util.py @@ -167,7 +167,7 @@ def from_timestamp(timestamp: float, tz_offset: float) -> datetime: return utc_dt -def parse_date(string_date: str) -> Tuple[int, int]: +def parse_date(string_date: Union[str, datetime]) -> Tuple[int, int]: """ Parse the given date as one of the following @@ -182,8 +182,10 @@ def parse_date(string_date: str) -> Tuple[int, int]: :note: Date can also be YYYY.MM.DD, MM/DD/YYYY and DD.MM.YYYY. """ if isinstance(string_date, datetime) and string_date.tzinfo: - offset = -int(string_date.utcoffset().total_seconds()) + offset = -int(string_date.utcoffset().total_seconds()) # type: ignore[union-attr] return int(string_date.astimezone(utc).timestamp()), offset + else: + assert isinstance(string_date, str) # for mypy # git time try: @@ -338,7 +340,7 @@ class Traversable(Protocol): """ # Commit and Submodule have id.__attribute__ as IterableObj # Tree has id.__attribute__ inherited from IndexObject - if isinstance(self, (TraversableIterableObj, Has_id_attribute)): + if isinstance(self, Has_id_attribute): id = self._id_attribute_ else: id = "" # shouldn't reach here, unless Traversable subclass created with no _id_attribute_ -- cgit v1.2.1 From 13e0730b449e8ace2c7aa691d588febb4bed510c Mon Sep 17 00:00:00 2001 From: Yobmod Date: Mon, 2 Aug 2021 16:16:11 +0100 Subject: Fix parse_date typing --- git/objects/util.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'git/objects/util.py') diff --git a/git/objects/util.py b/git/objects/util.py index 9c9ce773..d7472b5d 100644 --- a/git/objects/util.py +++ b/git/objects/util.py @@ -181,11 +181,13 @@ def parse_date(string_date: Union[str, datetime]) -> Tuple[int, int]: :raise ValueError: If the format could not be understood :note: Date can also be YYYY.MM.DD, MM/DD/YYYY and DD.MM.YYYY. """ - if isinstance(string_date, datetime) and string_date.tzinfo: - offset = -int(string_date.utcoffset().total_seconds()) # type: ignore[union-attr] + if isinstance(string_date, datetime): + if string_date.tzinfo: + utcoffset = string_date.utcoffset() + offset = -int(utcoffset.total_seconds()) if utcoffset else 0 return int(string_date.astimezone(utc).timestamp()), offset else: - assert isinstance(string_date, str) # for mypy + assert isinstance(string_date, str), f"string_date={string_date}, type={type(string_date)}" # for mypy # git time try: -- cgit v1.2.1 From 730f11936364314b76738ed06bdd9222dc9de2ac Mon Sep 17 00:00:00 2001 From: Yobmod Date: Mon, 2 Aug 2021 16:30:32 +0100 Subject: Fix parse_date typing 2 --- git/objects/util.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'git/objects/util.py') diff --git a/git/objects/util.py b/git/objects/util.py index d7472b5d..e3e7d3ba 100644 --- a/git/objects/util.py +++ b/git/objects/util.py @@ -182,9 +182,11 @@ def parse_date(string_date: Union[str, datetime]) -> Tuple[int, int]: :note: Date can also be YYYY.MM.DD, MM/DD/YYYY and DD.MM.YYYY. """ if isinstance(string_date, datetime): - if string_date.tzinfo: + if string_date.tzinfo and string_date.utcoffset(): utcoffset = string_date.utcoffset() offset = -int(utcoffset.total_seconds()) if utcoffset else 0 + else: + offset = 0 return int(string_date.astimezone(utc).timestamp()), offset else: assert isinstance(string_date, str), f"string_date={string_date}, type={type(string_date)}" # for mypy -- cgit v1.2.1 From 2fe13cad9c889b8628119ab5ee139038b0c164fd Mon Sep 17 00:00:00 2001 From: Yobmod Date: Mon, 2 Aug 2021 16:54:31 +0100 Subject: Fix parse_date typing 3 --- git/objects/util.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'git/objects/util.py') diff --git a/git/objects/util.py b/git/objects/util.py index e3e7d3ba..6e3f688e 100644 --- a/git/objects/util.py +++ b/git/objects/util.py @@ -181,13 +181,11 @@ def parse_date(string_date: Union[str, datetime]) -> Tuple[int, int]: :raise ValueError: If the format could not be understood :note: Date can also be YYYY.MM.DD, MM/DD/YYYY and DD.MM.YYYY. """ - if isinstance(string_date, datetime): - if string_date.tzinfo and string_date.utcoffset(): - utcoffset = string_date.utcoffset() - offset = -int(utcoffset.total_seconds()) if utcoffset else 0 - else: - offset = 0 + if isinstance(string_date, datetime) and string_date.tzinfo: + utcoffset = string_date.utcoffset() + offset = -int(utcoffset.total_seconds()) if utcoffset else 0 return int(string_date.astimezone(utc).timestamp()), offset + else: assert isinstance(string_date, str), f"string_date={string_date}, type={type(string_date)}" # for mypy -- cgit v1.2.1 From 024b69669811dc3aa5a018eb3df5535202edf5f9 Mon Sep 17 00:00:00 2001 From: Yobmod Date: Mon, 2 Aug 2021 17:09:03 +0100 Subject: Fix parse_date typing 4 --- git/objects/util.py | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) (limited to 'git/objects/util.py') diff --git a/git/objects/util.py b/git/objects/util.py index 6e3f688e..1ca6f050 100644 --- a/git/objects/util.py +++ b/git/objects/util.py @@ -181,16 +181,15 @@ def parse_date(string_date: Union[str, datetime]) -> Tuple[int, int]: :raise ValueError: If the format could not be understood :note: Date can also be YYYY.MM.DD, MM/DD/YYYY and DD.MM.YYYY. """ - if isinstance(string_date, datetime) and string_date.tzinfo: - utcoffset = string_date.utcoffset() - offset = -int(utcoffset.total_seconds()) if utcoffset else 0 - return int(string_date.astimezone(utc).timestamp()), offset + if isinstance(string_date, datetime): + if string_date.tzinfo: + utcoffset = cast(timedelta, string_date.utcoffset()) # typeguard, if tzinfoand is not None + offset = -int(utcoffset.total_seconds()) + return int(string_date.astimezone(utc).timestamp()), offset + else: + raise ValueError(f"Unsupported date format or type: {string_date}" % string_date) else: - assert isinstance(string_date, str), f"string_date={string_date}, type={type(string_date)}" # for mypy - - # git time - try: if string_date.count(' ') == 1 and string_date.rfind(':') == -1: timestamp, offset_str = string_date.split() if timestamp.startswith('@'): @@ -244,13 +243,9 @@ def parse_date(string_date: Union[str, datetime]) -> Tuple[int, int]: continue # END exception handling # END for each fmt - # still here ? fail raise ValueError("no format matched") # END handle format - except Exception as e: - raise ValueError("Unsupported date format: %s" % string_date) from e - # END handle exceptions # precompiled regex -- cgit v1.2.1 From e2f8367b53b14acb8e1a86f33334f92a5a306878 Mon Sep 17 00:00:00 2001 From: Yobmod Date: Mon, 2 Aug 2021 17:15:06 +0100 Subject: Fix parse_date typing 5 --- git/objects/util.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'git/objects/util.py') diff --git a/git/objects/util.py b/git/objects/util.py index 1ca6f050..d3d8d38b 100644 --- a/git/objects/util.py +++ b/git/objects/util.py @@ -187,9 +187,10 @@ def parse_date(string_date: Union[str, datetime]) -> Tuple[int, int]: offset = -int(utcoffset.total_seconds()) return int(string_date.astimezone(utc).timestamp()), offset else: - raise ValueError(f"Unsupported date format or type: {string_date}" % string_date) + raise ValueError(f"string_date datetime object without tzinfo, {string_date}") - else: + # git time + try: if string_date.count(' ') == 1 and string_date.rfind(':') == -1: timestamp, offset_str = string_date.split() if timestamp.startswith('@'): @@ -243,9 +244,13 @@ def parse_date(string_date: Union[str, datetime]) -> Tuple[int, int]: continue # END exception handling # END for each fmt + # still here ? fail raise ValueError("no format matched") # END handle format + except Exception as e: + raise ValueError(f"Unsupported date format or type: {string_date}" % string_date) from e + # END handle exceptions # precompiled regex -- cgit v1.2.1 From d30bc0722ee32c501c021bde511640ff6620a203 Mon Sep 17 00:00:00 2001 From: Yobmod Date: Mon, 2 Aug 2021 17:19:33 +0100 Subject: Fix parse_date typing 6 --- git/objects/util.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'git/objects/util.py') diff --git a/git/objects/util.py b/git/objects/util.py index d3d8d38b..16d4c0ac 100644 --- a/git/objects/util.py +++ b/git/objects/util.py @@ -249,7 +249,7 @@ def parse_date(string_date: Union[str, datetime]) -> Tuple[int, int]: raise ValueError("no format matched") # END handle format except Exception as e: - raise ValueError(f"Unsupported date format or type: {string_date}" % string_date) from e + raise ValueError(f"Unsupported date format or type: {string_date}, type={type(string_date)}") from e # END handle exceptions -- cgit v1.2.1 From 6470ad4a413fb7fbd9f2d3b9da1720c13ffc92bb Mon Sep 17 00:00:00 2001 From: Yobmod Date: Mon, 2 Aug 2021 17:24:18 +0100 Subject: Fix parse_date typing 7 --- git/objects/util.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'git/objects/util.py') diff --git a/git/objects/util.py b/git/objects/util.py index 16d4c0ac..0b843301 100644 --- a/git/objects/util.py +++ b/git/objects/util.py @@ -187,7 +187,9 @@ def parse_date(string_date: Union[str, datetime]) -> Tuple[int, int]: offset = -int(utcoffset.total_seconds()) return int(string_date.astimezone(utc).timestamp()), offset else: - raise ValueError(f"string_date datetime object without tzinfo, {string_date}") + # should just return timestamp, 0? + return int(string_date.astimezone(utc).timestamp()), 0 + # raise ValueError(f"string_date datetime object without tzinfo, {string_date}") # git time try: -- cgit v1.2.1 From 481f672baab666d6e2f81e9288a5f3c42c884a8e Mon Sep 17 00:00:00 2001 From: Yobmod Date: Mon, 2 Aug 2021 17:56:06 +0100 Subject: Add __future__.annotations to repo/base.py --- git/objects/util.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'git/objects/util.py') diff --git a/git/objects/util.py b/git/objects/util.py index 0b843301..16d4c0ac 100644 --- a/git/objects/util.py +++ b/git/objects/util.py @@ -187,9 +187,7 @@ def parse_date(string_date: Union[str, datetime]) -> Tuple[int, int]: offset = -int(utcoffset.total_seconds()) return int(string_date.astimezone(utc).timestamp()), offset else: - # should just return timestamp, 0? - return int(string_date.astimezone(utc).timestamp()), 0 - # raise ValueError(f"string_date datetime object without tzinfo, {string_date}") + raise ValueError(f"string_date datetime object without tzinfo, {string_date}") # git time try: -- cgit v1.2.1