From: Vladimír Vondruš Date: Sat, 28 Sep 2024 00:15:01 +0000 (+0200) Subject: documentation/python: expand annotation tests with string fallbacks. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~cjwatson/git?a=commitdiff_plain;h=a797c7f88feb88841dff4e93e22b7af83db6f13f;p=blog.git documentation/python: expand annotation tests with string fallbacks. 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. --- diff --git a/documentation/test_python/inspect_annotations/inspect_annotations-py37+38.html b/documentation/test_python/inspect_annotations/inspect_annotations-py37+38.html index c47f8b86..5e58b0b1 100644 --- a/documentation/test_python/inspect_annotations/inspect_annotations-py37+38.html +++ b/documentation/test_python/inspect_annotations/inspect_annotations-py37+38.html @@ -93,6 +93,10 @@ def annotation_generic(a: typing.List[Tp]) -> Tp
Annotation with a generic type
+
+ def annotation_invalid() -> Foo.Bar +
+
Annotation with an invalid annotation, which is kept as a string
def annotation_list_noparam(a: typing.List[T])
@@ -115,10 +119,10 @@ def annotation_union(a: typing.Union[float, int])
Annotation with the Union type
-
- def annotation_union_of_undefined(a: typing.Union[int, something.Undefined]) +
+ def annotation_union_of_forward_reference(a: typing.Union[int, something.Undefined])
-
Annotation with an union that has an undefined type inside, where we can't use isinstance either
+
Annotation with an union that has a forward reference inside, where we can't use isinstance either
def annotation_union_second_bracketed(a: typing.Union[float, typing.List[int]])
diff --git a/documentation/test_python/inspect_annotations/inspect_annotations.html b/documentation/test_python/inspect_annotations/inspect_annotations.html index b5b454c1..cc15e4b8 100644 --- a/documentation/test_python/inspect_annotations/inspect_annotations.html +++ b/documentation/test_python/inspect_annotations/inspect_annotations.html @@ -93,6 +93,10 @@ def annotation_generic(a: typing.List[Tp]) -> Tp
Annotation with a generic type
+
+ def annotation_invalid() -> Foo.Bar +
+
Annotation with an invalid annotation, which is kept as a string
def annotation_list_noparam(a: typing.List)
@@ -115,10 +119,10 @@ def annotation_union(a: typing.Union[float, int])
Annotation with the Union type
-
- def annotation_union_of_undefined(a: typing.Union[int, something.Undefined]) +
+ def annotation_union_of_forward_reference(a: typing.Union[int, something.Undefined])
-
Annotation with an union that has an undefined type inside, where we can't use isinstance either
+
Annotation with an union that has a forward reference inside, where we can't use isinstance either
def annotation_union_second_bracketed(a: typing.Union[float, typing.List[int]])
diff --git a/documentation/test_python/inspect_annotations/inspect_annotations.py b/documentation/test_python/inspect_annotations/inspect_annotations.py index a03d50b4..8a9c26a1 100644 --- a/documentation/test_python/inspect_annotations/inspect_annotations.py +++ b/documentation/test_python/inspect_annotations/inspect_annotations.py @@ -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."""