Skip to content

Commit

Permalink
chore(types): include error code on type ignores
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
  • Loading branch information
henryiii committed Mar 29, 2022
1 parent a80528f commit 7105781
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 18 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Expand Up @@ -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.*"]
Expand Down
2 changes: 1 addition & 1 deletion rich/color.py
Expand Up @@ -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
)
Expand Down
6 changes: 3 additions & 3 deletions rich/console.py
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions rich/pretty.py
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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:
Expand Down Expand Up @@ -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

Expand Down
12 changes: 6 additions & 6 deletions rich/repr.py
Expand Up @@ -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]))
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions rich/traceback.py
Expand Up @@ -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:
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 7105781

Please sign in to comment.