From 9e4b146941a9a31d952b19cfcf016f248882a826 Mon Sep 17 00:00:00 2001 From: Paul Cristian Sarbu Date: Tue, 27 Jun 2023 15:35:45 +0200 Subject: python: Add type hints and fix style in test scripts For maximum compatibility, we use the uppercase types from the typing package instead of the built-in types, therefore compliant with PEP 484 and PEP 526. --- test/end-to-end/target-cache/data/pydicts/bar.py | 1 + test/end-to-end/target-cache/data/pydicts/dict_converter.py | 10 ++++++---- test/end-to-end/target-cache/data/pydicts/foo.py | 1 + 3 files changed, 8 insertions(+), 4 deletions(-) (limited to 'test/end-to-end/target-cache') diff --git a/test/end-to-end/target-cache/data/pydicts/bar.py b/test/end-to-end/target-cache/data/pydicts/bar.py index 251cbab3..4a85fc0c 100644 --- a/test/end-to-end/target-cache/data/pydicts/bar.py +++ b/test/end-to-end/target-cache/data/pydicts/bar.py @@ -12,4 +12,5 @@ # See the License for the specific language governing permissions and # limitations under the License. +# type: ignore {"foo": "", None: ["bar"]} diff --git a/test/end-to-end/target-cache/data/pydicts/dict_converter.py b/test/end-to-end/target-cache/data/pydicts/dict_converter.py index 61cf2e8d..605f7615 100755 --- a/test/end-to-end/target-cache/data/pydicts/dict_converter.py +++ b/test/end-to-end/target-cache/data/pydicts/dict_converter.py @@ -16,24 +16,26 @@ import sys import ast import json -import yaml +import yaml # this package has lax type hints + +from typing import Any if len(sys.argv) < 4: print(f"usage: {sys.argv[0]} [py|json|yaml] [py|json|yaml] ") sys.exit(1) with open(sys.argv[3]) as f: - data = {} + data: Any = {} if sys.argv[1] == "py": data = ast.literal_eval(f.read()) elif sys.argv[1] == "json": data = json.load(f) elif sys.argv[1] == "yaml": - data = yaml.load(f) + data = yaml.load(f, Loader=yaml.Loader) # type: ignore if (sys.argv[2] == "py"): print(data) elif sys.argv[2] == "json": print(json.dumps(data, indent=2)) elif sys.argv[2] == "yaml": - print(yaml.dump(data, indent=2)) + print(yaml.dump(data, indent=2)) # type: ignore diff --git a/test/end-to-end/target-cache/data/pydicts/foo.py b/test/end-to-end/target-cache/data/pydicts/foo.py index 3218bb76..854c3a3c 100644 --- a/test/end-to-end/target-cache/data/pydicts/foo.py +++ b/test/end-to-end/target-cache/data/pydicts/foo.py @@ -12,4 +12,5 @@ # See the License for the specific language governing permissions and # limitations under the License. +# type: ignore {"foo": "", 0: 4711} -- cgit v1.2.3