Constructs a inspect.Signature object for a type.
It uses the class-level annotations as the parameters so
that we can treat the classes and functions the same
Source code in /home/sean/sourcecode/arc/arc/define/classful.py
defclass_signature(cls:type)->inspect.Signature:"""Constructs a `inspect.Signature` object for a type. It uses the class-level annotations as the parameters so that we can treat the classes and functions the same """annotations=t.get_type_hints(cls,include_extras=True)defaults={name:getattr(cls,name)fornameindir(cls)ifnotisdunder(name)}attrs={}forname,annotationinannotations.items():attrs[name]=(annotation,inspect.Parameter.empty)forname,defaultindefaults.items():ifinspect.isfunction(default):continueifnameinattrs:attrs[name]=(attrs[name][0],default)else:attrs[name]=(t.Any,default)parameters=[inspect.Parameter(name=name,kind=inspect.Parameter.POSITIONAL_OR_KEYWORD,default=default,annotation=annotation,)forname,(annotation,default)inattrs.items()]sig=inspect.Signature(sorted(parameters,key=lambdap:notp.defaultisinspect.Parameter.empty))# inspect.signature() checks for a cached signature object# at __signature__. So we can cache it there# to generate the correct signature object# during the parameter building processsetattr(cls,"__signature__",sig)returnsig