This is how we make the ProtocolBase inject the ContractFunc via the type signature. After a lot of research, this goes slightly outside of the bounds for type hinting, but I think the improved expressiveness makes it fully worthwhile.
def__init__(self,**kwargs):""" This is how we make the ProtocolBase inject the ContractFunc via the type signature. After a lot of research, this goes slightly outside of the bounds for type hinting, but I think the improved expressiveness makes it fully worthwhile. """super().__init__(**kwargs)foralias,funcinself._func_sigs.items():name=aliasifis_annotation(func):annotation_args=get_args(func)args=annotation_args[0]forannotationinannotation_args:ifisinstance(annotation,Name):name=annotation.valueelse:args=funcT,U=get_args(args)setattr(self,alias,ContractFunc[T,U](# type: ignorefunc=FuncSignature[T,U](name=name,alias=alias),# type: ignorecontract=self,),)
defmodel_post_init(self,__context):network=self.__class__._networkobject.__setattr__(self,"_network",network)# overwrite the .rpc() classmethodobject.__setattr__(self,"rpc",self._rpc)
@classmethoddefrpc(cls)->"RPC":""" This uses the default network, unless a network has been provided """from._transportimport_force_get_global_rpcifcls._networkisNone:return_force_get_global_rpc()response=_force_get_global_rpc(cls._network)returnresponse