From ed752aa8a20bf4d494c8736b168345d233ed46bf Mon Sep 17 00:00:00 2001 From: Bob Halley Date: Thu, 13 Aug 2020 17:52:49 -0700 Subject: [PATCH] copy the signature of __init__ too --- dns/_immutable_attr.py | 5 +++++ dns/_immutable_ctx.py | 3 +++ 2 files changed, 8 insertions(+) diff --git a/dns/_immutable_attr.py b/dns/_immutable_attr.py index bf8aebc5..f7b9f8b0 100644 --- a/dns/_immutable_attr.py +++ b/dns/_immutable_attr.py @@ -4,6 +4,10 @@ # which doesn't have Context Variables. This implementation is somewhat # costly for classes with slots, as it adds a __dict__ to them. + +import inspect + + class _Immutable: """Immutable mixin class""" @@ -48,6 +52,7 @@ def _immutable_init(f): # If we started the initialzation, establish immutability # by removing the attribute that allows mutation object.__delattr__(args[0], '_immutable_init') + nf.__signature__ = inspect.signature(f) return nf diff --git a/dns/_immutable_ctx.py b/dns/_immutable_ctx.py index 400ab6ce..ececdbeb 100644 --- a/dns/_immutable_ctx.py +++ b/dns/_immutable_ctx.py @@ -5,6 +5,8 @@ # with slots immutable. It's also faster. import contextvars +import inspect + _in__init__ = contextvars.ContextVar('_immutable_in__init__', default=False) @@ -39,6 +41,7 @@ def _immutable_init(f): f(*args, **kwargs) finally: _in__init__.reset(previous) + nf.__signature__ = inspect.signature(f) return nf -- 2.47.3