import{_ as i,c as a,o as n,ae as l}from"./chunks/framework.BHrE6nLq.js";const g=JSON.parse('{"title":"utils","description":"","frontmatter":{"title":"utils","order":100},"headers":[],"relativePath":"en/dev/api/plugin/func_call/utils.md","filePath":"en/dev/api/plugin/func_call/utils.md","lastUpdated":null}'),t={name:"en/dev/api/plugin/func_call/utils.md"};function e(p,s,h,k,r,o){return n(),a("div",null,s[0]||(s[0]=[l(`<h1 id="module-nonebot-plugin-marshoai-plugin-func-call-utils" tabindex="-1"><strong>Module</strong> <code>nonebot_plugin_marshoai.plugin.func_call.utils</code> <a class="header-anchor" href="#module-nonebot-plugin-marshoai-plugin-func-call-utils" aria-label="Permalink to &quot;**Module** \`nonebot_plugin_marshoai.plugin.func_call.utils\`&quot;">​</a></h1><hr><h3 id="func-copy-signature-func-f-callable-callable-any-f" tabindex="-1"><em><strong>func</strong></em> <code>copy_signature(func: F) -&gt; Callable[[Callable[..., Any]], F]</code> <a class="header-anchor" href="#func-copy-signature-func-f-callable-callable-any-f" aria-label="Permalink to &quot;***func*** \`copy_signature(func: F) -&gt; Callable[[Callable[..., Any]], F]\`&quot;">​</a></h3><p><strong>Description</strong>: 复制函数签名和文档字符串的装饰器</p><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/nonebot-plugin-marshoai/tree/main/nonebot_plugin_marshoai/plugin/func_call/utils.py#L8" target="_blank">View on GitHub</a></summary><div class="language-python vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">python</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">def</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> copy_signature</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(func: F) -&gt; Callable[[Callable[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">...</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, Any]], F]:</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">    def</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> decorator</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(wrapper: Callable[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">...</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, Any]) -&gt; F:</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">        @wraps</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(func)</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">        def</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> wrapped</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">*</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">args: Any, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">**</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">kwargs: Any) -&gt; Any:</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">            return</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> wrapper(</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">*</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">args, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">**</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">kwargs)</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">        return</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> wrapped</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">    return</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> decorator</span></span></code></pre></div></details><hr><h3 id="func-async-wrap-func-f-f" tabindex="-1"><em><strong>func</strong></em> <code>async_wrap(func: F) -&gt; F</code> <a class="header-anchor" href="#func-async-wrap-func-f-f" aria-label="Permalink to &quot;***func*** \`async_wrap(func: F) -&gt; F\`&quot;">​</a></h3><p><strong>Description</strong>: 装饰器，将同步函数包装为异步函数</p><p><strong>Arguments</strong>:</p><blockquote><ul><li>func (F): 函数对象</li></ul></blockquote><p><strong>Return</strong>: F: 包装后的函数对象</p><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/nonebot-plugin-marshoai/tree/main/nonebot_plugin_marshoai/plugin/func_call/utils.py#L21" target="_blank">View on GitHub</a></summary><div class="language-python vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">python</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">def</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> async_wrap</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(func: F) -&gt; F:</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">    @wraps</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(func)</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">    async</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> def</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> wrapper</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">*</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">args: Any, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">**</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">kwargs: Any) -&gt; Any:</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">        return</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> func(</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">*</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">args, </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">**</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">kwargs)</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">    return</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> wrapper</span></span></code></pre></div></details><hr><h3 id="func-is-coroutine-callable-call-callable-any-bool" tabindex="-1"><em><strong>func</strong></em> <code>is_coroutine_callable(call: Callable[..., Any]) -&gt; bool</code> <a class="header-anchor" href="#func-is-coroutine-callable-call-callable-any-bool" aria-label="Permalink to &quot;***func*** \`is_coroutine_callable(call: Callable[..., Any]) -&gt; bool\`&quot;">​</a></h3><p><strong>Description</strong>: 判断是否为async def 函数 请注意：是否为 async def 函数与该函数是否能被await调用是两个不同的概念，具体取决于函数返回值是否为awaitable对象</p><p><strong>Arguments</strong>:</p><blockquote><ul><li>call: 可调用对象</li></ul></blockquote><p><strong>Return</strong>: bool: 是否为async def函数</p><details><summary><b>Source code</b> or <a href="https://github.com/LiteyukiStudio/nonebot-plugin-marshoai/tree/main/nonebot_plugin_marshoai/plugin/func_call/utils.py#L38" target="_blank">View on GitHub</a></summary><div class="language-python vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">python</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">def</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> is_coroutine_callable</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(call: Callable[</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">...</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, Any]) -&gt; </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">bool</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">:</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">    if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> inspect.isroutine(call):</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">        return</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> inspect.iscoroutinefunction(call)</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">    if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> inspect.isclass(call):</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">        return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> False</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">    func_ </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> getattr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(call, </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;__call__&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">None</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">    return</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> inspect.iscoroutinefunction(func_)</span></span></code></pre></div></details>`,19)]))}const d=i(t,[["render",e]]);export{g as __pageData,d as default};
