From 5bda68b8364a81f533df04e3b56cda3dbd65ae4f Mon Sep 17 00:00:00 2001 From: Samuel Marks <807580+SamuelMarks@users.noreply.github.com> Date: Sat, 25 Nov 2023 23:56:07 -0500 Subject: [PATCH] [cdd/docstring/utils/parse_utils.py] Guard word length ; [cdd/shared/ast_utils.py] Guard no default ; [cdd/tests/test_utils_for_tests.py] `tensorboard_doc_str_no_args_str` -> `tensorboard_doc_str_no_args_str.rstrip(" ")` --- cdd/docstring/utils/parse_utils.py | 2 +- cdd/shared/ast_utils.py | 2 +- cdd/tests/test_shared/test_ast_utils.py | 2 +- cdd/tests/test_sqlalchemy/test_emit_sqlalchemy_utils.py | 2 +- cdd/tests/test_utils_for_tests.py | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cdd/docstring/utils/parse_utils.py b/cdd/docstring/utils/parse_utils.py index 6a9df148..d923aedb 100644 --- a/cdd/docstring/utils/parse_utils.py +++ b/cdd/docstring/utils/parse_utils.py @@ -257,7 +257,7 @@ def parse_adhoc_doc_for_typ(doc, name): if candidate_type is not None: return candidate_type - elif "/" in words[2]: + elif len(words) > 2 and "/" in words[2]: return "Union[{}]".format(",".join(sorted(words[2].split("/")))) return None diff --git a/cdd/shared/ast_utils.py b/cdd/shared/ast_utils.py index ac750fdc..2aeb648f 100644 --- a/cdd/shared/ast_utils.py +++ b/cdd/shared/ast_utils.py @@ -191,7 +191,7 @@ def param2ast(param): # ) elif needs_quoting(_param["typ"]): val = ( - _param["default"] + _param.get("default") if _param.get("default") in (None, NoneStr) else quote(_param["default"]) ) diff --git a/cdd/tests/test_shared/test_ast_utils.py b/cdd/tests/test_shared/test_ast_utils.py index e717e33e..168e8e5a 100644 --- a/cdd/tests/test_shared/test_ast_utils.py +++ b/cdd/tests/test_shared/test_ast_utils.py @@ -1269,7 +1269,7 @@ def test_merge_modules(self) -> None: ) ) - def test_optimise_imports(self): + def test_optimise_imports(self) -> None: """Tests that `optimise_imports` deduplicates""" run_ast_test( self, diff --git a/cdd/tests/test_sqlalchemy/test_emit_sqlalchemy_utils.py b/cdd/tests/test_sqlalchemy/test_emit_sqlalchemy_utils.py index ae157153..ed226990 100644 --- a/cdd/tests/test_sqlalchemy/test_emit_sqlalchemy_utils.py +++ b/cdd/tests/test_sqlalchemy/test_emit_sqlalchemy_utils.py @@ -110,7 +110,7 @@ def test_ensure_has_primary_key_from_id(self) -> None: ir["params"]["id"]["doc"] = "[PK] {}".format(ir["params"]["id"]["doc"]) self.assertDictEqual(res, ir) - def test_generate_create_from_attr_staticmethod(self): + def test_generate_create_from_attr_staticmethod(self) -> None: """Tests that `generate_create_from_attr` staticmethod is correctly constructed""" run_ast_test( self, diff --git a/cdd/tests/test_utils_for_tests.py b/cdd/tests/test_utils_for_tests.py index 8169c0a1..cbf047d0 100644 --- a/cdd/tests/test_utils_for_tests.py +++ b/cdd/tests/test_utils_for_tests.py @@ -123,7 +123,7 @@ def test_remove_args_from_docstring(self) -> None: """ self.assertEqual( remove_args_from_docstring(tensorboard_doc_str), - tensorboard_doc_str_no_args_str, + tensorboard_doc_str_no_args_str.rstrip(" "), )