Skip to content

Commit ff3e771

Browse files
committed
Deployed 205b235 with MkDocs version: 1.5.3
1 parent a991ede commit ff3e771

11 files changed

Lines changed: 1850 additions & 235 deletions

File tree

advanced/index.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,12 +1073,12 @@ <h2 id="filter-variables">Filter Variables</h2>
10731073
</span><span id="__span-0-28"><a id="__codelineno-0-28" name="__codelineno-0-28" href="#__codelineno-0-28"></a><span class="p">)</span>
10741074
</span></code></pre></div>
10751075
<h2 id="function-extensions">Function Extensions</h2>
1076-
<p>Add, remove or replace <a href="../functions/">filter functions</a> by updating the <a href="../api/#jsonpath.env.JSONPathEnvironment.function_extensions"><code>function_extensions</code></a> attribute of a <a href="../api/#jsonpath.env.JSONPathEnvironment"><code>JSONPathEnvironment</code></a>. It is a regular Python dictionary mapping filter function names to any <a href="https://docs.python.org/3/library/typing.html#typing.Callable">callable</a>, like a function or class with a <code>__call__</code> method.</p>
1076+
<p>Add, remove or replace <a href="../functions/">filter functions</a> by updating the <a href="../api/#jsonpath.JSONPathEnvironment.function_extensions"><code>function_extensions</code></a> attribute of a <a href="../api/#jsonpath.JSONPathEnvironment"><code>JSONPathEnvironment</code></a>. It is a regular Python dictionary mapping filter function names to any <a href="https://docs.python.org/3/library/typing.html#typing.Callable">callable</a>, like a function or class with a <code>__call__</code> method.</p>
10771077
<h3 id="type-system-for-function-expressions">Type System for Function Expressions</h3>
10781078
<p><a href="https://datatracker.ietf.org/doc/html/rfc9535#name-type-system-for-function-ex">Section 2.4.1</a> of RFC 9535 defines a type system for function expressions and requires that we check that filter expressions are well-typed. With that in mind, you are encouraged to implement custom filter functions by extending <a href="../api/#jsonpath.function_extensions.FilterFunction"><code>jsonpath.function_extensions.FilterFunction</code></a>, which forces you to be explicit about the <a href="../api/#jsonpath.function_extensions.ExpressionType">types</a> of arguments the function extension accepts and the type of its return value.</p>
10791079
<div class="admonition info">
10801080
<p class="admonition-title">Info</p>
1081-
<p><a href="../api/#jsonpath.function_extensions.FilterFunction"><code>FilterFunction</code></a> was new in Python JSONPath version 0.10.0. Prior to that we did not enforce function expression well-typedness. To use any arbitrary <a href="https://docs.python.org/3/library/typing.html#typing.Callable">callable</a> as a function extension - or if you don't want built-in filter functions to raise a <code>JSONPathTypeError</code> for function expressions that are not well-typed - set <a href="../api/#jsonpath.env.JSONPathEnvironment.well_typed"><code>well_typed</code></a> to <code>False</code> when constructing a <a href="../api/#jsonpath.env.JSONPathEnvironment"><code>JSONPathEnvironment</code></a>.</p>
1081+
<p><a href="../api/#jsonpath.function_extensions.FilterFunction"><code>FilterFunction</code></a> was new in Python JSONPath version 0.10.0. Prior to that we did not enforce function expression well-typedness. To use any arbitrary <a href="https://docs.python.org/3/library/typing.html#typing.Callable">callable</a> as a function extension - or if you don't want built-in filter functions to raise a <code>JSONPathTypeError</code> for function expressions that are not well-typed - set <a href="../api/#jsonpath.JSONPathEnvironment.well_typed"><code>well_typed</code></a> to <code>False</code> when constructing a <a href="../api/#jsonpath.JSONPathEnvironment"><code>JSONPathEnvironment</code></a>.</p>
10821082
</div>
10831083
<h3 id="example">Example</h3>
10841084
<p>As an example, we'll add a <code>min()</code> filter function, which will return the minimum of a sequence of values. If any of the values are not comparable, we'll return the special <code>undefined</code> value instead.</p>
@@ -1150,7 +1150,7 @@ <h3 id="built-in-functions">Built-in Functions</h3>
11501150
</span><span id="__span-5-20"><a id="__codelineno-5-20" name="__codelineno-5-20" href="#__codelineno-5-20"></a><span class="n">env</span> <span class="o">=</span> <span class="n">MyEnv</span><span class="p">()</span>
11511151
</span></code></pre></div>
11521152
<h3 id="compile-time-validation">Compile Time Validation</h3>
1153-
<p>Calls to <a href="#type-system-for-function-expressions">type-aware</a> function extension are validated at JSONPath compile-time automatically. If <a href="../api/#jsonpath.env.JSONPathEnvironment.well_typed"><code>well_typed</code></a> is set to <code>False</code> or a custom function extension does not inherit from <a href="../api/#jsonpath.function_extensions.FilterFunction"><code>FilterFunction</code></a>, its arguments can be validated by implementing the function as a class with a <code>__call__</code> method, and a <code>validate</code> method. <code>validate</code> will be called after parsing the function, giving you the opportunity to inspect its arguments and raise a <code>JSONPathTypeError</code> should any arguments be unacceptable. If defined, <code>validate</code> must take a reference to the current environment, an argument list and the token pointing to the start of the function call.</p>
1153+
<p>Calls to <a href="#type-system-for-function-expressions">type-aware</a> function extension are validated at JSONPath compile-time automatically. If <a href="../api/#jsonpath.JSONPathEnvironment.well_typed"><code>well_typed</code></a> is set to <code>False</code> or a custom function extension does not inherit from <a href="../api/#jsonpath.function_extensions.FilterFunction"><code>FilterFunction</code></a>, its arguments can be validated by implementing the function as a class with a <code>__call__</code> method, and a <code>validate</code> method. <code>validate</code> will be called after parsing the function, giving you the opportunity to inspect its arguments and raise a <code>JSONPathTypeError</code> should any arguments be unacceptable. If defined, <code>validate</code> must take a reference to the current environment, an argument list and the token pointing to the start of the function call.</p>
11541154
<div class="language-python highlight"><pre><span></span><code><span id="__span-6-1"><a id="__codelineno-6-1" name="__codelineno-6-1" href="#__codelineno-6-1"></a><span class="k">def</span> <span class="nf">validate</span><span class="p">(</span>
11551155
</span><span id="__span-6-2"><a id="__codelineno-6-2" name="__codelineno-6-2" href="#__codelineno-6-2"></a> <span class="bp">self</span><span class="p">,</span>
11561156
</span><span id="__span-6-3"><a id="__codelineno-6-3" name="__codelineno-6-3" href="#__codelineno-6-3"></a> <span class="n">env</span><span class="p">:</span> <span class="n">JSONPathEnvironment</span><span class="p">,</span>

0 commit comments

Comments
 (0)