diff --git a/cdd/argparse_function/utils/emit_utils.py b/cdd/argparse_function/utils/emit_utils.py index 6cf46997..5a731bdb 100644 --- a/cdd/argparse_function/utils/emit_utils.py +++ b/cdd/argparse_function/utils/emit_utils.py @@ -111,7 +111,7 @@ def parse_out_param(expr, require_default=False, emit_default_doc=True): ), "str", ) - name = get_value(expr.value.args[0])[len("--") :] + name: str = get_value(expr.value.args[0])[len("--") :] default = next( ( get_value(key_word.value) diff --git a/cdd/class_/parse.py b/cdd/class_/parse.py index d1cf861d..1d740c30 100644 --- a/cdd/class_/parse.py +++ b/cdd/class_/parse.py @@ -310,7 +310,7 @@ def _class_from_memory( "from_type": "cls", } if class_name is None: - class_name = parsed_body.name + class_name: Optional[str] = parsed_body.name body_ir: IntermediateRepr = class_( class_def=parsed_body, class_name=class_name, @@ -358,7 +358,7 @@ def _merge_inner_function( }) :rtype: ```dict``` """ - function_def = next( + function_def: Optional[FunctionDef] = next( filter( lambda func: func.name == merge_inner_function, filter(rpartial(isinstance, FunctionDef), ast.walk(class_def)), @@ -367,7 +367,7 @@ def _merge_inner_function( ) if function_def is not None: - function_type = ( + function_type: str = ( "static" if not function_def.args.args else function_def.args.args[0].arg ) inner_ir: IntermediateRepr = cdd.function.parse.function( diff --git a/cdd/compound/exmod.py b/cdd/compound/exmod.py index 214aacb8..82949f45 100644 --- a/cdd/compound/exmod.py +++ b/cdd/compound/exmod.py @@ -8,6 +8,7 @@ from itertools import chain, groupby from operator import attrgetter, itemgetter from os import makedirs, path +from typing import Optional import cdd.class_.parse import cdd.compound.exmod_utils @@ -99,7 +100,7 @@ def exmod( elif not path.isdir(output_directory): makedirs(output_directory) - emit_name = ( + emit_name: Optional[str] = ( emit_name[0] if emit_name is not None and len(emit_name) == 1 diff --git a/cdd/compound/exmod_utils.py b/cdd/compound/exmod_utils.py index 793b4f09..70981341 100644 --- a/cdd/compound/exmod_utils.py +++ b/cdd/compound/exmod_utils.py @@ -9,6 +9,7 @@ from operator import attrgetter, eq from os import environ, extsep, makedirs, path from sys import stdout +from typing import Optional import cdd.argparse_function.emit import cdd.class_ @@ -236,7 +237,7 @@ def emit_file_on_hierarchy( if relative_filename_path.startswith(module_name_as_path + path.sep): relative_filename_path = relative_filename_path[len(new_module_name_as_path) :] if not name and ir.get("name") is not None: - name = ir.get("name") + name: Optional[str] = ir.get("name") output_dir_is_module = output_directory.replace(path.sep, ".").endswith( new_module_name diff --git a/cdd/compound/gen.py b/cdd/compound/gen.py index 404c86e5..9cf539fb 100644 --- a/cdd/compound/gen.py +++ b/cdd/compound/gen.py @@ -181,7 +181,7 @@ def gen( module_path, _, symbol_name = input_mapping.rpartition(".") - emit_name = sanitise_emit_name(emit_name) + emit_name: str = sanitise_emit_name(emit_name) if path.isfile(input_mapping): input_mapping = file_to_input_mapping(input_mapping, parse_name) elif path.isdir(input_mapping): diff --git a/cdd/compound/openapi/gen_openapi.py b/cdd/compound/openapi/gen_openapi.py index c84b06f2..1fe338d3 100644 --- a/cdd/compound/openapi/gen_openapi.py +++ b/cdd/compound/openapi/gen_openapi.py @@ -89,15 +89,15 @@ def construct_parameters_and_request_bodies(route, path_dict): """ if ":" in route: path_dict["parameters"] = [] - object_name = path_dict.get( + object_name: str = path_dict.get( "get", path_dict.get("delete", {"summary": "`Object`"}) )["summary"] - fst = object_name.find("`") - object_name = ( + fst: int = object_name.find("`") + object_name: str = ( object_name[fst + 1 : object_name.find("`", fst + 1)] or "Object" ) - route = "/".join( + route: str = "/".join( map( lambda r: ( lambda pk: ( diff --git a/cdd/shared/cst_utils.py b/cdd/shared/cst_utils.py index 9e5026ca..4f913458 100644 --- a/cdd/shared/cst_utils.py +++ b/cdd/shared/cst_utils.py @@ -456,7 +456,7 @@ def cst_parse_one_node(statement, state): if words: if len(words) > 1: - name = get_construct_name(words) + name: Optional[str] = get_construct_name(words) if name is not None: return ( ClassDefinitionStart diff --git a/cdd/shared/docstring_parsers.py b/cdd/shared/docstring_parsers.py index 458890bb..2cf6c6bf 100644 --- a/cdd/shared/docstring_parsers.py +++ b/cdd/shared/docstring_parsers.py @@ -525,7 +525,7 @@ def _set_name_and_type(param, infer_type, word_wrap, none_default_for_kwargs=Fal ) if name is not None and (name.endswith("kwargs") or name.startswith("**")): - name = name.lstrip("*") + name: str = name.lstrip("*") if _param.get("typ", "dict") == "dict": _param["typ"] = "Optional[dict]" # if ( @@ -535,7 +535,7 @@ def _set_name_and_type(param, infer_type, word_wrap, none_default_for_kwargs=Fal # ) and none_default_for_kwargs: # _param["default"] = NoneStr elif name is not None and name.startswith("*"): - name = name[1:] + name: str = name[1:] if _param.get("typ") is None: _param["typ"] = "tuple" if "default" not in _param: @@ -969,16 +969,16 @@ def _parse_phase_rest( )[1] ) else: - fst_space = line.find(" ") - nxt_colon = line.find(":", fst_space) - name = line[fst_space + 1 : nxt_colon] + fst_space: int = line.find(" ") + nxt_colon: int = line.find(":", fst_space) + name: str = line[fst_space + 1 : nxt_colon] if param[0] is not None and not param[0] == name: if not param[0][0] == "*": intermediate_repr["params"][param[0]] = param[1] param = [None, {}] - val = (lambda s_: s_ if parse_original_whitespace else s_.strip())( + val: str = (lambda s_: s_ if parse_original_whitespace else s_.strip())( line[nxt_colon + 1 :] ) diff --git a/cdd/shared/parse/utils/parser_utils.py b/cdd/shared/parse/utils/parser_utils.py index 5cefbe1f..d74cae3d 100644 --- a/cdd/shared/parse/utils/parser_utils.py +++ b/cdd/shared/parse/utils/parser_utils.py @@ -399,7 +399,7 @@ def get_parser(node, parse_name): :rtype: ```Callable[[...], dict]```` """ if parse_name in (None, "infer"): - parse_name = infer(node) + parse_name: str = infer(node) parse_name = { "class": "class_", "sqlalchemy_hybrid": "sqlalchemy", diff --git a/cdd/shared/pure_utils.py b/cdd/shared/pure_utils.py index a95bae2d..f7945162 100644 --- a/cdd/shared/pure_utils.py +++ b/cdd/shared/pure_utils.py @@ -167,6 +167,7 @@ def identity(*args, **kwargs): PY_GTE_3_8: bool = _python_major_minor >= (3, 8) PY_GTE_3_9: bool = _python_major_minor >= (3, 9) PY_GTE_3_10: bool = _python_major_minor >= (3, 10) +PY_GTE_3_11: bool = _python_major_minor >= (3, 11) PY_GTE_3_12: bool = _python_major_minor >= (3, 12) ENCODING = "# -*- coding: utf-8 -*-" @@ -1278,6 +1279,7 @@ def namespaced_upper_camelcase_to_pascal(s, sep="__"): "ENCODING", "INIT_FILENAME", "PY3_8", + "PY_GTE_3_11", "PY_GTE_3_12", "PY_GTE_3_8", "PY_GTE_3_9", diff --git a/cdd/shared/types.py b/cdd/shared/types.py index aaea1b9a..9ab62cbd 100644 --- a/cdd/shared/types.py +++ b/cdd/shared/types.py @@ -1,16 +1,22 @@ """ Shared types """ -from _ast import AnnAssign, Assign -from cdd.shared.pure_utils import PY_GTE_3_8, PY_GTE_3_9 +from ast import AnnAssign, Assign + +from cdd.shared.pure_utils import PY_GTE_3_8, PY_GTE_3_9, PY_GTE_3_11 if PY_GTE_3_8: if PY_GTE_3_9: from collections import OrderedDict else: from typing import OrderedDict - from typing import Any, List, Optional, Required, TypedDict, Union + from typing import Any, List, Optional, TypedDict, Union + + if PY_GTE_3_11: + from typing import Required + else: + from typing_extensions import Required else: from typing_extensions import ( Any, @@ -33,15 +39,19 @@ ParamVal = TypedDict("ParamVal", {"typ": str, "doc": Optional[str], "default": Any}) +Internal = TypedDict( + "Internal", + { + "original_doc_str": Optional[str], + "body": List[Union[AnnAssign, Assign]], + }, +) IntermediateRepr = TypedDict( "IntermediateRepr", { "name": Required[Optional[str]], "type": Optional[str], - "_internal": { - "original_doc_str": Optional[str], - "body": List[Union[AnnAssign, Assign]], - }, + "_internal": Internal, "doc": Required[Optional[str]], "params": Required[OrderedDict[str, ParamVal]], "returns": Required[ diff --git a/cdd/sqlalchemy/emit.py b/cdd/sqlalchemy/emit.py index b6e4898e..381e6f57 100644 --- a/cdd/sqlalchemy/emit.py +++ b/cdd/sqlalchemy/emit.py @@ -8,6 +8,7 @@ from itertools import chain from operator import add from os import environ +from typing import Optional import cdd.compound.openapi.utils.emit_utils from cdd.docstring.emit import docstring @@ -225,7 +226,7 @@ def sqlalchemy( """ if class_name is None and intermediate_repr["name"]: - class_name = intermediate_repr["name"] + class_name: Optional[str] = intermediate_repr["name"] assert class_name is not None, "`class_name` is `None`" return ClassDef( diff --git a/cdd/tests/mocks/exmod.py b/cdd/tests/mocks/exmod.py index 0114086f..2ed50eba 100644 --- a/cdd/tests/mocks/exmod.py +++ b/cdd/tests/mocks/exmod.py @@ -7,7 +7,7 @@ extracts the `__author__` and `__version__` """ -from ast import Assign, set_value, Str, parse +from ast import Assign, Constant, Str, parse from operator import attrgetter from os import path from os.path import extsep @@ -30,9 +30,9 @@ def main(): parsed_init = parse(f.read()) __author__, __version__ = map( - lambda node: node.value if isinstance(node, set_value) else node.s, + lambda node: node.s if isinstance(node, Str) else node.value, filter( - lambda node: isinstance(node, (set_value, Str)), + lambda node: isinstance(node, (Constant, Str)), map( attrgetter("value"), filter(lambda node: isinstance(node, Assign), parsed_init.body), diff --git a/cdd/tests/test_cli/test_cli_gen.py b/cdd/tests/test_cli/test_cli_gen.py index 6fff3c0d..ea1de201 100644 --- a/cdd/tests/test_cli/test_cli_gen.py +++ b/cdd/tests/test_cli/test_cli_gen.py @@ -24,7 +24,7 @@ def test_gen_fails(self) -> None: def test_existent_file_fails(self) -> None: """Tests nonexistent file throws the right error""" with TemporaryDirectory() as tempdir: - filename = os.path.join( + filename: str = os.path.join( tempdir, "delete_this_1{__file___basename}".format( __file___basename=os.path.basename(__file__) @@ -55,7 +55,7 @@ def test_existent_file_fails(self) -> None: def test_gen(self) -> None: """Tests CLI interface gets all the way to the gen call without error""" with TemporaryDirectory() as tempdir: - output_filename = os.path.join( + output_filename: str = os.path.join( tempdir, "classes{extsep}py".format(extsep=extsep) ) diff --git a/cdd/tests/test_cli/test_cli_sync.py b/cdd/tests/test_cli/test_cli_sync.py index b9515e83..f7475a85 100644 --- a/cdd/tests/test_cli/test_cli_sync.py +++ b/cdd/tests/test_cli/test_cli_sync.py @@ -28,7 +28,7 @@ def test_version(self) -> None: def test_args_example0(self) -> None: """Tests CLI interface sets namespace correctly""" with TemporaryDirectory() as tempdir: - filename = os.path.join( + filename: str = os.path.join( os.path.realpath(tempdir), "delete_this_0{}".format(os.path.basename(__file__)), ) @@ -70,15 +70,15 @@ def test_args_example1(self) -> None: """Tests CLI interface sets namespace correctly""" with TemporaryDirectory() as tempdir: - argparse_filename = os.path.join( + argparse_filename: str = os.path.join( os.path.realpath(tempdir), "argparse{extsep}py".format(extsep=extsep), ) - class_filename = os.path.join( + class_filename: str = os.path.join( os.path.realpath(tempdir), "class_{extsep}py".format(extsep=extsep), ) - method_filename = os.path.join( + method_filename: str = os.path.join( os.path.realpath(tempdir), "method{extsep}py".format(extsep=extsep), ) @@ -125,7 +125,7 @@ def test_args_example1(self) -> None: def test_non_existent_file_fails(self) -> None: """Tests nonexistent file throws the right error""" with TemporaryDirectory() as tempdir: - filename = os.path.join( + filename: str = os.path.join( os.path.realpath(tempdir), "delete_this_1{}".format(os.path.basename(__file__)), ) @@ -159,7 +159,7 @@ def test_missing_argument_fails(self) -> None: def test_missing_argument_fails_insufficient_args(self) -> None: """Tests missing argument throws the right error""" with TemporaryDirectory() as tempdir: - filename = os.path.join( + filename: str = os.path.join( os.path.realpath(tempdir), "delete_this_2{}".format(os.path.basename(__file__)), ) diff --git a/cdd/tests/test_cli/test_cli_sync_properties.py b/cdd/tests/test_cli/test_cli_sync_properties.py index 5e6ccd27..fa208665 100644 --- a/cdd/tests/test_cli/test_cli_sync_properties.py +++ b/cdd/tests/test_cli/test_cli_sync_properties.py @@ -25,7 +25,7 @@ def test_sync_properties_fails(self) -> None: def test_non_existent_file_fails(self) -> None: """Tests nonexistent file throws the right error""" with TemporaryDirectory() as tempdir: - filename = os.path.join( + filename: str = os.path.join( tempdir, "delete_this_1{}".format(os.path.basename(__file__)), ) @@ -50,11 +50,11 @@ def test_non_existent_file_fails(self) -> None: ) with TemporaryDirectory() as tempdir: - input_filename = os.path.join( + input_filename: str = os.path.join( tempdir, "input_filename{extsep}py".format(extsep=extsep), ) - output_filename = os.path.join( + output_filename: str = os.path.join( tempdir, "output_filename{extsep}py".format(extsep=extsep), ) @@ -82,10 +82,10 @@ def test_non_existent_file_fails(self) -> None: def test_sync_properties(self) -> None: """Tests CLI interface gets all the way to the sync_properties call without error""" with TemporaryDirectory() as tempdir: - input_filename = os.path.join( + input_filename: str = os.path.join( tempdir, "class_{extsep}py".format(extsep=extsep) ) - output_filename = os.path.join( + output_filename: str = os.path.join( tempdir, "method{extsep}py".format(extsep=extsep) ) open(input_filename, "wt").close() diff --git a/cdd/tests/test_compound/test_exmod.py b/cdd/tests/test_compound/test_exmod.py index ba74012f..3c04d4b2 100644 --- a/cdd/tests/test_compound/test_exmod.py +++ b/cdd/tests/test_compound/test_exmod.py @@ -28,12 +28,12 @@ class TestExMod(TestCase): """Test class for exmod.py""" - parent_name = "" - parent_dir = "" - child_name = "" - child_dir = "" - grandchild_name = "" - grandchild_dir = "" + parent_name: str = "" + parent_dir: str = "" + child_name: str = "" + child_dir: str = "" + grandchild_name: str = "" + grandchild_dir: str = "" module_hierarchy = () @classmethod diff --git a/cdd/tests/test_compound/test_gen.py b/cdd/tests/test_compound/test_gen.py index ed0cece5..649affeb 100644 --- a/cdd/tests/test_compound/test_gen.py +++ b/cdd/tests/test_compound/test_gen.py @@ -60,7 +60,7 @@ def populate_files(tempdir, input_module_str=None): :return: input filename, input str, expected_output :rtype: ```Tuple[str, str, str, Module]``` """ - input_filename = os.path.join(tempdir, "input{extsep}py".format(extsep=extsep)) + input_filename: str = os.path.join(tempdir, "input{extsep}py".format(extsep=extsep)) input_class_name: str = "Foo" input_class_ast = cdd.class_.emit.class_( cdd.function.parse.function(deepcopy(method_adder_ast)), @@ -159,7 +159,7 @@ def tearDownClass(cls) -> None: def test_gen(self) -> None: """Tests `gen`""" - output_filename = os.path.join( + output_filename: str = os.path.join( self.tempdir, "test_gen_output{extsep}py".format(extsep=extsep) ) with patch("sys.stdout", new_callable=StringIO), patch( @@ -189,7 +189,7 @@ def test_gen(self) -> None: def test_gen_with_imports_from_file(self) -> None: """Tests `gen` with `imports_from_file`""" - output_filename = os.path.join( + output_filename: str = os.path.join( self.tempdir, "test_gen_with_imports_from_file_output{extsep}py".format(extsep=extsep), ) @@ -237,7 +237,7 @@ def test_gen_with_imports_from_file(self) -> None: def test_gen_with_imports_from_file_and_prepended_import(self) -> None: """Tests `gen` with `imports_from_file` and `prepend`""" - output_filename = os.path.join( + output_filename: str = os.path.join( self.tempdir, "test_gen_with_imports_from_file_and_prepended_import_output{extsep}py".format( extsep=extsep diff --git a/cdd/tests/test_compound/test_openapi_sub.py b/cdd/tests/test_compound/test_openapi_sub.py index c8fd8212..1c459d5c 100644 --- a/cdd/tests/test_compound/test_openapi_sub.py +++ b/cdd/tests/test_compound/test_openapi_sub.py @@ -34,8 +34,12 @@ def test_openapi_bulk(self) -> None: temp_dir_join = partial(path.join, tempdir) open(temp_dir_join("__init__{extsep}py".format(extsep=extsep)), "a").close() - models_filename = temp_dir_join("models{extsep}py".format(extsep=extsep)) - routes_filename = temp_dir_join("routes{extsep}py".format(extsep=extsep)) + models_filename: str = temp_dir_join( + "models{extsep}py".format(extsep=extsep) + ) + routes_filename: str = temp_dir_join( + "routes{extsep}py".format(extsep=extsep) + ) with open(models_filename, "wt") as f: f.write( diff --git a/cdd/tests/test_compound/test_sync_properties.py b/cdd/tests/test_compound/test_sync_properties.py index 84590101..84a946bf 100644 --- a/cdd/tests/test_compound/test_sync_properties.py +++ b/cdd/tests/test_compound/test_sync_properties.py @@ -28,8 +28,12 @@ def populate_files(tempdir, input_str=None, output_str=None): :return: input filename, input str, input_str filename :rtype: ```Tuple[str, str, str]``` """ - input_filename = os.path.join(tempdir, "class_{extsep}py".format(extsep=extsep)) - output_filename = os.path.join(tempdir, "method{extsep}py".format(extsep=extsep)) + input_filename: str = os.path.join( + tempdir, "class_{extsep}py".format(extsep=extsep) + ) + output_filename: str = os.path.join( + tempdir, "method{extsep}py".format(extsep=extsep) + ) input_str: str = input_str or ( "from {package} import Literal\n\n" "class Foo(object):\n" @@ -338,10 +342,10 @@ def test_sync_properties_output_param_wrap_fails(self) -> None: def test_sync_properties_eval_fails(self) -> None: """Tests `sync_properties` fails with `call=True` and dots""" with TemporaryDirectory() as tempdir: - input_filename = os.path.join( + input_filename: str = os.path.join( tempdir, "input_{extsep}py".format(extsep=extsep) ) - output_filename = os.path.join( + output_filename: str = os.path.join( tempdir, "input_str{extsep}py".format(extsep=extsep) ) diff --git a/cdd/tests/test_emit/test_emit_file.py b/cdd/tests/test_emit/test_emit_file.py index 5ca92108..0ff9869b 100644 --- a/cdd/tests/test_emit/test_emit_file.py +++ b/cdd/tests/test_emit/test_emit_file.py @@ -31,7 +31,7 @@ def test_to_file(self) -> None: """ with TemporaryDirectory() as tempdir: - filename = os.path.join( + filename: str = os.path.join( tempdir, "delete_me{extsep}py".format(extsep=extsep) ) try: diff --git a/cdd/tests/test_function/test_emit_function.py b/cdd/tests/test_function/test_emit_function.py index fac2cfce..63a4e42b 100644 --- a/cdd/tests/test_function/test_emit_function.py +++ b/cdd/tests/test_function/test_emit_function.py @@ -59,7 +59,7 @@ def test_to_function(self) -> None: ) ) - function_name = function_def.name + function_name: str = function_def.name function_type = get_function_type(function_def) gen_ast = cdd.function.emit.function( @@ -129,7 +129,7 @@ def test_to_function_with_type_annotations(self) -> None: ) ) ) - function_name = function_def.name + function_name: str = function_def.name function_type = get_function_type(function_def) function_def.body[0].value = set_value( "\n{tab}{ds}{tab}".format( @@ -184,7 +184,7 @@ def test_to_function_emit_as_kwonlyargs(self) -> None: ) ) ) - function_name = function_def.name + function_name: str = function_def.name function_type = get_function_type(function_def) gen_ast = cdd.function.emit.function( diff --git a/cdd/tests/test_shared/test_conformance.py b/cdd/tests/test_shared/test_conformance.py index bd8e75fe..dd675def 100644 --- a/cdd/tests/test_shared/test_conformance.py +++ b/cdd/tests/test_shared/test_conformance.py @@ -244,7 +244,7 @@ def test__conform_filename_nonexistent(self) -> None: """Tests that _conform_filename returns the right result""" with TemporaryDirectory() as tempdir: - argparse_function_filename = os.path.realpath( + argparse_function_filename: str = os.path.realpath( os.path.join(tempdir, "no_file_here{extsep}py".format(extsep=extsep)) ) @@ -263,7 +263,7 @@ def test__conform_filename_filled(self) -> None: """Tests that _conform_filename returns the right result""" with TemporaryDirectory() as tempdir: - argparse_function_filename = os.path.realpath( + argparse_function_filename: str = os.path.realpath( os.path.join( tempdir, "correct_contents{extsep}py".format(extsep=extsep) ) @@ -290,7 +290,7 @@ def test__conform_filename_unchanged(self) -> None: """Tests that _conform_filename returns the right result""" with TemporaryDirectory() as tempdir: - argparse_function_filename = os.path.realpath( + argparse_function_filename: str = os.path.realpath( os.path.join( tempdir, "do_not_touch_this{extsep}py".format(extsep=extsep) ) diff --git a/cdd/tests/test_sqlalchemy/test_emit_sqlalchemy_utils.py b/cdd/tests/test_sqlalchemy/test_emit_sqlalchemy_utils.py index ebe7eab4..76a01ddb 100644 --- a/cdd/tests/test_sqlalchemy/test_emit_sqlalchemy_utils.py +++ b/cdd/tests/test_sqlalchemy/test_emit_sqlalchemy_utils.py @@ -4,6 +4,7 @@ import ast import json +from _ast import ClassDef from ast import ( Assign, Call, @@ -293,7 +294,7 @@ def test_update_with_imports_from_columns(self) -> None: with open(node_filename, "wt") as f: f.write(to_code(node_pk_with_phase1_fk)) - element_class = sqlalchemy_table_to_class(element_pk_fk_ass) + element_class: ClassDef = sqlalchemy_table_to_class(element_pk_fk_ass) element_class.name = "Element" with open(element_filename, "wt") as f: @@ -342,7 +343,7 @@ def test_update_fk_for_file(self) -> None: ``` """ with TemporaryDirectory() as tempdir: - mod_name = "test_update_with_imports_from_columns" + mod_name: str = "test_update_with_imports_from_columns" temp_mod_dir: str = path.join(tempdir, mod_name) mkdir(temp_mod_dir) node_filename: str = path.join( diff --git a/cdd/tests/test_sqlalchemy/test_parse_sqlalchemy_utils.py b/cdd/tests/test_sqlalchemy/test_parse_sqlalchemy_utils.py index 70a31221..dcc9d1f4 100644 --- a/cdd/tests/test_sqlalchemy/test_parse_sqlalchemy_utils.py +++ b/cdd/tests/test_sqlalchemy/test_parse_sqlalchemy_utils.py @@ -1,7 +1,7 @@ """ Tests for the utils that is used by the SQLalchemy parsers """ - +from _ast import ClassDef from ast import keyword from copy import deepcopy from unittest import TestCase @@ -104,7 +104,7 @@ def test_get_table_name(self) -> None: Tests `get_table_name` """ self.assertEqual(get_table_name(config_decl_base_ast), "config_tbl") - no_table_name = deepcopy(config_decl_base_ast) + no_table_name: ClassDef = deepcopy(config_decl_base_ast) del no_table_name.body[1] self.assertEqual(get_table_name(no_table_name), "Config") diff --git a/cdd/tests/utils_for_tests.py b/cdd/tests/utils_for_tests.py index c80b7729..aaf2261a 100644 --- a/cdd/tests/utils_for_tests.py +++ b/cdd/tests/utils_for_tests.py @@ -257,9 +257,9 @@ def inspectable_compile(s, modname=None): :rtype: ```Any``` """ fh = NamedTemporaryFile(suffix="{extsep}py".format(extsep=extsep)) - filename = fh.name + filename: str = fh.name try: - modname = modname or path.splitext(path.basename(filename))[0] + modname: str = modname or path.splitext(path.basename(filename))[0] assert modname not in modules # our loader is a dummy one which just spits out our source loader = ShowSourceLoader(modname, s)