From 6f481c9e2379cc470d2fb392b6fd495fc7cc8f21 Mon Sep 17 00:00:00 2001 From: Brett Smith Date: Sat, 18 Nov 2023 10:18:22 -0500 Subject: [PATCH] 21136: Use typing generics for builtins in api_resources The immediate problem this solves is that using `list` unqualified as an annotation causes pdoc to resolve it as the current class' `list` method, which is not correct. We could also specify `builtins.list`, but since it doesn't support subscripting in Python 3.8, that generates a lot of noisy warnings right now. So this solution is better for now, and we'll probably migrate to `builtins.list` in the future. Arvados-DCO-1.1-Signed-off-by: Brett Smith --- sdk/python/discovery2pydoc.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/sdk/python/discovery2pydoc.py b/sdk/python/discovery2pydoc.py index 6ca3aafeb6..d2f206c80f 100755 --- a/sdk/python/discovery2pydoc.py +++ b/sdk/python/discovery2pydoc.py @@ -96,24 +96,24 @@ to list the specific keys you need. Refer to the API documentation for details. _MODULE_PRELUDE = ''' import sys +from typing import Any, Dict, List if sys.version_info < (3, 8): - from typing import Any from typing_extensions import TypedDict else: - from typing import Any, TypedDict + from typing import TypedDict ''' _TYPE_MAP = { # Map the API's JavaScript-based type names to Python annotations. # Some of these may disappear after Arvados issue #19795 is fixed. - 'Array': 'list', - 'array': 'list', + 'Array': 'List', + 'array': 'List', 'boolean': 'bool', # datetime fields are strings in ISO 8601 format. 'datetime': 'str', - 'Hash': 'dict[str, Any]', + 'Hash': 'Dict[str, Any]', 'integer': 'int', - 'object': 'dict[str, Any]', + 'object': 'Dict[str, Any]', 'string': 'str', 'text': 'str', } @@ -221,7 +221,7 @@ class Method: try: returns = get_type_annotation(self._spec['response']['$ref']) except KeyError: - returns = 'dict[str, Any]' + returns = 'Dict[str, Any]' return inspect.Signature(parameters, return_annotation=returns) def doc(self, doc_slice: slice=slice(None)) -> str: -- 2.30.2