Skip to content

Commit

Permalink
Deployed 205b235 with MkDocs version: 1.5.3
Browse files Browse the repository at this point in the history
  • Loading branch information
jg-rp committed Aug 5, 2024
1 parent a991ede commit ff3e771
Show file tree
Hide file tree
Showing 11 changed files with 1,850 additions and 235 deletions.
6 changes: 3 additions & 3 deletions advanced/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1073,12 +1073,12 @@ <h2 id="filter-variables">Filter Variables</h2>
</span><span id="__span-0-28"><a id="__codelineno-0-28" name="__codelineno-0-28" href="#__codelineno-0-28"></a><span class="p">)</span>
</span></code></pre></div>
<h2 id="function-extensions">Function Extensions</h2>
<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>
<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>
<h3 id="type-system-for-function-expressions">Type System for Function Expressions</h3>
<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>
<div class="admonition info">
<p class="admonition-title">Info</p>
<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>
<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>
</div>
<h3 id="example">Example</h3>
<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>
Expand Down Expand Up @@ -1150,7 +1150,7 @@ <h3 id="built-in-functions">Built-in Functions</h3>
</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>
</span></code></pre></div>
<h3 id="compile-time-validation">Compile Time Validation</h3>
<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>
<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>
<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>
</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>
</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>
Expand Down
Loading

0 comments on commit ff3e771

Please sign in to comment.