From: Bob Halley Date: Fri, 14 Aug 2020 00:52:49 +0000 (-0700) Subject: copy the signature of __init__ too X-Git-Tag: v2.1.0rc1~77 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ed752aa8a20bf4d494c8736b168345d233ed46bf;p=thirdparty%2Fdnspython.git copy the signature of __init__ too --- 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