From 920a98cb6113bf002fb1df11951196b0130f524a Mon Sep 17 00:00:00 2001 From: cosmicBboy Date: Sat, 16 Jan 2021 13:02:31 -0500 Subject: [PATCH] prevent mypy Check getattr error for registered checks --- pandera/checks.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/pandera/checks.py b/pandera/checks.py index 126e7696d..bc02d2def 100644 --- a/pandera/checks.py +++ b/pandera/checks.py @@ -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