Skip to content

Commit

Permalink
prevent mypy Check getattr error for registered checks
Browse files Browse the repository at this point in the history
  • Loading branch information
cosmicBboy committed Jan 24, 2021
1 parent cc6587f commit 920a98c
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion pandera/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,18 @@ def __repr__(self):
)


class Check(_CheckBase):
class _CheckMeta(type):
"""Check metaclass."""

def __getattr__(cls, name: str) -> Any:
"""Prevent attribute errors for registered checks."""
attr = cls.__dict__.get(name)
if attr is None:
raise AttributeError(f"'{cls}' object has no attribute '{name}'")
return attr


class Check(_CheckBase, metaclass=_CheckMeta):
"""Check a pandas Series or DataFrame for certain properties."""

REGISTERED_CUSTOM_CHECKS: Dict[str, Callable] = {} # noqa
Expand Down

0 comments on commit 920a98c

Please sign in to comment.