chiark / gitweb /
documentation/python: expand annotation tests with string fallbacks.
authorVladimír Vondruš <mosra@centrum.cz>
Sat, 28 Sep 2024 00:15:01 +0000 (02:15 +0200)
committerVladimír Vondruš <mosra@centrum.cz>
Sat, 28 Sep 2024 01:44:29 +0000 (03:44 +0200)
In both cases the actual annotation is left as a string. Those were so
far tested only as part of inspect_type_links, but the behavior isn't
limited to linking.

documentation/test_python/inspect_annotations/inspect_annotations-py37+38.html
documentation/test_python/inspect_annotations/inspect_annotations.html
documentation/test_python/inspect_annotations/inspect_annotations.py

index c47f8b8645e5c8fccfa27e02895d99e3af45c096..5e58b0b1937c3f231d83e3845f4a0720e027f84e 100644 (file)
               <span class="m-doc-wrap-bumper">def <a href="#annotation_generic" class="m-doc-self">annotation_generic</a>(</span><span class="m-doc-wrap">a: typing.List[Tp]) -&gt; Tp</span>
             </dt>
             <dd>Annotation with a generic type</dd>
+            <dt id="annotation_invalid">
+              <span class="m-doc-wrap-bumper">def <a href="#annotation_invalid" class="m-doc-self">annotation_invalid</a>(</span><span class="m-doc-wrap">) -&gt; Foo.Bar</span>
+            </dt>
+            <dd>Annotation with an invalid annotation, which is kept as a string</dd>
             <dt id="annotation_list_noparam">
               <span class="m-doc-wrap-bumper">def <a href="#annotation_list_noparam" class="m-doc-self">annotation_list_noparam</a>(</span><span class="m-doc-wrap">a: typing.List[T])</span>
             </dt>
               <span class="m-doc-wrap-bumper">def <a href="#annotation_union" class="m-doc-self">annotation_union</a>(</span><span class="m-doc-wrap">a: typing.Union[float, int])</span>
             </dt>
             <dd>Annotation with the Union type</dd>
-            <dt id="annotation_union_of_undefined">
-              <span class="m-doc-wrap-bumper">def <a href="#annotation_union_of_undefined" class="m-doc-self">annotation_union_of_undefined</a>(</span><span class="m-doc-wrap">a: typing.Union[int, something.Undefined])</span>
+            <dt id="annotation_union_of_forward_reference">
+              <span class="m-doc-wrap-bumper">def <a href="#annotation_union_of_forward_reference" class="m-doc-self">annotation_union_of_forward_reference</a>(</span><span class="m-doc-wrap">a: typing.Union[int, something.Undefined])</span>
             </dt>
-            <dd>Annotation with an union that has an undefined type inside, where we can&#x27;t use isinstance either</dd>
+            <dd>Annotation with an union that has a forward reference inside, where we can&#x27;t use isinstance either</dd>
             <dt id="annotation_union_second_bracketed">
               <span class="m-doc-wrap-bumper">def <a href="#annotation_union_second_bracketed" class="m-doc-self">annotation_union_second_bracketed</a>(</span><span class="m-doc-wrap">a: typing.Union[float, typing.List[int]])</span>
             </dt>
index b5b454c134babc7a738f22ce690593f347fbf66b..cc15e4b8332503a16864ea800f9a6657614c2045 100644 (file)
               <span class="m-doc-wrap-bumper">def <a href="#annotation_generic" class="m-doc-self">annotation_generic</a>(</span><span class="m-doc-wrap">a: typing.List[Tp]) -&gt; Tp</span>
             </dt>
             <dd>Annotation with a generic type</dd>
+            <dt id="annotation_invalid">
+              <span class="m-doc-wrap-bumper">def <a href="#annotation_invalid" class="m-doc-self">annotation_invalid</a>(</span><span class="m-doc-wrap">) -&gt; Foo.Bar</span>
+            </dt>
+            <dd>Annotation with an invalid annotation, which is kept as a string</dd>
             <dt id="annotation_list_noparam">
               <span class="m-doc-wrap-bumper">def <a href="#annotation_list_noparam" class="m-doc-self">annotation_list_noparam</a>(</span><span class="m-doc-wrap">a: typing.List)</span>
             </dt>
               <span class="m-doc-wrap-bumper">def <a href="#annotation_union" class="m-doc-self">annotation_union</a>(</span><span class="m-doc-wrap">a: typing.Union[float, int])</span>
             </dt>
             <dd>Annotation with the Union type</dd>
-            <dt id="annotation_union_of_undefined">
-              <span class="m-doc-wrap-bumper">def <a href="#annotation_union_of_undefined" class="m-doc-self">annotation_union_of_undefined</a>(</span><span class="m-doc-wrap">a: typing.Union[int, something.Undefined])</span>
+            <dt id="annotation_union_of_forward_reference">
+              <span class="m-doc-wrap-bumper">def <a href="#annotation_union_of_forward_reference" class="m-doc-self">annotation_union_of_forward_reference</a>(</span><span class="m-doc-wrap">a: typing.Union[int, something.Undefined])</span>
             </dt>
-            <dd>Annotation with an union that has an undefined type inside, where we can&#x27;t use isinstance either</dd>
+            <dd>Annotation with an union that has a forward reference inside, where we can&#x27;t use isinstance either</dd>
             <dt id="annotation_union_second_bracketed">
               <span class="m-doc-wrap-bumper">def <a href="#annotation_union_second_bracketed" class="m-doc-self">annotation_union_second_bracketed</a>(</span><span class="m-doc-wrap">a: typing.Union[float, typing.List[int]])</span>
             </dt>
index a03d50b474e0db459e1eeae94b3c07f9e93083fd..8a9c26a152c0ee573f01072230453e78d69e853d 100644 (file)
@@ -71,8 +71,11 @@ def annotation_optional(a: Optional[float]):
 def annotation_union_second_bracketed(a: Union[float, List[int]]):
     """Annotation with the Union type and second type bracketed, where we can't use isinstance"""
 
-def annotation_union_of_undefined(a: Union[int, 'something.Undefined']):
-    """Annotation with an union that has an undefined type inside, where we can't use isinstance either"""
+def annotation_union_of_forward_reference(a: Union[int, 'something.Undefined']):
+    """Annotation with an union that has a forward reference inside, where we can't use isinstance either"""
+
+def annotation_invalid() -> 'Foo.Bar':
+    """Annotation with an invalid annotation, which is kept as a string"""
 
 def annotation_list_noparam(a: List):
     """Annotation with the unparametrized List type. 3.7 and 3.8 adds an implicit TypeVar to it, 3.6, 3.9 and 3.10 not, so the output is different between the versions."""