Browse Source

Decorator

pull/46/head
Jure Šorn 4 years ago
parent
commit
7722824acd
2 changed files with 4 additions and 4 deletions
  1. 4
      README.md
  2. 4
      index.html

4
README.md

@ -904,7 +904,7 @@ def debug(func):
def add(x, y):
return x + y
```
* **Wraps is a helper decorator that copies the metadata of a passed function (func) to the function it is wrapping (out).**
* **Wraps is a helper decorator that copies the metadata of the passed function (func) to the function it is wrapping (out).**
* **Without it `'add.__name__'` would return `'out'`.**
### LRU Cache
@ -918,7 +918,7 @@ def fib(n):
return n if n < 2 else fib(n-2) + fib(n-1)
```
* **Recursion depth is limited to 1000 by default. To increase it use `'sys.setrecursionlimit(<depth>)'`.**
* **In CPython recursion depth is limited to 1000 by default. To increase it use `'sys.setrecursionlimit(<depth>)'`.**
### Parametrized Decorator
**A decorator that accepts arguments and returns a normal decorator that accepts a function.**

4
index.html

@ -882,7 +882,7 @@ creature = Creature(Point(<span class="hljs-number">0</span>, <span class="hljs
<ul>
<li><strong>Wraps is a helper decorator that copies the metadata of a passed function (func) to the function it is wrapping (out).</strong></li>
<li><strong>Wraps is a helper decorator that copies the metadata of the passed function (func) to the function it is wrapping (out).</strong></li>
<li><strong>Without it <code class="python hljs"><span class="hljs-string">'add.__name__'</span></code> would return <code class="python hljs"><span class="hljs-string">'out'</span></code>.</strong></li>
</ul>
<div><h3 id="lrucache">LRU Cache</h3><p><strong>Decorator that caches function's return values. All function's arguments must be hashable.</strong></p><pre><code class="python language-python hljs"><span class="hljs-keyword">from</span> functools <span class="hljs-keyword">import</span> lru_cache
@ -894,7 +894,7 @@ creature = Creature(Point(<span class="hljs-number">0</span>, <span class="hljs
<ul>
<li><strong>Recursion depth is limited to 1000 by default. To increase it use <code class="python hljs"><span class="hljs-string">'sys.setrecursionlimit(&lt;depth&gt;)'</span></code>.</strong></li>
<li><strong>In CPython recursion depth is limited to 1000 by default. To increase it use <code class="python hljs"><span class="hljs-string">'sys.setrecursionlimit(&lt;depth&gt;)'</span></code>.</strong></li>
</ul>
<div><h3 id="parametrizeddecorator">Parametrized Decorator</h3><p><strong>A decorator that accepts arguments and returns a normal decorator that accepts a function.</strong></p><pre><code class="python language-python hljs"><span class="hljs-keyword">from</span> functools <span class="hljs-keyword">import</span> wraps

Loading…
Cancel
Save