From d911ebb99cf6e2c3983d633625dbd1a7abc409af Mon Sep 17 00:00:00 2001 From: Patrick Kidger <33688385+patrick-kidger@users.noreply.github.com> Date: Sun, 22 Jan 2023 11:43:36 -0800 Subject: [PATCH] Fix abstractmethods being ignored after @jaxtyped --- jaxtyping/decorator.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/jaxtyping/decorator.py b/jaxtyping/decorator.py index a269d00..41505ea 100644 --- a/jaxtyping/decorator.py +++ b/jaxtyping/decorator.py @@ -31,7 +31,12 @@ class _Jaxtyped: self.fn = fn def __get__(self, instance, owner): - return ft.wraps(self.fn)(_Jaxtyped(self.fn.__get__(instance, owner))) + if instance is None: + # Don't create a new _Jaxtyped object in this case. Otherwise anything + # assigned to methods (e.g. `__isabstractmethod__`) just gets swallowed. + return self + else: + return ft.wraps(self.fn)(_Jaxtyped(self.fn.__get__(instance, owner))) def __call__(self, *args, **kwargs): try: