Browse Source

ref: add minimal pyi stubs for progressbar (#68810)

<!-- Describe your PR here. -->
anthony sottile 11 months ago
parent
commit
73a34ee820

+ 2 - 0
fixtures/stubs-for-mypy/progressbar/__init__.pyi

@@ -0,0 +1,2 @@
+from .widgets import Percentage as Percentage, Bar as Bar, ETA as ETA
+from .bar import ProgressBar as ProgressBar

+ 14 - 0
fixtures/stubs-for-mypy/progressbar/bar.pyi

@@ -0,0 +1,14 @@
+from typing import Sequence
+
+from .widgets import WidgetBase
+
+class ProgressBar:
+    def __init__(
+        self,
+        widgets: Sequence[str | WidgetBase] = ...,
+        max_value: int = ...,
+        min_poll_interval: float = ...,
+    ) -> None: ...
+    def start(self) -> None: ...
+    def update(self, value: int) -> None: ...
+    def finish(self) -> None: ...

+ 4 - 0
fixtures/stubs-for-mypy/progressbar/widgets.pyi

@@ -0,0 +1,4 @@
+class WidgetBase: ...
+class Percentage(WidgetBase): ...
+class Bar(WidgetBase): ...
+class ETA(WidgetBase): ...

+ 0 - 1
pyproject.toml

@@ -102,7 +102,6 @@ module = [
     "onelogin.saml2.constants.*",
     "onelogin.saml2.constants.*",
     "onelogin.saml2.idp_metadata_parser.*",
     "onelogin.saml2.idp_metadata_parser.*",
     "phabricator.*",
     "phabricator.*",
-    "progressbar.*",
     "rb.*",
     "rb.*",
     "requests_oauthlib.*",
     "requests_oauthlib.*",
     "sqlparse.*",
     "sqlparse.*",

+ 8 - 9
src/sentry/utils/query.py

@@ -215,16 +215,15 @@ class WithProgressBar:
         self.caption = str(caption or "Progress")
         self.caption = str(caption or "Progress")
 
 
     def __iter__(self):
     def __iter__(self):
-        widgets = [
-            f"{self.caption}: ",
-            progressbar.Percentage(),
-            " ",
-            progressbar.Bar(),
-            " ",
-            progressbar.ETA(),
-        ]
         pbar = progressbar.ProgressBar(
         pbar = progressbar.ProgressBar(
-            widgets=widgets,
+            widgets=[
+                f"{self.caption}: ",
+                progressbar.Percentage(),
+                " ",
+                progressbar.Bar(),
+                " ",
+                progressbar.ETA(),
+            ],
             max_value=self.count,
             max_value=self.count,
             # The default update interval is every 0.1s,
             # The default update interval is every 0.1s,
             # which for large migrations would easily logspam GoCD.
             # which for large migrations would easily logspam GoCD.