From 71057811841514394ca97ff5906903dc64e1ac09 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Tue, 29 Mar 2022 12:16:16 -0400 Subject: [PATCH] chore(types): include error code on type ignores Signed-off-by: Henry Schreiner --- pyproject.toml | 1 + rich/color.py | 2 +- rich/console.py | 6 +++--- rich/pretty.py | 12 ++++++------ rich/repr.py | 12 ++++++------ rich/traceback.py | 4 ++-- 6 files changed, 19 insertions(+), 18 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 1a14cabcf..c9f22e5cc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -57,6 +57,7 @@ files = ["rich"] warn_unused_configs = true show_error_codes = true strict = true +enable_error_code = ["ignore-without-code"] [[tool.mypy.overrides]] module = ["pygments.*", "IPython.*", "commonmark.*", "ipywidgets.*"] diff --git a/rich/color.py b/rich/color.py index b6c56a1ee..6bca2da92 100644 --- a/rich/color.py +++ b/rich/color.py @@ -607,7 +607,7 @@ def blend_rgb( if color_number < 16: table.add_row(color_cell, f"{color_number}", Text(f'"{name}"')) else: - color = EIGHT_BIT_PALETTE[color_number] # type: ignore + color = EIGHT_BIT_PALETTE[color_number] # type: ignore[has-type] table.add_row( color_cell, str(color_number), Text(f'"{name}"'), color.hex, color.rgb ) diff --git a/rich/console.py b/rich/console.py index f78f200b1..2a9a86dab 100644 --- a/rich/console.py +++ b/rich/console.py @@ -524,10 +524,10 @@ def _replace(*args: Any, **kwargs: Any) -> Group: def _is_jupyter() -> bool: # pragma: no cover """Check if we're running in a Jupyter notebook.""" try: - get_ipython # type: ignore + get_ipython # type: ignore[name-defined] except NameError: return False - ipython = get_ipython() # type: ignore + ipython = get_ipython() # type: ignore[name-defined] shell = ipython.__class__.__name__ if "google.colab" in str(ipython.__class__) or shell == "ZMQInteractiveShell": return True # Jupyter notebook or qtconsole @@ -1249,7 +1249,7 @@ def render( renderable = rich_cast(renderable) if hasattr(renderable, "__rich_console__") and not isclass(renderable): - render_iterable = renderable.__rich_console__(self, _options) # type: ignore + render_iterable = renderable.__rich_console__(self, _options) # type: ignore[union-attr] elif isinstance(renderable, str): text_renderable = self.render_str( renderable, highlight=_options.highlight, markup=_options.markup diff --git a/rich/pretty.py b/rich/pretty.py index 57f3e62e2..8de12787d 100644 --- a/rich/pretty.py +++ b/rich/pretty.py @@ -29,7 +29,7 @@ try: import attr as _attr_module except ImportError: # pragma: no cover - _attr_module = None # type: ignore + _attr_module = None # type: ignore[assignment] from . import get_console from ._loop import loop_last @@ -207,7 +207,7 @@ def display_hook(value: Any) -> None: """Replacement sys.displayhook which prettifies objects with Rich.""" if value is not None: assert console is not None - builtins._ = None # type: ignore + builtins._ = None # type: ignore[attr-defined] console.print( value if _safe_isinstance(value, RichRenderable) @@ -221,13 +221,13 @@ def display_hook(value: Any) -> None: ), crop=crop, ) - builtins._ = value # type: ignore + builtins._ = value # type: ignore[attr-defined] try: # pragma: no cover - ip = get_ipython() # type: ignore + ip = get_ipython() # type: ignore[name-defined] from IPython.core.formatters import BaseFormatter - class RichFormatter(BaseFormatter): # type: ignore + class RichFormatter(BaseFormatter): # type: ignore[misc] pprint: bool = True def __call__(self, value: Any) -> Any: @@ -984,7 +984,7 @@ class StockKeepingUnit(NamedTuple): ), "Broken": BrokenRepr(), } - data["foo"].append(data) # type: ignore + data["foo"].append(data) # type: ignore[attr-defined] from rich import print diff --git a/rich/repr.py b/rich/repr.py index 4f3170b70..8bdfdae2a 100644 --- a/rich/repr.py +++ b/rich/repr.py @@ -48,8 +48,8 @@ def auto_repr(self: T) -> str: repr_str: List[str] = [] append = repr_str.append - angular: bool = getattr(self.__rich_repr__, "angular", False) # type: ignore - for arg in self.__rich_repr__(): # type: ignore + angular: bool = getattr(self.__rich_repr__, "angular", False) # type: ignore[attr-defined] + for arg in self.__rich_repr__(): # type: ignore[attr-defined] if isinstance(arg, tuple): if len(arg) == 1: append(repr(arg[0])) @@ -90,12 +90,12 @@ def auto_rich_repr(self: Type[T]) -> Result: if not hasattr(cls, "__rich_repr__"): auto_rich_repr.__doc__ = "Build a rich repr" - cls.__rich_repr__ = auto_rich_repr # type: ignore + cls.__rich_repr__ = auto_rich_repr # type: ignore[attr-defined] auto_repr.__doc__ = "Return repr(self)" - cls.__repr__ = auto_repr # type: ignore + cls.__repr__ = auto_repr # type: ignore[assignment] if angular is not None: - cls.__rich_repr__.angular = angular # type: ignore + cls.__rich_repr__.angular = angular # type: ignore[attr-defined] return cls if cls is None: @@ -144,7 +144,7 @@ def __rich_repr__(self) -> Result: console.print(foo, width=30) console.rule("Angular repr") - Foo.__rich_repr__.angular = True # type: ignore + Foo.__rich_repr__.angular = True # type: ignore[attr-defined] console.print(foo) diff --git a/rich/traceback.py b/rich/traceback.py index 912821cbd..0d764b7cb 100644 --- a/rich/traceback.py +++ b/rich/traceback.py @@ -130,7 +130,7 @@ def ipy_display_traceback( try: # pragma: no cover # if within ipython, use customized traceback - ip = get_ipython() # type: ignore + ip = get_ipython() # type: ignore[name-defined] ipy_excepthook_closure(ip) return sys.excepthook except Exception: @@ -669,7 +669,7 @@ def error() -> None: try: foo(0) except: - slfkjsldkfj # type: ignore + slfkjsldkfj # type: ignore[name-defined] except: console.print_exception(show_locals=True)