Skip to content

Commit

Permalink
deploy: 13d622e
Browse files Browse the repository at this point in the history
  • Loading branch information
brentyi committed Nov 13, 2024
1 parent 4129a2a commit 40832a2
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 29 deletions.
Binary file modified .doctrees/environment.pickle
Binary file not shown.
10 changes: 4 additions & 6 deletions _modules/tyro/_fields/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -484,14 +484,12 @@ <h1>Source code for tyro._fields</h1><div class="highlight"><pre>
<span class="bp">self</span><span class="p">,</span> <span class="n">new_type_stripped</span><span class="p">:</span> <span class="n">TypeForm</span><span class="p">[</span><span class="n">Any</span><span class="p">]</span> <span class="o">|</span> <span class="n">Callable</span>
<span class="p">)</span> <span class="o">-&gt;</span> <span class="n">FieldDefinition</span><span class="p">:</span>
<span class="k">if</span> <span class="n">get_origin</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">type</span><span class="p">)</span> <span class="ow">is</span> <span class="n">Annotated</span><span class="p">:</span>
<span class="n">new_type</span> <span class="o">=</span> <span class="n">Annotated</span><span class="o">.</span><span class="n">__class_getitem__</span><span class="p">(</span> <span class="c1"># type: ignore</span>
<span class="p">(</span><span class="n">new_type_stripped</span><span class="p">,</span> <span class="o">*</span><span class="n">get_args</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">type</span><span class="p">)[</span><span class="mi">1</span><span class="p">:])</span>
<span class="p">)</span>
<span class="n">new_type</span> <span class="o">=</span> <span class="n">Annotated</span><span class="p">[(</span><span class="n">new_type_stripped</span><span class="p">,</span> <span class="o">*</span><span class="n">get_args</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">type</span><span class="p">)[</span><span class="mi">1</span><span class="p">:])]</span> <span class="c1"># type: ignore</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">new_type</span> <span class="o">=</span> <span class="n">new_type_stripped</span>
<span class="n">new_type</span> <span class="o">=</span> <span class="n">new_type_stripped</span> <span class="c1"># type: ignore</span>
<span class="k">return</span> <span class="n">dataclasses</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span>
<span class="bp">self</span><span class="p">,</span>
<span class="nb">type</span><span class="o">=</span><span class="n">new_type</span><span class="p">,</span>
<span class="nb">type</span><span class="o">=</span><span class="n">new_type</span><span class="p">,</span> <span class="c1"># type: ignore</span>
<span class="n">type_stripped</span><span class="o">=</span><span class="n">new_type_stripped</span><span class="p">,</span>
<span class="p">)</span></div>

Expand Down Expand Up @@ -712,7 +710,7 @@ <h1>Source code for tyro._fields</h1><div class="highlight"><pre>
<span class="c1"># param.annotation doesn&#39;t resolve forward references.</span>
<span class="n">typ</span><span class="o">=</span><span class="n">typ</span>
<span class="k">if</span> <span class="n">default_instance</span> <span class="ow">in</span> <span class="n">MISSING_SINGLETONS</span>
<span class="k">else</span> <span class="n">Annotated</span><span class="o">.</span><span class="n">__class_getitem__</span><span class="p">((</span><span class="n">typ</span><span class="p">,</span> <span class="n">_markers</span><span class="o">.</span><span class="n">_OPTIONAL_GROUP</span><span class="p">)),</span> <span class="c1"># type: ignore</span>
<span class="k">else</span> <span class="n">Annotated</span><span class="p">[(</span><span class="n">typ</span><span class="p">,</span> <span class="n">_markers</span><span class="o">.</span><span class="n">_OPTIONAL_GROUP</span><span class="p">)],</span> <span class="c1"># type: ignore</span>
<span class="n">default</span><span class="o">=</span><span class="n">default</span><span class="p">,</span>
<span class="n">is_default_from_default_instance</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
<span class="n">helptext</span><span class="o">=</span><span class="n">helptext</span><span class="p">,</span>
Expand Down
10 changes: 4 additions & 6 deletions _modules/tyro/_parsers/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -735,12 +735,12 @@ <h1>Source code for tyro._parsers</h1><div class="highlight"><pre>
<span class="nb">len</span><span class="p">(</span><span class="n">found_subcommand_configs</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span>
<span class="ow">and</span> <span class="n">found_subcommand_configs</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">constructor_factory</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span>
<span class="p">):</span>
<span class="n">options</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">Annotated</span><span class="o">.</span><span class="n">__class_getitem__</span><span class="p">(</span> <span class="c1"># type: ignore</span>
<span class="n">options</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">Annotated</span><span class="p">[</span> <span class="c1"># type: ignore</span>
<span class="p">(</span>
<span class="n">found_subcommand_configs</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">constructor_factory</span><span class="p">(),</span>
<span class="o">*</span><span class="n">_resolver</span><span class="o">.</span><span class="n">unwrap_annotated</span><span class="p">(</span><span class="n">option</span><span class="p">,</span> <span class="s2">&quot;all&quot;</span><span class="p">)[</span><span class="mi">1</span><span class="p">],</span>
<span class="p">)</span>
<span class="p">)</span>
<span class="p">]</span>

<span class="c1"># Exit if we don&#39;t contain any nested types.</span>
<span class="k">if</span> <span class="ow">not</span> <span class="nb">any</span><span class="p">(</span>
Expand Down Expand Up @@ -842,13 +842,11 @@ <h1>Source code for tyro._parsers</h1><div class="highlight"><pre>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">annotations</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">option</span> <span class="o">=</span> <span class="n">option_origin</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">option</span> <span class="o">=</span> <span class="n">Annotated</span><span class="o">.</span><span class="n">__class_getitem__</span><span class="p">(</span> <span class="c1"># type: ignore</span>
<span class="p">(</span><span class="n">option_origin</span><span class="p">,)</span> <span class="o">+</span> <span class="n">annotations</span>
<span class="p">)</span>
<span class="n">option</span> <span class="o">=</span> <span class="n">Annotated</span><span class="p">[(</span><span class="n">option_origin</span><span class="p">,)</span> <span class="o">+</span> <span class="n">annotations</span><span class="p">]</span> <span class="c1"># type: ignore</span>

<span class="k">with</span> <span class="n">_fields</span><span class="o">.</span><span class="n">FieldDefinition</span><span class="o">.</span><span class="n">marker_context</span><span class="p">(</span><span class="nb">tuple</span><span class="p">(</span><span class="n">field</span><span class="o">.</span><span class="n">markers</span><span class="p">)):</span>
<span class="n">subparser</span> <span class="o">=</span> <span class="n">ParserSpecification</span><span class="o">.</span><span class="n">from_callable_or_type</span><span class="p">(</span>
<span class="n">option</span><span class="p">,</span>
<span class="n">option</span><span class="p">,</span> <span class="c1"># type: ignore</span>
<span class="n">markers</span><span class="o">=</span><span class="n">field</span><span class="o">.</span><span class="n">markers</span><span class="p">,</span>
<span class="n">description</span><span class="o">=</span><span class="n">subcommand_config</span><span class="o">.</span><span class="n">description</span><span class="p">,</span>
<span class="n">parent_classes</span><span class="o">=</span><span class="n">parent_classes</span><span class="p">,</span>
Expand Down
20 changes: 8 additions & 12 deletions _modules/tyro/_resolver/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -439,12 +439,12 @@ <h1>Source code for tyro._resolver</h1><div class="highlight"><pre>
<span class="p">)</span> <span class="o">-&gt;</span> <span class="n">TypeOrCallableOrNone</span><span class="p">:</span>
<span class="c1"># Handle type aliases, eg via the `type` statement in Python 3.12.</span>
<span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">typ</span><span class="p">,</span> <span class="n">TypeAliasType</span><span class="p">):</span>
<span class="k">return</span> <span class="n">Annotated</span><span class="o">.</span><span class="n">__class_getitem__</span><span class="p">(</span>
<span class="k">return</span> <span class="n">Annotated</span><span class="p">[</span>
<span class="p">(</span>
<span class="n">cast</span><span class="p">(</span><span class="n">Any</span><span class="p">,</span> <span class="n">resolve_newtype_and_aliases</span><span class="p">(</span><span class="n">typ</span><span class="o">.</span><span class="n">__value__</span><span class="p">)),</span>
<span class="n">TyroTypeAliasBreadCrumb</span><span class="p">(</span><span class="n">typ</span><span class="o">.</span><span class="vm">__name__</span><span class="p">),</span>
<span class="p">)</span>
<span class="p">)</span>
<span class="p">]</span>

<span class="c1"># We&#39;ll unwrap NewType annotations here; this is needed before issubclass</span>
<span class="c1"># checks!</span>
Expand All @@ -458,7 +458,7 @@ <h1>Source code for tyro._resolver</h1><div class="highlight"><pre>
<span class="n">typ</span> <span class="o">=</span> <span class="n">resolve_newtype_and_aliases</span><span class="p">(</span><span class="nb">getattr</span><span class="p">(</span><span class="n">typ</span><span class="p">,</span> <span class="s2">&quot;__supertype__&quot;</span><span class="p">))</span>

<span class="k">if</span> <span class="n">return_name</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">typ</span> <span class="o">=</span> <span class="n">Annotated</span><span class="o">.</span><span class="n">__class_getitem__</span><span class="p">((</span><span class="n">typ</span><span class="p">,</span> <span class="n">TyroTypeAliasBreadCrumb</span><span class="p">(</span><span class="n">return_name</span><span class="p">)))</span> <span class="c1"># type: ignore</span>
<span class="n">typ</span> <span class="o">=</span> <span class="n">Annotated</span><span class="p">[(</span><span class="n">typ</span><span class="p">,</span> <span class="n">TyroTypeAliasBreadCrumb</span><span class="p">(</span><span class="n">return_name</span><span class="p">))]</span> <span class="c1"># type: ignore</span>

<span class="k">return</span> <span class="n">cast</span><span class="p">(</span><span class="n">TypeOrCallableOrNone</span><span class="p">,</span> <span class="n">typ</span><span class="p">)</span></div>

Expand Down Expand Up @@ -497,9 +497,7 @@ <h1>Source code for tyro._resolver</h1><div class="highlight"><pre>

<span class="k">if</span> <span class="n">superclass</span> <span class="ow">is</span> <span class="n">Any</span> <span class="ow">or</span> <span class="nb">issubclass</span><span class="p">(</span><span class="n">potential_subclass</span><span class="p">,</span> <span class="n">superclass</span><span class="p">):</span> <span class="c1"># type: ignore</span>
<span class="k">if</span> <span class="n">get_origin</span><span class="p">(</span><span class="n">typ</span><span class="p">)</span> <span class="ow">is</span> <span class="n">Annotated</span><span class="p">:</span>
<span class="k">return</span> <span class="n">Annotated</span><span class="o">.</span><span class="n">__class_getitem__</span><span class="p">(</span> <span class="c1"># type: ignore</span>
<span class="p">(</span><span class="n">potential_subclass</span><span class="p">,)</span> <span class="o">+</span> <span class="n">get_args</span><span class="p">(</span><span class="n">typ</span><span class="p">)[</span><span class="mi">1</span><span class="p">:]</span>
<span class="p">)</span>
<span class="k">return</span> <span class="n">Annotated</span><span class="p">[(</span><span class="n">potential_subclass</span><span class="p">,)</span> <span class="o">+</span> <span class="n">get_args</span><span class="p">(</span><span class="n">typ</span><span class="p">)[</span><span class="mi">1</span><span class="p">:]]</span> <span class="c1"># type: ignore</span>
<span class="n">typ</span> <span class="o">=</span> <span class="n">cast</span><span class="p">(</span><span class="n">TypeOrCallable</span><span class="p">,</span> <span class="n">potential_subclass</span><span class="p">)</span>
<span class="k">except</span> <span class="ne">TypeError</span><span class="p">:</span>
<span class="c1"># TODO: document where this TypeError can be raised, and reduce the amount of</span>
Expand Down Expand Up @@ -529,9 +527,7 @@ <h1>Source code for tyro._resolver</h1><div class="highlight"><pre>
<span class="p">)</span>
<span class="ow">and</span> <span class="n">anno</span><span class="o">.</span><span class="n">constructor_factory</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span>
<span class="p">):</span>
<span class="k">return</span> <span class="n">Annotated</span><span class="o">.</span><span class="n">__class_getitem__</span><span class="p">(</span> <span class="c1"># type: ignore</span>
<span class="p">(</span><span class="n">anno</span><span class="o">.</span><span class="n">constructor_factory</span><span class="p">(),)</span> <span class="o">+</span> <span class="n">annotations</span>
<span class="p">)</span>
<span class="k">return</span> <span class="n">Annotated</span><span class="p">[(</span><span class="n">anno</span><span class="o">.</span><span class="n">constructor_factory</span><span class="p">(),)</span> <span class="o">+</span> <span class="n">annotations</span><span class="p">]</span> <span class="c1"># type: ignore</span>
<span class="k">return</span> <span class="n">typ</span></div>


Expand Down Expand Up @@ -930,7 +926,7 @@ <h1>Source code for tyro._resolver</h1><div class="highlight"><pre>
<span class="k">return</span> <span class="n">typ</span><span class="p">,</span> <span class="n">type_from_typevar</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">return</span> <span class="p">(</span>
<span class="n">Annotated</span><span class="o">.</span><span class="n">__class_getitem__</span><span class="p">((</span><span class="n">typ</span><span class="p">,</span> <span class="o">*</span><span class="n">annotations</span><span class="p">)),</span> <span class="c1"># type: ignore</span>
<span class="n">Annotated</span><span class="p">[(</span><span class="n">typ</span><span class="p">,</span> <span class="o">*</span><span class="n">annotations</span><span class="p">)],</span> <span class="c1"># type: ignore</span>
<span class="n">type_from_typevar</span><span class="p">,</span>
<span class="p">)</span></div>

Expand Down Expand Up @@ -969,12 +965,12 @@ <h1>Source code for tyro._resolver</h1><div class="highlight"><pre>
<span class="n">non_none</span> <span class="o">=</span> <span class="n">args</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="k">if</span> <span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="ow">is</span> <span class="n">NoneType</span> <span class="k">else</span> <span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
<span class="k">if</span> <span class="n">get_origin</span><span class="p">(</span><span class="n">non_none</span><span class="p">)</span> <span class="ow">is</span> <span class="n">Annotated</span><span class="p">:</span>
<span class="n">annotated_args</span> <span class="o">=</span> <span class="n">get_args</span><span class="p">(</span><span class="n">non_none</span><span class="p">)</span>
<span class="n">out</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">=</span> <span class="n">Annotated</span><span class="o">.</span><span class="n">__class_getitem__</span><span class="p">(</span> <span class="c1"># type: ignore</span>
<span class="n">out</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">=</span> <span class="n">Annotated</span><span class="p">[</span> <span class="c1"># type: ignore</span>
<span class="p">(</span>
<span class="n">Union</span><span class="o">.</span><span class="fm">__getitem__</span><span class="p">((</span><span class="n">annotated_args</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="kc">None</span><span class="p">)),</span> <span class="c1"># type: ignore</span>
<span class="o">*</span><span class="n">annotated_args</span><span class="p">[</span><span class="mi">1</span><span class="p">:],</span>
<span class="p">)</span>
<span class="p">)</span>
<span class="p">]</span>
<span class="k">return</span> <span class="n">out</span>

<span class="k">except</span> <span class="ne">TypeError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span> <span class="c1"># pragma: no cover</span>
Expand Down
2 changes: 1 addition & 1 deletion _modules/tyro/conf/_markers/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ <h1>Source code for tyro.conf._markers</h1><div class="highlight"><pre>

<span class="k">class</span> <span class="nc">_Marker</span><span class="p">(</span><span class="n">_singleton</span><span class="o">.</span><span class="n">Singleton</span><span class="p">):</span>
<span class="k">def</span> <span class="fm">__getitem__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">key</span><span class="p">):</span>
<span class="k">return</span> <span class="n">Annotated</span><span class="o">.</span><span class="n">__class_getitem__</span><span class="p">((</span><span class="n">key</span><span class="p">,</span> <span class="bp">self</span><span class="p">))</span> <span class="c1"># type: ignore</span>
<span class="k">return</span> <span class="n">Annotated</span><span class="p">[(</span><span class="n">key</span><span class="p">,</span> <span class="bp">self</span><span class="p">)]</span> <span class="c1"># type: ignore</span>


<span class="n">Marker</span> <span class="o">=</span> <span class="n">Any</span>
Expand Down
Loading

0 comments on commit 40832a2

Please sign in to comment.