From 97c5c7456d4c673f868f0b8975f9ea9da3c480cc Mon Sep 17 00:00:00 2001 From: Gin-Config Team Date: Tue, 9 Sep 2025 06:30:02 -0700 Subject: [PATCH] an internal change PiperOrigin-RevId: 804882890 --- gin/config.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/gin/config.py b/gin/config.py index 5e060aa..455c014 100644 --- a/gin/config.py +++ b/gin/config.py @@ -573,6 +573,15 @@ def _decorate_fn_or_cls(decorator, """ if not inspect.isclass(fn_or_cls): # pytype: disable=wrong-arg-types return decorator(_ensure_wrappability(fn_or_cls)) + + try: + # We check if the class can be subclassed. Some built-in types + # can't be, and will raise a TypeError here. In this case, + # we fall back to treating `fn_or_cls` as a function. + type(fn_or_cls.__name__ + 'GinSubclass', (fn_or_cls,), {}) + except TypeError: + return decorator(_ensure_wrappability(fn_or_cls)) + cls = fn_or_cls if avoid_class_mutation: # This approach enables @gin.register and gin.external_configurable(), and