Repository: brettcannon/gidgethub (python)

Issue:
Provide a reasonable string represenation for RateLimit

Pull request:
Implement __str__() for RateLimit
Closes #45 

Patch:
diff --git a/README.rst b/README.rst
index 0e30209..d487ed4 100644
--- a/README.rst
+++ b/README.rst
@@ -58,7 +58,7 @@ cat's name, Gidget, as part of the name. Since "Gidget" somewhat sounds like
 Changelog
 ---------
 
-2.4.2 (under development)
+2.5.0 (under development)
 '''''''''''''''''''''''''
 
 - Tighten type hints for parameters that have a default of ``None``
@@ -66,6 +66,9 @@ Changelog
 
 - Tweak code to not change semantics but reach 100% coverage.
 
+- Provide a human-readable string representation of
+  ``gidgethub.sansio.RateLimit``.
+
 
 2.4.1
 '''''
diff --git a/gidgethub/sansio.py b/gidgethub/sansio.py
index f614998..e342e88 100644
--- a/gidgethub/sansio.py
+++ b/gidgethub/sansio.py
@@ -217,6 +217,10 @@ class RateLimit:
             now = datetime.datetime.now(datetime.timezone.utc)
             return now > self.reset_datetime
 
+    def __str__(self) -> str:
+        """Provide all details in a reasonable format."""
+        return f"< {self.remaining:,}/{self.limit:,} until {self.reset_datetime} >"
+
     @classmethod
     def from_http(cls, headers: Mapping) -> "RateLimit":
         """Gather rate limit information from HTTP headers.
diff --git a/setup.py b/setup.py
index d309059..7faa72d 100644
--- a/setup.py
+++ b/setup.py
@@ -13,7 +13,7 @@ long_description = pathlib.Path("README.rst").read_text("utf-8")
 
 setuptools.setup(
     name="gidgethub",
-    version="2.4.2.dev",
+    version="2.5.0.dev",
     description="An async GitHub API library",
     long_description=long_description,
     url="https://gidgethub.readthedocs.io",


Test patch:
diff --git a/gidgethub/test/test_sansio.py b/gidgethub/test/test_sansio.py
index 66b438f..cffbf3e 100644
--- a/gidgethub/test/test_sansio.py
+++ b/gidgethub/test/test_sansio.py
@@ -208,6 +208,16 @@ class TestRateLimit:
         assert rate_limit.remaining == left
         assert rate_limit.reset_datetime == reset
 
+    def test___str__(self):
+        left = 4200
+        rate = 65000
+        reset = datetime.datetime.now(datetime.timezone.utc)
+        message = str(sansio.RateLimit(limit=rate, remaining=left,
+                                       reset_epoch=reset.timestamp()))
+        assert format(left, ',') in message
+        assert format(rate, ',') in message
+        assert str(reset) in message
+
 
 def sample(directory, status_code):
     # pytest doesn't set __spec__.origin :(