Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GithubObject.last_modified_datetime to have last_modified as a datetime #2772

Merged
merged 7 commits into from
Nov 26, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions github/GithubObject.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,13 @@ def last_modified(self) -> Optional[str]:
"""
return self._headers.get(Consts.RES_LAST_MODIFIED) # type: ignore

@property
def last_modified_datetime(self) -> Optional[datetime]:
"""
:type: datetime
"""
return self._makeDatetimeAttribute(self._headers.get(Consts.RES_LAST_MODIFIED)) # type: ignore
chouetz marked this conversation as resolved.
Show resolved Hide resolved

def get__repr__(self, params: Dict[str, Any]) -> str:
"""
Converts the object to a nicely printable string.
Expand Down
6 changes: 3 additions & 3 deletions github/GithubRetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ def __init__(self, secondary_rate_wait: float = DEFAULT_SECONDARY_RATE_WAIT, **k

def new(self, **kw: Any) -> Self:
kw.update(dict(secondary_rate_wait=self.secondary_rate_wait))
return super().new(**kw)
return super().new(**kw) # type: ignore

def increment(
self,
method: Optional[str] = None,
url: Optional[str] = None,
response: Optional[HTTPResponse] = None,
response: Optional[HTTPResponse] = None, # type: ignore[override]
error: Optional[Exception] = None,
_pool: Optional[ConnectionPool] = None,
_stacktrace: Optional[TracebackType] = None,
Expand Down Expand Up @@ -197,7 +197,7 @@ def get_backoff_time() -> float:
return super().increment(method, url, response, error, _pool, _stacktrace)

@staticmethod
def get_content(resp: HTTPResponse, url: str) -> bytes:
def get_content(resp: HTTPResponse, url: str) -> bytes: # type: ignore[override]
# logic taken from HTTPAdapter.build_response (requests.adapters)
response = Response()

Expand Down
6 changes: 5 additions & 1 deletion tests/GithubObject.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import unittest
from datetime import datetime, timedelta, timezone

from dateutil.tz.tz import tzoffset
from dateutil.tz.tz import tzoffset, tzutc

from . import Framework

Expand Down Expand Up @@ -78,6 +78,10 @@ def testMakeDatetimeAttribute(self):
"2021-01-23T12:34:56.000-06:00",
datetime(2021, 1, 23, 12, 34, 56, tzinfo=tzoffset(None, -21600)),
),
(
"Mon, 11 Sep 2023 14:07:29 GMT",
datetime(2023, 9, 11, 14, 7, 29, tzinfo=tzutc()),
),
]:
actual = gho.GithubObject._makeDatetimeAttribute(value)
self.assertEqual(gho._ValuedAttribute, type(actual), value)
Expand Down