From bb1e449cff55bdfc30c8257690fd8eadb2891871 Mon Sep 17 00:00:00 2001 From: Arsam Islami Date: Fri, 13 Oct 2023 21:02:25 +0200 Subject: [PATCH 001/109] Added stub generator and functionality for generating a module + imports + package information + class + methods + attr --- src/safeds_stubgen/api_analyzer/__init__.py | 2 + .../api_analyzer/_generate_stubs.py | 238 ++++++++++++++++++ src/safeds_stubgen/api_analyzer/cli/_cli.py | 5 +- .../api_analyzer/test_generate_stubs.py | 0 4 files changed, 244 insertions(+), 1 deletion(-) create mode 100644 src/safeds_stubgen/api_analyzer/_generate_stubs.py create mode 100644 tests/safeds_stubgen/api_analyzer/test_generate_stubs.py diff --git a/src/safeds_stubgen/api_analyzer/__init__.py b/src/safeds_stubgen/api_analyzer/__init__.py index a4babdd1..ac771bbe 100644 --- a/src/safeds_stubgen/api_analyzer/__init__.py +++ b/src/safeds_stubgen/api_analyzer/__init__.py @@ -2,6 +2,7 @@ from __future__ import annotations from ._api import API, Attribute, Class, Function, Parameter, ParameterAssignment +from ._generate_stubs import StubsGenerator from ._get_api import get_api from ._mypy_helpers import get_classdef_definitions, get_funcdef_definitions, get_mypyfile_definitions from ._package_metadata import distribution, distribution_version, package_root @@ -44,6 +45,7 @@ "Parameter", "ParameterAssignment", "SetType", + "StubsGenerator", "TupleType", "UnionType", ] diff --git a/src/safeds_stubgen/api_analyzer/_generate_stubs.py b/src/safeds_stubgen/api_analyzer/_generate_stubs.py new file mode 100644 index 00000000..7a940516 --- /dev/null +++ b/src/safeds_stubgen/api_analyzer/_generate_stubs.py @@ -0,0 +1,238 @@ +from __future__ import annotations + +from pathlib import Path +from typing import Any, TextIO + + +# Todo: Wir ignorieren self parameter im Init, also sollten wir für __init__ Funktionen is_self für parameter +# überprüfen und diesen als Namen dann immer "self" geben, damit diese bei der Classen Erstellung ignoriert werden +# können +# Todo: In der api.json output Datei alle Listen zu dictionaries, da wir sonst immer durch alle Einträge iterieren +# müssen +class StubsGenerator: + api_data: dict[str, Any] + out_path: Path + + def __init__(self, api_data: dict[str, Any], out_path: Path) -> None: + self.api_data = api_data + self.out_path = out_path + + def generate_stubs(self) -> None: + create_directory(Path(self.out_path / self.api_data["package"])) + self._create_module_files() + + # Todo Handle __init__ files + # Dont create modules that start with "_" unless they are reexported with an alias without "_" + # or contain a reexported or public class (?) + def _create_module_files(self) -> None: + modules = self.api_data["modules"] + + for module in modules: + if module["name"] == "__init__": + continue + + module_dir = Path(self.out_path / module["id"]) + create_directory(module_dir) + + file_path = Path(self.out_path / module["id"] / f"{module["name"]}.sdsstub") + create_file(file_path) + + with file_path.open("w") as f: + # Create package info + package_info = module["id"].replace("/", ".") + f.write(f"package {package_info} + \n\n") + + # Create imports + self._write_qualified_imports(f, module["qualified_imports"]) + self._write_wildcard_imports(f, module["wildcard_imports"]) + + # Todo Create global functions + self._write_global_functions() + + # Create classes & class attr. & class methods + for class_ in self.api_data["classes"]: + if class_["is_public"] and class_["id"] in module["classes"]: + self._write_class(f, class_) + + # Todo Create enums & enum instances + self._write_enum() + + # Todo assigned_by, constructors, subclassing + def _write_class(self, f: TextIO, class_data: dict): + # Constructor parameter + class_parameter: list[str] = [] + constructor = class_data["constructor"] + if constructor: + for parameter_id in constructor["parameters"]: + parameter_data = get_data_by_id(self.api_data["parameters"], parameter_id) + if parameter_data["name"] == "self": + continue + class_parameter.append(f"{parameter_data['name']}: {parameter_data['type']['name']}") + + # Class signature line + parameter = ", ".join(class_parameter) + class_sign = f"class {class_data['name']}({parameter}) {{" + f.write(class_sign) + + # Attributes + class_attributes: list[str] = [] + for attribute_id in class_data["attributes"]: + attribute_data = get_data_by_id(self.api_data["attributes"], attribute_id) + if not attribute_data["is_public"]: + continue + + attr_type = create_type_string(attribute_data["type"]) + type_string = f": {attr_type}" if attr_type else "" + class_attributes.append( + f"attr {attribute_data['name']}" + f"{type_string}", + ) + + attributes = "\n\t".join(class_attributes) + f.write(f"\n\t{attributes}") + + # Methods + class_methods: list[str] = [] + for method_id in class_data["methods"]: + method_data = get_data_by_id(self.api_data["functions"], method_id) + if not method_data["is_public"]: + continue + class_methods.append(self._create_function_string(method_data)) + methods = "\n\n\t".join(class_methods) + f.write(f"\n\n\t{methods}") + + # Close class + f.write("\n}") + + # Todo Wie werden mutiple results dargestellt? + def _create_function_string(self, method_data: dict) -> str: + static = "static " if method_data["is_static"] else "" + + # Parameters + parameters: list[str] = [] + for parameter_id in method_data["parameters"]: + parameter_data = get_data_by_id(self.api_data["parameters"], parameter_id) + if parameter_data["name"] == "self": + continue + param_type = create_type_string(parameter_data["type"]) + type_string = f": {param_type}" if param_type else "" + parameters.append( + f"{parameter_data['name']}" + f"{type_string}", + ) + method_params = ", ".join(parameters) + + # Results + results: list[str] = [] + for result_id in method_data["results"]: + result_data = get_data_by_id(self.api_data["results"], result_id) + ret_type = create_type_string(result_data["type"]) + type_string = f": {ret_type}" if ret_type else "" + results.append( + f"{result_data['name']}" + f"{type_string}", + ) + method_results = f" -> {', '.join(results)}" if results else "" + + return f"{static}fun {method_data['name']}({method_params}){method_results}" + + @staticmethod + def _write_qualified_imports(f: TextIO, qualified_imports: list) -> None: + if not qualified_imports: + return + + imports: list[str] = [] + for qualified_import in qualified_imports: + qualified_name = qualified_import["qualified_name"] + split_qname = qualified_name.split(".") + name = split_qname.pop(-1) + import_path = ".".join(split_qname) + from_path = "" + if import_path: + from_path = f"from {import_path} " + + alias = f" as {qualified_import['alias']}" if qualified_import["alias"] else "" + + imports.append( + f"{from_path}import {name}{alias}", + ) + + f.write(f"{'\n'.join(imports)} \n\n") + + @staticmethod + def _write_wildcard_imports(f: TextIO, wildcard_imports: list) -> None: + if not wildcard_imports: + return + + imports = [ + f"from {wildcard_import['module_name']} import *" + for wildcard_import in wildcard_imports + ] + + f.write(f"{'\n'.join(imports)} \n\n") + + def _write_global_functions(self): + pass + + def _write_enum(self): + pass + + +def create_type_string(type_data: dict | None): + if type_data is None: + return "" + + kind = type_data["kind"] + if kind == "NamedType": + name = type_data["name"] + match name: + case "tuple": + return "Tuple" + case "int": + return "Int" + case "str": + return "String" + case "bool": + return "Boolean" + case "float": + return "Float" + case _: + return name + elif kind in {"OptionalType", "FinalType"}: + # Cut out the "Type" in the kind name + name = kind[0:-4] + return f"{name}[{create_type_string(type_data)}]" + elif kind in {"TupleType", "SetType", "ListType", "UnionType"}: + types = [ + create_type_string(type_) + for type_ in type_data["types"] + ] + # Cut out the "Type" in the kind name + name = kind[0:-4] + return f"{name}[{', '.join(types)}]" + elif kind == "DictType": + return ( + f"Dict[" + f"{create_type_string(type_data["key_type"])}, " + f"{create_type_string(type_data["value_type"])}]" + ) + elif kind == "LiteralType": + return f"Literal[{', '.join(type_data['literals'])}]" + + raise ValueError(f"Unexpected type: {kind}") + + +def create_directory(path: Path) -> None: + if not Path.exists(path): + Path.mkdir(path) + + +def create_file(path: Path) -> None: + Path(path).touch() + + +def get_data_by_id(data: list[dict], item_id: str) -> dict: + for item in data: + if item["id"] == item_id: + return item + raise ValueError("Data not found.") diff --git a/src/safeds_stubgen/api_analyzer/cli/_cli.py b/src/safeds_stubgen/api_analyzer/cli/_cli.py index 2700136a..acd80f69 100644 --- a/src/safeds_stubgen/api_analyzer/cli/_cli.py +++ b/src/safeds_stubgen/api_analyzer/cli/_cli.py @@ -5,7 +5,7 @@ from pathlib import Path from typing import TYPE_CHECKING -from safeds_stubgen.api_analyzer import get_api +from safeds_stubgen.api_analyzer import StubsGenerator, get_api if TYPE_CHECKING: from safeds_stubgen.docstring_parsing import DocstringStyle @@ -87,3 +87,6 @@ def _run_api_command( api = get_api(package, src_dir_path, docstring_style, is_test_run) out_file_api = out_dir_path.joinpath(f"{package}__api.json") api.to_json_file(out_file_api) + + stubs_generator = StubsGenerator(api.to_dict(), out_dir_path) + stubs_generator.generate_stubs() diff --git a/tests/safeds_stubgen/api_analyzer/test_generate_stubs.py b/tests/safeds_stubgen/api_analyzer/test_generate_stubs.py new file mode 100644 index 00000000..e69de29b From a7a067c4942999afbc7e66f61ac778de2ec67c62 Mon Sep 17 00:00:00 2001 From: Arsam Islami Date: Fri, 13 Oct 2023 21:47:42 +0200 Subject: [PATCH 002/109] Stubs generator now generates global functions and enums; some small fixes --- .../api_analyzer/_generate_stubs.py | 56 ++++++++++++------- 1 file changed, 37 insertions(+), 19 deletions(-) diff --git a/src/safeds_stubgen/api_analyzer/_generate_stubs.py b/src/safeds_stubgen/api_analyzer/_generate_stubs.py index 7a940516..cc34ee61 100644 --- a/src/safeds_stubgen/api_analyzer/_generate_stubs.py +++ b/src/safeds_stubgen/api_analyzer/_generate_stubs.py @@ -40,22 +40,28 @@ def _create_module_files(self) -> None: with file_path.open("w") as f: # Create package info package_info = module["id"].replace("/", ".") - f.write(f"package {package_info} + \n\n") + f.write(f"package {package_info}\n\n") # Create imports self._write_qualified_imports(f, module["qualified_imports"]) self._write_wildcard_imports(f, module["wildcard_imports"]) + f.write("\n\n") - # Todo Create global functions - self._write_global_functions() + # Create global functions + for function in self.api_data["functions"]: + if function["is_public"] and function["id"] in module["functions"]: + function_string = self._create_function_string(function) + f.write(f"{function_string}\n\n") - # Create classes & class attr. & class methods + # Create classes, class attr. & class methods for class_ in self.api_data["classes"]: if class_["is_public"] and class_["id"] in module["classes"]: self._write_class(f, class_) - # Todo Create enums & enum instances - self._write_enum() + # Create enums & enum instances + for enum in self.api_data["enums"]: + if enum["id"] in module["enums"]: + self._write_enum(f, enum) # Todo assigned_by, constructors, subclassing def _write_class(self, f: TextIO, class_data: dict): @@ -104,7 +110,6 @@ def _write_class(self, f: TextIO, class_data: dict): # Close class f.write("\n}") - # Todo Wie werden mutiple results dargestellt? def _create_function_string(self, method_data: dict) -> str: static = "static " if method_data["is_static"] else "" @@ -157,7 +162,7 @@ def _write_qualified_imports(f: TextIO, qualified_imports: list) -> None: f"{from_path}import {name}{alias}", ) - f.write(f"{'\n'.join(imports)} \n\n") + f.write(f"{'\n'.join(imports)}") @staticmethod def _write_wildcard_imports(f: TextIO, wildcard_imports: list) -> None: @@ -169,13 +174,19 @@ def _write_wildcard_imports(f: TextIO, wildcard_imports: list) -> None: for wildcard_import in wildcard_imports ] - f.write(f"{'\n'.join(imports)} \n\n") + f.write(f"{'\n'.join(imports)}") - def _write_global_functions(self): - pass + def _write_enum(self, f: TextIO, enum_data: dict) -> None: + # Signature + f.write(f"enum {enum_data['name']} {{\n") - def _write_enum(self): - pass + # Enum instances + for enum_instance_id in enum_data["instances"]: + instance = get_data_by_id(self.api_data["enum_instances"], enum_instance_id) + f.write(f"\t{instance['name']},\n") + + # Close + f.write("}\n\n") def create_type_string(type_data: dict | None): @@ -209,13 +220,20 @@ def create_type_string(type_data: dict | None): ] # Cut out the "Type" in the kind name name = kind[0:-4] - return f"{name}[{', '.join(types)}]" + types_string = "" + if types: + types_string = f"[{', '.join(types)}]" + return f"{name}{types_string}" elif kind == "DictType": - return ( - f"Dict[" - f"{create_type_string(type_data["key_type"])}, " - f"{create_type_string(type_data["value_type"])}]" - ) + key_data = create_type_string(type_data["key_type"]) + value_data = create_type_string(type_data["value_type"]) + key_value_data = "" + if key_data: + if value_data: + key_value_data = f"[{key_data}, {value_data}]" + else: + key_value_data = f"[{key_data}]" + return f"Dict{key_value_data}" elif kind == "LiteralType": return f"Literal[{', '.join(type_data['literals'])}]" From d75601547c10bdeb6d73c876f6d984fd29ca5367 Mon Sep 17 00:00:00 2001 From: Arsam Islami Date: Sat, 14 Oct 2023 16:52:30 +0200 Subject: [PATCH 003/109] Added superclasses & parameter default values to stub generator --- .../api_analyzer/_generate_stubs.py | 82 +++++++++++++------ 1 file changed, 58 insertions(+), 24 deletions(-) diff --git a/src/safeds_stubgen/api_analyzer/_generate_stubs.py b/src/safeds_stubgen/api_analyzer/_generate_stubs.py index cc34ee61..ebc05611 100644 --- a/src/safeds_stubgen/api_analyzer/_generate_stubs.py +++ b/src/safeds_stubgen/api_analyzer/_generate_stubs.py @@ -66,18 +66,22 @@ def _create_module_files(self) -> None: # Todo assigned_by, constructors, subclassing def _write_class(self, f: TextIO, class_data: dict): # Constructor parameter - class_parameter: list[str] = [] constructor = class_data["constructor"] + parameter_info = "" if constructor: - for parameter_id in constructor["parameters"]: - parameter_data = get_data_by_id(self.api_data["parameters"], parameter_id) - if parameter_data["name"] == "self": - continue - class_parameter.append(f"{parameter_data['name']}: {parameter_data['type']['name']}") + parameter_info = self._create_parameter_string(constructor) + + # Superclasses + superclasses = class_data["superclasses"] + superclass_info = "" + if superclasses: + superclass_names = [] + for superclass in superclasses: + superclass_names.append(split_import_id(superclass)[1]) + superclass_info = f" sub {', '.join(superclass_names)}" # Class signature line - parameter = ", ".join(class_parameter) - class_sign = f"class {class_data['name']}({parameter}) {{" + class_sign = f"class {class_data['name']}{superclass_info}{parameter_info} {{" f.write(class_sign) # Attributes @@ -114,18 +118,7 @@ def _create_function_string(self, method_data: dict) -> str: static = "static " if method_data["is_static"] else "" # Parameters - parameters: list[str] = [] - for parameter_id in method_data["parameters"]: - parameter_data = get_data_by_id(self.api_data["parameters"], parameter_id) - if parameter_data["name"] == "self": - continue - param_type = create_type_string(parameter_data["type"]) - type_string = f": {param_type}" if param_type else "" - parameters.append( - f"{parameter_data['name']}" - f"{type_string}", - ) - method_params = ", ".join(parameters) + method_params = self._create_parameter_string(method_data) # Results results: list[str] = [] @@ -139,7 +132,40 @@ def _create_function_string(self, method_data: dict) -> str: ) method_results = f" -> {', '.join(results)}" if results else "" - return f"{static}fun {method_data['name']}({method_params}){method_results}" + return f"{static}fun {method_data['name']}{method_params}{method_results}" + + def _create_parameter_string(self, node_data: dict[str, Any]) -> str: + parameters: list[str] = [] + for parameter_id in node_data["parameters"]: + parameter_data = get_data_by_id(self.api_data["parameters"], parameter_id) + + # Skip self parameters + if parameter_data["name"] == "self": + continue + + # Default value + param_value = "" + param_default_value = parameter_data["default_value"] + if param_default_value is not None: + if isinstance(param_default_value, str): + if parameter_data["type"]["kind"] == "NamedType" and parameter_data["type"]["name"] != "str": + default_value = f"{param_default_value}" + else: + default_value = f'"{param_default_value}"' + else: + default_value = param_default_value + param_value = f" = {default_value}" + + # Parameter type + param_type = create_type_string(parameter_data["type"]) + type_string = f": {param_type}" if param_type else "" + + # Create string and append to the list + parameters.append( + f"{parameter_data['name']}" + f"{type_string}{param_value}", + ) + return f"({', '.join(parameters)})" if parameters else "" @staticmethod def _write_qualified_imports(f: TextIO, qualified_imports: list) -> None: @@ -149,9 +175,7 @@ def _write_qualified_imports(f: TextIO, qualified_imports: list) -> None: imports: list[str] = [] for qualified_import in qualified_imports: qualified_name = qualified_import["qualified_name"] - split_qname = qualified_name.split(".") - name = split_qname.pop(-1) - import_path = ".".join(split_qname) + import_path, name = split_import_id(qualified_name) from_path = "" if import_path: from_path = f"from {import_path} " @@ -189,6 +213,16 @@ def _write_enum(self, f: TextIO, enum_data: dict) -> None: f.write("}\n\n") +def split_import_id(id_: str) -> tuple[str, str]: + if "." not in id_: + return "", id_ + + split_qname = id_.split(".") + name = split_qname.pop(-1) + import_path = ".".join(split_qname) + return import_path, name + + def create_type_string(type_data: dict | None): if type_data is None: return "" From 59d2732973fe12ca970ec8c97ad264a2e825fd31 Mon Sep 17 00:00:00 2001 From: Arsam Islami Date: Sat, 14 Oct 2023 18:33:49 +0200 Subject: [PATCH 004/109] Refactoring & some small fixes --- .../api_analyzer/_generate_stubs.py | 83 ++++++++++++------- 1 file changed, 53 insertions(+), 30 deletions(-) diff --git a/src/safeds_stubgen/api_analyzer/_generate_stubs.py b/src/safeds_stubgen/api_analyzer/_generate_stubs.py index ebc05611..3afcd2c9 100644 --- a/src/safeds_stubgen/api_analyzer/_generate_stubs.py +++ b/src/safeds_stubgen/api_analyzer/_generate_stubs.py @@ -4,10 +4,10 @@ from typing import Any, TextIO -# Todo: Wir ignorieren self parameter im Init, also sollten wir für __init__ Funktionen is_self für parameter +# Todo Frage:: Wir ignorieren self parameter im Init, also sollten wir für __init__ Funktionen is_self für parameter # überprüfen und diesen als Namen dann immer "self" geben, damit diese bei der Classen Erstellung ignoriert werden # können -# Todo: In der api.json output Datei alle Listen zu dictionaries, da wir sonst immer durch alle Einträge iterieren +# Todo Frage: In der api.json output Datei alle Listen zu dictionaries, da wir sonst immer durch alle Einträge iterieren # müssen class StubsGenerator: api_data: dict[str, Any] @@ -22,7 +22,7 @@ def generate_stubs(self) -> None: self._create_module_files() # Todo Handle __init__ files - # Dont create modules that start with "_" unless they are reexported with an alias without "_" + # Todo Frage: Dont create modules that start with "_" unless they are reexported with an alias without "_" # or contain a reexported or public class (?) def _create_module_files(self) -> None: modules = self.api_data["modules"] @@ -45,7 +45,7 @@ def _create_module_files(self) -> None: # Create imports self._write_qualified_imports(f, module["qualified_imports"]) self._write_wildcard_imports(f, module["wildcard_imports"]) - f.write("\n\n") + f.write("\n") # Create global functions for function in self.api_data["functions"]: @@ -63,13 +63,13 @@ def _create_module_files(self) -> None: if enum["id"] in module["enums"]: self._write_enum(f, enum) - # Todo assigned_by, constructors, subclassing - def _write_class(self, f: TextIO, class_data: dict): + # Todo assigned_by, constructors + def _write_class(self, f: TextIO, class_data: dict) -> None: # Constructor parameter constructor = class_data["constructor"] parameter_info = "" if constructor: - parameter_info = self._create_parameter_string(constructor) + parameter_info = self._create_parameter_string(constructor["parameters"]) # Superclasses superclasses = class_data["superclasses"] @@ -114,15 +114,22 @@ def _write_class(self, f: TextIO, class_data: dict): # Close class f.write("\n}") - def _create_function_string(self, method_data: dict) -> str: - static = "static " if method_data["is_static"] else "" + def _create_function_string(self, func_data: dict) -> str: + static = "static " if func_data["is_static"] else "" # Parameters - method_params = self._create_parameter_string(method_data) + func_params = self._create_parameter_string(func_data["parameters"]) + if not func_params: + func_params = "()" # Results + func_results = self._create_result_string(func_data["results"]) + + return f"{static}fun {func_data['name']}{func_params}{func_results}" + + def _create_result_string(self, function_result_ids: list[str]) -> str: results: list[str] = [] - for result_id in method_data["results"]: + for result_id in function_result_ids: result_data = get_data_by_id(self.api_data["results"], result_id) ret_type = create_type_string(result_data["type"]) type_string = f": {ret_type}" if ret_type else "" @@ -130,26 +137,33 @@ def _create_function_string(self, method_data: dict) -> str: f"{result_data['name']}" f"{type_string}", ) - method_results = f" -> {', '.join(results)}" if results else "" - - return f"{static}fun {method_data['name']}{method_params}{method_results}" + if results: + if len(results) == 1: + return f" -> {results[0]}" + return f" -> ({', '.join(results)})" + return "" - def _create_parameter_string(self, node_data: dict[str, Any]) -> str: + def _create_parameter_string(self, param_ids: list[str]) -> str: parameters: list[str] = [] - for parameter_id in node_data["parameters"]: - parameter_data = get_data_by_id(self.api_data["parameters"], parameter_id) + for param_id in param_ids: + param_data = get_data_by_id(self.api_data["parameters"], param_id) # Skip self parameters - if parameter_data["name"] == "self": + if param_data["name"] == "self": continue # Default value param_value = "" - param_default_value = parameter_data["default_value"] + param_default_value = param_data["default_value"] if param_default_value is not None: if isinstance(param_default_value, str): - if parameter_data["type"]["kind"] == "NamedType" and parameter_data["type"]["name"] != "str": - default_value = f"{param_default_value}" + if param_data["type"]["kind"] == "NamedType" and param_data["type"]["name"] != "str": + if param_default_value == "False": + default_value = "false" + elif param_default_value == "True": + default_value = "true" + else: + default_value = f"{param_default_value}" else: default_value = f'"{param_default_value}"' else: @@ -157,12 +171,12 @@ def _create_parameter_string(self, node_data: dict[str, Any]) -> str: param_value = f" = {default_value}" # Parameter type - param_type = create_type_string(parameter_data["type"]) + param_type = create_type_string(param_data["type"]) type_string = f": {param_type}" if param_type else "" # Create string and append to the list parameters.append( - f"{parameter_data['name']}" + f"{param_data['name']}" f"{type_string}{param_value}", ) return f"({', '.join(parameters)})" if parameters else "" @@ -186,7 +200,7 @@ def _write_qualified_imports(f: TextIO, qualified_imports: list) -> None: f"{from_path}import {name}{alias}", ) - f.write(f"{'\n'.join(imports)}") + f.write(f"{'\n'.join(imports)}\n") @staticmethod def _write_wildcard_imports(f: TextIO, wildcard_imports: list) -> None: @@ -198,8 +212,9 @@ def _write_wildcard_imports(f: TextIO, wildcard_imports: list) -> None: for wildcard_import in wildcard_imports ] - f.write(f"{'\n'.join(imports)}") + f.write(f"{'\n'.join(imports)}\n") + # Todo Frage: https://dsl.safeds.com/en/latest/language/common/types/#enum-types ff. def _write_enum(self, f: TextIO, enum_data: dict) -> None: # Signature f.write(f"enum {enum_data['name']} {{\n") @@ -241,22 +256,30 @@ def create_type_string(type_data: dict | None): return "Boolean" case "float": return "Float" + case "None": + return "null" case _: return name - elif kind in {"OptionalType", "FinalType"}: - # Cut out the "Type" in the kind name - name = kind[0:-4] - return f"{name}[{create_type_string(type_data)}]" + elif kind == "FinalType": + return f"Final[{create_type_string(type_data)}]" + elif kind == "OptionalType": + return f"{create_type_string(type_data)}?" + # Todo Frage: Groß- und Kleinschreibung der Listen-Arten? "union" klein (warum überhaupt nur Union?), Rest? elif kind in {"TupleType", "SetType", "ListType", "UnionType"}: types = [ create_type_string(type_) for type_ in type_data["types"] ] + # Cut out the "Type" in the kind name name = kind[0:-4] + if name == "Union": + name = "union" + types_string = "" if types: - types_string = f"[{', '.join(types)}]" + types_string = f"<{', '.join(types)}>" if types else "" + return f"{name}{types_string}" elif kind == "DictType": key_data = create_type_string(type_data["key_type"]) From a2baa05958b0eac48e24e973bfc25fa3772a964c Mon Sep 17 00:00:00 2001 From: Arsam Islami Date: Sat, 14 Oct 2023 18:41:32 +0200 Subject: [PATCH 005/109] Refactoring --- src/safeds_stubgen/api_analyzer/_generate_stubs.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/safeds_stubgen/api_analyzer/_generate_stubs.py b/src/safeds_stubgen/api_analyzer/_generate_stubs.py index 3afcd2c9..a8fe23b7 100644 --- a/src/safeds_stubgen/api_analyzer/_generate_stubs.py +++ b/src/safeds_stubgen/api_analyzer/_generate_stubs.py @@ -29,13 +29,16 @@ def _create_module_files(self) -> None: for module in modules: if module["name"] == "__init__": + # self._create_reexport_files() continue + # Create module dir module_dir = Path(self.out_path / module["id"]) create_directory(module_dir) + # Create and open module file file_path = Path(self.out_path / module["id"] / f"{module["name"]}.sdsstub") - create_file(file_path) + Path(file_path).touch() with file_path.open("w") as f: # Create package info @@ -302,10 +305,6 @@ def create_directory(path: Path) -> None: Path.mkdir(path) -def create_file(path: Path) -> None: - Path(path).touch() - - def get_data_by_id(data: list[dict], item_id: str) -> dict: for item in data: if item["id"] == item_id: From 4a3b8bdb6ed49d207e3eeb766d0aeb41ac1f635b Mon Sep 17 00:00:00 2001 From: Arsam Date: Tue, 17 Oct 2023 23:21:46 +0200 Subject: [PATCH 006/109] fixes & refactoring --- src/safeds_stubgen/api_analyzer/_generate_stubs.py | 8 +++++--- src/safeds_stubgen/api_analyzer/_get_api.py | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/safeds_stubgen/api_analyzer/_generate_stubs.py b/src/safeds_stubgen/api_analyzer/_generate_stubs.py index a8fe23b7..74fd7380 100644 --- a/src/safeds_stubgen/api_analyzer/_generate_stubs.py +++ b/src/safeds_stubgen/api_analyzer/_generate_stubs.py @@ -37,7 +37,7 @@ def _create_module_files(self) -> None: create_directory(module_dir) # Create and open module file - file_path = Path(self.out_path / module["id"] / f"{module["name"]}.sdsstub") + file_path = Path(self.out_path / module["id"] / f"{module['name']}.sdsstub") Path(file_path).touch() with file_path.open("w") as f: @@ -203,7 +203,8 @@ def _write_qualified_imports(f: TextIO, qualified_imports: list) -> None: f"{from_path}import {name}{alias}", ) - f.write(f"{'\n'.join(imports)}\n") + all_imports = "\n".join(imports) + f.write(f"{all_imports}\n") @staticmethod def _write_wildcard_imports(f: TextIO, wildcard_imports: list) -> None: @@ -215,7 +216,8 @@ def _write_wildcard_imports(f: TextIO, wildcard_imports: list) -> None: for wildcard_import in wildcard_imports ] - f.write(f"{'\n'.join(imports)}\n") + all_imports = "\n".join(imports) + f.write(f"{all_imports}\n") # Todo Frage: https://dsl.safeds.com/en/latest/language/common/types/#enum-types ff. def _write_enum(self, f: TextIO, enum_data: dict) -> None: diff --git a/src/safeds_stubgen/api_analyzer/_get_api.py b/src/safeds_stubgen/api_analyzer/_get_api.py index ebb9c9a3..b66ba59d 100644 --- a/src/safeds_stubgen/api_analyzer/_get_api.py +++ b/src/safeds_stubgen/api_analyzer/_get_api.py @@ -76,8 +76,8 @@ def _get_mypy_ast(files: list[str], package_paths: list[Path], root: Path) -> li # Build mypy checker mypyfiles, opt = mypy_main.process_options(files) - opt.preserve_asts = True - opt.fine_grained_incremental = True + opt.preserve_asts = True # Disable the memory optimization of freeing ASTs when possible + opt.fine_grained_incremental = True # Only check parts of the code that have changed since the last check result = mypy_build.build(mypyfiles, options=opt) # Check mypy data key root start From 975293bc76db677ddc32c79b338ffd363915f6fb Mon Sep 17 00:00:00 2001 From: Arsam Date: Fri, 20 Oct 2023 14:58:12 +0200 Subject: [PATCH 007/109] Fixed a bug in the get_api call | Stub-Generator: some fixes and added TODO messages for the SafeDS Stubs, if unallowed type hints were used --- .../api_analyzer/_generate_stubs.py | 233 +++++++++++------- src/safeds_stubgen/api_analyzer/_get_api.py | 2 +- 2 files changed, 142 insertions(+), 93 deletions(-) diff --git a/src/safeds_stubgen/api_analyzer/_generate_stubs.py b/src/safeds_stubgen/api_analyzer/_generate_stubs.py index 74fd7380..ec37a94d 100644 --- a/src/safeds_stubgen/api_analyzer/_generate_stubs.py +++ b/src/safeds_stubgen/api_analyzer/_generate_stubs.py @@ -4,26 +4,25 @@ from typing import Any, TextIO -# Todo Frage:: Wir ignorieren self parameter im Init, also sollten wir für __init__ Funktionen is_self für parameter -# überprüfen und diesen als Namen dann immer "self" geben, damit diese bei der Classen Erstellung ignoriert werden -# können -# Todo Frage: In der api.json output Datei alle Listen zu dictionaries, da wir sonst immer durch alle Einträge iterieren -# müssen +# Todo Zugriff auf Daten der API per API-Class, damit man direkt auf die Dictionaries zugreifen kann und nicht über alle +# Listen iterieren muss +# // TODO: Tuples are not allowed in SafeDS. +# // TODO: This List has more than one inner type, which is not allowed. class StubsGenerator: api_data: dict[str, Any] out_path: Path + current_todo_msgs: set[str] def __init__(self, api_data: dict[str, Any], out_path: Path) -> None: self.api_data = api_data self.out_path = out_path + self.current_todo_msgs = set() def generate_stubs(self) -> None: create_directory(Path(self.out_path / self.api_data["package"])) self._create_module_files() # Todo Handle __init__ files - # Todo Frage: Dont create modules that start with "_" unless they are reexported with an alias without "_" - # or contain a reexported or public class (?) def _create_module_files(self) -> None: modules = self.api_data["modules"] @@ -53,26 +52,28 @@ def _create_module_files(self) -> None: # Create global functions for function in self.api_data["functions"]: if function["is_public"] and function["id"] in module["functions"]: - function_string = self._create_function_string(function) + function_string = self._create_function_string(function, 0, is_class_method=False) f.write(f"{function_string}\n\n") # Create classes, class attr. & class methods for class_ in self.api_data["classes"]: if class_["is_public"] and class_["id"] in module["classes"]: - self._write_class(f, class_) + self._write_class(f, class_, 0) # Create enums & enum instances for enum in self.api_data["enums"]: if enum["id"] in module["enums"]: self._write_enum(f, enum) - # Todo assigned_by, constructors - def _write_class(self, f: TextIO, class_data: dict) -> None: + # Todo assigned by https://dsl.safeds.com/en/latest/language/common/parameters/#matching-optionality -> Siehe E-Mail + # -> "// Todo Falsch blabla" über die Zeile generieren + # Todo create inner class + def _write_class(self, f: TextIO, class_data: dict, indent_quant: int) -> None: # Constructor parameter constructor = class_data["constructor"] parameter_info = "" if constructor: - parameter_info = self._create_parameter_string(constructor["parameters"]) + parameter_info = self._create_parameter_string(constructor["parameters"], is_instance_method=True) # Superclasses superclasses = class_data["superclasses"] @@ -84,7 +85,7 @@ def _write_class(self, f: TextIO, class_data: dict) -> None: superclass_info = f" sub {', '.join(superclass_names)}" # Class signature line - class_sign = f"class {class_data['name']}{superclass_info}{parameter_info} {{" + class_sign = f"{self.create_todo_msg(0)}class {class_data['name']}{parameter_info}{superclass_info} {{" f.write(class_sign) # Attributes @@ -94,67 +95,79 @@ def _write_class(self, f: TextIO, class_data: dict) -> None: if not attribute_data["is_public"]: continue - attr_type = create_type_string(attribute_data["type"]) + attr_type = self._create_type_string(attribute_data["type"]) type_string = f": {attr_type}" if attr_type else "" class_attributes.append( + f"{self.create_todo_msg(indent_quant + 1)}" f"attr {attribute_data['name']}" f"{type_string}", ) - attributes = "\n\t".join(class_attributes) + indentations = "\t" * (indent_quant + 1) + attributes = f"\n{indentations}".join(class_attributes) f.write(f"\n\t{attributes}") + # Todo Classes + # Methods class_methods: list[str] = [] for method_id in class_data["methods"]: method_data = get_data_by_id(self.api_data["functions"], method_id) if not method_data["is_public"]: continue - class_methods.append(self._create_function_string(method_data)) + class_methods.append( + self._create_function_string(method_data, indent_quant + 1, is_class_method=True), + ) methods = "\n\n\t".join(class_methods) f.write(f"\n\n\t{methods}") # Close class f.write("\n}") - def _create_function_string(self, func_data: dict) -> str: - static = "static " if func_data["is_static"] else "" + def _create_function_string(self, func_data: dict, indent_quant: int, is_class_method: bool = False) -> str: + is_static = func_data["is_static"] + static = "static " if is_static else "" # Parameters - func_params = self._create_parameter_string(func_data["parameters"]) + is_instance_method = not is_static and is_class_method + func_params = self._create_parameter_string(func_data["parameters"], is_instance_method) if not func_params: func_params = "()" - # Results - func_results = self._create_result_string(func_data["results"]) - - return f"{static}fun {func_data['name']}{func_params}{func_results}" + return ( + f"{self.create_todo_msg(indent_quant)}" + f"{static}fun {func_data['name']}{func_params}" + f"{self._create_result_string(func_data['results'])}" + ) def _create_result_string(self, function_result_ids: list[str]) -> str: results: list[str] = [] for result_id in function_result_ids: result_data = get_data_by_id(self.api_data["results"], result_id) - ret_type = create_type_string(result_data["type"]) + ret_type = self._create_type_string(result_data["type"]) type_string = f": {ret_type}" if ret_type else "" results.append( f"{result_data['name']}" f"{type_string}", ) + if results: if len(results) == 1: return f" -> {results[0]}" return f" -> ({', '.join(results)})" return "" - def _create_parameter_string(self, param_ids: list[str]) -> str: + def _create_parameter_string(self, param_ids: list[str], is_instance_method: bool = False) -> str: parameters: list[str] = [] + first_loop_skipped = False for param_id in param_ids: - param_data = get_data_by_id(self.api_data["parameters"], param_id) - - # Skip self parameters - if param_data["name"] == "self": + # Skip self parameter for functions + if is_instance_method and not first_loop_skipped: + first_loop_skipped = True continue + param_data = get_data_by_id(self.api_data["parameters"], param_id) + # Default value param_value = "" param_default_value = param_data["default_value"] @@ -174,7 +187,7 @@ def _create_parameter_string(self, param_ids: list[str]) -> str: param_value = f" = {default_value}" # Parameter type - param_type = create_type_string(param_data["type"]) + param_type = self._create_type_string(param_data["type"]) type_string = f": {param_type}" if param_type else "" # Create string and append to the list @@ -182,7 +195,9 @@ def _create_parameter_string(self, param_ids: list[str]) -> str: f"{param_data['name']}" f"{type_string}{param_value}", ) - return f"({', '.join(parameters)})" if parameters else "" + if parameters: + return f"({', '.join(parameters)})" + return "" @staticmethod def _write_qualified_imports(f: TextIO, qualified_imports: list) -> None: @@ -219,7 +234,6 @@ def _write_wildcard_imports(f: TextIO, wildcard_imports: list) -> None: all_imports = "\n".join(imports) f.write(f"{all_imports}\n") - # Todo Frage: https://dsl.safeds.com/en/latest/language/common/types/#enum-types ff. def _write_enum(self, f: TextIO, enum_data: dict) -> None: # Signature f.write(f"enum {enum_data['name']} {{\n") @@ -227,11 +241,105 @@ def _write_enum(self, f: TextIO, enum_data: dict) -> None: # Enum instances for enum_instance_id in enum_data["instances"]: instance = get_data_by_id(self.api_data["enum_instances"], enum_instance_id) - f.write(f"\t{instance['name']},\n") + f.write(f"\t{instance['name']}" + ",\n") # Close f.write("}\n\n") + # Todo AnotherClass? anstatt union + def _create_type_string(self, type_data: dict | None) -> str: + """Create a SafeDS stubs type string.""" + if type_data is None: + return "" + + kind = type_data["kind"] + if kind == "NamedType": + name = type_data["name"] + match name: + case "tuple": + self.current_todo_msgs.add("Tuple") + return "Tuple" + case "int": + return "Int" + case "str": + return "String" + case "bool": + return "Boolean" + case "float": + return "Float" + case "None": + return "null" + case _: + return name + elif kind == "FinalType": + return self._create_type_string(type_data) + elif kind == "OptionalType": + return f"{self._create_type_string(type_data)}?" + elif kind in {"SetType", "ListType"}: + types = [ + self._create_type_string(type_) + for type_ in type_data["types"] + ] + + # Cut out the "Type" in the kind name + name = kind[0:-4] + + if types: + if len(types) >= 2: + self.current_todo_msgs.add(name) + return f"{name}<{', '.join(types)}>" + return f"{name}" + elif kind == "UnionType": + types = [ + self._create_type_string(type_) + for type_ in type_data["types"] + ] + + if types: + return f"union<{', '.join(types)}>" + return "" + elif kind == "TupleType": + self.current_todo_msgs.add("Tuple") + types = [ + self._create_type_string(type_) + for type_ in type_data["types"] + ] + + if types: + return f"Tuple<{', '.join(types)}>" + return "Tuple" + elif kind == "DictType": + key_data = self._create_type_string(type_data["key_type"]) + value_data = self._create_type_string(type_data["value_type"]) + if key_data: + if value_data: + return f"Map<{key_data}, {value_data}>" + return f"Map<{key_data}>" + return "Map" + elif kind == "LiteralType": + return f"literal<{', '.join(type_data['literals'])}>" + + raise ValueError(f"Unexpected type: {kind}") + + def create_todo_msg(self, indenta_quant: int) -> str: + if not self.current_todo_msgs: + return "" + + todo_msgs = [] + for msg in self.current_todo_msgs: + if msg == "Tuple": + todo_msgs.append("Tuple types are not allowed") + elif msg in {"List", "Set"}: + todo_msgs.append(f"{msg} type has to many type arguments") + else: + raise ValueError(f"Unknown todo message: {msg}") + + # Empty the message list + self.current_todo_msgs = set() + + indentations = "\t" * indenta_quant + return f"// Todo {', '.join(todo_msgs)}\n{indentations}" + def split_import_id(id_: str) -> tuple[str, str]: if "." not in id_: @@ -243,65 +351,6 @@ def split_import_id(id_: str) -> tuple[str, str]: return import_path, name -def create_type_string(type_data: dict | None): - if type_data is None: - return "" - - kind = type_data["kind"] - if kind == "NamedType": - name = type_data["name"] - match name: - case "tuple": - return "Tuple" - case "int": - return "Int" - case "str": - return "String" - case "bool": - return "Boolean" - case "float": - return "Float" - case "None": - return "null" - case _: - return name - elif kind == "FinalType": - return f"Final[{create_type_string(type_data)}]" - elif kind == "OptionalType": - return f"{create_type_string(type_data)}?" - # Todo Frage: Groß- und Kleinschreibung der Listen-Arten? "union" klein (warum überhaupt nur Union?), Rest? - elif kind in {"TupleType", "SetType", "ListType", "UnionType"}: - types = [ - create_type_string(type_) - for type_ in type_data["types"] - ] - - # Cut out the "Type" in the kind name - name = kind[0:-4] - if name == "Union": - name = "union" - - types_string = "" - if types: - types_string = f"<{', '.join(types)}>" if types else "" - - return f"{name}{types_string}" - elif kind == "DictType": - key_data = create_type_string(type_data["key_type"]) - value_data = create_type_string(type_data["value_type"]) - key_value_data = "" - if key_data: - if value_data: - key_value_data = f"[{key_data}, {value_data}]" - else: - key_value_data = f"[{key_data}]" - return f"Dict{key_value_data}" - elif kind == "LiteralType": - return f"Literal[{', '.join(type_data['literals'])}]" - - raise ValueError(f"Unexpected type: {kind}") - - def create_directory(path: Path) -> None: if not Path.exists(path): Path.mkdir(path) diff --git a/src/safeds_stubgen/api_analyzer/_get_api.py b/src/safeds_stubgen/api_analyzer/_get_api.py index b66ba59d..0e7cffbf 100644 --- a/src/safeds_stubgen/api_analyzer/_get_api.py +++ b/src/safeds_stubgen/api_analyzer/_get_api.py @@ -83,7 +83,7 @@ def _get_mypy_ast(files: list[str], package_paths: list[Path], root: Path) -> li # Check mypy data key root start parts = root.parts graph_keys = list(result.graph.keys()) - root_start_after = 0 + root_start_after = -1 for i in range(len(parts)): if ".".join(parts[i:]) in graph_keys: root_start_after = i From 519aaaea4f34502f615c304fb361fe4327117d75 Mon Sep 17 00:00:00 2001 From: Arsam Date: Fri, 20 Oct 2023 15:26:38 +0200 Subject: [PATCH 008/109] Added nested classes for the stubs generator --- .../api_analyzer/_generate_stubs.py | 35 ++++++++++++------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/src/safeds_stubgen/api_analyzer/_generate_stubs.py b/src/safeds_stubgen/api_analyzer/_generate_stubs.py index ec37a94d..31bf837a 100644 --- a/src/safeds_stubgen/api_analyzer/_generate_stubs.py +++ b/src/safeds_stubgen/api_analyzer/_generate_stubs.py @@ -6,8 +6,6 @@ # Todo Zugriff auf Daten der API per API-Class, damit man direkt auf die Dictionaries zugreifen kann und nicht über alle # Listen iterieren muss -# // TODO: Tuples are not allowed in SafeDS. -# // TODO: This List has more than one inner type, which is not allowed. class StubsGenerator: api_data: dict[str, Any] out_path: Path @@ -67,8 +65,10 @@ def _create_module_files(self) -> None: # Todo assigned by https://dsl.safeds.com/en/latest/language/common/parameters/#matching-optionality -> Siehe E-Mail # -> "// Todo Falsch blabla" über die Zeile generieren - # Todo create inner class def _write_class(self, f: TextIO, class_data: dict, indent_quant: int) -> None: + class_indentation = "\t" * indent_quant + inner_indentations = class_indentation + "\t" + # Constructor parameter constructor = class_data["constructor"] parameter_info = "" @@ -85,8 +85,10 @@ def _write_class(self, f: TextIO, class_data: dict, indent_quant: int) -> None: superclass_info = f" sub {', '.join(superclass_names)}" # Class signature line - class_sign = f"{self.create_todo_msg(0)}class {class_data['name']}{parameter_info}{superclass_info} {{" - f.write(class_sign) + f.write( + f"{class_indentation}{self.create_todo_msg(0)}class " + f"{class_data['name']}{parameter_info}{superclass_info} {{" + ) # Attributes class_attributes: list[str] = [] @@ -103,11 +105,14 @@ def _write_class(self, f: TextIO, class_data: dict, indent_quant: int) -> None: f"{type_string}", ) - indentations = "\t" * (indent_quant + 1) - attributes = f"\n{indentations}".join(class_attributes) - f.write(f"\n\t{attributes}") + attributes = f"\n{inner_indentations}".join(class_attributes) + f.write(f"\n{inner_indentations}{attributes}") - # Todo Classes + # Inner classes + for inner_class_id in class_data["classes"]: + f.write("\n\n") # Todo + inner_class_data = get_data_by_id(self.api_data["classes"], inner_class_id) + self._write_class(f, inner_class_data, indent_quant + 1) # Methods class_methods: list[str] = [] @@ -118,11 +123,11 @@ def _write_class(self, f: TextIO, class_data: dict, indent_quant: int) -> None: class_methods.append( self._create_function_string(method_data, indent_quant + 1, is_class_method=True), ) - methods = "\n\n\t".join(class_methods) - f.write(f"\n\n\t{methods}") + methods = f"\n\n{inner_indentations}".join(class_methods) + f.write(f"\n\n{inner_indentations}{methods}") # Close class - f.write("\n}") + f.write(f"\n{class_indentation}}}") def _create_function_string(self, func_data: dict, indent_quant: int, is_class_method: bool = False) -> str: is_static = func_data["is_static"] @@ -246,7 +251,6 @@ def _write_enum(self, f: TextIO, enum_data: dict) -> None: # Close f.write("}\n\n") - # Todo AnotherClass? anstatt union def _create_type_string(self, type_data: dict | None) -> str: """Create a SafeDS stubs type string.""" if type_data is None: @@ -296,6 +300,11 @@ def _create_type_string(self, type_data: dict | None) -> str: ] if types: + if len(types) == 2 and "null" in types: + if types[0] == "null": + return f"{types[1]}?" + else: + return f"{types[0]}?" return f"union<{', '.join(types)}>" return "" elif kind == "TupleType": From 78143ea50ef1c4d1edbe826d15066eb6549fbad9 Mon Sep 17 00:00:00 2001 From: Arsam Date: Fri, 20 Oct 2023 18:30:06 +0200 Subject: [PATCH 009/109] Refactoring stubs generator: Access to data of the API via API class, so that one can access the dictionaries directly and does not have to iterate over all lists. --- src/safeds_stubgen/api_analyzer/__init__.py | 17 +- src/safeds_stubgen/api_analyzer/_api.py | 6 +- .../api_analyzer/_generate_stubs.py | 179 ++++++++++-------- .../api_analyzer/_mypy_helpers.py | 2 + src/safeds_stubgen/api_analyzer/cli/_cli.py | 2 +- 5 files changed, 120 insertions(+), 86 deletions(-) diff --git a/src/safeds_stubgen/api_analyzer/__init__.py b/src/safeds_stubgen/api_analyzer/__init__.py index ac771bbe..097ecff5 100644 --- a/src/safeds_stubgen/api_analyzer/__init__.py +++ b/src/safeds_stubgen/api_analyzer/__init__.py @@ -1,7 +1,18 @@ """API-Analyzer for the Safe-DS stubs generator.""" from __future__ import annotations -from ._api import API, Attribute, Class, Function, Parameter, ParameterAssignment +from ._api import ( + API, + Attribute, + Class, + Enum, + Function, + Parameter, + ParameterAssignment, + QualifiedImport, + Result, + WildcardImport, +) from ._generate_stubs import StubsGenerator from ._get_api import get_api from ._mypy_helpers import get_classdef_definitions, get_funcdef_definitions, get_mypyfile_definitions @@ -30,6 +41,7 @@ "DictType", "distribution", "distribution_version", + "Enum", "EnumType", "FinalType", "Function", @@ -44,8 +56,11 @@ "package_root", "Parameter", "ParameterAssignment", + "QualifiedImport", + "Result", "SetType", "StubsGenerator", "TupleType", "UnionType", + "WildcardImport", ] diff --git a/src/safeds_stubgen/api_analyzer/_api.py b/src/safeds_stubgen/api_analyzer/_api.py index 201ac5b6..a8e90dc8 100644 --- a/src/safeds_stubgen/api_analyzer/_api.py +++ b/src/safeds_stubgen/api_analyzer/_api.py @@ -165,7 +165,7 @@ def to_dict(self) -> dict[str, Any]: class Class: id: str name: str - superclasses: list[Class] + superclasses: list[str] is_public: bool docstring: ClassDocstring constructor: Function | None = None @@ -286,7 +286,8 @@ class ParameterAssignment(PythonEnum): IMPLICIT parameters appear on instance methods (usually called "self") and on class methods (usually called "cls"). POSITION_ONLY parameters precede the "/" in a parameter list. NAME_ONLY parameters follow the "*" or the POSITIONAL_VARARGS parameter ("*args"). Between the "/" and the "*" the POSITION_OR_NAME parameters reside. Finally, - the parameter list might optionally include a NAMED_VARARG parameter ("**kwargs"). + the parameter list might optionally include a NAMED_VARARG parameter ("**kwargs"). OPT_POS_ONLY is an illegal state + in which an optional parameter can only be passed by position. """ IMPLICIT = "IMPLICIT" @@ -295,6 +296,7 @@ class ParameterAssignment(PythonEnum): POSITIONAL_VARARG = "POSITIONAL_VARARG" NAME_ONLY = "NAME_ONLY" NAMED_VARARG = "NAMED_VARARG" + OPT_POS_ONLY = "OPT_POS_ONLY" @dataclass(frozen=True) diff --git a/src/safeds_stubgen/api_analyzer/_generate_stubs.py b/src/safeds_stubgen/api_analyzer/_generate_stubs.py index 31bf837a..d1264cb3 100644 --- a/src/safeds_stubgen/api_analyzer/_generate_stubs.py +++ b/src/safeds_stubgen/api_analyzer/_generate_stubs.py @@ -1,107 +1,121 @@ from __future__ import annotations from pathlib import Path -from typing import Any, TextIO +from typing import TextIO + +from safeds_stubgen.api_analyzer import ( + API, + Class, + Enum, + Function, + Parameter, + ParameterAssignment, + QualifiedImport, + Result, + WildcardImport, +) -# Todo Zugriff auf Daten der API per API-Class, damit man direkt auf die Dictionaries zugreifen kann und nicht über alle -# Listen iterieren muss class StubsGenerator: - api_data: dict[str, Any] + api: API out_path: Path current_todo_msgs: set[str] - def __init__(self, api_data: dict[str, Any], out_path: Path) -> None: - self.api_data = api_data + def __init__(self, api: API, out_path: Path) -> None: + self.api = api self.out_path = out_path self.current_todo_msgs = set() def generate_stubs(self) -> None: - create_directory(Path(self.out_path / self.api_data["package"])) + create_directory(Path(self.out_path / self.api.package)) self._create_module_files() # Todo Handle __init__ files def _create_module_files(self) -> None: - modules = self.api_data["modules"] + modules = self.api.modules.values() for module in modules: - if module["name"] == "__init__": + module_name = module.name + module_id = module.id + + if module_name == "__init__": # self._create_reexport_files() continue # Create module dir - module_dir = Path(self.out_path / module["id"]) + module_dir = Path(self.out_path / module_id) create_directory(module_dir) # Create and open module file - file_path = Path(self.out_path / module["id"] / f"{module['name']}.sdsstub") + file_path = Path(self.out_path / module_id / f"{module_name}.sdsstub") Path(file_path).touch() with file_path.open("w") as f: # Create package info - package_info = module["id"].replace("/", ".") + package_info = module_id.replace("/", ".") f.write(f"package {package_info}\n\n") # Create imports - self._write_qualified_imports(f, module["qualified_imports"]) - self._write_wildcard_imports(f, module["wildcard_imports"]) + self._write_qualified_imports(f, module.qualified_imports) + self._write_wildcard_imports(f, module.wildcard_imports) f.write("\n") # Create global functions - for function in self.api_data["functions"]: - if function["is_public"] and function["id"] in module["functions"]: + for function in module.global_functions: + if function.is_public: function_string = self._create_function_string(function, 0, is_class_method=False) f.write(f"{function_string}\n\n") # Create classes, class attr. & class methods - for class_ in self.api_data["classes"]: - if class_["is_public"] and class_["id"] in module["classes"]: + for class_ in module.classes: + if class_.is_public: self._write_class(f, class_, 0) # Create enums & enum instances - for enum in self.api_data["enums"]: - if enum["id"] in module["enums"]: - self._write_enum(f, enum) + for enum in module.enums: + self._write_enum(f, enum) - # Todo assigned by https://dsl.safeds.com/en/latest/language/common/parameters/#matching-optionality -> Siehe E-Mail - # -> "// Todo Falsch blabla" über die Zeile generieren - def _write_class(self, f: TextIO, class_data: dict, indent_quant: int) -> None: + def _write_class(self, f: TextIO, class_: Class, indent_quant: int) -> None: class_indentation = "\t" * indent_quant inner_indentations = class_indentation + "\t" # Constructor parameter - constructor = class_data["constructor"] + constructor = class_.constructor parameter_info = "" if constructor: - parameter_info = self._create_parameter_string(constructor["parameters"], is_instance_method=True) + parameter_info = self._create_parameter_string(constructor.parameters, is_instance_method=True) # Superclasses - superclasses = class_data["superclasses"] + superclasses = class_.superclasses superclass_info = "" if superclasses: - superclass_names = [] - for superclass in superclasses: - superclass_names.append(split_import_id(superclass)[1]) + superclass_names = [ + split_import_id(superclass)[1] + for superclass in superclasses + ] superclass_info = f" sub {', '.join(superclass_names)}" # Class signature line f.write( f"{class_indentation}{self.create_todo_msg(0)}class " - f"{class_data['name']}{parameter_info}{superclass_info} {{" + f"{class_.name}{parameter_info}{superclass_info} {{" ) # Attributes class_attributes: list[str] = [] - for attribute_id in class_data["attributes"]: - attribute_data = get_data_by_id(self.api_data["attributes"], attribute_id) - if not attribute_data["is_public"]: + for attribute in class_.attributes: + if not attribute.is_public: continue - attr_type = self._create_type_string(attribute_data["type"]) + attribute_type = None + if attribute.type: + attribute_type = attribute.type.to_dict() + + attr_type = self._create_type_string(attribute_type) type_string = f": {attr_type}" if attr_type else "" class_attributes.append( f"{self.create_todo_msg(indent_quant + 1)}" - f"attr {attribute_data['name']}" + f"attr {attribute.name}" f"{type_string}", ) @@ -109,19 +123,17 @@ def _write_class(self, f: TextIO, class_data: dict, indent_quant: int) -> None: f.write(f"\n{inner_indentations}{attributes}") # Inner classes - for inner_class_id in class_data["classes"]: + for inner_class in class_.classes: f.write("\n\n") # Todo - inner_class_data = get_data_by_id(self.api_data["classes"], inner_class_id) - self._write_class(f, inner_class_data, indent_quant + 1) + self._write_class(f, inner_class, indent_quant + 1) # Methods class_methods: list[str] = [] - for method_id in class_data["methods"]: - method_data = get_data_by_id(self.api_data["functions"], method_id) - if not method_data["is_public"]: + for method in class_.methods: + if not method.is_public: continue class_methods.append( - self._create_function_string(method_data, indent_quant + 1, is_class_method=True), + self._create_function_string(method, indent_quant + 1, is_class_method=True), ) methods = f"\n\n{inner_indentations}".join(class_methods) f.write(f"\n\n{inner_indentations}{methods}") @@ -129,30 +141,30 @@ def _write_class(self, f: TextIO, class_data: dict, indent_quant: int) -> None: # Close class f.write(f"\n{class_indentation}}}") - def _create_function_string(self, func_data: dict, indent_quant: int, is_class_method: bool = False) -> str: - is_static = func_data["is_static"] + def _create_function_string(self, function: Function, indent_quant: int, is_class_method: bool = False) -> str: + is_static = function.is_static static = "static " if is_static else "" # Parameters is_instance_method = not is_static and is_class_method - func_params = self._create_parameter_string(func_data["parameters"], is_instance_method) + func_params = self._create_parameter_string(function.parameters, is_instance_method) if not func_params: func_params = "()" return ( f"{self.create_todo_msg(indent_quant)}" - f"{static}fun {func_data['name']}{func_params}" - f"{self._create_result_string(func_data['results'])}" + f"{static}fun {function.name}{func_params}" + f"{self._create_result_string(function.results)}" ) - def _create_result_string(self, function_result_ids: list[str]) -> str: + def _create_result_string(self, function_results: list[Result]) -> str: results: list[str] = [] - for result_id in function_result_ids: - result_data = get_data_by_id(self.api_data["results"], result_id) - ret_type = self._create_type_string(result_data["type"]) + for result in function_results: + result_type = result.type.to_dict() + ret_type = self._create_type_string(result_type) type_string = f": {ret_type}" if ret_type else "" results.append( - f"{result_data['name']}" + f"{result.name}" f"{type_string}", ) @@ -162,23 +174,22 @@ def _create_result_string(self, function_result_ids: list[str]) -> str: return f" -> ({', '.join(results)})" return "" - def _create_parameter_string(self, param_ids: list[str], is_instance_method: bool = False) -> str: - parameters: list[str] = [] + def _create_parameter_string(self, parameters: list[Parameter], is_instance_method: bool = False) -> str: + parameters_data: list[str] = [] first_loop_skipped = False - for param_id in param_ids: + for parameter in parameters: # Skip self parameter for functions if is_instance_method and not first_loop_skipped: first_loop_skipped = True continue - param_data = get_data_by_id(self.api_data["parameters"], param_id) - # Default value param_value = "" - param_default_value = param_data["default_value"] + param_default_value = parameter.default_value + parameter_type_data = parameter.type.to_dict() if param_default_value is not None: if isinstance(param_default_value, str): - if param_data["type"]["kind"] == "NamedType" and param_data["type"]["name"] != "str": + if parameter_type_data["kind"] == "NamedType" and parameter_type_data["name"] != "str": if param_default_value == "False": default_value = "false" elif param_default_value == "True": @@ -191,33 +202,40 @@ def _create_parameter_string(self, param_ids: list[str], is_instance_method: boo default_value = param_default_value param_value = f" = {default_value}" + # Check if assigned_by is not illegal + assigned_by = parameter.assigned_by + if assigned_by == ParameterAssignment.OPT_POS_ONLY: + self.current_todo_msgs.add("OPT_POS_ONLY") + elif assigned_by == ParameterAssignment.NAME_ONLY and not parameter.is_optional: + self.current_todo_msgs.add("REQ_NAME_ONLY") + # Parameter type - param_type = self._create_type_string(param_data["type"]) + param_type = self._create_type_string(parameter_type_data) type_string = f": {param_type}" if param_type else "" # Create string and append to the list - parameters.append( - f"{param_data['name']}" + parameters_data.append( + f"{parameter.name}" f"{type_string}{param_value}", ) - if parameters: - return f"({', '.join(parameters)})" + if parameters_data: + return f"({', '.join(parameters_data)})" return "" @staticmethod - def _write_qualified_imports(f: TextIO, qualified_imports: list) -> None: + def _write_qualified_imports(f: TextIO, qualified_imports: list[QualifiedImport]) -> None: if not qualified_imports: return imports: list[str] = [] for qualified_import in qualified_imports: - qualified_name = qualified_import["qualified_name"] + qualified_name = qualified_import.qualified_name import_path, name = split_import_id(qualified_name) from_path = "" if import_path: from_path = f"from {import_path} " - alias = f" as {qualified_import['alias']}" if qualified_import["alias"] else "" + alias = f" as {qualified_import.alias}" if qualified_import.alias else "" imports.append( f"{from_path}import {name}{alias}", @@ -227,26 +245,26 @@ def _write_qualified_imports(f: TextIO, qualified_imports: list) -> None: f.write(f"{all_imports}\n") @staticmethod - def _write_wildcard_imports(f: TextIO, wildcard_imports: list) -> None: + def _write_wildcard_imports(f: TextIO, wildcard_imports: list[WildcardImport]) -> None: if not wildcard_imports: return imports = [ - f"from {wildcard_import['module_name']} import *" + f"from {wildcard_import.module_name} import *" for wildcard_import in wildcard_imports ] all_imports = "\n".join(imports) f.write(f"{all_imports}\n") - def _write_enum(self, f: TextIO, enum_data: dict) -> None: + @staticmethod + def _write_enum(f: TextIO, enum_data: Enum) -> None: # Signature - f.write(f"enum {enum_data['name']} {{\n") + f.write(f"enum {enum_data.name} {{\n") # Enum instances - for enum_instance_id in enum_data["instances"]: - instance = get_data_by_id(self.api_data["enum_instances"], enum_instance_id) - f.write(f"\t{instance['name']}" + ",\n") + for enum_instance in enum_data.instances: + f.write(f"\t{enum_instance.name}" + ",\n") # Close f.write("}\n\n") @@ -340,6 +358,10 @@ def create_todo_msg(self, indenta_quant: int) -> str: todo_msgs.append("Tuple types are not allowed") elif msg in {"List", "Set"}: todo_msgs.append(f"{msg} type has to many type arguments") + elif msg == "OPT_POS_ONLY": + todo_msgs.append("Illegal parameter assignment: Optional but position only") + elif msg == "REQ_NAME_ONLY": + todo_msgs.append("Illegal parameter assignment: Required but name only") else: raise ValueError(f"Unknown todo message: {msg}") @@ -363,10 +385,3 @@ def split_import_id(id_: str) -> tuple[str, str]: def create_directory(path: Path) -> None: if not Path.exists(path): Path.mkdir(path) - - -def get_data_by_id(data: list[dict], item_id: str) -> dict: - for item in data: - if item["id"] == item_id: - return item - raise ValueError("Data not found.") diff --git a/src/safeds_stubgen/api_analyzer/_mypy_helpers.py b/src/safeds_stubgen/api_analyzer/_mypy_helpers.py index 951a349b..40b8200d 100644 --- a/src/safeds_stubgen/api_analyzer/_mypy_helpers.py +++ b/src/safeds_stubgen/api_analyzer/_mypy_helpers.py @@ -106,5 +106,7 @@ def get_argument_kind(arg: Argument) -> ParameterAssignment: return ParameterAssignment.NAME_ONLY elif arg.kind == ArgKind.ARG_STAR2: return ParameterAssignment.NAMED_VARARG + elif arg.kind == ArgKind.ARG_OPT and arg.pos_only: + return ParameterAssignment.OPT_POS_ONLY else: raise ValueError("Could not find an appropriate parameter assignment.") diff --git a/src/safeds_stubgen/api_analyzer/cli/_cli.py b/src/safeds_stubgen/api_analyzer/cli/_cli.py index acd80f69..85c08ba6 100644 --- a/src/safeds_stubgen/api_analyzer/cli/_cli.py +++ b/src/safeds_stubgen/api_analyzer/cli/_cli.py @@ -88,5 +88,5 @@ def _run_api_command( out_file_api = out_dir_path.joinpath(f"{package}__api.json") api.to_json_file(out_file_api) - stubs_generator = StubsGenerator(api.to_dict(), out_dir_path) + stubs_generator = StubsGenerator(api, out_dir_path) stubs_generator.generate_stubs() From aa6e543f67ebbf8238a031e5dbc8977d591dc053 Mon Sep 17 00:00:00 2001 From: Arsam Date: Fri, 20 Oct 2023 18:38:09 +0200 Subject: [PATCH 010/109] some fixes --- .../api_analyzer/_generate_stubs.py | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/safeds_stubgen/api_analyzer/_generate_stubs.py b/src/safeds_stubgen/api_analyzer/_generate_stubs.py index d1264cb3..677d829e 100644 --- a/src/safeds_stubgen/api_analyzer/_generate_stubs.py +++ b/src/safeds_stubgen/api_analyzer/_generate_stubs.py @@ -53,18 +53,17 @@ def _create_module_files(self) -> None: with file_path.open("w") as f: # Create package info package_info = module_id.replace("/", ".") - f.write(f"package {package_info}\n\n") + f.write(f"package {package_info}\n") # Create imports self._write_qualified_imports(f, module.qualified_imports) self._write_wildcard_imports(f, module.wildcard_imports) - f.write("\n") # Create global functions for function in module.global_functions: if function.is_public: function_string = self._create_function_string(function, 0, is_class_method=False) - f.write(f"{function_string}\n\n") + f.write(f"\n{function_string}\n") # Create classes, class attr. & class methods for class_ in module.classes: @@ -97,7 +96,7 @@ def _write_class(self, f: TextIO, class_: Class, indent_quant: int) -> None: # Class signature line f.write( - f"{class_indentation}{self.create_todo_msg(0)}class " + f"\n{class_indentation}{self.create_todo_msg(0)}class " f"{class_.name}{parameter_info}{superclass_info} {{" ) @@ -119,12 +118,12 @@ def _write_class(self, f: TextIO, class_: Class, indent_quant: int) -> None: f"{type_string}", ) - attributes = f"\n{inner_indentations}".join(class_attributes) - f.write(f"\n{inner_indentations}{attributes}") + if class_attributes: + attributes = f"\n{inner_indentations}".join(class_attributes) + f.write(f"\n{inner_indentations}{attributes}\n") # Inner classes for inner_class in class_.classes: - f.write("\n\n") # Todo self._write_class(f, inner_class, indent_quant + 1) # Methods @@ -135,11 +134,12 @@ def _write_class(self, f: TextIO, class_: Class, indent_quant: int) -> None: class_methods.append( self._create_function_string(method, indent_quant + 1, is_class_method=True), ) - methods = f"\n\n{inner_indentations}".join(class_methods) - f.write(f"\n\n{inner_indentations}{methods}") + if class_methods: + methods = f"\n\n{inner_indentations}".join(class_methods) + f.write(f"\n{inner_indentations}{methods}\n") # Close class - f.write(f"\n{class_indentation}}}") + f.write(f"{class_indentation}}}\n") def _create_function_string(self, function: Function, indent_quant: int, is_class_method: bool = False) -> str: is_static = function.is_static @@ -242,7 +242,7 @@ def _write_qualified_imports(f: TextIO, qualified_imports: list[QualifiedImport] ) all_imports = "\n".join(imports) - f.write(f"{all_imports}\n") + f.write(f"\n{all_imports}\n") @staticmethod def _write_wildcard_imports(f: TextIO, wildcard_imports: list[WildcardImport]) -> None: @@ -255,19 +255,19 @@ def _write_wildcard_imports(f: TextIO, wildcard_imports: list[WildcardImport]) - ] all_imports = "\n".join(imports) - f.write(f"{all_imports}\n") + f.write(f"\n{all_imports}\n") @staticmethod def _write_enum(f: TextIO, enum_data: Enum) -> None: # Signature - f.write(f"enum {enum_data.name} {{\n") + f.write(f"\nenum {enum_data.name} {{\n") # Enum instances for enum_instance in enum_data.instances: f.write(f"\t{enum_instance.name}" + ",\n") # Close - f.write("}\n\n") + f.write("}\n") def _create_type_string(self, type_data: dict | None) -> str: """Create a SafeDS stubs type string.""" From 5e51e2ea0458ae0b59380f0efb36da9614fe935c Mon Sep 17 00:00:00 2001 From: Arsam Date: Mon, 23 Oct 2023 15:09:39 +0200 Subject: [PATCH 011/109] Fixed a bug in _get_api.py which prevented analysing packages with different path lengths. Fixed a bug _ast_visitor.py for the api data creation, in which the id of modules did not correctly represent their path. --- .../api_analyzer/_ast_visitor.py | 19 +++++++++++++++---- src/safeds_stubgen/api_analyzer/_get_api.py | 2 +- .../__snapshots__/test_main.ambr | 6 +++--- .../__snapshots__/test__get_api.ambr | 4 ++-- 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/safeds_stubgen/api_analyzer/_ast_visitor.py b/src/safeds_stubgen/api_analyzer/_ast_visitor.py index 381bc14d..0e050ee3 100644 --- a/src/safeds_stubgen/api_analyzer/_ast_visitor.py +++ b/src/safeds_stubgen/api_analyzer/_ast_visitor.py @@ -95,13 +95,24 @@ def enter_moduledef(self, node: MypyFile) -> None: elif isinstance(definition, ExpressionStmt) and isinstance(definition.expr, StrExpr): docstring = definition.expr.value + # Create module id to get the full path + module_id_parts = node.fullname.split(self.api.package)[1:] + for i, id_part in enumerate(module_id_parts): + if id_part.startswith("."): + module_id_parts[i] = id_part[1:] + elif id_part.endswith("."): + module_id_parts[i] = id_part[:-1] + module_id_parts[i] = module_id_parts[i].replace(".", "/") + module_id = "/".join([self.api.package, *module_id_parts]) + id_ = self.__get_id(module_id) + # If we are checking a package node.name will be the package name, but since we get import information from # the __init__.py file we set the name to __init__ if is_package: name = "__init__" + id_ += name else: name = node.name - id_ = self.__get_id(name) # Remember module, so we can later add classes and global functions module = Module( @@ -626,9 +637,9 @@ def is_public(self, name: str, qualified_name: str) -> bool: return all(not it.startswith("_") for it in qualified_name.split(".")[:-1]) def __get_id(self, name: str) -> str: - segments = [self.api.package] - segments += [ - it.name + segments = [ + it.id if isinstance(it, Module) # Special case, to get the module path info the id + else it.name for it in self.__declaration_stack if not isinstance(it, list) # Check for the linter, on runtime can never be list type ] diff --git a/src/safeds_stubgen/api_analyzer/_get_api.py b/src/safeds_stubgen/api_analyzer/_get_api.py index ebb9c9a3..bcfeb9ea 100644 --- a/src/safeds_stubgen/api_analyzer/_get_api.py +++ b/src/safeds_stubgen/api_analyzer/_get_api.py @@ -83,7 +83,7 @@ def _get_mypy_ast(files: list[str], package_paths: list[Path], root: Path) -> li # Check mypy data key root start parts = root.parts graph_keys = list(result.graph.keys()) - root_start_after = 0 + root_start_after = -1 for i in range(len(parts)): if ".".join(parts[i:]) in graph_keys: root_start_after = i diff --git a/tests/safeds_stubgen/__snapshots__/test_main.ambr b/tests/safeds_stubgen/__snapshots__/test_main.ambr index c52b6094..d4b89b38 100644 --- a/tests/safeds_stubgen/__snapshots__/test_main.ambr +++ b/tests/safeds_stubgen/__snapshots__/test_main.ambr @@ -698,7 +698,7 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/another_module/AnotherClass', + 'id': 'test_package/another_path/another_module/AnotherClass', 'is_public': True, 'methods': list([ ]), @@ -1977,7 +1977,7 @@ }), dict({ 'classes': list([ - 'test_package/another_module/AnotherClass', + 'test_package/another_path/another_module/AnotherClass', ]), 'docstring': ''' Another Module Docstring. @@ -1989,7 +1989,7 @@ ]), 'functions': list([ ]), - 'id': 'test_package/another_module', + 'id': 'test_package/another_path/another_module', 'name': 'another_module', 'qualified_imports': list([ ]), diff --git a/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr b/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr index d48634ff..fc173fb1 100644 --- a/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr +++ b/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr @@ -2756,7 +2756,7 @@ # name: test_modules_another_module dict({ 'classes': list([ - 'test_package/another_module/AnotherClass', + 'test_package/another_path/another_module/AnotherClass', ]), 'docstring': ''' Another Module Docstring. @@ -2768,7 +2768,7 @@ ]), 'functions': list([ ]), - 'id': 'test_package/another_module', + 'id': 'test_package/another_path/another_module', 'name': 'another_module', 'qualified_imports': list([ ]), From 3a61470ccaf30157b042393bcda6ae4e386d6f7c Mon Sep 17 00:00:00 2001 From: megalinter-bot <129584137+megalinter-bot@users.noreply.github.com> Date: Mon, 23 Oct 2023 13:14:01 +0000 Subject: [PATCH 012/109] style: apply automated linter fixes --- src/safeds_stubgen/api_analyzer/_ast_visitor.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/safeds_stubgen/api_analyzer/_ast_visitor.py b/src/safeds_stubgen/api_analyzer/_ast_visitor.py index 0e050ee3..7d41222e 100644 --- a/src/safeds_stubgen/api_analyzer/_ast_visitor.py +++ b/src/safeds_stubgen/api_analyzer/_ast_visitor.py @@ -638,8 +638,7 @@ def is_public(self, name: str, qualified_name: str) -> bool: def __get_id(self, name: str) -> str: segments = [ - it.id if isinstance(it, Module) # Special case, to get the module path info the id - else it.name + it.id if isinstance(it, Module) else it.name # Special case, to get the module path info the id for it in self.__declaration_stack if not isinstance(it, list) # Check for the linter, on runtime can never be list type ] From 87d8886966c741aa49e2c7a77ee1b80de65c7deb Mon Sep 17 00:00:00 2001 From: Arsam Date: Mon, 23 Oct 2023 15:43:30 +0200 Subject: [PATCH 013/109] Created new package for stubs generation functions, created test file (w/o tests), fixed a bug where creating directories for stubs would cause an exception --- src/safeds_stubgen/api_analyzer/__init__.py | 2 -- src/safeds_stubgen/api_analyzer/cli/_cli.py | 3 ++- src/safeds_stubgen/stubs_generator/__init__.py | 8 ++++++++ .../_generate_stubs.py | 18 ++++++++++++------ .../safeds_stubgen/stubs_generator/__init__.py | 1 + .../stubs_generator/test_generate_stubs.py | 17 +++++++++++++++++ 6 files changed, 40 insertions(+), 9 deletions(-) create mode 100644 src/safeds_stubgen/stubs_generator/__init__.py rename src/safeds_stubgen/{api_analyzer => stubs_generator}/_generate_stubs.py (96%) create mode 100644 tests/safeds_stubgen/stubs_generator/__init__.py create mode 100644 tests/safeds_stubgen/stubs_generator/test_generate_stubs.py diff --git a/src/safeds_stubgen/api_analyzer/__init__.py b/src/safeds_stubgen/api_analyzer/__init__.py index 097ecff5..63ab3098 100644 --- a/src/safeds_stubgen/api_analyzer/__init__.py +++ b/src/safeds_stubgen/api_analyzer/__init__.py @@ -13,7 +13,6 @@ Result, WildcardImport, ) -from ._generate_stubs import StubsGenerator from ._get_api import get_api from ._mypy_helpers import get_classdef_definitions, get_funcdef_definitions, get_mypyfile_definitions from ._package_metadata import distribution, distribution_version, package_root @@ -59,7 +58,6 @@ "QualifiedImport", "Result", "SetType", - "StubsGenerator", "TupleType", "UnionType", "WildcardImport", diff --git a/src/safeds_stubgen/api_analyzer/cli/_cli.py b/src/safeds_stubgen/api_analyzer/cli/_cli.py index 85c08ba6..67c4cb91 100644 --- a/src/safeds_stubgen/api_analyzer/cli/_cli.py +++ b/src/safeds_stubgen/api_analyzer/cli/_cli.py @@ -5,7 +5,8 @@ from pathlib import Path from typing import TYPE_CHECKING -from safeds_stubgen.api_analyzer import StubsGenerator, get_api +from safeds_stubgen.api_analyzer import get_api +from safeds_stubgen.stubs_generator import StubsGenerator if TYPE_CHECKING: from safeds_stubgen.docstring_parsing import DocstringStyle diff --git a/src/safeds_stubgen/stubs_generator/__init__.py b/src/safeds_stubgen/stubs_generator/__init__.py new file mode 100644 index 00000000..d6e89475 --- /dev/null +++ b/src/safeds_stubgen/stubs_generator/__init__.py @@ -0,0 +1,8 @@ +"""API-Analyzer for the Safe-DS stubs generator.""" +from __future__ import annotations + +from ._generate_stubs import StubsGenerator + +__all__ = [ + "StubsGenerator", +] diff --git a/src/safeds_stubgen/api_analyzer/_generate_stubs.py b/src/safeds_stubgen/stubs_generator/_generate_stubs.py similarity index 96% rename from src/safeds_stubgen/api_analyzer/_generate_stubs.py rename to src/safeds_stubgen/stubs_generator/_generate_stubs.py index 677d829e..978b968a 100644 --- a/src/safeds_stubgen/api_analyzer/_generate_stubs.py +++ b/src/safeds_stubgen/stubs_generator/_generate_stubs.py @@ -30,7 +30,6 @@ def generate_stubs(self) -> None: create_directory(Path(self.out_path / self.api.package)) self._create_module_files() - # Todo Handle __init__ files def _create_module_files(self) -> None: modules = self.api.modules.values() @@ -39,7 +38,9 @@ def _create_module_files(self) -> None: module_id = module.id if module_name == "__init__": - # self._create_reexport_files() + # Todo Handle __init__ files + # Todo Handle reexported files that are already created + self._create_reexported_files() continue # Create module dir @@ -47,7 +48,7 @@ def _create_module_files(self) -> None: create_directory(module_dir) # Create and open module file - file_path = Path(self.out_path / module_id / f"{module_name}.sdsstub") + file_path = Path(module_dir / f"{module_name}.sdsstub") Path(file_path).touch() with file_path.open("w") as f: @@ -74,6 +75,9 @@ def _create_module_files(self) -> None: for enum in module.enums: self._write_enum(f, enum) + def _create_reexported_files(self): + pass + def _write_class(self, f: TextIO, class_: Class, indent_quant: int) -> None: class_indentation = "\t" * indent_quant inner_indentations = class_indentation + "\t" @@ -355,7 +359,7 @@ def create_todo_msg(self, indenta_quant: int) -> str: todo_msgs = [] for msg in self.current_todo_msgs: if msg == "Tuple": - todo_msgs.append("Tuple types are not allowed") + todo_msgs.append("Tuple types are not allowed in SafeDS") elif msg in {"List", "Set"}: todo_msgs.append(f"{msg} type has to many type arguments") elif msg == "OPT_POS_ONLY": @@ -383,5 +387,7 @@ def split_import_id(id_: str) -> tuple[str, str]: def create_directory(path: Path) -> None: - if not Path.exists(path): - Path.mkdir(path) + for i, _ in enumerate(path.parts): + new_path = Path("/".join(path.parts[:i+1])) + if not new_path.exists(): + Path.mkdir(new_path) diff --git a/tests/safeds_stubgen/stubs_generator/__init__.py b/tests/safeds_stubgen/stubs_generator/__init__.py new file mode 100644 index 00000000..9d48db4f --- /dev/null +++ b/tests/safeds_stubgen/stubs_generator/__init__.py @@ -0,0 +1 @@ +from __future__ import annotations diff --git a/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py b/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py new file mode 100644 index 00000000..5043e7c2 --- /dev/null +++ b/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py @@ -0,0 +1,17 @@ +from __future__ import annotations + +from pathlib import Path + +from safeds_stubgen.api_analyzer import get_api +from safeds_stubgen.stubs_generator import StubsGenerator + +# Setup - Run API to create stub files +_lib_dir = Path(__file__).parent.parent.parent +_test_package_name = "test_package" +_test_package_dir = Path(_lib_dir / "tests" / "data" / _test_package_name) +_out_dir = Path(_lib_dir / "tests" / "data" / "out") +_out_dir_stubs = Path(_out_dir / _test_package_name) + +api = get_api(_test_package_name, _test_package_dir, is_test_run=True) +stubs_generator = StubsGenerator(api, _out_dir) +stubs_generator.generate_stubs() From 3d8aee41f016590cd1ed7a655eb6a286ae324aa9 Mon Sep 17 00:00:00 2001 From: Arsam Date: Mon, 23 Oct 2023 16:46:19 +0200 Subject: [PATCH 014/109] Added test cases for files, directories, classes, functions and attributes that have the same name as the source package --- .../api_analyzer/_ast_visitor.py | 11 +- .../test_package/test_package/__init__.py | 0 .../test_package/test_package/test_package.py | 8 ++ .../__snapshots__/test_main.ambr | 122 ++++++++++++++++++ .../__snapshots__/test__get_api.ambr | 84 ++++++++++++ .../api_analyzer/test__get_api.py | 20 +++ 6 files changed, 238 insertions(+), 7 deletions(-) create mode 100644 tests/data/test_package/test_package/__init__.py create mode 100644 tests/data/test_package/test_package/test_package.py diff --git a/src/safeds_stubgen/api_analyzer/_ast_visitor.py b/src/safeds_stubgen/api_analyzer/_ast_visitor.py index 0e050ee3..04f0ebe4 100644 --- a/src/safeds_stubgen/api_analyzer/_ast_visitor.py +++ b/src/safeds_stubgen/api_analyzer/_ast_visitor.py @@ -97,13 +97,10 @@ def enter_moduledef(self, node: MypyFile) -> None: # Create module id to get the full path module_id_parts = node.fullname.split(self.api.package)[1:] - for i, id_part in enumerate(module_id_parts): - if id_part.startswith("."): - module_id_parts[i] = id_part[1:] - elif id_part.endswith("."): - module_id_parts[i] = id_part[:-1] - module_id_parts[i] = module_id_parts[i].replace(".", "/") - module_id = "/".join([self.api.package, *module_id_parts]) + module_id = self.api.package.join(module_id_parts) + if module_id.startswith("."): + module_id = module_id[1:] + module_id = f"{self.api.package}/{module_id.replace(".", "/")}" id_ = self.__get_id(module_id) # If we are checking a package node.name will be the package name, but since we get import information from diff --git a/tests/data/test_package/test_package/__init__.py b/tests/data/test_package/test_package/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/data/test_package/test_package/test_package.py b/tests/data/test_package/test_package/test_package.py new file mode 100644 index 00000000..901fb715 --- /dev/null +++ b/tests/data/test_package/test_package/test_package.py @@ -0,0 +1,8 @@ +class TestPackage: + def test_package(self): + return self.test_package + + +# noinspection PyPep8Naming +class test_package: + test_package: int = 1 diff --git a/tests/safeds_stubgen/__snapshots__/test_main.ambr b/tests/safeds_stubgen/__snapshots__/test_main.ambr index d4b89b38..79cb6a84 100644 --- a/tests/safeds_stubgen/__snapshots__/test_main.ambr +++ b/tests/safeds_stubgen/__snapshots__/test_main.ambr @@ -602,6 +602,21 @@ 'name': 'int', }), }), + dict({ + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_package/test_package/test_package/test_package/test_package', + 'is_public': True, + 'is_static': True, + 'name': 'test_package', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'int', + }), + }), ]), 'classes': list([ dict({ @@ -1134,6 +1149,48 @@ 'superclasses': list([ ]), }), + dict({ + 'attributes': list([ + ]), + 'classes': list([ + ]), + 'constructor': None, + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_package/test_package/test_package/TestPackage', + 'is_public': True, + 'methods': list([ + 'test_package/test_package/test_package/TestPackage/test_package', + ]), + 'name': 'TestPackage', + 'reexported_by': list([ + ]), + 'superclasses': list([ + ]), + }), + dict({ + 'attributes': list([ + 'test_package/test_package/test_package/test_package/test_package', + ]), + 'classes': list([ + ]), + 'constructor': None, + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_package/test_package/test_package/test_package', + 'is_public': True, + 'methods': list([ + ]), + 'name': 'test_package', + 'reexported_by': list([ + ]), + 'superclasses': list([ + ]), + }), ]), 'distribution': '', 'enum_instances': list([ @@ -1862,6 +1919,23 @@ 'test_package/test_module/global_func/result_1', ]), }), + dict({ + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_package/test_package/test_package/TestPackage/test_package', + 'is_public': True, + 'is_static': False, + 'name': 'test_package', + 'parameters': list([ + 'test_package/test_package/test_package/TestPackage/test_package/self', + ]), + 'reexported_by': list([ + ]), + 'results': list([ + ]), + }), ]), 'modules': list([ dict({ @@ -2095,6 +2169,38 @@ }), ]), }), + dict({ + 'classes': list([ + 'test_package/test_package/test_package/TestPackage', + 'test_package/test_package/test_package/test_package', + ]), + 'docstring': '', + 'enums': list([ + ]), + 'functions': list([ + ]), + 'id': 'test_package/test_package/test_package', + 'name': 'test_package', + 'qualified_imports': list([ + ]), + 'wildcard_imports': list([ + ]), + }), + dict({ + 'classes': list([ + ]), + 'docstring': '', + 'enums': list([ + ]), + 'functions': list([ + ]), + 'id': 'test_package/test_package__init__', + 'name': '__init__', + 'qualified_imports': list([ + ]), + 'wildcard_imports': list([ + ]), + }), ]), 'package': 'test_package', 'parameters': list([ @@ -2828,6 +2934,22 @@ ]), }), }), + dict({ + 'assigned_by': 'IMPLICIT', + 'default_value': None, + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_package/test_package/test_package/TestPackage/test_package/self', + 'is_optional': False, + 'name': 'self', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'TestPackage', + }), + }), ]), 'results': list([ dict({ diff --git a/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr b/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr index fc173fb1..af3adeb2 100644 --- a/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr +++ b/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr @@ -616,6 +616,25 @@ }), ]) # --- +# name: test_class_attributes_test_package + list([ + dict({ + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_package/test_package/test_package/test_package/test_package', + 'is_public': True, + 'is_static': True, + 'name': 'test_package', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'int', + }), + }), + ]) +# --- # name: test_class_methods_EpydocDocstringClass list([ dict({ @@ -1448,6 +1467,29 @@ ]), }) # --- +# name: test_classes_TestPackage + dict({ + 'attributes': list([ + ]), + 'classes': list([ + ]), + 'constructor': None, + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_package/test_package/test_package/TestPackage', + 'is_public': True, + 'methods': list([ + 'test_package/test_package/test_package/TestPackage/test_package', + ]), + 'name': 'TestPackage', + 'reexported_by': list([ + ]), + 'superclasses': list([ + ]), + }) +# --- # name: test_classes__PrivateClass dict({ 'attributes': list([ @@ -1513,6 +1555,29 @@ ]), }) # --- +# name: test_classes_test_package + dict({ + 'attributes': list([ + 'test_package/test_package/test_package/test_package/test_package', + ]), + 'classes': list([ + ]), + 'constructor': None, + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_package/test_package/test_package/test_package', + 'is_public': True, + 'methods': list([ + ]), + 'name': 'test_package', + 'reexported_by': list([ + ]), + 'superclasses': list([ + ]), + }) +# --- # name: test_enum_instances_AnotherTestEnum list([ dict({ @@ -2881,3 +2946,22 @@ ]), }) # --- +# name: test_modules_test_package + dict({ + 'classes': list([ + 'test_package/test_package/test_package/TestPackage', + 'test_package/test_package/test_package/test_package', + ]), + 'docstring': '', + 'enums': list([ + ]), + 'functions': list([ + ]), + 'id': 'test_package/test_package/test_package', + 'name': 'test_package', + 'qualified_imports': list([ + ]), + 'wildcard_imports': list([ + ]), + }) +# --- diff --git a/tests/safeds_stubgen/api_analyzer/test__get_api.py b/tests/safeds_stubgen/api_analyzer/test__get_api.py index 68024ceb..8b7ae699 100644 --- a/tests/safeds_stubgen/api_analyzer/test__get_api.py +++ b/tests/safeds_stubgen/api_analyzer/test__get_api.py @@ -106,6 +106,11 @@ def test_modules_another_module(snapshot: SnapshotAssertion) -> None: assert module_data == snapshot +def test_modules_test_package(snapshot: SnapshotAssertion) -> None: + module_data = _get_specific_module_data("test_package") + assert module_data == snapshot + + def test_modules_test_enums(snapshot: SnapshotAssertion) -> None: module_data = _get_specific_module_data("test_enums") assert module_data == snapshot @@ -223,6 +228,16 @@ def test_classes_FourthReexportClass(snapshot: SnapshotAssertion) -> None: # no assert class_data == snapshot +def test_classes_TestPackage(snapshot: SnapshotAssertion) -> None: # noqa: N802 + class_data = _get_specific_class_data("TestPackage", "plaintext") + assert class_data == snapshot + + +def test_classes_test_package(snapshot: SnapshotAssertion) -> None: + class_data = _get_specific_class_data("test_package", "plaintext") + assert class_data == snapshot + + # ############################## Class Attributes ############################## # def get_class_attribute_data(class_name: str, docstring_style: str) -> list: class_data: dict = _get_specific_class_data(class_name) @@ -280,6 +295,11 @@ def test_class_attributes_GoogleDocstringClass(snapshot: SnapshotAssertion) -> N assert class_data == snapshot +def test_class_attributes_test_package(snapshot: SnapshotAssertion) -> None: + class_data = get_class_attribute_data("test_package", "plaintext") + assert class_data == snapshot + + # ############################## Enums ############################## # def test_enums_EnumTest(snapshot: SnapshotAssertion) -> None: # noqa: N802 enum_data = _get_specific_class_data("EnumTest", is_enum=True) From 7f4dd646f28b7602757b554fa3bbee3f23ad2ade Mon Sep 17 00:00:00 2001 From: Arsam Date: Mon, 23 Oct 2023 16:53:58 +0200 Subject: [PATCH 015/109] linter fix --- src/safeds_stubgen/api_analyzer/_ast_visitor.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/safeds_stubgen/api_analyzer/_ast_visitor.py b/src/safeds_stubgen/api_analyzer/_ast_visitor.py index b685a601..ed81f856 100644 --- a/src/safeds_stubgen/api_analyzer/_ast_visitor.py +++ b/src/safeds_stubgen/api_analyzer/_ast_visitor.py @@ -100,8 +100,9 @@ def enter_moduledef(self, node: MypyFile) -> None: module_id = self.api.package.join(module_id_parts) if module_id.startswith("."): module_id = module_id[1:] - module_id = f"{self.api.package}/{module_id.replace(".", "/")}" - id_ = self.__get_id(module_id) + module_id = module_id.replace(".", "/") + formatted_module_id = f"{self.api.package}/{module_id}" + id_ = self.__get_id(formatted_module_id) # If we are checking a package node.name will be the package name, but since we get import information from # the __init__.py file we set the name to __init__ From cbf2efabe9533e620e73db3e69b6d70bb58cdbb4 Mon Sep 17 00:00:00 2001 From: Arsam Date: Sun, 5 Nov 2023 14:57:17 +0100 Subject: [PATCH 016/109] Removed OPT_POS_ONLY from ParameterAssignment enum and added todos --- src/safeds_stubgen/api_analyzer/_api.py | 4 +-- .../api_analyzer/_mypy_helpers.py | 4 +-- .../stubs_generator/_generate_stubs.py | 28 ++++++++++++++++++- 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/safeds_stubgen/api_analyzer/_api.py b/src/safeds_stubgen/api_analyzer/_api.py index a8e90dc8..7439796c 100644 --- a/src/safeds_stubgen/api_analyzer/_api.py +++ b/src/safeds_stubgen/api_analyzer/_api.py @@ -286,8 +286,7 @@ class ParameterAssignment(PythonEnum): IMPLICIT parameters appear on instance methods (usually called "self") and on class methods (usually called "cls"). POSITION_ONLY parameters precede the "/" in a parameter list. NAME_ONLY parameters follow the "*" or the POSITIONAL_VARARGS parameter ("*args"). Between the "/" and the "*" the POSITION_OR_NAME parameters reside. Finally, - the parameter list might optionally include a NAMED_VARARG parameter ("**kwargs"). OPT_POS_ONLY is an illegal state - in which an optional parameter can only be passed by position. + the parameter list might optionally include a NAMED_VARARG parameter ("**kwargs"). """ IMPLICIT = "IMPLICIT" @@ -296,7 +295,6 @@ class ParameterAssignment(PythonEnum): POSITIONAL_VARARG = "POSITIONAL_VARARG" NAME_ONLY = "NAME_ONLY" NAMED_VARARG = "NAMED_VARARG" - OPT_POS_ONLY = "OPT_POS_ONLY" @dataclass(frozen=True) diff --git a/src/safeds_stubgen/api_analyzer/_mypy_helpers.py b/src/safeds_stubgen/api_analyzer/_mypy_helpers.py index 40b8200d..03d1d0ea 100644 --- a/src/safeds_stubgen/api_analyzer/_mypy_helpers.py +++ b/src/safeds_stubgen/api_analyzer/_mypy_helpers.py @@ -96,7 +96,7 @@ def mypy_type_to_abstract_type(mypy_type: Instance | ProperType | MypyType) -> A def get_argument_kind(arg: Argument) -> ParameterAssignment: if arg.variable.is_self or arg.variable.is_cls: return ParameterAssignment.IMPLICIT - elif arg.kind == ArgKind.ARG_POS and arg.pos_only: + elif (arg.kind == ArgKind.ARG_POS or arg.kind == ArgKind.ARG_OPT) and arg.pos_only: return ParameterAssignment.POSITION_ONLY elif arg.kind in (ArgKind.ARG_OPT, ArgKind.ARG_POS) and not arg.pos_only: return ParameterAssignment.POSITION_OR_NAME @@ -106,7 +106,5 @@ def get_argument_kind(arg: Argument) -> ParameterAssignment: return ParameterAssignment.NAME_ONLY elif arg.kind == ArgKind.ARG_STAR2: return ParameterAssignment.NAMED_VARARG - elif arg.kind == ArgKind.ARG_OPT and arg.pos_only: - return ParameterAssignment.OPT_POS_ONLY else: raise ValueError("Could not find an appropriate parameter assignment.") diff --git a/src/safeds_stubgen/stubs_generator/_generate_stubs.py b/src/safeds_stubgen/stubs_generator/_generate_stubs.py index 978b968a..eed36778 100644 --- a/src/safeds_stubgen/stubs_generator/_generate_stubs.py +++ b/src/safeds_stubgen/stubs_generator/_generate_stubs.py @@ -16,6 +16,32 @@ ) +# Todo Null nicht als type (für bspw. Arugmente), stattdessen "Nothing?" +""" Todo https://github.com/Safe-DS/DSL/blob/main/syntaxes/safe-ds.tmLanguage.json + { + "name": "constant.language.safe-ds", + "match": "\\b(false|null|true)\\b" + }, + { + "name": "storage.type.safe-ds", + "match": "\\b(annotation|attr|class|enum|fun|package|pipeline|schema|segment|val)\\b" + }, + { + "name": "storage.modifier.safe-ds", + "match": "\\b(const|in|internal|out|private|static)\\b" + }, + { + "name": "keyword.operator.safe-ds", + "match": "\\b(and|not|or|sub|super)\\b" + }, + { + "name": "keyword.other.safe-ds", + "match": "\\b(as|from|import|literal|union|where|yield)\\b" + } + + In den match Felder -> bspw.: Bei enum import `enum` +""" +# Todo Keine Kommas nach Enum Instanzen class StubsGenerator: api: API out_path: Path @@ -208,7 +234,7 @@ def _create_parameter_string(self, parameters: list[Parameter], is_instance_meth # Check if assigned_by is not illegal assigned_by = parameter.assigned_by - if assigned_by == ParameterAssignment.OPT_POS_ONLY: + if assigned_by == ParameterAssignment.POSITION_ONLY and parameter.default_value is not None: self.current_todo_msgs.add("OPT_POS_ONLY") elif assigned_by == ParameterAssignment.NAME_ONLY and not parameter.is_optional: self.current_todo_msgs.add("REQ_NAME_ONLY") From 5ad4b696c978798442962ab7b1f84fcafa3753cc Mon Sep 17 00:00:00 2001 From: Arsam Date: Sun, 5 Nov 2023 18:56:59 +0100 Subject: [PATCH 017/109] Added tests for the stubs generation --- .../stubs_generator/_generate_stubs.py | 61 ++++---- .../test_stub_generation/attribute_module.py | 36 +++++ .../data/test_stub_generation/class_module.py | 15 ++ .../data/test_stub_generation/enum_module.py | 19 +++ .../test_stub_generation/function_module.py | 49 +++++++ .../test_stub_generation/import_module.py | 11 ++ .../test_file_creation/__init__.py | 9 ++ .../test_file_creation/_module_2.py | 2 + .../test_file_creation/_module_3.py | 2 + .../test_file_creation/_module_4.py | 2 + .../test_file_creation/_module_6.py | 2 + .../test_file_creation/module_1.py | 2 + .../test_file_creation/package_1/module_5.py | 2 + .../__snapshots__/test_generate_stubs.ambr | 138 ++++++++++++++++++ .../stubs_generator/test_generate_stubs.py | 80 +++++++++- 15 files changed, 396 insertions(+), 34 deletions(-) create mode 100644 tests/data/test_stub_generation/attribute_module.py create mode 100644 tests/data/test_stub_generation/class_module.py create mode 100644 tests/data/test_stub_generation/enum_module.py create mode 100644 tests/data/test_stub_generation/function_module.py create mode 100644 tests/data/test_stub_generation/import_module.py create mode 100644 tests/data/test_stub_generation/test_file_creation/__init__.py create mode 100644 tests/data/test_stub_generation/test_file_creation/_module_2.py create mode 100644 tests/data/test_stub_generation/test_file_creation/_module_3.py create mode 100644 tests/data/test_stub_generation/test_file_creation/_module_4.py create mode 100644 tests/data/test_stub_generation/test_file_creation/_module_6.py create mode 100644 tests/data/test_stub_generation/test_file_creation/module_1.py create mode 100644 tests/data/test_stub_generation/test_file_creation/package_1/module_5.py create mode 100644 tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr diff --git a/src/safeds_stubgen/stubs_generator/_generate_stubs.py b/src/safeds_stubgen/stubs_generator/_generate_stubs.py index eed36778..d3f4e55f 100644 --- a/src/safeds_stubgen/stubs_generator/_generate_stubs.py +++ b/src/safeds_stubgen/stubs_generator/_generate_stubs.py @@ -1,5 +1,6 @@ from __future__ import annotations +import shutil from pathlib import Path from typing import TextIO @@ -16,32 +17,7 @@ ) -# Todo Null nicht als type (für bspw. Arugmente), stattdessen "Nothing?" -""" Todo https://github.com/Safe-DS/DSL/blob/main/syntaxes/safe-ds.tmLanguage.json - { - "name": "constant.language.safe-ds", - "match": "\\b(false|null|true)\\b" - }, - { - "name": "storage.type.safe-ds", - "match": "\\b(annotation|attr|class|enum|fun|package|pipeline|schema|segment|val)\\b" - }, - { - "name": "storage.modifier.safe-ds", - "match": "\\b(const|in|internal|out|private|static)\\b" - }, - { - "name": "keyword.operator.safe-ds", - "match": "\\b(and|not|or|sub|super)\\b" - }, - { - "name": "keyword.other.safe-ds", - "match": "\\b(as|from|import|literal|union|where|yield)\\b" - } - - In den match Felder -> bspw.: Bei enum import `enum` -""" -# Todo Keine Kommas nach Enum Instanzen +# Todo Docstrings class StubsGenerator: api: API out_path: Path @@ -101,6 +77,15 @@ def _create_module_files(self) -> None: for enum in module.enums: self._write_enum(f, enum) + # Todo Frage: + # Delete the file, if it has no content besides the "package" information in the first line + with file_path.open("r") as f: + delete_file = False + if sum(1 for _ in f) <= 1: + delete_file = True + if delete_file: + shutil.rmtree(module_dir) + def _create_reexported_files(self): pass @@ -127,7 +112,7 @@ def _write_class(self, f: TextIO, class_: Class, indent_quant: int) -> None: # Class signature line f.write( f"\n{class_indentation}{self.create_todo_msg(0)}class " - f"{class_.name}{parameter_info}{superclass_info} {{" + f"{class_.name}{parameter_info}{superclass_info} {{", ) # Attributes @@ -261,6 +246,10 @@ def _write_qualified_imports(f: TextIO, qualified_imports: list[QualifiedImport] for qualified_import in qualified_imports: qualified_name = qualified_import.qualified_name import_path, name = split_import_id(qualified_name) + + import_path = replace_if_safeds_keyword(import_path) + name = replace_if_safeds_keyword(name) + from_path = "" if import_path: from_path = f"from {import_path} " @@ -294,7 +283,7 @@ def _write_enum(f: TextIO, enum_data: Enum) -> None: # Enum instances for enum_instance in enum_data.instances: - f.write(f"\t{enum_instance.name}" + ",\n") + f.write(f"\t{enum_instance.name}" + "\n") # Close f.write("}\n") @@ -304,6 +293,7 @@ def _create_type_string(self, type_data: dict | None) -> str: if type_data is None: return "" + none_type_name = "Nothing?" kind = type_data["kind"] if kind == "NamedType": name = type_data["name"] @@ -320,7 +310,7 @@ def _create_type_string(self, type_data: dict | None) -> str: case "float": return "Float" case "None": - return "null" + return none_type_name case _: return name elif kind == "FinalType": @@ -348,8 +338,8 @@ def _create_type_string(self, type_data: dict | None) -> str: ] if types: - if len(types) == 2 and "null" in types: - if types[0] == "null": + if len(types) == 2 and none_type_name in types: + if types[0] == none_type_name: return f"{types[1]}?" else: return f"{types[0]}?" @@ -402,6 +392,15 @@ def create_todo_msg(self, indenta_quant: int) -> str: return f"// Todo {', '.join(todo_msgs)}\n{indentations}" +# Todo Frage: An welchem Stellen soll ersetz werden? Auch Variablen und Enum Instanzen? +def replace_if_safeds_keyword(keyword: str) -> str: + if keyword in {"as", "from", "import", "literal", "union", "where", "yield", "false", "null", "true", "annotation", + "attr", "class", "enum", "fun", "package", "pipeline", "schema", "segment", "val", "const", "in", + "internal", "out", "private", "static", "and", "not", "or", "sub", "super"}: + return f"`{keyword}`" + return keyword + + def split_import_id(id_: str) -> tuple[str, str]: if "." not in id_: return "", id_ diff --git a/tests/data/test_stub_generation/attribute_module.py b/tests/data/test_stub_generation/attribute_module.py new file mode 100644 index 00000000..b8670430 --- /dev/null +++ b/tests/data/test_stub_generation/attribute_module.py @@ -0,0 +1,36 @@ +class A: + ... + + +class B: + type_hint_public: int + _type_hint_private: int + + no_type_hint_public = 1 + _no_type_hint_private = 1 + + object_attr: A + + tuple_attr_1: tuple + tuple_attr_2: tuple[str | int] + tuple_attr_3: tuple[str, int] + + list_attr_1: list + list_attr_2: list[str | A] + list_attr_3: list[str, A] + list_attr_4: list[str, A | int] + + dict_attr_1: dict + dict_attr_2: dict[str, int] + dict_attr_3: dict[str | int, None | A] + + bool_attr: bool + none_attr: None + flaot_attr: float + int_or_bool_attr: int | bool + str_attr_with_none_value: str = None + + mulit_attr_1, _mulit_attr_2_private = (123456, "I am a String") + mulit_attr_3 = _mulit_attr_4_private = ["I am some", "kind of list"] + mulit_attr_5, mulit_attr_6 = ("A", "B") + mulit_attr_7 = mulit_attr_8 = "A" diff --git a/tests/data/test_stub_generation/class_module.py b/tests/data/test_stub_generation/class_module.py new file mode 100644 index 00000000..1e98aa01 --- /dev/null +++ b/tests/data/test_stub_generation/class_module.py @@ -0,0 +1,15 @@ +class A: + ... + + +class B(A): + def __init__(self, a: int, b: A | None): ... + + def f(self): ... + + +class C(A, B): + attr_1: int + attr_2: int + + def f1(self): ... diff --git a/tests/data/test_stub_generation/enum_module.py b/tests/data/test_stub_generation/enum_module.py new file mode 100644 index 00000000..6ebb1697 --- /dev/null +++ b/tests/data/test_stub_generation/enum_module.py @@ -0,0 +1,19 @@ +from enum import Enum, IntEnum +from enum import Enum as _Enum + + +class EnumTest(Enum): + ONE = "first" + TWO = (2, 2) + THREE = 3 + FOUR = FIVE = "forth and fifth" + SIX, SEVEN = ("sixth", 7) + EIGHT, NINE = "89" + + +class EnumTest2(_Enum): + TEN = "TEN" + + +class EnumTest3(IntEnum): + ELEVEN = 11 diff --git a/tests/data/test_stub_generation/function_module.py b/tests/data/test_stub_generation/function_module.py new file mode 100644 index 00000000..cfed4395 --- /dev/null +++ b/tests/data/test_stub_generation/function_module.py @@ -0,0 +1,49 @@ +class A: + ... + + +class B: + def __init__(self, init_param): ... + + def class_method(self, a: A) -> A: ... + + @staticmethod + def static_class_method() -> None: ... + + +def _private(): ... +def public_no_params_no_result(): ... + + +def params( + i: int, + union: int | bool, + lst: list[int], + obj: A, +): ... + + +def illegal_params( + none: None, + none_union: None | bool, + tpl: tuple[int, str, bool, int], + lst: list[int, str] +): ... + + +def param_position(self, a, /, b: bool, c=1, *, d=A(), e: int = 1): ... + + +def opt_pos_only(required, optional=1, /): ... + + +def req_name_only(*, required, optional=1): ... + + +def arg(*args, **kwargs): ... + + +def one_result() -> int: ... + + +def muliple_results() -> tuple[str, int, bool, A]: ... diff --git a/tests/data/test_stub_generation/import_module.py b/tests/data/test_stub_generation/import_module.py new file mode 100644 index 00000000..5a34cd5d --- /dev/null +++ b/tests/data/test_stub_generation/import_module.py @@ -0,0 +1,11 @@ +# Keyword +from enum import IntEnum + +# Alias +from enum import Enum as _Enum + +# Keyword as alias +import mypy as static + +# Wildcard +from math import * diff --git a/tests/data/test_stub_generation/test_file_creation/__init__.py b/tests/data/test_stub_generation/test_file_creation/__init__.py new file mode 100644 index 00000000..fac487d1 --- /dev/null +++ b/tests/data/test_stub_generation/test_file_creation/__init__.py @@ -0,0 +1,9 @@ +from ._module_2 import _private_reexported +from ._module_3 import Reexported +from ._module_6 import public_reexported + +__all__ = [ + "_private_reexported", + "Reexported", + "public_reexported", +] diff --git a/tests/data/test_stub_generation/test_file_creation/_module_2.py b/tests/data/test_stub_generation/test_file_creation/_module_2.py new file mode 100644 index 00000000..409a4623 --- /dev/null +++ b/tests/data/test_stub_generation/test_file_creation/_module_2.py @@ -0,0 +1,2 @@ +def _private_reexported(): + ... diff --git a/tests/data/test_stub_generation/test_file_creation/_module_3.py b/tests/data/test_stub_generation/test_file_creation/_module_3.py new file mode 100644 index 00000000..b183e1b8 --- /dev/null +++ b/tests/data/test_stub_generation/test_file_creation/_module_3.py @@ -0,0 +1,2 @@ +class Reexported: + ... diff --git a/tests/data/test_stub_generation/test_file_creation/_module_4.py b/tests/data/test_stub_generation/test_file_creation/_module_4.py new file mode 100644 index 00000000..7edaa6c3 --- /dev/null +++ b/tests/data/test_stub_generation/test_file_creation/_module_4.py @@ -0,0 +1,2 @@ +class _Private: + ... diff --git a/tests/data/test_stub_generation/test_file_creation/_module_6.py b/tests/data/test_stub_generation/test_file_creation/_module_6.py new file mode 100644 index 00000000..f4dcae5e --- /dev/null +++ b/tests/data/test_stub_generation/test_file_creation/_module_6.py @@ -0,0 +1,2 @@ +def public_reexported(): + ... diff --git a/tests/data/test_stub_generation/test_file_creation/module_1.py b/tests/data/test_stub_generation/test_file_creation/module_1.py new file mode 100644 index 00000000..aa27c8af --- /dev/null +++ b/tests/data/test_stub_generation/test_file_creation/module_1.py @@ -0,0 +1,2 @@ +class C: + ... diff --git a/tests/data/test_stub_generation/test_file_creation/package_1/module_5.py b/tests/data/test_stub_generation/test_file_creation/package_1/module_5.py new file mode 100644 index 00000000..aa27c8af --- /dev/null +++ b/tests/data/test_stub_generation/test_file_creation/package_1/module_5.py @@ -0,0 +1,2 @@ +class C: + ... diff --git a/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr b/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr new file mode 100644 index 00000000..df801a83 --- /dev/null +++ b/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr @@ -0,0 +1,138 @@ +# serializer version: 1 +# name: test_class_attribute_creation + ''' + package test_stub_generation.attribute_module + + class A {} + + class B { + attr type_hint_public: Int + attr no_type_hint_public + attr object_attr: A + // Todo Tuple types are not allowed in SafeDS + attr tuple_attr_1: Tuple + // Todo Tuple types are not allowed in SafeDS + attr tuple_attr_2: Tuple> + // Todo Tuple types are not allowed in SafeDS + attr tuple_attr_3: Tuple + attr list_attr_1: List + attr list_attr_2: List> + // Todo List type has to many type arguments + attr list_attr_3: List + // Todo List type has to many type arguments + attr list_attr_4: List> + attr dict_attr_1: Map + attr dict_attr_2: Map + attr dict_attr_3: Map, A?> + attr bool_attr: Boolean + attr none_attr: Nothing? + attr flaot_attr: Float + attr int_or_bool_attr: union + attr str_attr_with_none_value: String + attr mulit_attr_1 + attr mulit_attr_3 + attr mulit_attr_5 + attr mulit_attr_6 + attr mulit_attr_7 + attr mulit_attr_8 + } + + ''' +# --- +# name: test_class_creation + ''' + package test_stub_generation.class_module + + class A {} + + class B(a: Int, b: A?) sub A { + fun f() + } + + class C sub A, B { + attr attr_1: Int + attr attr_2: Int + + fun f1() + } + + ''' +# --- +# name: test_enum_creation + ''' + package test_stub_generation.enum_module + + from `enum` import Enum + from `enum` import IntEnum + from `enum` import Enum as _Enum + + enum EnumTest { + ONE + TWO + THREE + FOUR + FIVE + SIX + SEVEN + EIGHT + NINE + } + + enum EnumTest2 { + TEN + } + + enum EnumTest3 { + ELEVEN + } + + ''' +# --- +# name: test_function_creation + ''' + package test_stub_generation.function_module + + fun public_no_params_no_result() + + fun params(i: Int, union: union, lst: List, obj: A) -> result_1: Any + + // Todo Tuple types are not allowed in SafeDS + fun illegal_params(none: Nothing?, none_union: Boolean?, tpl: Tuple, lst: List) -> result_1: Any + + fun param_position(self: Any, a: Any, b: Boolean, c: Any = 1, d: Any, e: Int = 1) -> result_1: Any + + // Todo Illegal parameter assignment: Optional but position only + fun opt_pos_only(required: Any, optional: Any = 1) + + // Todo Illegal parameter assignment: Required but name only + fun req_name_only(required: Any, optional: Any = 1) + + // Todo Tuple types are not allowed in SafeDS + fun arg(args: Tuple, kwargs: Map) + + fun one_result() -> result_1: Int + + fun muliple_results() -> (result_1: String, result_2: Int, result_3: Boolean, result_4: A) + + class A {} + + class B(init_param: Any) { + fun class_method(a: A) -> result_1: A + + static fun static_class_method() + } + + ''' +# --- +# name: test_import_creation + ''' + package test_stub_generation.import_module + + from `enum` import IntEnum + from `enum` import Enum as _Enum + import mypy as static + + from math import * + + ''' +# --- diff --git a/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py b/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py index 5043e7c2..f1e7d499 100644 --- a/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py +++ b/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py @@ -1,17 +1,91 @@ from __future__ import annotations from pathlib import Path +from typing import TYPE_CHECKING from safeds_stubgen.api_analyzer import get_api from safeds_stubgen.stubs_generator import StubsGenerator +if TYPE_CHECKING: + from syrupy import SnapshotAssertion + # Setup - Run API to create stub files _lib_dir = Path(__file__).parent.parent.parent -_test_package_name = "test_package" -_test_package_dir = Path(_lib_dir / "tests" / "data" / _test_package_name) -_out_dir = Path(_lib_dir / "tests" / "data" / "out") +_test_package_name = "test_stub_generation" +_test_package_dir = Path(_lib_dir / "data" / _test_package_name) +_out_dir = Path(_lib_dir / "data" / "out") _out_dir_stubs = Path(_out_dir / _test_package_name) api = get_api(_test_package_name, _test_package_dir, is_test_run=True) stubs_generator = StubsGenerator(api, _out_dir) stubs_generator.generate_stubs() + + +# ############################## Utilites ############################## # +def _assert_file_creation_recursive(python_path: Path, stub_path: Path) -> None: + assert python_path.is_dir() + assert stub_path.is_dir() + + python_files: list[Path] = list(python_path.iterdir()) + stub_files: list[Path] = list(stub_path.iterdir()) + + # Remove __init__ files and private files without public reexported content. + # We reexport public content from _module_3 and _module_6, not from _module_2 and _module_4. + for i, item in enumerate(python_files): + if item.is_file() and item.stem in {"__init__", "_module_2", "_module_4"}: + python_files.pop(i) + + assert len(python_files) == len(stub_files) + + for py_item, stub_item in zip(python_files, stub_files, strict=True): + if py_item.is_file(): + assert stub_item.is_dir() + stub_files = list(stub_item.iterdir()) + assert len(stub_files) == 1 + assert stub_files[0].stem == py_item.stem + else: + _assert_file_creation_recursive(py_item, stub_item) + + +def assert_stubs_snapshot(filename: str, snapshot: SnapshotAssertion) -> None: + stubs_file = Path(_out_dir_stubs / filename / f"{filename}.sdsstub") + with stubs_file.open("r") as f: + assert f.read() == snapshot + + +# ############################## Test ############################## # +def test_file_creation() -> None: + _assert_file_creation_recursive( + python_path=Path(_test_package_dir / "test_file_creation"), + stub_path=Path(_out_dir_stubs / "test_file_creation") + ) + + +# Todo Check snapshot +def test_class_creation(snapshot: SnapshotAssertion) -> None: + assert_stubs_snapshot("class_module", snapshot) + + +# Todo Check snapshot +def test_class_attribute_creation(snapshot: SnapshotAssertion) -> None: + assert_stubs_snapshot("attribute_module", snapshot) + + +# Todo Check snapshot +def test_function_creation(snapshot: SnapshotAssertion) -> None: + assert_stubs_snapshot("function_module", snapshot) + + +# Todo Check snapshot +def test_enum_creation(snapshot: SnapshotAssertion) -> None: + assert_stubs_snapshot("enum_module", snapshot) + + +# Todo Check snapshot +def test_import_creation(snapshot: SnapshotAssertion) -> None: + assert_stubs_snapshot("import_module", snapshot) + + +# Todo +def test_docstring_creation() -> None: ... +def test_reexport_creation() -> None: ... From cf745d8c974fc86951ba0ce36530cc874d6df267 Mon Sep 17 00:00:00 2001 From: Arsam Date: Mon, 6 Nov 2023 14:34:21 +0100 Subject: [PATCH 018/109] Added more test data and cases, added todos, refactoring --- .../stubs_generator/_generate_stubs.py | 58 ++++++++++++++----- .../test_stub_generation/attribute_module.py | 3 + .../data/test_stub_generation/class_module.py | 6 ++ .../data/test_stub_generation/enum_module.py | 4 ++ .../test_stub_generation/function_module.py | 17 +++++- .../__snapshots__/test_generate_stubs.ambr | 16 ++++- .../stubs_generator/test_generate_stubs.py | 5 +- 7 files changed, 89 insertions(+), 20 deletions(-) diff --git a/src/safeds_stubgen/stubs_generator/_generate_stubs.py b/src/safeds_stubgen/stubs_generator/_generate_stubs.py index d3f4e55f..56d52c1d 100644 --- a/src/safeds_stubgen/stubs_generator/_generate_stubs.py +++ b/src/safeds_stubgen/stubs_generator/_generate_stubs.py @@ -17,7 +17,7 @@ ) -# Todo Docstrings +# Todo Docstrings / Descriptions class StubsGenerator: api: API out_path: Path @@ -40,9 +40,6 @@ def _create_module_files(self) -> None: module_id = module.id if module_name == "__init__": - # Todo Handle __init__ files - # Todo Handle reexported files that are already created - self._create_reexported_files() continue # Create module dir @@ -75,7 +72,7 @@ def _create_module_files(self) -> None: # Create enums & enum instances for enum in module.enums: - self._write_enum(f, enum) + self._write_enum(f, enum, 0) # Todo Frage: # Delete the file, if it has no content besides the "package" information in the first line @@ -86,9 +83,6 @@ def _create_module_files(self) -> None: if delete_file: shutil.rmtree(module_dir) - def _create_reexported_files(self): - pass - def _write_class(self, f: TextIO, class_: Class, indent_quant: int) -> None: class_indentation = "\t" * indent_quant inner_indentations = class_indentation + "\t" @@ -277,16 +271,26 @@ def _write_wildcard_imports(f: TextIO, wildcard_imports: list[WildcardImport]) - f.write(f"\n{all_imports}\n") @staticmethod - def _write_enum(f: TextIO, enum_data: Enum) -> None: + def _write_enum(f: TextIO, enum_data: Enum, indent_quant: int) -> None: + indentations = "\t" * (indent_quant + 1) + enum_text = "" + # Signature - f.write(f"\nenum {enum_data.name} {{\n") + enum_text += f"\nenum {enum_data.name} {{" # Enum instances - for enum_instance in enum_data.instances: - f.write(f"\t{enum_instance.name}" + "\n") + instances = enum_data.instances + if instances: + enum_text += "\n" + + for enum_instance in instances: + enum_text += f"{indentations}{enum_instance.name}\n" # Close - f.write("}\n") + enum_text += "}\n" + + # Write + f.write(enum_text) def _create_type_string(self, type_data: dict | None) -> str: """Create a SafeDS stubs type string.""" @@ -392,6 +396,34 @@ def create_todo_msg(self, indenta_quant: int) -> str: return f"// Todo {', '.join(todo_msgs)}\n{indentations}" +# Todo Frage: Where to use? Classes, Enums, Functions, Attributes, Parameters, Enum Instances? +# PascalCase vs camelCase +# Do we keep underscores at the end or the beginning of a name? +def convert_snake_to_camel_case(name: str) -> str: + underscore_count_start = 0 + for character in name: + if character == "_": + underscore_count_start += 1 + else: + break + + underscore_count_end = 0 + for i in reversed(range(len(name))): + if name[i] == "_": + underscore_count_end += 1 + else: + break + + name_parts = name[underscore_count_start:-underscore_count_end].split("_") + + camel_case = name_parts[0] + "".join( + t.title() + for t in name_parts[1:] + ) + + return f"{underscore_count_start * "_"}{camel_case}{underscore_count_end * "_"}" + + # Todo Frage: An welchem Stellen soll ersetz werden? Auch Variablen und Enum Instanzen? def replace_if_safeds_keyword(keyword: str) -> str: if keyword in {"as", "from", "import", "literal", "union", "where", "yield", "false", "null", "true", "annotation", diff --git a/tests/data/test_stub_generation/attribute_module.py b/tests/data/test_stub_generation/attribute_module.py index b8670430..38297b6b 100644 --- a/tests/data/test_stub_generation/attribute_module.py +++ b/tests/data/test_stub_generation/attribute_module.py @@ -34,3 +34,6 @@ class B: mulit_attr_3 = _mulit_attr_4_private = ["I am some", "kind of list"] mulit_attr_5, mulit_attr_6 = ("A", "B") mulit_attr_7 = mulit_attr_8 = "A" + + def __init__(self): + self.init_attr: bool = False diff --git a/tests/data/test_stub_generation/class_module.py b/tests/data/test_stub_generation/class_module.py index 1e98aa01..7b491fa7 100644 --- a/tests/data/test_stub_generation/class_module.py +++ b/tests/data/test_stub_generation/class_module.py @@ -13,3 +13,9 @@ class C(A, B): attr_2: int def f1(self): ... + + +class D: + class E: + class F: + ... diff --git a/tests/data/test_stub_generation/enum_module.py b/tests/data/test_stub_generation/enum_module.py index 6ebb1697..34520ec0 100644 --- a/tests/data/test_stub_generation/enum_module.py +++ b/tests/data/test_stub_generation/enum_module.py @@ -17,3 +17,7 @@ class EnumTest2(_Enum): class EnumTest3(IntEnum): ELEVEN = 11 + + +class EmptyEnum(Enum, IntEnum): + ... diff --git a/tests/data/test_stub_generation/function_module.py b/tests/data/test_stub_generation/function_module.py index cfed4395..e533efbc 100644 --- a/tests/data/test_stub_generation/function_module.py +++ b/tests/data/test_stub_generation/function_module.py @@ -11,7 +11,9 @@ def class_method(self, a: A) -> A: ... def static_class_method() -> None: ... -def _private(): ... +def _private(a): ... + + def public_no_params_no_result(): ... @@ -25,9 +27,15 @@ def params( def illegal_params( none: None, - none_union: None | bool, + none_union: None | None, tpl: tuple[int, str, bool, int], - lst: list[int, str] + lst: list[int, str], + _: int = "String" +): ... + + +def special_params( + none_union: None | bool, ): ... @@ -43,6 +51,9 @@ def req_name_only(*, required, optional=1): ... def arg(*args, **kwargs): ... +def args_type(*args: int, **kwargs: int): ... + + def one_result() -> int: ... diff --git a/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr b/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr index df801a83..476210b8 100644 --- a/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr +++ b/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr @@ -35,6 +35,7 @@ attr mulit_attr_6 attr mulit_attr_7 attr mulit_attr_8 + attr init_attr: Boolean } ''' @@ -56,6 +57,12 @@ fun f1() } + class D { + class E { + class F { } + } + } + ''' # --- # name: test_enum_creation @@ -86,6 +93,8 @@ ELEVEN } + enum EmptyEnum {} + ''' # --- # name: test_function_creation @@ -97,7 +106,9 @@ fun params(i: Int, union: union, lst: List, obj: A) -> result_1: Any // Todo Tuple types are not allowed in SafeDS - fun illegal_params(none: Nothing?, none_union: Boolean?, tpl: Tuple, lst: List) -> result_1: Any + fun illegal_params(none: Nothing?, none_union: Nothing??, tpl: Tuple, lst: List, _: Int = String) -> result_1: Any + + fun special_params(none_union: Boolean?) -> result_1: Any fun param_position(self: Any, a: Any, b: Boolean, c: Any = 1, d: Any, e: Int = 1) -> result_1: Any @@ -110,6 +121,9 @@ // Todo Tuple types are not allowed in SafeDS fun arg(args: Tuple, kwargs: Map) + // Todo Tuple types are not allowed in SafeDS + fun args_type(args: Tuple, kwargs: Map) -> result_1: Any + fun one_result() -> result_1: Int fun muliple_results() -> (result_1: String, result_2: Int, result_3: Boolean, result_4: A) diff --git a/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py b/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py index f1e7d499..a5f08dba 100644 --- a/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py +++ b/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py @@ -21,7 +21,7 @@ stubs_generator.generate_stubs() -# ############################## Utilites ############################## # +# Utilites def _assert_file_creation_recursive(python_path: Path, stub_path: Path) -> None: assert python_path.is_dir() assert stub_path.is_dir() @@ -53,7 +53,7 @@ def assert_stubs_snapshot(filename: str, snapshot: SnapshotAssertion) -> None: assert f.read() == snapshot -# ############################## Test ############################## # +# ############################## Tests ############################## # def test_file_creation() -> None: _assert_file_creation_recursive( python_path=Path(_test_package_dir / "test_file_creation"), @@ -88,4 +88,3 @@ def test_import_creation(snapshot: SnapshotAssertion) -> None: # Todo def test_docstring_creation() -> None: ... -def test_reexport_creation() -> None: ... From e433458b263da08d14e171e8ae847e1921a52c85 Mon Sep 17 00:00:00 2001 From: Arsam Date: Mon, 6 Nov 2023 15:25:35 +0100 Subject: [PATCH 019/109] Refactoring --- .../stubs_generator/_generate_stubs.py | 67 ++++++++++--------- 1 file changed, 36 insertions(+), 31 deletions(-) diff --git a/src/safeds_stubgen/stubs_generator/_generate_stubs.py b/src/safeds_stubgen/stubs_generator/_generate_stubs.py index 56d52c1d..b5c4cfe1 100644 --- a/src/safeds_stubgen/stubs_generator/_generate_stubs.py +++ b/src/safeds_stubgen/stubs_generator/_generate_stubs.py @@ -2,7 +2,6 @@ import shutil from pathlib import Path -from typing import TextIO from safeds_stubgen.api_analyzer import ( API, @@ -53,26 +52,33 @@ def _create_module_files(self) -> None: with file_path.open("w") as f: # Create package info package_info = module_id.replace("/", ".") - f.write(f"package {package_info}\n") + module_text = f"package {package_info}\n" # Create imports - self._write_qualified_imports(f, module.qualified_imports) - self._write_wildcard_imports(f, module.wildcard_imports) + qualified_imports = self._create_qualified_imports_string(module.qualified_imports) + if qualified_imports: + module_text += f"\n{qualified_imports}\n" + + wildcard_imports = self._create_wildcard_imports_string(module.wildcard_imports) + if wildcard_imports: + module_text += f"\n{wildcard_imports}\n" # Create global functions for function in module.global_functions: if function.is_public: - function_string = self._create_function_string(function, 0, is_class_method=False) - f.write(f"\n{function_string}\n") + module_text += f"\n{self._create_function_string(function, 0, is_class_method=False)}\n" # Create classes, class attr. & class methods for class_ in module.classes: if class_.is_public: - self._write_class(f, class_, 0) + module_text += f"\n{self._create_class_string(class_, 0)}\n" # Create enums & enum instances for enum in module.enums: - self._write_enum(f, enum, 0) + module_text += f"\n{self._create_enum(enum, 0)}\n" + + # Write module + f.write(module_text) # Todo Frage: # Delete the file, if it has no content besides the "package" information in the first line @@ -83,9 +89,10 @@ def _create_module_files(self) -> None: if delete_file: shutil.rmtree(module_dir) - def _write_class(self, f: TextIO, class_: Class, indent_quant: int) -> None: + def _create_class_string(self, class_: Class, indent_quant: int) -> str: class_indentation = "\t" * indent_quant inner_indentations = class_indentation + "\t" + class_text = "" # Constructor parameter constructor = class_.constructor @@ -104,9 +111,9 @@ def _write_class(self, f: TextIO, class_: Class, indent_quant: int) -> None: superclass_info = f" sub {', '.join(superclass_names)}" # Class signature line - f.write( - f"\n{class_indentation}{self.create_todo_msg(0)}class " - f"{class_.name}{parameter_info}{superclass_info} {{", + class_text += ( + f"{class_indentation}{self.create_todo_msg(0)}class " + f"{class_.name}{parameter_info}{superclass_info} {{" ) # Attributes @@ -129,11 +136,11 @@ def _write_class(self, f: TextIO, class_: Class, indent_quant: int) -> None: if class_attributes: attributes = f"\n{inner_indentations}".join(class_attributes) - f.write(f"\n{inner_indentations}{attributes}\n") + class_text += f"\n{inner_indentations}{attributes}\n" # Inner classes for inner_class in class_.classes: - self._write_class(f, inner_class, indent_quant + 1) + class_text += f"\n{self._create_class_string(inner_class, indent_quant + 1)}\n" # Methods class_methods: list[str] = [] @@ -145,10 +152,12 @@ def _write_class(self, f: TextIO, class_: Class, indent_quant: int) -> None: ) if class_methods: methods = f"\n\n{inner_indentations}".join(class_methods) - f.write(f"\n{inner_indentations}{methods}\n") + class_text += f"\n{inner_indentations}{methods}\n" # Close class - f.write(f"{class_indentation}}}\n") + class_text += f"{class_indentation}}}" + + return class_text def _create_function_string(self, function: Function, indent_quant: int, is_class_method: bool = False) -> str: is_static = function.is_static @@ -232,9 +241,9 @@ def _create_parameter_string(self, parameters: list[Parameter], is_instance_meth return "" @staticmethod - def _write_qualified_imports(f: TextIO, qualified_imports: list[QualifiedImport]) -> None: + def _create_qualified_imports_string(qualified_imports: list[QualifiedImport]) -> str: if not qualified_imports: - return + return "" imports: list[str] = [] for qualified_import in qualified_imports: @@ -254,29 +263,27 @@ def _write_qualified_imports(f: TextIO, qualified_imports: list[QualifiedImport] f"{from_path}import {name}{alias}", ) - all_imports = "\n".join(imports) - f.write(f"\n{all_imports}\n") + return "\n".join(imports) @staticmethod - def _write_wildcard_imports(f: TextIO, wildcard_imports: list[WildcardImport]) -> None: + def _create_wildcard_imports_string(wildcard_imports: list[WildcardImport]) -> str: if not wildcard_imports: - return + return "" imports = [ f"from {wildcard_import.module_name} import *" for wildcard_import in wildcard_imports ] - all_imports = "\n".join(imports) - f.write(f"\n{all_imports}\n") + return "\n".join(imports) @staticmethod - def _write_enum(f: TextIO, enum_data: Enum, indent_quant: int) -> None: + def _create_enum(enum_data: Enum, indent_quant: int) -> str: indentations = "\t" * (indent_quant + 1) enum_text = "" # Signature - enum_text += f"\nenum {enum_data.name} {{" + enum_text += f"enum {enum_data.name} {{" # Enum instances instances = enum_data.instances @@ -286,11 +293,9 @@ def _write_enum(f: TextIO, enum_data: Enum, indent_quant: int) -> None: for enum_instance in instances: enum_text += f"{indentations}{enum_instance.name}\n" - # Close - enum_text += "}\n" - - # Write - f.write(enum_text) + # Close & Return + enum_text += "}" + return enum_text def _create_type_string(self, type_data: dict | None) -> str: """Create a SafeDS stubs type string.""" From 291e13c66d82afaae6ca26554b58c8a905fa1a67 Mon Sep 17 00:00:00 2001 From: Arsam Date: Mon, 6 Nov 2023 15:33:07 +0100 Subject: [PATCH 020/109] Linter fix --- src/safeds_stubgen/stubs_generator/_generate_stubs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/safeds_stubgen/stubs_generator/_generate_stubs.py b/src/safeds_stubgen/stubs_generator/_generate_stubs.py index b5c4cfe1..6d0721cd 100644 --- a/src/safeds_stubgen/stubs_generator/_generate_stubs.py +++ b/src/safeds_stubgen/stubs_generator/_generate_stubs.py @@ -426,7 +426,7 @@ def convert_snake_to_camel_case(name: str) -> str: for t in name_parts[1:] ) - return f"{underscore_count_start * "_"}{camel_case}{underscore_count_end * "_"}" + return f"{underscore_count_start * '_'}{camel_case}{underscore_count_end * '_'}" # Todo Frage: An welchem Stellen soll ersetz werden? Auch Variablen und Enum Instanzen? From 3872ee003a3f0dea9f661525aabcb2c05154535a Mon Sep 17 00:00:00 2001 From: Arsam Date: Wed, 8 Nov 2023 16:41:10 +0100 Subject: [PATCH 021/109] Added a TODO for stubs if a class has multiple inheritances, empty enum or class body are removed, added static modifier for class attributes, adjusted todo messages for stubs, added () for class constructors --- .../stubs_generator/_generate_stubs.py | 48 ++++++---- .../__snapshots__/test_generate_stubs.ambr | 93 ++++++++++--------- 2 files changed, 76 insertions(+), 65 deletions(-) diff --git a/src/safeds_stubgen/stubs_generator/_generate_stubs.py b/src/safeds_stubgen/stubs_generator/_generate_stubs.py index 6d0721cd..da3d33d6 100644 --- a/src/safeds_stubgen/stubs_generator/_generate_stubs.py +++ b/src/safeds_stubgen/stubs_generator/_generate_stubs.py @@ -110,10 +110,13 @@ def _create_class_string(self, class_: Class, indent_quant: int) -> str: ] superclass_info = f" sub {', '.join(superclass_names)}" + if len(superclasses) > 1: + self.current_todo_msgs.add("multiple_inheritance") + # Class signature line - class_text += ( + class_signature = ( f"{class_indentation}{self.create_todo_msg(0)}class " - f"{class_.name}{parameter_info}{superclass_info} {{" + f"{class_.name}({parameter_info}){superclass_info}" ) # Attributes @@ -126,11 +129,15 @@ def _create_class_string(self, class_: Class, indent_quant: int) -> str: if attribute.type: attribute_type = attribute.type.to_dict() + static_string = "" + if attribute.is_static: + static_string = "static " + attr_type = self._create_type_string(attribute_type) type_string = f": {attr_type}" if attr_type else "" class_attributes.append( f"{self.create_todo_msg(indent_quant + 1)}" - f"attr {attribute.name}" + f"{static_string}attr {attribute.name}" f"{type_string}", ) @@ -154,10 +161,14 @@ def _create_class_string(self, class_: Class, indent_quant: int) -> str: methods = f"\n\n{inner_indentations}".join(class_methods) class_text += f"\n{inner_indentations}{methods}\n" + # If the does not have a body, we just return the signature line + if not class_text: + return class_signature + # Close class class_text += f"{class_indentation}}}" - return class_text + return f"{class_signature} {{{class_text}" def _create_function_string(self, function: Function, indent_quant: int, is_class_method: bool = False) -> str: is_static = function.is_static @@ -166,12 +177,10 @@ def _create_function_string(self, function: Function, indent_quant: int, is_clas # Parameters is_instance_method = not is_static and is_class_method func_params = self._create_parameter_string(function.parameters, is_instance_method) - if not func_params: - func_params = "()" return ( f"{self.create_todo_msg(indent_quant)}" - f"{static}fun {function.name}{func_params}" + f"{static}fun {function.name}({func_params})" f"{self._create_result_string(function.results)}" ) @@ -237,7 +246,7 @@ def _create_parameter_string(self, parameters: list[Parameter], is_instance_meth f"{type_string}{param_value}", ) if parameters_data: - return f"({', '.join(parameters_data)})" + return f"{', '.join(parameters_data)}" return "" @staticmethod @@ -280,22 +289,21 @@ def _create_wildcard_imports_string(wildcard_imports: list[WildcardImport]) -> s @staticmethod def _create_enum(enum_data: Enum, indent_quant: int) -> str: indentations = "\t" * (indent_quant + 1) - enum_text = "" # Signature - enum_text += f"enum {enum_data.name} {{" + enum_signature = f"enum {enum_data.name}" - # Enum instances + # Enum body + enum_text = "" instances = enum_data.instances if instances: enum_text += "\n" for enum_instance in instances: enum_text += f"{indentations}{enum_instance.name}\n" + return f"{enum_signature} {{{enum_text}}}" - # Close & Return - enum_text += "}" - return enum_text + return enum_signature def _create_type_string(self, type_data: dict | None) -> str: """Create a SafeDS stubs type string.""" @@ -384,13 +392,15 @@ def create_todo_msg(self, indenta_quant: int) -> str: todo_msgs = [] for msg in self.current_todo_msgs: if msg == "Tuple": - todo_msgs.append("Tuple types are not allowed in SafeDS") + todo_msgs.append("Safe-DS does not support tuple types.") elif msg in {"List", "Set"}: - todo_msgs.append(f"{msg} type has to many type arguments") + todo_msgs.append(f"{msg} type has to many type arguments.") elif msg == "OPT_POS_ONLY": - todo_msgs.append("Illegal parameter assignment: Optional but position only") + todo_msgs.append("Safe-DS does not support optional but position only parameter assignments.") elif msg == "REQ_NAME_ONLY": - todo_msgs.append("Illegal parameter assignment: Required but name only") + todo_msgs.append("Safe-DS does not support required but name only parameter assignments.") + elif msg == "multiple_inheritance": + todo_msgs.append("Safe-DS does not support multiple inheritance.") else: raise ValueError(f"Unknown todo message: {msg}") @@ -398,7 +408,7 @@ def create_todo_msg(self, indenta_quant: int) -> str: self.current_todo_msgs = set() indentations = "\t" * indenta_quant - return f"// Todo {', '.join(todo_msgs)}\n{indentations}" + return f"// TODO {', '.join(todo_msgs)}\n{indentations}" # Todo Frage: Where to use? Classes, Enums, Functions, Attributes, Parameters, Enum Instances? diff --git a/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr b/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr index 476210b8..a1c23736 100644 --- a/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr +++ b/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr @@ -3,38 +3,38 @@ ''' package test_stub_generation.attribute_module - class A {} - - class B { - attr type_hint_public: Int - attr no_type_hint_public - attr object_attr: A - // Todo Tuple types are not allowed in SafeDS - attr tuple_attr_1: Tuple - // Todo Tuple types are not allowed in SafeDS - attr tuple_attr_2: Tuple> - // Todo Tuple types are not allowed in SafeDS - attr tuple_attr_3: Tuple - attr list_attr_1: List - attr list_attr_2: List> - // Todo List type has to many type arguments - attr list_attr_3: List - // Todo List type has to many type arguments - attr list_attr_4: List> - attr dict_attr_1: Map - attr dict_attr_2: Map - attr dict_attr_3: Map, A?> - attr bool_attr: Boolean - attr none_attr: Nothing? - attr flaot_attr: Float - attr int_or_bool_attr: union - attr str_attr_with_none_value: String - attr mulit_attr_1 - attr mulit_attr_3 - attr mulit_attr_5 - attr mulit_attr_6 - attr mulit_attr_7 - attr mulit_attr_8 + class A() + + class B() { + static attr type_hint_public: Int + static attr no_type_hint_public + static attr object_attr: A + // TODO Safe-DS does not support tuple types. + static attr tuple_attr_1: Tuple + // TODO Safe-DS does not support tuple types. + static attr tuple_attr_2: Tuple> + // TODO Safe-DS does not support tuple types. + static attr tuple_attr_3: Tuple + static attr list_attr_1: List + static attr list_attr_2: List> + // TODO List type has to many type arguments. + static attr list_attr_3: List + // TODO List type has to many type arguments. + static attr list_attr_4: List> + static attr dict_attr_1: Map + static attr dict_attr_2: Map + static attr dict_attr_3: Map, A?> + static attr bool_attr: Boolean + static attr none_attr: Nothing? + static attr flaot_attr: Float + static attr int_or_bool_attr: union + static attr str_attr_with_none_value: String + static attr mulit_attr_1 + static attr mulit_attr_3 + static attr mulit_attr_5 + static attr mulit_attr_6 + static attr mulit_attr_7 + static attr mulit_attr_8 attr init_attr: Boolean } @@ -44,22 +44,23 @@ ''' package test_stub_generation.class_module - class A {} + class A() class B(a: Int, b: A?) sub A { fun f() } - class C sub A, B { - attr attr_1: Int - attr attr_2: Int + // TODO Safe-DS does not support multiple inheritance. + class C() sub A, B { + static attr attr_1: Int + static attr attr_2: Int fun f1() } - class D { - class E { - class F { } + class D() { + class E() { + class F() } } @@ -93,7 +94,7 @@ ELEVEN } - enum EmptyEnum {} + enum EmptyEnum ''' # --- @@ -105,30 +106,30 @@ fun params(i: Int, union: union, lst: List, obj: A) -> result_1: Any - // Todo Tuple types are not allowed in SafeDS + // TODO Safe-DS does not support tuple types. fun illegal_params(none: Nothing?, none_union: Nothing??, tpl: Tuple, lst: List, _: Int = String) -> result_1: Any fun special_params(none_union: Boolean?) -> result_1: Any fun param_position(self: Any, a: Any, b: Boolean, c: Any = 1, d: Any, e: Int = 1) -> result_1: Any - // Todo Illegal parameter assignment: Optional but position only + // TODO Safe-DS does not support optional but position only parameter assignments. fun opt_pos_only(required: Any, optional: Any = 1) - // Todo Illegal parameter assignment: Required but name only + // TODO Safe-DS does not support required but name only parameter assignments. fun req_name_only(required: Any, optional: Any = 1) - // Todo Tuple types are not allowed in SafeDS + // TODO Safe-DS does not support tuple types. fun arg(args: Tuple, kwargs: Map) - // Todo Tuple types are not allowed in SafeDS + // TODO Safe-DS does not support tuple types. fun args_type(args: Tuple, kwargs: Map) -> result_1: Any fun one_result() -> result_1: Int fun muliple_results() -> (result_1: String, result_2: Int, result_3: Boolean, result_4: A) - class A {} + class A() class B(init_param: Any) { fun class_method(a: A) -> result_1: A From 7c902f52946c355916556e6ab6a36026014a92cd Mon Sep 17 00:00:00 2001 From: Arsam Date: Wed, 8 Nov 2023 17:52:22 +0100 Subject: [PATCH 022/109] Added handling for methods with @classmethod decorator and adjusted test snapshots --- src/safeds_stubgen/api_analyzer/_mypy_helpers.py | 5 +++++ tests/data/test_stub_generation/function_module.py | 7 +++++-- .../stubs_generator/__snapshots__/test_generate_stubs.ambr | 6 ++++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/safeds_stubgen/api_analyzer/_mypy_helpers.py b/src/safeds_stubgen/api_analyzer/_mypy_helpers.py index 03d1d0ea..9deaf56f 100644 --- a/src/safeds_stubgen/api_analyzer/_mypy_helpers.py +++ b/src/safeds_stubgen/api_analyzer/_mypy_helpers.py @@ -55,6 +55,11 @@ def mypy_type_to_abstract_type(mypy_type: Instance | ProperType | MypyType) -> A elif isinstance(mypy_type, mp_types.UnboundType): # Todo Aliasing: Import auflösen return sds_types.NamedType(name=mypy_type.name) + elif isinstance(mypy_type, mp_types.TypeType): + # The first parameter of cls methods + type_item = mypy_type.item + if isinstance(type_item, Instance): + return sds_types.NamedType(name=type_item.type.name) # Builtins elif isinstance(mypy_type, Instance): diff --git a/tests/data/test_stub_generation/function_module.py b/tests/data/test_stub_generation/function_module.py index e533efbc..0a0030af 100644 --- a/tests/data/test_stub_generation/function_module.py +++ b/tests/data/test_stub_generation/function_module.py @@ -5,11 +5,14 @@ class A: class B: def __init__(self, init_param): ... - def class_method(self, a: A) -> A: ... + def instance_method(self, a: A) -> A: ... @staticmethod def static_class_method() -> None: ... + @classmethod + def class_method(cls): ... + def _private(a): ... @@ -57,4 +60,4 @@ def args_type(*args: int, **kwargs: int): ... def one_result() -> int: ... -def muliple_results() -> tuple[str, int, bool, A]: ... +def multiple_results() -> tuple[str, int, bool, A]: ... diff --git a/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr b/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr index a1c23736..87c0bc8d 100644 --- a/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr +++ b/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr @@ -127,14 +127,16 @@ fun one_result() -> result_1: Int - fun muliple_results() -> (result_1: String, result_2: Int, result_3: Boolean, result_4: A) + fun multiple_results() -> (result_1: String, result_2: Int, result_3: Boolean, result_4: A) class A() class B(init_param: Any) { - fun class_method(a: A) -> result_1: A + fun instance_method(a: A) -> result_1: A static fun static_class_method() + + fun class_method() } ''' From 37efa8143c98089e6e33046016dd4ae4634391b5 Mon Sep 17 00:00:00 2001 From: Arsam Date: Wed, 8 Nov 2023 17:57:48 +0100 Subject: [PATCH 023/109] Refactoring --- src/safeds_stubgen/api_analyzer/_mypy_helpers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/safeds_stubgen/api_analyzer/_mypy_helpers.py b/src/safeds_stubgen/api_analyzer/_mypy_helpers.py index 9deaf56f..ac3edf06 100644 --- a/src/safeds_stubgen/api_analyzer/_mypy_helpers.py +++ b/src/safeds_stubgen/api_analyzer/_mypy_helpers.py @@ -101,7 +101,7 @@ def mypy_type_to_abstract_type(mypy_type: Instance | ProperType | MypyType) -> A def get_argument_kind(arg: Argument) -> ParameterAssignment: if arg.variable.is_self or arg.variable.is_cls: return ParameterAssignment.IMPLICIT - elif (arg.kind == ArgKind.ARG_POS or arg.kind == ArgKind.ARG_OPT) and arg.pos_only: + elif arg.kind in {ArgKind.ARG_POS, ArgKind.ARG_OPT} and arg.pos_only: return ParameterAssignment.POSITION_ONLY elif arg.kind in (ArgKind.ARG_OPT, ArgKind.ARG_POS) and not arg.pos_only: return ParameterAssignment.POSITION_OR_NAME From 3f008d427e6cbe14e1a17ed33d91fc73e9832eb3 Mon Sep 17 00:00:00 2001 From: Arsam Date: Fri, 10 Nov 2023 11:43:52 +0100 Subject: [PATCH 024/109] (WIP) Refactoring, tiny bug fixes and adding todos --- .../api_analyzer/_mypy_helpers.py | 27 +++---- .../stubs_generator/_generate_stubs.py | 79 +++++++++---------- .../test_stub_generation/attribute_module.py | 8 +- .../test_stub_generation/function_module.py | 10 +-- 4 files changed, 61 insertions(+), 63 deletions(-) diff --git a/src/safeds_stubgen/api_analyzer/_mypy_helpers.py b/src/safeds_stubgen/api_analyzer/_mypy_helpers.py index ac3edf06..5b4695ab 100644 --- a/src/safeds_stubgen/api_analyzer/_mypy_helpers.py +++ b/src/safeds_stubgen/api_analyzer/_mypy_helpers.py @@ -66,20 +66,19 @@ def mypy_type_to_abstract_type(mypy_type: Instance | ProperType | MypyType) -> A type_name = mypy_type.type.name if type_name in {"int", "str", "bool", "float"}: return sds_types.NamedType(name=type_name) - elif type_name == "tuple": - return sds_types.TupleType(types=[]) - elif type_name == "list": - for arg in mypy_type.args: - types.append( - mypy_type_to_abstract_type(arg), - ) - return sds_types.ListType(types=types) - elif type_name == "set": - for arg in mypy_type.args: - types.append( - mypy_type_to_abstract_type(arg), - ) - return sds_types.SetType(types=types) + + # Iterable builtins + elif type_name in {"tuple", "list", "set"}: + types = [ + mypy_type_to_abstract_type(arg) + for arg in mypy_type.args + ] + return { + "tuple": sds_types.TupleType, + "list": sds_types.ListType, + "set": sds_types.SetType, + }[type_name](types=types) + elif type_name == "dict": key_type = mypy_type_to_abstract_type(mypy_type.args[0]) value_types = [mypy_type_to_abstract_type(arg) for arg in mypy_type.args[1:]] diff --git a/src/safeds_stubgen/stubs_generator/_generate_stubs.py b/src/safeds_stubgen/stubs_generator/_generate_stubs.py index da3d33d6..19e37ddd 100644 --- a/src/safeds_stubgen/stubs_generator/_generate_stubs.py +++ b/src/safeds_stubgen/stubs_generator/_generate_stubs.py @@ -158,8 +158,8 @@ def _create_class_string(self, class_: Class, indent_quant: int) -> str: self._create_function_string(method, indent_quant + 1, is_class_method=True), ) if class_methods: - methods = f"\n\n{inner_indentations}".join(class_methods) - class_text += f"\n{inner_indentations}{methods}\n" + methods = "\n\n".join(class_methods) + class_text += f"\n{methods}\n" # If the does not have a body, we just return the signature line if not class_text: @@ -171,6 +171,7 @@ def _create_class_string(self, class_: Class, indent_quant: int) -> str: return f"{class_signature} {{{class_text}" def _create_function_string(self, function: Function, indent_quant: int, is_class_method: bool = False) -> str: + """Create a function string for Safe-DS stubs.""" is_static = function.is_static static = "static " if is_static else "" @@ -178,9 +179,11 @@ def _create_function_string(self, function: Function, indent_quant: int, is_clas is_instance_method = not is_static and is_class_method func_params = self._create_parameter_string(function.parameters, is_instance_method) + # Create string and return + inner_indentations = indent_quant * "\t" return ( f"{self.create_todo_msg(indent_quant)}" - f"{static}fun {function.name}({func_params})" + f"{inner_indentations}{static}fun {function.name}({func_params})" f"{self._create_result_string(function.results)}" ) @@ -236,6 +239,15 @@ def _create_parameter_string(self, parameters: list[Parameter], is_instance_meth elif assigned_by == ParameterAssignment.NAME_ONLY and not parameter.is_optional: self.current_todo_msgs.add("REQ_NAME_ONLY") + # Mypy assignes *args parameters the tuple type, which is not supported in Safe-DS. Therefor we overwrite it + # and set the type to a list. + if assigned_by == ParameterAssignment.POSITIONAL_VARARG: + parameter_type_data["kind"] = "ListType" + + # Safe-DS does not support variadic parameters. + if assigned_by in {ParameterAssignment.POSITIONAL_VARARG, ParameterAssignment.NAMED_VARARG}: + self.current_todo_msgs.add("variadic") + # Parameter type param_type = self._create_type_string(parameter_type_data) type_string = f": {param_type}" if param_type else "" @@ -389,57 +401,44 @@ def create_todo_msg(self, indenta_quant: int) -> str: if not self.current_todo_msgs: return "" - todo_msgs = [] - for msg in self.current_todo_msgs: - if msg == "Tuple": - todo_msgs.append("Safe-DS does not support tuple types.") - elif msg in {"List", "Set"}: - todo_msgs.append(f"{msg} type has to many type arguments.") - elif msg == "OPT_POS_ONLY": - todo_msgs.append("Safe-DS does not support optional but position only parameter assignments.") - elif msg == "REQ_NAME_ONLY": - todo_msgs.append("Safe-DS does not support required but name only parameter assignments.") - elif msg == "multiple_inheritance": - todo_msgs.append("Safe-DS does not support multiple inheritance.") - else: - raise ValueError(f"Unknown todo message: {msg}") + todo_msgs = [ + { + "Tuple": "// TODO Safe-DS does not support tuple types.", + "List": "// TODO List type has to many type arguments.", + "Set": "// TODO Set type has to many type arguments.", + "OPT_POS_ONLY": "// TODO Safe-DS does not support optional but position only parameter assignments.", + "REQ_NAME_ONLY": "// TODO Safe-DS does not support required but name only parameter assignments.", + "multiple_inheritance": "// TODO Safe-DS does not support multiple inheritance.", + "variadic": "// TODO Safe-DS does not support variadic parameters.", + }[msg] + for msg in self.current_todo_msgs + ] # Empty the message list self.current_todo_msgs = set() indentations = "\t" * indenta_quant - return f"// TODO {', '.join(todo_msgs)}\n{indentations}" + return indentations + f"\n{indentations}".join(todo_msgs) + "\n" -# Todo Frage: Where to use? Classes, Enums, Functions, Attributes, Parameters, Enum Instances? -# PascalCase vs camelCase -# Do we keep underscores at the end or the beginning of a name? +# Todo Where to use? Functions, Attributes, Parameters, Enum Instances? +# __get_function_name__ --> getFunctionName +# Sollt vor der replace_if_safeds_keyword Funktion aufgerufen werden +# Todo Not working if the name does not end with underscores, since the counter will be 0 and split the name at [0:0] def convert_snake_to_camel_case(name: str) -> str: - underscore_count_start = 0 - for character in name: - if character == "_": - underscore_count_start += 1 - else: - break - - underscore_count_end = 0 - for i in reversed(range(len(name))): - if name[i] == "_": - underscore_count_end += 1 - else: - break + # Count underscores in front and behind the name + underscore_count_start = len(name) - len(name.lstrip("_")) + underscore_count_end = len(name) - len(name.rstrip("_")) + # Remove underscores and join in camelCase name_parts = name[underscore_count_start:-underscore_count_end].split("_") - - camel_case = name_parts[0] + "".join( - t.title() - for t in name_parts[1:] + return name_parts[0] + "".join( + part.title() for part in name_parts[1:] ) - return f"{underscore_count_start * '_'}{camel_case}{underscore_count_end * '_'}" - # Todo Frage: An welchem Stellen soll ersetz werden? Auch Variablen und Enum Instanzen? +# -> Parameter, Attr., Enum instances def replace_if_safeds_keyword(keyword: str) -> str: if keyword in {"as", "from", "import", "literal", "union", "where", "yield", "false", "null", "true", "annotation", "attr", "class", "enum", "fun", "package", "pipeline", "schema", "segment", "val", "const", "in", diff --git a/tests/data/test_stub_generation/attribute_module.py b/tests/data/test_stub_generation/attribute_module.py index 38297b6b..931eb7c9 100644 --- a/tests/data/test_stub_generation/attribute_module.py +++ b/tests/data/test_stub_generation/attribute_module.py @@ -30,10 +30,10 @@ class B: int_or_bool_attr: int | bool str_attr_with_none_value: str = None - mulit_attr_1, _mulit_attr_2_private = (123456, "I am a String") - mulit_attr_3 = _mulit_attr_4_private = ["I am some", "kind of list"] - mulit_attr_5, mulit_attr_6 = ("A", "B") - mulit_attr_7 = mulit_attr_8 = "A" + multi_attr_1, _multi_attr_2_private = (123456, "I am a String") + multi_attr_3 = _multi_attr_4_private = ["I am some", "kind of list"] + multi_attr_5, multi_attr_6 = ("A", "B") + multi_attr_7 = multi_attr_8 = "A" def __init__(self): self.init_attr: bool = False diff --git a/tests/data/test_stub_generation/function_module.py b/tests/data/test_stub_generation/function_module.py index 0a0030af..01929c12 100644 --- a/tests/data/test_stub_generation/function_module.py +++ b/tests/data/test_stub_generation/function_module.py @@ -29,16 +29,16 @@ def params( def illegal_params( - none: None, - none_union: None | None, - tpl: tuple[int, str, bool, int], lst: list[int, str], - _: int = "String" + tpl: tuple[int, str, bool, int], + _: int = "String", ): ... def special_params( - none_union: None | bool, + none_bool_union: None | bool, + none_union: None | None, + none: None, ): ... From 852767f96c8dd224d8bbdecb1d569e202a820978 Mon Sep 17 00:00:00 2001 From: Arsam Islami Date: Mon, 13 Nov 2023 13:25:50 +0100 Subject: [PATCH 025/109] Attributes, Parameter and Enum instances will be converted to camelCase for Safe-DS stubs and will also be checked for keyword and escaped if necessary. Function names will also be converted to camelCase. Added unit test for the _convert_snake_to_camel_case function --- .../stubs_generator/_generate_stubs.py | 132 +++++++++++++----- tests/data/test_package/test_enums.py | 2 +- .../stubs_generator/test_generate_stubs.py | 53 +++++++ 3 files changed, 149 insertions(+), 38 deletions(-) diff --git a/src/safeds_stubgen/stubs_generator/_generate_stubs.py b/src/safeds_stubgen/stubs_generator/_generate_stubs.py index 19e37ddd..0915d030 100644 --- a/src/safeds_stubgen/stubs_generator/_generate_stubs.py +++ b/src/safeds_stubgen/stubs_generator/_generate_stubs.py @@ -98,7 +98,9 @@ def _create_class_string(self, class_: Class, indent_quant: int) -> str: constructor = class_.constructor parameter_info = "" if constructor: - parameter_info = self._create_parameter_string(constructor.parameters, is_instance_method=True) + parameter_info = self._create_parameter_string( + constructor.parameters, class_indentation, is_instance_method=True + ) # Superclasses superclasses = class_.superclasses @@ -129,21 +131,33 @@ def _create_class_string(self, class_: Class, indent_quant: int) -> str: if attribute.type: attribute_type = attribute.type.to_dict() - static_string = "" - if attribute.is_static: - static_string = "static " + static_string = "static " if attribute.is_static else "" + + # Convert name to camelCase and add PythonName annotation + attr_name = attribute.name + attr_name_camel_case = _convert_snake_to_camel_case(attr_name) + attr_name_annotation = "" + if attr_name_camel_case != attr_name: + attr_name_annotation = f"{self._create_name_annotation(attr_name)}\n{inner_indentations}" + + # Check if name is a Safe-DS keyword and escape it if necessary + attr_name_camel_case = self._replace_if_safeds_keyword(attr_name_camel_case) + # Create type information attr_type = self._create_type_string(attribute_type) type_string = f": {attr_type}" if attr_type else "" + + # Create attribute string class_attributes.append( f"{self.create_todo_msg(indent_quant + 1)}" - f"{static_string}attr {attribute.name}" + f"{inner_indentations}{attr_name_annotation}" + f"{static_string}attr {attr_name_camel_case}" f"{type_string}", ) if class_attributes: - attributes = f"\n{inner_indentations}".join(class_attributes) - class_text += f"\n{inner_indentations}{attributes}\n" + attributes = "\n".join(class_attributes) + class_text += f"\n{attributes}\n" # Inner classes for inner_class in class_.classes: @@ -174,16 +188,24 @@ def _create_function_string(self, function: Function, indent_quant: int, is_clas """Create a function string for Safe-DS stubs.""" is_static = function.is_static static = "static " if is_static else "" + indentations = indent_quant * "\t" # Parameters is_instance_method = not is_static and is_class_method - func_params = self._create_parameter_string(function.parameters, is_instance_method) + func_params = self._create_parameter_string(function.parameters, indentations, is_instance_method) + + # Convert function name to camelCase + name = function.name + camel_case_name = _convert_snake_to_camel_case(name) + function_name_annotation = "" + if camel_case_name != name: + function_name_annotation = f"{indentations}{self._create_name_annotation(name)}\n" # Create string and return - inner_indentations = indent_quant * "\t" return ( f"{self.create_todo_msg(indent_quant)}" - f"{inner_indentations}{static}fun {function.name}({func_params})" + f"{function_name_annotation}" + f"{indentations}{static}fun {camel_case_name}({func_params})" f"{self._create_result_string(function.results)}" ) @@ -204,8 +226,11 @@ def _create_result_string(self, function_results: list[Result]) -> str: return f" -> ({', '.join(results)})" return "" - def _create_parameter_string(self, parameters: list[Parameter], is_instance_method: bool = False) -> str: + def _create_parameter_string( + self, parameters: list[Parameter], indent: str, is_instance_method: bool = False + ) -> str: parameters_data: list[str] = [] + indent = indent + "\t" first_loop_skipped = False for parameter in parameters: # Skip self parameter for functions @@ -252,17 +277,29 @@ def _create_parameter_string(self, parameters: list[Parameter], is_instance_meth param_type = self._create_type_string(parameter_type_data) type_string = f": {param_type}" if param_type else "" + # Convert to camelCase if necessary + name = parameter.name + camel_case_name = _convert_snake_to_camel_case(name) + name_annotation = "" + if camel_case_name != name: + # Memorize the changed name for the @PythonName() annotation + name_annotation = f"{self._create_name_annotation(name)} " + + # Check if it's a Safe-DS keyword and escape it + camel_case_name = self._replace_if_safeds_keyword(camel_case_name) + # Create string and append to the list parameters_data.append( - f"{parameter.name}" + f"{name_annotation}{camel_case_name}" f"{type_string}{param_value}", ) + if parameters_data: - return f"{', '.join(parameters_data)}" + inner_param_data = f",\n{indent}".join(parameters_data) + return f"\n{indent}{inner_param_data}\n{indent[:-1]}" return "" - @staticmethod - def _create_qualified_imports_string(qualified_imports: list[QualifiedImport]) -> str: + def _create_qualified_imports_string(self, qualified_imports: list[QualifiedImport]) -> str: if not qualified_imports: return "" @@ -271,8 +308,8 @@ def _create_qualified_imports_string(qualified_imports: list[QualifiedImport]) - qualified_name = qualified_import.qualified_name import_path, name = split_import_id(qualified_name) - import_path = replace_if_safeds_keyword(import_path) - name = replace_if_safeds_keyword(name) + import_path = self._replace_if_safeds_keyword(import_path) + name = self._replace_if_safeds_keyword(name) from_path = "" if import_path: @@ -298,8 +335,7 @@ def _create_wildcard_imports_string(wildcard_imports: list[WildcardImport]) -> s return "\n".join(imports) - @staticmethod - def _create_enum(enum_data: Enum, indent_quant: int) -> str: + def _create_enum(self, enum_data: Enum, indent_quant: int) -> str: indentations = "\t" * (indent_quant + 1) # Signature @@ -312,7 +348,19 @@ def _create_enum(enum_data: Enum, indent_quant: int) -> str: enum_text += "\n" for enum_instance in instances: - enum_text += f"{indentations}{enum_instance.name}\n" + name = enum_instance.name + + # Todo Frage: Sicher, dass wir Enum Instancen umschreiben? + # Convert snake_case names to camelCase + camel_case_name = _convert_snake_to_camel_case(name) + annotation = "" + if camel_case_name != name: + annotation = f"{indentations}{self._create_name_annotation(name)}\n" + + # Check if the name is a Safe-DS keyword and escape it + camel_case_name = self._replace_if_safeds_keyword(camel_case_name) + + enum_text += f"{annotation}{indentations}{camel_case_name}\n" return f"{enum_signature} {{{enum_text}}}" return enum_signature @@ -420,33 +468,43 @@ def create_todo_msg(self, indenta_quant: int) -> str: indentations = "\t" * indenta_quant return indentations + f"\n{indentations}".join(todo_msgs) + "\n" + @staticmethod + def _create_name_annotation(name: str) -> str: + return f'@PythonName("{name}")' + + @staticmethod + def _replace_if_safeds_keyword(keyword: str) -> str: + if keyword in {"as", "from", "import", "literal", "union", "where", "yield", "false", "null", "true", + "annotation", + "attr", "class", "enum", "fun", "package", "pipeline", "schema", "segment", "val", "const", "in", + "internal", "out", "private", "static", "and", "not", "or", "sub", "super"}: + return f"`{keyword}`" + return keyword + + +# Todo Frage: mixed_snake_camelCase_naMe -> mixedSnakeCamelCaseNaMe | _ -> _ ? Special cases? Results (Darstellung)? +def _convert_snake_to_camel_case(name: str) -> str: + if name == "_": + return name -# Todo Where to use? Functions, Attributes, Parameters, Enum Instances? -# __get_function_name__ --> getFunctionName -# Sollt vor der replace_if_safeds_keyword Funktion aufgerufen werden -# Todo Not working if the name does not end with underscores, since the counter will be 0 and split the name at [0:0] -def convert_snake_to_camel_case(name: str) -> str: # Count underscores in front and behind the name underscore_count_start = len(name) - len(name.lstrip("_")) underscore_count_end = len(name) - len(name.rstrip("_")) + if underscore_count_end == 0: + cleaned_name = name[underscore_count_start:] + else: + cleaned_name = name[underscore_count_start:-underscore_count_end] + # Remove underscores and join in camelCase - name_parts = name[underscore_count_start:-underscore_count_end].split("_") + name_parts = cleaned_name.split("_") return name_parts[0] + "".join( - part.title() for part in name_parts[1:] + part[0].upper() + part[1:] + for part in name_parts[1:] + if part ) -# Todo Frage: An welchem Stellen soll ersetz werden? Auch Variablen und Enum Instanzen? -# -> Parameter, Attr., Enum instances -def replace_if_safeds_keyword(keyword: str) -> str: - if keyword in {"as", "from", "import", "literal", "union", "where", "yield", "false", "null", "true", "annotation", - "attr", "class", "enum", "fun", "package", "pipeline", "schema", "segment", "val", "const", "in", - "internal", "out", "private", "static", "and", "not", "or", "sub", "super"}: - return f"`{keyword}`" - return keyword - - def split_import_id(id_: str) -> tuple[str, str]: if "." not in id_: return "", id_ diff --git a/tests/data/test_package/test_enums.py b/tests/data/test_package/test_enums.py index 432c8b8d..1d1b74c0 100644 --- a/tests/data/test_package/test_enums.py +++ b/tests/data/test_package/test_enums.py @@ -24,4 +24,4 @@ class _ReexportedEmptyEnum(_Enum): class AnotherTestEnum(IntEnum): - ELEVEN = 11 + number_eleven = 11 diff --git a/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py b/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py index a5f08dba..fa23d49d 100644 --- a/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py +++ b/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py @@ -3,9 +3,13 @@ from pathlib import Path from typing import TYPE_CHECKING +import pytest from safeds_stubgen.api_analyzer import get_api from safeds_stubgen.stubs_generator import StubsGenerator +# noinspection PyProtectedMember +from safeds_stubgen.stubs_generator._generate_stubs import _convert_snake_to_camel_case + if TYPE_CHECKING: from syrupy import SnapshotAssertion @@ -88,3 +92,52 @@ def test_import_creation(snapshot: SnapshotAssertion) -> None: # Todo def test_docstring_creation() -> None: ... + + +@pytest.mark.parametrize( + ("name", "expected_result"), + [ + ( + "", + "", + ), + ( + "_", + "_", + ), + ( + "__get_function_name__", + "getFunctionName", + ), + ( + "__get_function_name", + "getFunctionName", + ), + ( + "get_function_name__", + "getFunctionName", + ), + ( + "__getFunction_name__", + "getFunctionName", + ), + ( + "__get__function___name__", + "getFunctionName", + ), + ( + "__get_funCtion_NamE__", + "getFunCtionNamE", + ), + ( + "getFunctionName", + "getFunctionName", + ), + ( + "a_a_A_aAAaA_1_1_2_aAa", + "aAAAAAaA112AAa", + ), + ], +) +def test_convert_snake_to_camel_case(name: str, expected_result: str) -> None: + assert _convert_snake_to_camel_case(name) == expected_result From ef587b60db893a153dcaeff06519b366e7bc5e37 Mon Sep 17 00:00:00 2001 From: Arsam Islami Date: Mon, 13 Nov 2023 13:57:10 +0100 Subject: [PATCH 026/109] Refactoring --- .../stubs_generator/_generate_stubs.py | 58 +++++++++---------- 1 file changed, 27 insertions(+), 31 deletions(-) diff --git a/src/safeds_stubgen/stubs_generator/_generate_stubs.py b/src/safeds_stubgen/stubs_generator/_generate_stubs.py index 0915d030..1cf950bc 100644 --- a/src/safeds_stubgen/stubs_generator/_generate_stubs.py +++ b/src/safeds_stubgen/stubs_generator/_generate_stubs.py @@ -66,16 +66,16 @@ def _create_module_files(self) -> None: # Create global functions for function in module.global_functions: if function.is_public: - module_text += f"\n{self._create_function_string(function, 0, is_class_method=False)}\n" + module_text += f"\n{self._create_function_string(function, is_class_method=False)}\n" # Create classes, class attr. & class methods for class_ in module.classes: if class_.is_public: - module_text += f"\n{self._create_class_string(class_, 0)}\n" + module_text += f"\n{self._create_class_string(class_)}\n" # Create enums & enum instances for enum in module.enums: - module_text += f"\n{self._create_enum(enum, 0)}\n" + module_text += f"\n{self._create_enum_string(enum)}\n" # Write module f.write(module_text) @@ -89,8 +89,7 @@ def _create_module_files(self) -> None: if delete_file: shutil.rmtree(module_dir) - def _create_class_string(self, class_: Class, indent_quant: int) -> str: - class_indentation = "\t" * indent_quant + def _create_class_string(self, class_: Class, class_indentation: str = "") -> str: inner_indentations = class_indentation + "\t" class_text = "" @@ -117,7 +116,7 @@ def _create_class_string(self, class_: Class, indent_quant: int) -> str: # Class signature line class_signature = ( - f"{class_indentation}{self.create_todo_msg(0)}class " + f"{class_indentation}{self.create_todo_msg(class_indentation)}class " f"{class_.name}({parameter_info}){superclass_info}" ) @@ -149,7 +148,7 @@ def _create_class_string(self, class_: Class, indent_quant: int) -> str: # Create attribute string class_attributes.append( - f"{self.create_todo_msg(indent_quant + 1)}" + f"{self.create_todo_msg(inner_indentations)}" f"{inner_indentations}{attr_name_annotation}" f"{static_string}attr {attr_name_camel_case}" f"{type_string}", @@ -161,7 +160,7 @@ def _create_class_string(self, class_: Class, indent_quant: int) -> str: # Inner classes for inner_class in class_.classes: - class_text += f"\n{self._create_class_string(inner_class, indent_quant + 1)}\n" + class_text += f"\n{self._create_class_string(inner_class, inner_indentations)}\n" # Methods class_methods: list[str] = [] @@ -169,7 +168,7 @@ def _create_class_string(self, class_: Class, indent_quant: int) -> str: if not method.is_public: continue class_methods.append( - self._create_function_string(method, indent_quant + 1, is_class_method=True), + self._create_function_string(method, inner_indentations, is_class_method=True), ) if class_methods: methods = "\n\n".join(class_methods) @@ -184,11 +183,10 @@ def _create_class_string(self, class_: Class, indent_quant: int) -> str: return f"{class_signature} {{{class_text}" - def _create_function_string(self, function: Function, indent_quant: int, is_class_method: bool = False) -> str: + def _create_function_string(self, function: Function, indentations: str = "", is_class_method: bool = False) -> str: """Create a function string for Safe-DS stubs.""" is_static = function.is_static static = "static " if is_static else "" - indentations = indent_quant * "\t" # Parameters is_instance_method = not is_static and is_class_method @@ -203,7 +201,7 @@ def _create_function_string(self, function: Function, indent_quant: int, is_clas # Create string and return return ( - f"{self.create_todo_msg(indent_quant)}" + f"{self.create_todo_msg(indentations)}" f"{function_name_annotation}" f"{indentations}{static}fun {camel_case_name}({func_params})" f"{self._create_result_string(function.results)}" @@ -227,10 +225,9 @@ def _create_result_string(self, function_results: list[Result]) -> str: return "" def _create_parameter_string( - self, parameters: list[Parameter], indent: str, is_instance_method: bool = False + self, parameters: list[Parameter], indentations: str, is_instance_method: bool = False ) -> str: parameters_data: list[str] = [] - indent = indent + "\t" first_loop_skipped = False for parameter in parameters: # Skip self parameter for functions @@ -294,9 +291,10 @@ def _create_parameter_string( f"{type_string}{param_value}", ) + inner_indentations = indentations + "\t" if parameters_data: - inner_param_data = f",\n{indent}".join(parameters_data) - return f"\n{indent}{inner_param_data}\n{indent[:-1]}" + inner_param_data = f",\n{inner_indentations}".join(parameters_data) + return f"\n{inner_indentations}{inner_param_data}\n{indentations}" return "" def _create_qualified_imports_string(self, qualified_imports: list[QualifiedImport]) -> str: @@ -335,9 +333,8 @@ def _create_wildcard_imports_string(wildcard_imports: list[WildcardImport]) -> s return "\n".join(imports) - def _create_enum(self, enum_data: Enum, indent_quant: int) -> str: - indentations = "\t" * (indent_quant + 1) - + # Todo Frage: Wir unterstützen keine Schachtelungen von Enums, richtig? Weder in Enums noch in Klassen + def _create_enum_string(self, enum_data: Enum) -> str: # Signature enum_signature = f"enum {enum_data.name}" @@ -355,12 +352,12 @@ def _create_enum(self, enum_data: Enum, indent_quant: int) -> str: camel_case_name = _convert_snake_to_camel_case(name) annotation = "" if camel_case_name != name: - annotation = f"{indentations}{self._create_name_annotation(name)}\n" + annotation = f"\t{self._create_name_annotation(name)}\n" # Check if the name is a Safe-DS keyword and escape it camel_case_name = self._replace_if_safeds_keyword(camel_case_name) - enum_text += f"{annotation}{indentations}{camel_case_name}\n" + enum_text += f"{annotation}\t{camel_case_name}\n" return f"{enum_signature} {{{enum_text}}}" return enum_signature @@ -445,19 +442,19 @@ def _create_type_string(self, type_data: dict | None) -> str: raise ValueError(f"Unexpected type: {kind}") - def create_todo_msg(self, indenta_quant: int) -> str: + def create_todo_msg(self, indentations: str) -> str: if not self.current_todo_msgs: return "" todo_msgs = [ - { - "Tuple": "// TODO Safe-DS does not support tuple types.", - "List": "// TODO List type has to many type arguments.", - "Set": "// TODO Set type has to many type arguments.", - "OPT_POS_ONLY": "// TODO Safe-DS does not support optional but position only parameter assignments.", - "REQ_NAME_ONLY": "// TODO Safe-DS does not support required but name only parameter assignments.", - "multiple_inheritance": "// TODO Safe-DS does not support multiple inheritance.", - "variadic": "// TODO Safe-DS does not support variadic parameters.", + "// TODO " + { + "Tuple": "Safe-DS does not support tuple types.", + "List": "List type has to many type arguments.", + "Set": "Set type has to many type arguments.", + "OPT_POS_ONLY": "Safe-DS does not support optional but position only parameter assignments.", + "REQ_NAME_ONLY": "Safe-DS does not support required but name only parameter assignments.", + "multiple_inheritance": "Safe-DS does not support multiple inheritance.", + "variadic": "Safe-DS does not support variadic parameters.", }[msg] for msg in self.current_todo_msgs ] @@ -465,7 +462,6 @@ def create_todo_msg(self, indenta_quant: int) -> str: # Empty the message list self.current_todo_msgs = set() - indentations = "\t" * indenta_quant return indentations + f"\n{indentations}".join(todo_msgs) + "\n" @staticmethod From d04c4f71cdadd64fae5acdd55e27a20ed0b20270 Mon Sep 17 00:00:00 2001 From: Arsam Islami Date: Mon, 13 Nov 2023 14:39:41 +0100 Subject: [PATCH 027/109] Test snapshot update --- .../__snapshots__/test_main.ambr | 26 ++- .../__snapshots__/test__get_api.ambr | 14 +- .../__snapshots__/test_generate_stubs.ambr | 180 +++++++++++++----- 3 files changed, 157 insertions(+), 63 deletions(-) diff --git a/tests/safeds_stubgen/__snapshots__/test_main.ambr b/tests/safeds_stubgen/__snapshots__/test_main.ambr index 79cb6a84..de8ba21e 100644 --- a/tests/safeds_stubgen/__snapshots__/test_main.ambr +++ b/tests/safeds_stubgen/__snapshots__/test_main.ambr @@ -492,6 +492,10 @@ 'type': dict({ 'kind': 'TupleType', 'types': list([ + dict({ + 'kind': 'NamedType', + 'name': 'Any', + }), ]), }), }), @@ -1195,8 +1199,8 @@ 'distribution': '', 'enum_instances': list([ dict({ - 'id': 'test_package/test_enums/AnotherTestEnum/ELEVEN', - 'name': 'ELEVEN', + 'id': 'test_package/test_enums/AnotherTestEnum/number_eleven', + 'name': 'number_eleven', }), dict({ 'id': 'test_package/test_enums/EnumTest/EIGHT', @@ -1247,7 +1251,7 @@ }), 'id': 'test_package/test_enums/AnotherTestEnum', 'instances': list([ - 'test_package/test_enums/AnotherTestEnum/ELEVEN', + 'test_package/test_enums/AnotherTestEnum/number_eleven', ]), 'name': 'AnotherTestEnum', }), @@ -2171,16 +2175,14 @@ }), dict({ 'classes': list([ - 'test_package/test_package/test_package/TestPackage', - 'test_package/test_package/test_package/test_package', ]), 'docstring': '', 'enums': list([ ]), 'functions': list([ ]), - 'id': 'test_package/test_package/test_package', - 'name': 'test_package', + 'id': 'test_package/test_package/__init__', + 'name': '__init__', 'qualified_imports': list([ ]), 'wildcard_imports': list([ @@ -2188,14 +2190,16 @@ }), dict({ 'classes': list([ + 'test_package/test_package/test_package/TestPackage', + 'test_package/test_package/test_package/test_package', ]), 'docstring': '', 'enums': list([ ]), 'functions': list([ ]), - 'id': 'test_package/test_package__init__', - 'name': '__init__', + 'id': 'test_package/test_package/test_package', + 'name': 'test_package', 'qualified_imports': list([ ]), 'wildcard_imports': list([ @@ -2739,6 +2743,10 @@ 'type': dict({ 'kind': 'TupleType', 'types': list([ + dict({ + 'kind': 'NamedType', + 'name': 'Any', + }), ]), }), }), diff --git a/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr b/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr index af3adeb2..e56138b4 100644 --- a/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr +++ b/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr @@ -512,6 +512,10 @@ 'type': dict({ 'kind': 'TupleType', 'types': list([ + dict({ + 'kind': 'NamedType', + 'name': 'Any', + }), ]), }), }), @@ -1581,8 +1585,8 @@ # name: test_enum_instances_AnotherTestEnum list([ dict({ - 'id': 'test_package/test_enums/AnotherTestEnum/ELEVEN', - 'name': 'ELEVEN', + 'id': 'test_package/test_enums/AnotherTestEnum/number_eleven', + 'name': 'number_eleven', }), ]) # --- @@ -1642,7 +1646,7 @@ }), 'id': 'test_package/test_enums/AnotherTestEnum', 'instances': list([ - 'test_package/test_enums/AnotherTestEnum/ELEVEN', + 'test_package/test_enums/AnotherTestEnum/number_eleven', ]), 'name': 'AnotherTestEnum', }) @@ -2219,6 +2223,10 @@ 'type': dict({ 'kind': 'TupleType', 'types': list([ + dict({ + 'kind': 'NamedType', + 'name': 'Any', + }), ]), }), }), diff --git a/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr b/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr index 87c0bc8d..d1559d38 100644 --- a/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr +++ b/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr @@ -6,36 +6,61 @@ class A() class B() { - static attr type_hint_public: Int - static attr no_type_hint_public - static attr object_attr: A + @PythonName("type_hint_public") + static attr typeHintPublic: Int + @PythonName("no_type_hint_public") + static attr noTypeHintPublic + @PythonName("object_attr") + static attr objectAttr: A // TODO Safe-DS does not support tuple types. - static attr tuple_attr_1: Tuple + @PythonName("tuple_attr_1") + static attr tupleAttr1: Tuple // TODO Safe-DS does not support tuple types. - static attr tuple_attr_2: Tuple> + @PythonName("tuple_attr_2") + static attr tupleAttr2: Tuple> // TODO Safe-DS does not support tuple types. - static attr tuple_attr_3: Tuple - static attr list_attr_1: List - static attr list_attr_2: List> + @PythonName("tuple_attr_3") + static attr tupleAttr3: Tuple + @PythonName("list_attr_1") + static attr listAttr1: List + @PythonName("list_attr_2") + static attr listAttr2: List> // TODO List type has to many type arguments. - static attr list_attr_3: List + @PythonName("list_attr_3") + static attr listAttr3: List // TODO List type has to many type arguments. - static attr list_attr_4: List> - static attr dict_attr_1: Map - static attr dict_attr_2: Map - static attr dict_attr_3: Map, A?> - static attr bool_attr: Boolean - static attr none_attr: Nothing? - static attr flaot_attr: Float - static attr int_or_bool_attr: union - static attr str_attr_with_none_value: String - static attr mulit_attr_1 - static attr mulit_attr_3 - static attr mulit_attr_5 - static attr mulit_attr_6 - static attr mulit_attr_7 - static attr mulit_attr_8 - attr init_attr: Boolean + @PythonName("list_attr_4") + static attr listAttr4: List> + @PythonName("dict_attr_1") + static attr dictAttr1: Map + @PythonName("dict_attr_2") + static attr dictAttr2: Map + @PythonName("dict_attr_3") + static attr dictAttr3: Map, A?> + @PythonName("bool_attr") + static attr boolAttr: Boolean + @PythonName("none_attr") + static attr noneAttr: Nothing? + @PythonName("flaot_attr") + static attr flaotAttr: Float + @PythonName("int_or_bool_attr") + static attr intOrBoolAttr: union + @PythonName("str_attr_with_none_value") + static attr strAttrWithNoneValue: String + @PythonName("multi_attr_1") + static attr multiAttr1 + @PythonName("multi_attr_3") + static attr multiAttr3 + @PythonName("multi_attr_5") + static attr multiAttr5 + @PythonName("multi_attr_6") + static attr multiAttr6 + @PythonName("multi_attr_7") + static attr multiAttr7 + @PythonName("multi_attr_8") + static attr multiAttr8 + @PythonName("init_attr") + attr initAttr: Boolean } ''' @@ -46,14 +71,19 @@ class A() - class B(a: Int, b: A?) sub A { + class B( + a: Int, + b: A? + ) sub A { fun f() } // TODO Safe-DS does not support multiple inheritance. class C() sub A, B { - static attr attr_1: Int - static attr attr_2: Int + @PythonName("attr_1") + static attr attr1: Int + @PythonName("attr_2") + static attr attr2: Int fun f1() } @@ -102,41 +132,89 @@ ''' package test_stub_generation.function_module - fun public_no_params_no_result() + @PythonName("public_no_params_no_result") + fun publicNoParamsNoResult() - fun params(i: Int, union: union, lst: List, obj: A) -> result_1: Any + fun params( + i: Int, + `union`: union, + lst: List, + obj: A + ) -> result_1: Any // TODO Safe-DS does not support tuple types. - fun illegal_params(none: Nothing?, none_union: Nothing??, tpl: Tuple, lst: List, _: Int = String) -> result_1: Any - - fun special_params(none_union: Boolean?) -> result_1: Any - - fun param_position(self: Any, a: Any, b: Boolean, c: Any = 1, d: Any, e: Int = 1) -> result_1: Any + @PythonName("illegal_params") + fun illegalParams( + lst: List, + tpl: Tuple, + _: Int = String + ) -> result_1: Any + + @PythonName("special_params") + fun specialParams( + @PythonName("none_bool_union") noneBoolUnion: Boolean?, + @PythonName("none_union") noneUnion: Nothing??, + none: Nothing? + ) -> result_1: Any + + @PythonName("param_position") + fun paramPosition( + self: Any, + a: Any, + b: Boolean, + c: Any = 1, + d: Any, + e: Int = 1 + ) -> result_1: Any // TODO Safe-DS does not support optional but position only parameter assignments. - fun opt_pos_only(required: Any, optional: Any = 1) + @PythonName("opt_pos_only") + fun optPosOnly( + required: Any, + optional: Any = 1 + ) // TODO Safe-DS does not support required but name only parameter assignments. - fun req_name_only(required: Any, optional: Any = 1) - - // TODO Safe-DS does not support tuple types. - fun arg(args: Tuple, kwargs: Map) - - // TODO Safe-DS does not support tuple types. - fun args_type(args: Tuple, kwargs: Map) -> result_1: Any - - fun one_result() -> result_1: Int - - fun multiple_results() -> (result_1: String, result_2: Int, result_3: Boolean, result_4: A) + @PythonName("req_name_only") + fun reqNameOnly( + required: Any, + optional: Any = 1 + ) + + // TODO Safe-DS does not support variadic parameters. + fun arg( + args: List, + kwargs: Map + ) + + // TODO Safe-DS does not support variadic parameters. + @PythonName("args_type") + fun argsType( + args: List, + kwargs: Map + ) -> result_1: Any + + @PythonName("one_result") + fun oneResult() -> result_1: Int + + @PythonName("multiple_results") + fun multipleResults() -> (result_1: String, result_2: Int, result_3: Boolean, result_4: A) class A() - class B(init_param: Any) { - fun instance_method(a: A) -> result_1: A + class B( + @PythonName("init_param") initParam: Any + ) { + @PythonName("instance_method") + fun instanceMethod( + a: A + ) -> result_1: A - static fun static_class_method() + @PythonName("static_class_method") + static fun staticClassMethod() - fun class_method() + @PythonName("class_method") + fun classMethod() } ''' From 541fd4dfd33a52c689e22cab2ccdfd20897c1965 Mon Sep 17 00:00:00 2001 From: Arsam Islami Date: Mon, 13 Nov 2023 14:51:41 +0100 Subject: [PATCH 028/109] Removed test packages and updated test snapshots --- .../test_package/test_package/__init__.py | 0 .../test_package/test_package/test_package.py | 8 -- .../__snapshots__/test_main.ambr | 122 ------------------ .../__snapshots__/test__get_api.ambr | 84 ------------ .../api_analyzer/test__get_api.py | 20 --- .../api_analyzer/test_generate_stubs.py | 0 6 files changed, 234 deletions(-) delete mode 100644 tests/data/test_package/test_package/__init__.py delete mode 100644 tests/data/test_package/test_package/test_package.py delete mode 100644 tests/safeds_stubgen/api_analyzer/test_generate_stubs.py diff --git a/tests/data/test_package/test_package/__init__.py b/tests/data/test_package/test_package/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/tests/data/test_package/test_package/test_package.py b/tests/data/test_package/test_package/test_package.py deleted file mode 100644 index 901fb715..00000000 --- a/tests/data/test_package/test_package/test_package.py +++ /dev/null @@ -1,8 +0,0 @@ -class TestPackage: - def test_package(self): - return self.test_package - - -# noinspection PyPep8Naming -class test_package: - test_package: int = 1 diff --git a/tests/safeds_stubgen/__snapshots__/test_main.ambr b/tests/safeds_stubgen/__snapshots__/test_main.ambr index de8ba21e..64c6e64a 100644 --- a/tests/safeds_stubgen/__snapshots__/test_main.ambr +++ b/tests/safeds_stubgen/__snapshots__/test_main.ambr @@ -606,21 +606,6 @@ 'name': 'int', }), }), - dict({ - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_package/test_package/test_package/test_package', - 'is_public': True, - 'is_static': True, - 'name': 'test_package', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'int', - }), - }), ]), 'classes': list([ dict({ @@ -1153,48 +1138,6 @@ 'superclasses': list([ ]), }), - dict({ - 'attributes': list([ - ]), - 'classes': list([ - ]), - 'constructor': None, - 'docstring': dict({ - 'description': '', - 'full_docstring': '', - }), - 'id': 'test_package/test_package/test_package/TestPackage', - 'is_public': True, - 'methods': list([ - 'test_package/test_package/test_package/TestPackage/test_package', - ]), - 'name': 'TestPackage', - 'reexported_by': list([ - ]), - 'superclasses': list([ - ]), - }), - dict({ - 'attributes': list([ - 'test_package/test_package/test_package/test_package/test_package', - ]), - 'classes': list([ - ]), - 'constructor': None, - 'docstring': dict({ - 'description': '', - 'full_docstring': '', - }), - 'id': 'test_package/test_package/test_package/test_package', - 'is_public': True, - 'methods': list([ - ]), - 'name': 'test_package', - 'reexported_by': list([ - ]), - 'superclasses': list([ - ]), - }), ]), 'distribution': '', 'enum_instances': list([ @@ -1923,23 +1866,6 @@ 'test_package/test_module/global_func/result_1', ]), }), - dict({ - 'docstring': dict({ - 'description': '', - 'full_docstring': '', - }), - 'id': 'test_package/test_package/test_package/TestPackage/test_package', - 'is_public': True, - 'is_static': False, - 'name': 'test_package', - 'parameters': list([ - 'test_package/test_package/test_package/TestPackage/test_package/self', - ]), - 'reexported_by': list([ - ]), - 'results': list([ - ]), - }), ]), 'modules': list([ dict({ @@ -2173,38 +2099,6 @@ }), ]), }), - dict({ - 'classes': list([ - ]), - 'docstring': '', - 'enums': list([ - ]), - 'functions': list([ - ]), - 'id': 'test_package/test_package/__init__', - 'name': '__init__', - 'qualified_imports': list([ - ]), - 'wildcard_imports': list([ - ]), - }), - dict({ - 'classes': list([ - 'test_package/test_package/test_package/TestPackage', - 'test_package/test_package/test_package/test_package', - ]), - 'docstring': '', - 'enums': list([ - ]), - 'functions': list([ - ]), - 'id': 'test_package/test_package/test_package', - 'name': 'test_package', - 'qualified_imports': list([ - ]), - 'wildcard_imports': list([ - ]), - }), ]), 'package': 'test_package', 'parameters': list([ @@ -2942,22 +2836,6 @@ ]), }), }), - dict({ - 'assigned_by': 'IMPLICIT', - 'default_value': None, - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_package/test_package/TestPackage/test_package/self', - 'is_optional': False, - 'name': 'self', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'TestPackage', - }), - }), ]), 'results': list([ dict({ diff --git a/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr b/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr index e56138b4..ba8c7f61 100644 --- a/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr +++ b/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr @@ -620,25 +620,6 @@ }), ]) # --- -# name: test_class_attributes_test_package - list([ - dict({ - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_package/test_package/test_package/test_package', - 'is_public': True, - 'is_static': True, - 'name': 'test_package', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'int', - }), - }), - ]) -# --- # name: test_class_methods_EpydocDocstringClass list([ dict({ @@ -1471,29 +1452,6 @@ ]), }) # --- -# name: test_classes_TestPackage - dict({ - 'attributes': list([ - ]), - 'classes': list([ - ]), - 'constructor': None, - 'docstring': dict({ - 'description': '', - 'full_docstring': '', - }), - 'id': 'test_package/test_package/test_package/TestPackage', - 'is_public': True, - 'methods': list([ - 'test_package/test_package/test_package/TestPackage/test_package', - ]), - 'name': 'TestPackage', - 'reexported_by': list([ - ]), - 'superclasses': list([ - ]), - }) -# --- # name: test_classes__PrivateClass dict({ 'attributes': list([ @@ -1559,29 +1517,6 @@ ]), }) # --- -# name: test_classes_test_package - dict({ - 'attributes': list([ - 'test_package/test_package/test_package/test_package/test_package', - ]), - 'classes': list([ - ]), - 'constructor': None, - 'docstring': dict({ - 'description': '', - 'full_docstring': '', - }), - 'id': 'test_package/test_package/test_package/test_package', - 'is_public': True, - 'methods': list([ - ]), - 'name': 'test_package', - 'reexported_by': list([ - ]), - 'superclasses': list([ - ]), - }) -# --- # name: test_enum_instances_AnotherTestEnum list([ dict({ @@ -2954,22 +2889,3 @@ ]), }) # --- -# name: test_modules_test_package - dict({ - 'classes': list([ - 'test_package/test_package/test_package/TestPackage', - 'test_package/test_package/test_package/test_package', - ]), - 'docstring': '', - 'enums': list([ - ]), - 'functions': list([ - ]), - 'id': 'test_package/test_package/test_package', - 'name': 'test_package', - 'qualified_imports': list([ - ]), - 'wildcard_imports': list([ - ]), - }) -# --- diff --git a/tests/safeds_stubgen/api_analyzer/test__get_api.py b/tests/safeds_stubgen/api_analyzer/test__get_api.py index 8b7ae699..68024ceb 100644 --- a/tests/safeds_stubgen/api_analyzer/test__get_api.py +++ b/tests/safeds_stubgen/api_analyzer/test__get_api.py @@ -106,11 +106,6 @@ def test_modules_another_module(snapshot: SnapshotAssertion) -> None: assert module_data == snapshot -def test_modules_test_package(snapshot: SnapshotAssertion) -> None: - module_data = _get_specific_module_data("test_package") - assert module_data == snapshot - - def test_modules_test_enums(snapshot: SnapshotAssertion) -> None: module_data = _get_specific_module_data("test_enums") assert module_data == snapshot @@ -228,16 +223,6 @@ def test_classes_FourthReexportClass(snapshot: SnapshotAssertion) -> None: # no assert class_data == snapshot -def test_classes_TestPackage(snapshot: SnapshotAssertion) -> None: # noqa: N802 - class_data = _get_specific_class_data("TestPackage", "plaintext") - assert class_data == snapshot - - -def test_classes_test_package(snapshot: SnapshotAssertion) -> None: - class_data = _get_specific_class_data("test_package", "plaintext") - assert class_data == snapshot - - # ############################## Class Attributes ############################## # def get_class_attribute_data(class_name: str, docstring_style: str) -> list: class_data: dict = _get_specific_class_data(class_name) @@ -295,11 +280,6 @@ def test_class_attributes_GoogleDocstringClass(snapshot: SnapshotAssertion) -> N assert class_data == snapshot -def test_class_attributes_test_package(snapshot: SnapshotAssertion) -> None: - class_data = get_class_attribute_data("test_package", "plaintext") - assert class_data == snapshot - - # ############################## Enums ############################## # def test_enums_EnumTest(snapshot: SnapshotAssertion) -> None: # noqa: N802 enum_data = _get_specific_class_data("EnumTest", is_enum=True) diff --git a/tests/safeds_stubgen/api_analyzer/test_generate_stubs.py b/tests/safeds_stubgen/api_analyzer/test_generate_stubs.py deleted file mode 100644 index e69de29b..00000000 From 79fd8a2e2702ba56c7bc0097f0f27783b8cd6697 Mon Sep 17 00:00:00 2001 From: Arsam Islami Date: Mon, 13 Nov 2023 15:17:49 +0100 Subject: [PATCH 029/109] Adjusted test snapshots and removed enum imports for stub generator --- src/safeds_stubgen/stubs_generator/_generate_stubs.py | 4 ++++ tests/data/test_stub_generation/function_module.py | 1 + 2 files changed, 5 insertions(+) diff --git a/src/safeds_stubgen/stubs_generator/_generate_stubs.py b/src/safeds_stubgen/stubs_generator/_generate_stubs.py index 1cf950bc..22162322 100644 --- a/src/safeds_stubgen/stubs_generator/_generate_stubs.py +++ b/src/safeds_stubgen/stubs_generator/_generate_stubs.py @@ -309,6 +309,10 @@ def _create_qualified_imports_string(self, qualified_imports: list[QualifiedImpo import_path = self._replace_if_safeds_keyword(import_path) name = self._replace_if_safeds_keyword(name) + # Ignore enum imports, since those are build in types in Safe-DS stubs + if import_path == "enum" and name in {"Enum", "IntEnum"}: + continue + from_path = "" if import_path: from_path = f"from {import_path} " diff --git a/tests/data/test_stub_generation/function_module.py b/tests/data/test_stub_generation/function_module.py index 01929c12..d104e536 100644 --- a/tests/data/test_stub_generation/function_module.py +++ b/tests/data/test_stub_generation/function_module.py @@ -30,6 +30,7 @@ def params( def illegal_params( lst: list[int, str], + lst_2: list[int, str, int], tpl: tuple[int, str, bool, int], _: int = "String", ): ... From 1cda7923643edff6e76fff075df92c6b167958f8 Mon Sep 17 00:00:00 2001 From: Arsam Islami Date: Mon, 13 Nov 2023 15:39:07 +0100 Subject: [PATCH 030/109] Adjusted test snapshots and removed enum imports for stub generator --- src/safeds_stubgen/stubs_generator/_generate_stubs.py | 11 +++++------ .../__snapshots__/test_generate_stubs.ambr | 7 +------ 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/src/safeds_stubgen/stubs_generator/_generate_stubs.py b/src/safeds_stubgen/stubs_generator/_generate_stubs.py index 22162322..6e175816 100644 --- a/src/safeds_stubgen/stubs_generator/_generate_stubs.py +++ b/src/safeds_stubgen/stubs_generator/_generate_stubs.py @@ -306,17 +306,16 @@ def _create_qualified_imports_string(self, qualified_imports: list[QualifiedImpo qualified_name = qualified_import.qualified_name import_path, name = split_import_id(qualified_name) - import_path = self._replace_if_safeds_keyword(import_path) - name = self._replace_if_safeds_keyword(name) - # Ignore enum imports, since those are build in types in Safe-DS stubs if import_path == "enum" and name in {"Enum", "IntEnum"}: continue - from_path = "" - if import_path: - from_path = f"from {import_path} " + # Check if Safe-DS keywords are used and escape them if necessary + import_path = self._replace_if_safeds_keyword(import_path) + name = self._replace_if_safeds_keyword(name) + # Create string + from_path = f"from {import_path} " if import_path else "" alias = f" as {qualified_import.alias}" if qualified_import.alias else "" imports.append( diff --git a/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr b/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr index d1559d38..e019acfb 100644 --- a/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr +++ b/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr @@ -100,10 +100,6 @@ ''' package test_stub_generation.enum_module - from `enum` import Enum - from `enum` import IntEnum - from `enum` import Enum as _Enum - enum EnumTest { ONE TWO @@ -146,6 +142,7 @@ @PythonName("illegal_params") fun illegalParams( lst: List, + @PythonName("lst_2") lst2: List, tpl: Tuple, _: Int = String ) -> result_1: Any @@ -223,8 +220,6 @@ ''' package test_stub_generation.import_module - from `enum` import IntEnum - from `enum` import Enum as _Enum import mypy as static from math import * From 9ec9516fede673f0193464c86cc953f57bc4f492 Mon Sep 17 00:00:00 2001 From: Arsam Islami Date: Mon, 13 Nov 2023 15:42:14 +0100 Subject: [PATCH 031/109] Adjusted test snapshots --- .../stubs_generator/__snapshots__/test_generate_stubs.ambr | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr b/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr index e019acfb..c4d7dcc0 100644 --- a/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr +++ b/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr @@ -139,10 +139,11 @@ ) -> result_1: Any // TODO Safe-DS does not support tuple types. + // TODO List type has to many type arguments. @PythonName("illegal_params") fun illegalParams( - lst: List, - @PythonName("lst_2") lst2: List, + lst: List, + @PythonName("lst_2") lst2: List, tpl: Tuple, _: Int = String ) -> result_1: Any @@ -150,7 +151,7 @@ @PythonName("special_params") fun specialParams( @PythonName("none_bool_union") noneBoolUnion: Boolean?, - @PythonName("none_union") noneUnion: Nothing??, + @PythonName("none_union") noneUnion: Nothing?, none: Nothing? ) -> result_1: Any From 507e3f064f551a107abad24577174d21057461a8 Mon Sep 17 00:00:00 2001 From: Arsam Islami Date: Mon, 13 Nov 2023 16:00:30 +0100 Subject: [PATCH 032/109] Adjusted test snapshots and added escaping for keywords in imports --- .../stubs_generator/_generate_stubs.py | 26 ++++++++----------- .../__snapshots__/test_generate_stubs.ambr | 2 +- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/src/safeds_stubgen/stubs_generator/_generate_stubs.py b/src/safeds_stubgen/stubs_generator/_generate_stubs.py index 6e175816..3537fa56 100644 --- a/src/safeds_stubgen/stubs_generator/_generate_stubs.py +++ b/src/safeds_stubgen/stubs_generator/_generate_stubs.py @@ -310,27 +310,22 @@ def _create_qualified_imports_string(self, qualified_imports: list[QualifiedImpo if import_path == "enum" and name in {"Enum", "IntEnum"}: continue - # Check if Safe-DS keywords are used and escape them if necessary - import_path = self._replace_if_safeds_keyword(import_path) - name = self._replace_if_safeds_keyword(name) - - # Create string - from_path = f"from {import_path} " if import_path else "" - alias = f" as {qualified_import.alias}" if qualified_import.alias else "" + # Create string and check if Safe-DS keywords are used and escape them if necessary + from_path = f"from {self._replace_if_safeds_keyword(import_path)} " if import_path else "" + alias = f" as {self._replace_if_safeds_keyword(qualified_import.alias)}" if qualified_import.alias else "" imports.append( - f"{from_path}import {name}{alias}", + f"{from_path}import {self._replace_if_safeds_keyword(name)}{alias}", ) return "\n".join(imports) - @staticmethod - def _create_wildcard_imports_string(wildcard_imports: list[WildcardImport]) -> str: + def _create_wildcard_imports_string(self, wildcard_imports: list[WildcardImport]) -> str: if not wildcard_imports: return "" imports = [ - f"from {wildcard_import.module_name} import *" + f"from {self._replace_if_safeds_keyword(wildcard_import.module_name)} import *" for wildcard_import in wildcard_imports ] @@ -473,10 +468,11 @@ def _create_name_annotation(name: str) -> str: @staticmethod def _replace_if_safeds_keyword(keyword: str) -> str: - if keyword in {"as", "from", "import", "literal", "union", "where", "yield", "false", "null", "true", - "annotation", - "attr", "class", "enum", "fun", "package", "pipeline", "schema", "segment", "val", "const", "in", - "internal", "out", "private", "static", "and", "not", "or", "sub", "super"}: + if keyword in { + "as", "from", "import", "literal", "union", "where", "yield", "false", "null", "true", "annotation", "attr", + "class", "enum", "fun", "package", "pipeline", "schema", "segment", "val", "const", "in", "internal", "out", + "private", "static", "and", "not", "or", "sub", "super" + }: return f"`{keyword}`" return keyword diff --git a/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr b/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr index c4d7dcc0..fbb6aaa6 100644 --- a/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr +++ b/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr @@ -221,7 +221,7 @@ ''' package test_stub_generation.import_module - import mypy as static + import mypy as `static` from math import * From 912b6ca49ee81753f5e6d391b57c44f34fd50912 Mon Sep 17 00:00:00 2001 From: Arsam Islami Date: Mon, 13 Nov 2023 16:49:37 +0100 Subject: [PATCH 033/109] api_analyzer: Fixed a bug where lists with multiple types would not be correctly parsed --- src/safeds_stubgen/api_analyzer/_ast_visitor.py | 13 ++++++++++++- src/safeds_stubgen/api_analyzer/_mypy_helpers.py | 6 ++++++ .../__snapshots__/test_generate_stubs.ambr | 2 +- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/safeds_stubgen/api_analyzer/_ast_visitor.py b/src/safeds_stubgen/api_analyzer/_ast_visitor.py index 12ebc819..0999441b 100644 --- a/src/safeds_stubgen/api_analyzer/_ast_visitor.py +++ b/src/safeds_stubgen/api_analyzer/_ast_visitor.py @@ -513,7 +513,18 @@ def parse_parameter_data(self, node: FuncDef, function_id: str) -> list[Paramete mypy_type = argument.variable.type if mypy_type is None: # pragma: no cover raise ValueError("Argument has no type.") - arg_type = mypy_type_to_abstract_type(mypy_type) + + type_annotation = argument.type_annotation + if (isinstance(type_annotation, mp_types.UnboundType) and + type_annotation.name == "list" and + len(type_annotation.args) >= 2): + # A special case where the argument is a list with multiple types. We have to handle this case like this + # b/c something like list[int, str] is not allowed according to PEP and therefore not handled the normal + # way in Mypy. + arg_type = mypy_type_to_abstract_type(type_annotation) + else: + arg_type = mypy_type_to_abstract_type(mypy_type) + arg_kind = get_argument_kind(argument) default_value = None diff --git a/src/safeds_stubgen/api_analyzer/_mypy_helpers.py b/src/safeds_stubgen/api_analyzer/_mypy_helpers.py index 5b4695ab..10dc068f 100644 --- a/src/safeds_stubgen/api_analyzer/_mypy_helpers.py +++ b/src/safeds_stubgen/api_analyzer/_mypy_helpers.py @@ -53,6 +53,12 @@ def mypy_type_to_abstract_type(mypy_type: Instance | ProperType | MypyType) -> A elif isinstance(mypy_type, mp_types.NoneType): return sds_types.NamedType(name="None") elif isinstance(mypy_type, mp_types.UnboundType): + if mypy_type.name == "list": + types = [ + mypy_type_to_abstract_type(arg) + for arg in mypy_type.args + ] + return sds_types.ListType(types=types) # Todo Aliasing: Import auflösen return sds_types.NamedType(name=mypy_type.name) elif isinstance(mypy_type, mp_types.TypeType): diff --git a/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr b/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr index fbb6aaa6..233fb243 100644 --- a/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr +++ b/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr @@ -143,7 +143,7 @@ @PythonName("illegal_params") fun illegalParams( lst: List, - @PythonName("lst_2") lst2: List, + @PythonName("lst_2") lst2: List, tpl: Tuple, _: Int = String ) -> result_1: Any From 35f0dd1aac70a6cedb4aad9ae6f82390b5d28b45 Mon Sep 17 00:00:00 2001 From: Arsam Date: Tue, 14 Nov 2023 20:58:12 +0100 Subject: [PATCH 034/109] Added information for class methods to api analyzer and stubs generator --- src/safeds_stubgen/api_analyzer/_api.py | 2 ++ .../api_analyzer/_ast_visitor.py | 1 + .../stubs_generator/_generate_stubs.py | 24 ++++++++++++++----- tests/data/test_package/test_module.py | 8 +++++++ .../test_stub_generation/function_module.py | 2 +- 5 files changed, 30 insertions(+), 7 deletions(-) diff --git a/src/safeds_stubgen/api_analyzer/_api.py b/src/safeds_stubgen/api_analyzer/_api.py index 7439796c..16e34157 100644 --- a/src/safeds_stubgen/api_analyzer/_api.py +++ b/src/safeds_stubgen/api_analyzer/_api.py @@ -229,6 +229,7 @@ class Function: docstring: FunctionDocstring is_public: bool is_static: bool + is_class_method: bool = False results: list[Result] = field(default_factory=list) reexported_by: list[Module] = field(default_factory=list) parameters: list[Parameter] = field(default_factory=list) @@ -240,6 +241,7 @@ def to_dict(self) -> dict[str, Any]: "docstring": self.docstring.to_dict(), "is_public": self.is_public, "is_static": self.is_static, + "is_class_method": self.is_class_method, "results": [result.id for result in self.results], "reexported_by": [module.id for module in self.reexported_by], "parameters": [parameter.id for parameter in self.parameters], diff --git a/src/safeds_stubgen/api_analyzer/_ast_visitor.py b/src/safeds_stubgen/api_analyzer/_ast_visitor.py index 0999441b..4e2d75b4 100644 --- a/src/safeds_stubgen/api_analyzer/_ast_visitor.py +++ b/src/safeds_stubgen/api_analyzer/_ast_visitor.py @@ -201,6 +201,7 @@ def enter_funcdef(self, node: FuncDef) -> None: docstring=docstring, is_public=is_public, is_static=is_static, + is_class_method=node.is_class, results=results, reexported_by=reexported_by, parameters=arguments, diff --git a/src/safeds_stubgen/stubs_generator/_generate_stubs.py b/src/safeds_stubgen/stubs_generator/_generate_stubs.py index 3537fa56..42e83db8 100644 --- a/src/safeds_stubgen/stubs_generator/_generate_stubs.py +++ b/src/safeds_stubgen/stubs_generator/_generate_stubs.py @@ -66,7 +66,7 @@ def _create_module_files(self) -> None: # Create global functions for function in module.global_functions: if function.is_public: - module_text += f"\n{self._create_function_string(function, is_class_method=False)}\n" + module_text += f"\n{self._create_function_string(function, is_method=False)}\n" # Create classes, class attr. & class methods for class_ in module.classes: @@ -168,7 +168,7 @@ def _create_class_string(self, class_: Class, class_indentation: str = "") -> st if not method.is_public: continue class_methods.append( - self._create_function_string(method, inner_indentations, is_class_method=True), + self._create_function_string(method, inner_indentations, is_method=True), ) if class_methods: methods = "\n\n".join(class_methods) @@ -183,14 +183,25 @@ def _create_class_string(self, class_: Class, class_indentation: str = "") -> st return f"{class_signature} {{{class_text}" - def _create_function_string(self, function: Function, indentations: str = "", is_class_method: bool = False) -> str: + def _create_function_string(self, function: Function, indentations: str = "", is_method: bool = False) -> str: """Create a function string for Safe-DS stubs.""" + # Check if static or class method is_static = function.is_static - static = "static " if is_static else "" + is_class_method = function.is_class_method + + static = "" + if is_class_method or is_static: + static = "static " + + if is_class_method: + self.current_todo_msgs.add("class_method") # Parameters - is_instance_method = not is_static and is_class_method - func_params = self._create_parameter_string(function.parameters, indentations, is_instance_method) + func_params = self._create_parameter_string( + parameters=function.parameters, + indentations=indentations, + is_instance_method=not is_static and is_method + ) # Convert function name to camelCase name = function.name @@ -453,6 +464,7 @@ def create_todo_msg(self, indentations: str) -> str: "REQ_NAME_ONLY": "Safe-DS does not support required but name only parameter assignments.", "multiple_inheritance": "Safe-DS does not support multiple inheritance.", "variadic": "Safe-DS does not support variadic parameters.", + "class_method": "Safe-DS does not support class methods", }[msg] for msg in self.current_todo_msgs ] diff --git a/tests/data/test_package/test_module.py b/tests/data/test_package/test_module.py index 15bb47a5..e4ee31f0 100644 --- a/tests/data/test_package/test_module.py +++ b/tests/data/test_package/test_module.py @@ -103,6 +103,14 @@ def no_return_1(self): def no_return_2(self) -> None: pass + @classmethod + def class_method(cls) -> None: + pass + + @classmethod + def class_method_params(cls, param_1: int) -> bool: + pass + class NestedClass(_AcImportAlias): def nested_class_function(self, param_1: int) -> set[bool | None]: pass diff --git a/tests/data/test_stub_generation/function_module.py b/tests/data/test_stub_generation/function_module.py index d104e536..09fd0e85 100644 --- a/tests/data/test_stub_generation/function_module.py +++ b/tests/data/test_stub_generation/function_module.py @@ -8,7 +8,7 @@ def __init__(self, init_param): ... def instance_method(self, a: A) -> A: ... @staticmethod - def static_class_method() -> None: ... + def static_method() -> None: ... @classmethod def class_method(cls): ... From 164a416fdd728daa4093fc96e86997095115d069 Mon Sep 17 00:00:00 2001 From: Arsam Date: Tue, 14 Nov 2023 21:36:20 +0100 Subject: [PATCH 035/109] Fixed create type function for stubs generator for None types in Unions --- .../stubs_generator/_generate_stubs.py | 19 ++++++++++++++----- .../test_stub_generation/function_module.py | 7 ++++++- .../stubs_generator/test_generate_stubs.py | 1 + 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/safeds_stubgen/stubs_generator/_generate_stubs.py b/src/safeds_stubgen/stubs_generator/_generate_stubs.py index 42e83db8..9ee6ba20 100644 --- a/src/safeds_stubgen/stubs_generator/_generate_stubs.py +++ b/src/safeds_stubgen/stubs_generator/_generate_stubs.py @@ -415,17 +415,26 @@ def _create_type_string(self, type_data: dict | None) -> str: return f"{name}<{', '.join(types)}>" return f"{name}" elif kind == "UnionType": - types = [ + # Union items have to be unique + types = list({ self._create_type_string(type_) for type_ in type_data["types"] - ] + }) if types: if len(types) == 2 and none_type_name in types: - if types[0] == none_type_name: + # if None is one of the two possible types, we can remove the None and just return the other + # type with a question mark + if types[0] == types[1] == none_type_name: + return none_type_name + elif types[0] == none_type_name: return f"{types[1]}?" - else: - return f"{types[0]}?" + return f"{types[0]}?" + + # If the union contains only one type, return the type instead of creating an union + elif len(types) == 1: + return types[0] + return f"union<{', '.join(types)}>" return "" elif kind == "TupleType": diff --git a/tests/data/test_stub_generation/function_module.py b/tests/data/test_stub_generation/function_module.py index 09fd0e85..e04e48cd 100644 --- a/tests/data/test_stub_generation/function_module.py +++ b/tests/data/test_stub_generation/function_module.py @@ -37,8 +37,13 @@ def illegal_params( def special_params( - none_bool_union: None | bool, none_union: None | None, + none_bool_union: None | bool, + bool_none_union: bool | None, + none_bool_none_union: None | bool | None, + none_bool_int_union: None | bool | int, + none_none_bool_none_union: None | None | bool | None, + none_list_union_none_none: None | list[None | None] | None, none: None, ): ... diff --git a/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py b/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py index fa23d49d..7275b419 100644 --- a/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py +++ b/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py @@ -25,6 +25,7 @@ stubs_generator.generate_stubs() +# Todo Frage: Automatische Einrückung bei .ambr Dateien -> Snapshot Test schlagen deswegen fehl # Utilites def _assert_file_creation_recursive(python_path: Path, stub_path: Path) -> None: assert python_path.is_dir() From c2f34fc898ff5fd3798ff878bc697ced4b87e5aa Mon Sep 17 00:00:00 2001 From: Arsam Date: Fri, 17 Nov 2023 16:52:44 +0100 Subject: [PATCH 036/109] Removed automatic trailing whitespace trimming for .ambr (test snapshot) files; refactoring _generate_stubs.py; replaced _files.py with Path.glob --- .editorconfig | 3 + src/safeds_stubgen/api_analyzer/__init__.py | 2 + src/safeds_stubgen/api_analyzer/_files.py | 30 -- src/safeds_stubgen/api_analyzer/_get_api.py | 8 +- src/safeds_stubgen/api_analyzer/cli/_cli.py | 5 +- .../stubs_generator/__init__.py | 4 +- .../stubs_generator/_generate_stubs.py | 270 +++++++++--------- .../stubs_generator/test_generate_stubs.py | 6 +- 8 files changed, 154 insertions(+), 174 deletions(-) delete mode 100644 src/safeds_stubgen/api_analyzer/_files.py diff --git a/.editorconfig b/.editorconfig index c976a7f0..3fe87d19 100644 --- a/.editorconfig +++ b/.editorconfig @@ -10,3 +10,6 @@ insert_final_newline = true [{*.yaml,*.yml}] indent_size = 2 + +[*.ambr] +trim_trailing_whitespace = false diff --git a/src/safeds_stubgen/api_analyzer/__init__.py b/src/safeds_stubgen/api_analyzer/__init__.py index 63ab3098..eecfd505 100644 --- a/src/safeds_stubgen/api_analyzer/__init__.py +++ b/src/safeds_stubgen/api_analyzer/__init__.py @@ -7,6 +7,7 @@ Class, Enum, Function, + Module, Parameter, ParameterAssignment, QualifiedImport, @@ -50,6 +51,7 @@ "get_mypyfile_definitions", "ListType", "LiteralType", + "Module", "NamedType", "OptionalType", "package_root", diff --git a/src/safeds_stubgen/api_analyzer/_files.py b/src/safeds_stubgen/api_analyzer/_files.py deleted file mode 100644 index b5bc3d9c..00000000 --- a/src/safeds_stubgen/api_analyzer/_files.py +++ /dev/null @@ -1,30 +0,0 @@ -from __future__ import annotations - -import os -from pathlib import Path - - -def list_files(root_dir: Path, extension: str = "") -> list[str]: - """ - List all files in a directory and its subdirectories. - - Parameters - ---------- - root_dir: Path - The directory containing the files. - extension: str - The extension the files should have. - - Returns - ------- - files: list[str] - A list with absolute paths to the files. - """ - result: list[str] = [] - - for root, _, files in os.walk(root_dir): - for filename in files: - if filename.endswith(extension): - result.append(str(Path(root) / filename)) - - return result diff --git a/src/safeds_stubgen/api_analyzer/_get_api.py b/src/safeds_stubgen/api_analyzer/_get_api.py index 0e7cffbf..e20b1c6f 100644 --- a/src/safeds_stubgen/api_analyzer/_get_api.py +++ b/src/safeds_stubgen/api_analyzer/_get_api.py @@ -12,7 +12,6 @@ from ._api import API from ._ast_visitor import MyPyAstVisitor from ._ast_walker import ASTWalker -from ._files import list_files from ._package_metadata import distribution, distribution_version, package_root if TYPE_CHECKING: @@ -41,11 +40,10 @@ def get_api( walkable_files = [] package_paths = [] - for file in list_files(root, ".py"): - file_path = Path(file) + for file_path in root.glob(pattern="./**/*.py"): logging.info( "Working on file {posix_path}", - extra={"posix_path": file}, + extra={"posix_path": str(file_path)}, ) # Check if the current path is a test directory @@ -61,7 +59,7 @@ def get_api( ) continue - walkable_files.append(file) + walkable_files.append(str(file_path)) mypy_trees = _get_mypy_ast(walkable_files, package_paths, root) for tree in mypy_trees: diff --git a/src/safeds_stubgen/api_analyzer/cli/_cli.py b/src/safeds_stubgen/api_analyzer/cli/_cli.py index 67c4cb91..9ba64610 100644 --- a/src/safeds_stubgen/api_analyzer/cli/_cli.py +++ b/src/safeds_stubgen/api_analyzer/cli/_cli.py @@ -6,7 +6,7 @@ from typing import TYPE_CHECKING from safeds_stubgen.api_analyzer import get_api -from safeds_stubgen.stubs_generator import StubsGenerator +from safeds_stubgen.stubs_generator import generate_stubs if TYPE_CHECKING: from safeds_stubgen.docstring_parsing import DocstringStyle @@ -89,5 +89,4 @@ def _run_api_command( out_file_api = out_dir_path.joinpath(f"{package}__api.json") api.to_json_file(out_file_api) - stubs_generator = StubsGenerator(api, out_dir_path) - stubs_generator.generate_stubs() + generate_stubs(api, out_dir_path) diff --git a/src/safeds_stubgen/stubs_generator/__init__.py b/src/safeds_stubgen/stubs_generator/__init__.py index d6e89475..8065b081 100644 --- a/src/safeds_stubgen/stubs_generator/__init__.py +++ b/src/safeds_stubgen/stubs_generator/__init__.py @@ -1,8 +1,8 @@ """API-Analyzer for the Safe-DS stubs generator.""" from __future__ import annotations -from ._generate_stubs import StubsGenerator +from ._generate_stubs import generate_stubs __all__ = [ - "StubsGenerator", + "generate_stubs", ] diff --git a/src/safeds_stubgen/stubs_generator/_generate_stubs.py b/src/safeds_stubgen/stubs_generator/_generate_stubs.py index 9ee6ba20..0e5e7523 100644 --- a/src/safeds_stubgen/stubs_generator/_generate_stubs.py +++ b/src/safeds_stubgen/stubs_generator/_generate_stubs.py @@ -1,6 +1,5 @@ from __future__ import annotations -import shutil from pathlib import Path from safeds_stubgen.api_analyzer import ( @@ -8,6 +7,7 @@ Class, Enum, Function, + Module, Parameter, ParameterAssignment, QualifiedImport, @@ -16,78 +16,113 @@ ) -# Todo Docstrings / Descriptions -class StubsGenerator: - api: API - out_path: Path - current_todo_msgs: set[str] +def generate_stubs(api: API, out_path: Path) -> None: + """Generate Safe-DS stubs. - def __init__(self, api: API, out_path: Path) -> None: - self.api = api - self.out_path = out_path - self.current_todo_msgs = set() + Generates stub files from an API object and writes them to the out_path path. - def generate_stubs(self) -> None: - create_directory(Path(self.out_path / self.api.package)) - self._create_module_files() + Parameters + ---------- + api : API + The API object from which the stubs + out_path : Path + The path in which the stub files should be created. If no such path exists this function creates the directory + files. + """ + modules = api.modules.values() + if not modules: + return - def _create_module_files(self) -> None: - modules = self.api.modules.values() + Path(out_path / api.package).mkdir(parents=True, exist_ok=True) + generator = StubsStringGenerator() - for module in modules: - module_name = module.name - module_id = module.id + for module in modules: + module_name = module.name - if module_name == "__init__": - continue + if module_name == "__init__": + continue + + module_text = generator.create_module_string(module) + + # Each text block we create ends with "\n", therefore, is there is only the package information + # the file would look like this: "package path.to.package\n". With the split we can check if the module + # has enough information, if not, we won't create it in the first place. + if len(module_text.split("\n")) <= 2: + return + + # Create module dir + module_dir = Path(out_path / module.id) + module_dir.mkdir(parents=True, exist_ok=True) + + # Create and open module file + file_path = Path(module_dir / f"{module_name}.sdsstub") + Path(file_path).touch() + + with file_path.open("w") as f: + f.write(module_text) + + +def _convert_snake_to_camel_case(name: str) -> str: + if name == "_": + return name + + # Count underscores in front and behind the name + underscore_count_start = len(name) - len(name.lstrip("_")) + underscore_count_end = len(name) - len(name.rstrip("_")) + + if underscore_count_end == 0: + cleaned_name = name[underscore_count_start:] + else: + cleaned_name = name[underscore_count_start:-underscore_count_end] + + # Remove underscores and join in camelCase + name_parts = cleaned_name.split("_") + return name_parts[0] + "".join( + part[0].upper() + part[1:] + for part in name_parts[1:] + if part + ) + + +class StubsStringGenerator: + """Generate Safe-DS stub strings. + + Generates stub string for Safe-DS. Each part has its own method, but it all starts with the create_module_string + method. + """ + + def __init__(self) -> None: + self._current_todo_msgs: set[str] = set() + + def create_module_string(self, module: Module) -> str: + # Create package info + package_info = module.id.replace("/", ".") + module_text = f"package {package_info}\n" + + # Create imports + qualified_imports = self._create_qualified_imports_string(module.qualified_imports) + if qualified_imports: + module_text += f"\n{qualified_imports}\n" + + wildcard_imports = self._create_wildcard_imports_string(module.wildcard_imports) + if wildcard_imports: + module_text += f"\n{wildcard_imports}\n" - # Create module dir - module_dir = Path(self.out_path / module_id) - create_directory(module_dir) - - # Create and open module file - file_path = Path(module_dir / f"{module_name}.sdsstub") - Path(file_path).touch() - - with file_path.open("w") as f: - # Create package info - package_info = module_id.replace("/", ".") - module_text = f"package {package_info}\n" - - # Create imports - qualified_imports = self._create_qualified_imports_string(module.qualified_imports) - if qualified_imports: - module_text += f"\n{qualified_imports}\n" - - wildcard_imports = self._create_wildcard_imports_string(module.wildcard_imports) - if wildcard_imports: - module_text += f"\n{wildcard_imports}\n" - - # Create global functions - for function in module.global_functions: - if function.is_public: - module_text += f"\n{self._create_function_string(function, is_method=False)}\n" - - # Create classes, class attr. & class methods - for class_ in module.classes: - if class_.is_public: - module_text += f"\n{self._create_class_string(class_)}\n" - - # Create enums & enum instances - for enum in module.enums: - module_text += f"\n{self._create_enum_string(enum)}\n" - - # Write module - f.write(module_text) - - # Todo Frage: - # Delete the file, if it has no content besides the "package" information in the first line - with file_path.open("r") as f: - delete_file = False - if sum(1 for _ in f) <= 1: - delete_file = True - if delete_file: - shutil.rmtree(module_dir) + # Create global functions + for function in module.global_functions: + if function.is_public: + module_text += f"\n{self._create_function_string(function, is_method=False)}\n" + + # Create classes, class attr. & class methods + for class_ in module.classes: + if class_.is_public: + module_text += f"\n{self._create_class_string(class_)}\n" + + # Create enums & enum instances + for enum in module.enums: + module_text += f"\n{self._create_enum_string(enum)}\n" + + return module_text def _create_class_string(self, class_: Class, class_indentation: str = "") -> str: inner_indentations = class_indentation + "\t" @@ -106,17 +141,17 @@ def _create_class_string(self, class_: Class, class_indentation: str = "") -> st superclass_info = "" if superclasses: superclass_names = [ - split_import_id(superclass)[1] + self._split_import_id(superclass)[1] for superclass in superclasses ] superclass_info = f" sub {', '.join(superclass_names)}" if len(superclasses) > 1: - self.current_todo_msgs.add("multiple_inheritance") + self._current_todo_msgs.add("multiple_inheritance") # Class signature line class_signature = ( - f"{class_indentation}{self.create_todo_msg(class_indentation)}class " + f"{class_indentation}{self._create_todo_msg(class_indentation)}class " f"{class_.name}({parameter_info}){superclass_info}" ) @@ -148,7 +183,7 @@ def _create_class_string(self, class_: Class, class_indentation: str = "") -> st # Create attribute string class_attributes.append( - f"{self.create_todo_msg(inner_indentations)}" + f"{self._create_todo_msg(inner_indentations)}" f"{inner_indentations}{attr_name_annotation}" f"{static_string}attr {attr_name_camel_case}" f"{type_string}", @@ -194,7 +229,7 @@ def _create_function_string(self, function: Function, indentations: str = "", is static = "static " if is_class_method: - self.current_todo_msgs.add("class_method") + self._current_todo_msgs.add("class_method") # Parameters func_params = self._create_parameter_string( @@ -212,7 +247,7 @@ def _create_function_string(self, function: Function, indentations: str = "", is # Create string and return return ( - f"{self.create_todo_msg(indentations)}" + f"{self._create_todo_msg(indentations)}" f"{function_name_annotation}" f"{indentations}{static}fun {camel_case_name}({func_params})" f"{self._create_result_string(function.results)}" @@ -224,8 +259,10 @@ def _create_result_string(self, function_results: list[Result]) -> str: result_type = result.type.to_dict() ret_type = self._create_type_string(result_type) type_string = f": {ret_type}" if ret_type else "" + result_name = _convert_snake_to_camel_case(result.name) + result_name = self._replace_if_safeds_keyword(result_name) results.append( - f"{result.name}" + f"{result_name}" f"{type_string}", ) @@ -268,9 +305,9 @@ def _create_parameter_string( # Check if assigned_by is not illegal assigned_by = parameter.assigned_by if assigned_by == ParameterAssignment.POSITION_ONLY and parameter.default_value is not None: - self.current_todo_msgs.add("OPT_POS_ONLY") + self._current_todo_msgs.add("OPT_POS_ONLY") elif assigned_by == ParameterAssignment.NAME_ONLY and not parameter.is_optional: - self.current_todo_msgs.add("REQ_NAME_ONLY") + self._current_todo_msgs.add("REQ_NAME_ONLY") # Mypy assignes *args parameters the tuple type, which is not supported in Safe-DS. Therefor we overwrite it # and set the type to a list. @@ -279,7 +316,7 @@ def _create_parameter_string( # Safe-DS does not support variadic parameters. if assigned_by in {ParameterAssignment.POSITIONAL_VARARG, ParameterAssignment.NAMED_VARARG}: - self.current_todo_msgs.add("variadic") + self._current_todo_msgs.add("variadic") # Parameter type param_type = self._create_type_string(parameter_type_data) @@ -315,7 +352,7 @@ def _create_qualified_imports_string(self, qualified_imports: list[QualifiedImpo imports: list[str] = [] for qualified_import in qualified_imports: qualified_name = qualified_import.qualified_name - import_path, name = split_import_id(qualified_name) + import_path, name = self._split_import_id(qualified_name) # Ignore enum imports, since those are build in types in Safe-DS stubs if import_path == "enum" and name in {"Enum", "IntEnum"}: @@ -342,7 +379,6 @@ def _create_wildcard_imports_string(self, wildcard_imports: list[WildcardImport] return "\n".join(imports) - # Todo Frage: Wir unterstützen keine Schachtelungen von Enums, richtig? Weder in Enums noch in Klassen def _create_enum_string(self, enum_data: Enum) -> str: # Signature enum_signature = f"enum {enum_data.name}" @@ -356,7 +392,6 @@ def _create_enum_string(self, enum_data: Enum) -> str: for enum_instance in instances: name = enum_instance.name - # Todo Frage: Sicher, dass wir Enum Instancen umschreiben? # Convert snake_case names to camelCase camel_case_name = _convert_snake_to_camel_case(name) annotation = "" @@ -382,7 +417,7 @@ def _create_type_string(self, type_data: dict | None) -> str: name = type_data["name"] match name: case "tuple": - self.current_todo_msgs.add("Tuple") + self._current_todo_msgs.add("Tuple") return "Tuple" case "int": return "Int" @@ -411,15 +446,17 @@ def _create_type_string(self, type_data: dict | None) -> str: if types: if len(types) >= 2: - self.current_todo_msgs.add(name) + self._current_todo_msgs.add(name) return f"{name}<{', '.join(types)}>" return f"{name}" elif kind == "UnionType": - # Union items have to be unique + # Union items have to be unique. 'types' has to be a sorted list, since otherwise the snapshot tests would + # fail b/c element order in sets is non-deterministic. types = list({ self._create_type_string(type_) for type_ in type_data["types"] }) + types.sort() if types: if len(types) == 2 and none_type_name in types: @@ -431,14 +468,14 @@ def _create_type_string(self, type_data: dict | None) -> str: return f"{types[1]}?" return f"{types[0]}?" - # If the union contains only one type, return the type instead of creating an union + # If the union contains only one type, return the type instead of creating a union elif len(types) == 1: return types[0] return f"union<{', '.join(types)}>" return "" elif kind == "TupleType": - self.current_todo_msgs.add("Tuple") + self._current_todo_msgs.add("Tuple") types = [ self._create_type_string(type_) for type_ in type_data["types"] @@ -460,8 +497,10 @@ def _create_type_string(self, type_data: dict | None) -> str: raise ValueError(f"Unexpected type: {kind}") - def create_todo_msg(self, indentations: str) -> str: - if not self.current_todo_msgs: + # ############################### Utilities ############################### # + + def _create_todo_msg(self, indentations: str) -> str: + if not self._current_todo_msgs: return "" todo_msgs = [ @@ -475,14 +514,25 @@ def create_todo_msg(self, indentations: str) -> str: "variadic": "Safe-DS does not support variadic parameters.", "class_method": "Safe-DS does not support class methods", }[msg] - for msg in self.current_todo_msgs + for msg in self._current_todo_msgs ] + todo_msgs.sort() # Empty the message list - self.current_todo_msgs = set() + self._current_todo_msgs = set() return indentations + f"\n{indentations}".join(todo_msgs) + "\n" + @staticmethod + def _split_import_id(id_: str) -> tuple[str, str]: + if "." not in id_: + return "", id_ + + split_qname = id_.split(".") + name = split_qname.pop(-1) + import_path = ".".join(split_qname) + return import_path, name + @staticmethod def _create_name_annotation(name: str) -> str: return f'@PythonName("{name}")' @@ -492,47 +542,7 @@ def _replace_if_safeds_keyword(keyword: str) -> str: if keyword in { "as", "from", "import", "literal", "union", "where", "yield", "false", "null", "true", "annotation", "attr", "class", "enum", "fun", "package", "pipeline", "schema", "segment", "val", "const", "in", "internal", "out", - "private", "static", "and", "not", "or", "sub", "super" + "private", "static", "and", "not", "or", "sub", "super", "_" }: return f"`{keyword}`" return keyword - - -# Todo Frage: mixed_snake_camelCase_naMe -> mixedSnakeCamelCaseNaMe | _ -> _ ? Special cases? Results (Darstellung)? -def _convert_snake_to_camel_case(name: str) -> str: - if name == "_": - return name - - # Count underscores in front and behind the name - underscore_count_start = len(name) - len(name.lstrip("_")) - underscore_count_end = len(name) - len(name.rstrip("_")) - - if underscore_count_end == 0: - cleaned_name = name[underscore_count_start:] - else: - cleaned_name = name[underscore_count_start:-underscore_count_end] - - # Remove underscores and join in camelCase - name_parts = cleaned_name.split("_") - return name_parts[0] + "".join( - part[0].upper() + part[1:] - for part in name_parts[1:] - if part - ) - - -def split_import_id(id_: str) -> tuple[str, str]: - if "." not in id_: - return "", id_ - - split_qname = id_.split(".") - name = split_qname.pop(-1) - import_path = ".".join(split_qname) - return import_path, name - - -def create_directory(path: Path) -> None: - for i, _ in enumerate(path.parts): - new_path = Path("/".join(path.parts[:i+1])) - if not new_path.exists(): - Path.mkdir(new_path) diff --git a/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py b/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py index 7275b419..61f11d40 100644 --- a/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py +++ b/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py @@ -5,7 +5,7 @@ import pytest from safeds_stubgen.api_analyzer import get_api -from safeds_stubgen.stubs_generator import StubsGenerator +from safeds_stubgen.stubs_generator import generate_stubs # noinspection PyProtectedMember from safeds_stubgen.stubs_generator._generate_stubs import _convert_snake_to_camel_case @@ -21,11 +21,9 @@ _out_dir_stubs = Path(_out_dir / _test_package_name) api = get_api(_test_package_name, _test_package_dir, is_test_run=True) -stubs_generator = StubsGenerator(api, _out_dir) -stubs_generator.generate_stubs() +generate_stubs(api, _out_dir) -# Todo Frage: Automatische Einrückung bei .ambr Dateien -> Snapshot Test schlagen deswegen fehl # Utilites def _assert_file_creation_recursive(python_path: Path, stub_path: Path) -> None: assert python_path.is_dir() From bc188d4c28e1ec66e2694c8e2e6cce93afa4192a Mon Sep 17 00:00:00 2001 From: Arsam Date: Fri, 17 Nov 2023 19:58:50 +0100 Subject: [PATCH 037/109] Issue #37 - Added new type "CallableType" for api_analyzer and stubs generator --- src/safeds_stubgen/api_analyzer/__init__.py | 2 + .../api_analyzer/_mypy_helpers.py | 33 ++++++++-------- src/safeds_stubgen/api_analyzer/_types.py | 38 +++++++++++++++++-- .../stubs_generator/_generate_stubs.py | 31 +++++++++++++++ .../test_stub_generation/function_module.py | 6 +++ .../safeds_stubgen/api_analyzer/test_types.py | 24 ++++++++++++ 6 files changed, 116 insertions(+), 18 deletions(-) diff --git a/src/safeds_stubgen/api_analyzer/__init__.py b/src/safeds_stubgen/api_analyzer/__init__.py index eecfd505..45471b33 100644 --- a/src/safeds_stubgen/api_analyzer/__init__.py +++ b/src/safeds_stubgen/api_analyzer/__init__.py @@ -20,6 +20,7 @@ from ._types import ( AbstractType, BoundaryType, + CallableType, DictType, EnumType, FinalType, @@ -37,6 +38,7 @@ "API", "Attribute", "BoundaryType", + "CallableType", "Class", "DictType", "distribution", diff --git a/src/safeds_stubgen/api_analyzer/_mypy_helpers.py b/src/safeds_stubgen/api_analyzer/_mypy_helpers.py index 10dc068f..616800e3 100644 --- a/src/safeds_stubgen/api_analyzer/_mypy_helpers.py +++ b/src/safeds_stubgen/api_analyzer/_mypy_helpers.py @@ -31,34 +31,37 @@ def get_mypyfile_definitions(node: MypyFile) -> list: def mypy_type_to_abstract_type(mypy_type: Instance | ProperType | MypyType) -> AbstractType: - types = [] - # Iterable mypy types if isinstance(mypy_type, mp_types.TupleType): - for item in mypy_type.items: - types.append( - mypy_type_to_abstract_type(item), - ) - return sds_types.TupleType(types=types) + return sds_types.TupleType(types=[ + mypy_type_to_abstract_type(item) + for item in mypy_type.items + ]) elif isinstance(mypy_type, mp_types.UnionType): - for item in mypy_type.items: - types.append( - mypy_type_to_abstract_type(item), - ) - return sds_types.UnionType(types=types) + return sds_types.UnionType(types=[ + mypy_type_to_abstract_type(item) + for item in mypy_type.items + ]) # Special Cases + elif isinstance(mypy_type, mp_types.CallableType): + return sds_types.CallableType( + parameter_types=[ + mypy_type_to_abstract_type(arg_type) + for arg_type in mypy_type.arg_types + ], + return_type=mypy_type_to_abstract_type(mypy_type.ret_type) + ) elif isinstance(mypy_type, mp_types.AnyType): return sds_types.NamedType(name="Any") elif isinstance(mypy_type, mp_types.NoneType): return sds_types.NamedType(name="None") elif isinstance(mypy_type, mp_types.UnboundType): if mypy_type.name == "list": - types = [ + return sds_types.ListType(types=[ mypy_type_to_abstract_type(arg) for arg in mypy_type.args - ] - return sds_types.ListType(types=types) + ]) # Todo Aliasing: Import auflösen return sds_types.NamedType(name=mypy_type.name) elif isinstance(mypy_type, mp_types.TypeType): diff --git a/src/safeds_stubgen/api_analyzer/_types.py b/src/safeds_stubgen/api_analyzer/_types.py index f72e4890..43be968a 100644 --- a/src/safeds_stubgen/api_analyzer/_types.py +++ b/src/safeds_stubgen/api_analyzer/_types.py @@ -32,6 +32,8 @@ def from_dict(cls, d: dict[str, Any]) -> AbstractType: return TupleType.from_dict(d) case UnionType.__name__: return UnionType.from_dict(d) + case CallableType.__name__: + return CallableType.from_dict(d) case _: raise ValueError(f"Cannot parse {d['kind']} value.") @@ -278,6 +280,35 @@ def __hash__(self) -> int: return hash(frozenset([self.key_type, self.value_type])) +@dataclass(frozen=True) +class CallableType(AbstractType): + parameter_types: list[AbstractType] + return_type: AbstractType + + @classmethod + def from_dict(cls, d: dict[str, Any]) -> CallableType: + params = [] + for param in d["parameter_types"]: + type_ = AbstractType.from_dict(param) + if type_ is not None: + params.append(type_) + + return CallableType( + params, + AbstractType.from_dict(d["return_type"]) + ) + + def to_dict(self) -> dict[str, Any]: + return { + "kind": self.__class__.__name__, + "parameter_types": [t.to_dict() for t in self.parameter_types], + "return_type": self.return_type.to_dict(), + } + + def __hash__(self) -> int: + return hash(frozenset([*self.parameter_types, self.return_type])) + + @dataclass(frozen=True) class SetType(AbstractType): types: list[AbstractType] @@ -292,9 +323,10 @@ def from_dict(cls, d: dict[str, Any]) -> SetType: return SetType(types) def to_dict(self) -> dict[str, Any]: - type_list = [t.to_dict() for t in self.types] - - return {"kind": self.__class__.__name__, "types": type_list} + return { + "kind": self.__class__.__name__, + "types": [t.to_dict() for t in self.types], + } def __hash__(self) -> int: return hash(frozenset(self.types)) diff --git a/src/safeds_stubgen/stubs_generator/_generate_stubs.py b/src/safeds_stubgen/stubs_generator/_generate_stubs.py index 0e5e7523..29bca90f 100644 --- a/src/safeds_stubgen/stubs_generator/_generate_stubs.py +++ b/src/safeds_stubgen/stubs_generator/_generate_stubs.py @@ -1,6 +1,8 @@ from __future__ import annotations +import string from pathlib import Path +from typing import Generator from safeds_stubgen.api_analyzer import ( API, @@ -433,6 +435,25 @@ def _create_type_string(self, type_data: dict | None) -> str: return name elif kind == "FinalType": return self._create_type_string(type_data) + elif kind == "CallableType": + name_generator = self._callable_type_name_generator() + + params = [ + f"{next(name_generator)}: {self._create_type_string(parameter_type)}" + for parameter_type in type_data["parameter_types"] + ] + + return_type = type_data["return_type"] + if return_type["kind"] == "TupleType": + return_types = [ + f"{next(name_generator)}: {self._create_type_string(type_)}" + for type_ in return_type["types"] + ] + return_type_string = f"({', '.join(return_types)})" + else: + return_type_string = f"{next(name_generator)}: {self._create_type_string(return_type)}" + + return f"({', '.join(params)}) -> {return_type_string}" elif kind == "OptionalType": return f"{self._create_type_string(type_data)}?" elif kind in {"SetType", "ListType"}: @@ -499,6 +520,16 @@ def _create_type_string(self, type_data: dict | None) -> str: # ############################### Utilities ############################### # + @staticmethod + def _callable_type_name_generator() -> Generator: + """Generate a name for callable type parameters starting from 'a' until 'zz'.""" + while True: + for x in range(1, 27): + yield string.ascii_lowercase[x - 1] + for x in range(1, 27): + for y in range(1, 27): + yield string.ascii_lowercase[x - 1] + string.ascii_lowercase[y - 1] + def _create_todo_msg(self, indentations: str) -> str: if not self._current_todo_msgs: return "" diff --git a/tests/data/test_stub_generation/function_module.py b/tests/data/test_stub_generation/function_module.py index e04e48cd..cc1d5e9c 100644 --- a/tests/data/test_stub_generation/function_module.py +++ b/tests/data/test_stub_generation/function_module.py @@ -1,3 +1,6 @@ +from typing import Callable + + class A: ... @@ -67,3 +70,6 @@ def one_result() -> int: ... def multiple_results() -> tuple[str, int, bool, A]: ... + + +def callable_type(param: Callable[[str], tuple[int, str]]) -> Callable[[int, int], int]: ... diff --git a/tests/safeds_stubgen/api_analyzer/test_types.py b/tests/safeds_stubgen/api_analyzer/test_types.py index 02a7206e..21c33c8e 100644 --- a/tests/safeds_stubgen/api_analyzer/test_types.py +++ b/tests/safeds_stubgen/api_analyzer/test_types.py @@ -5,6 +5,7 @@ AbstractType, Attribute, BoundaryType, + CallableType, DictType, EnumType, FinalType, @@ -124,6 +125,29 @@ def test_union_type() -> None: assert hash(UnionType([NamedType("a")])) != hash(UnionType([NamedType("b")])) +def test_callable_type() -> None: + callable_type = CallableType( + parameter_types=[NamedType("str"), NamedType("int")], + return_type=TupleType(types=[NamedType("bool"), NamedType("None")]) + ) + callable_type_dict = { + "kind": "CallableType", + "parameter_types": [{"kind": "NamedType", "name": "str"}, {"kind": "NamedType", "name": "int"}], + "return_type": {"kind": "TupleType", "types": [ + {"kind": "NamedType", "name": "bool"}, {"kind": "NamedType", "name": "None"} + ]}, + } + + assert AbstractType.from_dict(callable_type_dict) == callable_type + assert CallableType.from_dict(callable_type_dict) == callable_type + assert callable_type.to_dict() == callable_type_dict + + assert CallableType([NamedType("a")], NamedType("a")) == CallableType([NamedType("a")], NamedType("a")) + assert hash(CallableType([NamedType("a")], NamedType("a"))) == hash(CallableType([NamedType("a")], NamedType("a"))) + assert CallableType([NamedType("a")], NamedType("a")) != CallableType([NamedType("b")], NamedType("a")) + assert hash(CallableType([NamedType("a")], NamedType("a"))) != hash(CallableType([NamedType("b")], NamedType("a"))) + + def test_list_type() -> None: list_type = ListType([NamedType("str"), NamedType("int")]) list_type_dict = { From 804f86a75693df7bbb551e9bf268bd4aad10cf8b Mon Sep 17 00:00:00 2001 From: Arsam Date: Fri, 17 Nov 2023 22:14:37 +0100 Subject: [PATCH 038/109] Updated test snapshots --- .../__snapshots__/test_main.ambr | 134 ++++++++++++++++++ .../__snapshots__/test__get_api.ambr | 68 +++++++++ .../__snapshots__/test_generate_stubs.ambr | 53 ++++--- 3 files changed, 235 insertions(+), 20 deletions(-) diff --git a/tests/safeds_stubgen/__snapshots__/test_main.ambr b/tests/safeds_stubgen/__snapshots__/test_main.ambr index 64c6e64a..bf1a98c9 100644 --- a/tests/safeds_stubgen/__snapshots__/test_main.ambr +++ b/tests/safeds_stubgen/__snapshots__/test_main.ambr @@ -724,6 +724,7 @@ 'full_docstring': '', }), 'id': 'test_package/test_docstrings/EpydocDocstringClass/__init__', + 'is_class_method': False, 'is_public': True, 'is_static': False, 'name': '__init__', @@ -777,6 +778,7 @@ 'full_docstring': '', }), 'id': 'test_package/test_docstrings/GoogleDocstringClass/__init__', + 'is_class_method': False, 'is_public': True, 'is_static': False, 'name': '__init__', @@ -836,6 +838,7 @@ 'full_docstring': '', }), 'id': 'test_package/test_docstrings/NumpyDocstringClass/__init__', + 'is_class_method': False, 'is_public': True, 'is_static': False, 'name': '__init__', @@ -903,6 +906,7 @@ 'full_docstring': '', }), 'id': 'test_package/test_docstrings/RestDocstringClass/__init__', + 'is_class_method': False, 'is_public': True, 'is_static': False, 'name': '__init__', @@ -991,6 +995,7 @@ ''', }), 'id': 'test_package/test_module/SomeClass/__init__', + 'is_class_method': False, 'is_public': True, 'is_static': False, 'name': '__init__', @@ -1025,6 +1030,8 @@ 'test_package/test_module/SomeClass/multiple_results', 'test_package/test_module/SomeClass/no_return_1', 'test_package/test_module/SomeClass/no_return_2', + 'test_package/test_module/SomeClass/class_method', + 'test_package/test_module/SomeClass/class_method_params', ]), 'name': 'SomeClass', 'reexported_by': list([ @@ -1069,6 +1076,7 @@ 'full_docstring': '', }), 'id': 'test_package/test_module/_PrivateClass/__init__', + 'is_class_method': False, 'is_public': False, 'is_static': False, 'name': '__init__', @@ -1244,6 +1252,7 @@ 'full_docstring': '', }), 'id': 'test_package/_reexport_module_1/ReexportClass/_private_class_method_of_reexported_class', + 'is_class_method': False, 'is_public': False, 'is_static': True, 'name': '_private_class_method_of_reexported_class', @@ -1261,6 +1270,7 @@ 'full_docstring': '', }), 'id': 'test_package/_reexport_module_1/reexported_function', + 'is_class_method': False, 'is_public': False, 'is_static': False, 'name': 'reexported_function', @@ -1277,6 +1287,7 @@ 'full_docstring': '', }), 'id': 'test_package/_reexport_module_2/reexported_function_2', + 'is_class_method': False, 'is_public': True, 'is_static': False, 'name': 'reexported_function_2', @@ -1294,6 +1305,7 @@ 'full_docstring': '', }), 'id': 'test_package/_reexport_module_3/reexported_function_3', + 'is_class_method': False, 'is_public': False, 'is_static': False, 'name': 'reexported_function_3', @@ -1311,6 +1323,7 @@ 'full_docstring': '', }), 'id': 'test_package/_reexport_module_4/_reexported_function_4', + 'is_class_method': False, 'is_public': False, 'is_static': False, 'name': '_reexported_function_4', @@ -1328,6 +1341,7 @@ 'full_docstring': '', }), 'id': 'test_package/_reexport_module_4/_unreexported_function', + 'is_class_method': False, 'is_public': False, 'is_static': False, 'name': '_unreexported_function', @@ -1344,6 +1358,7 @@ 'full_docstring': '', }), 'id': 'test_package/test_docstrings/EpydocDocstringClass/__init__', + 'is_class_method': False, 'is_public': True, 'is_static': False, 'name': '__init__', @@ -1380,6 +1395,7 @@ ''', }), 'id': 'test_package/test_docstrings/EpydocDocstringClass/epydoc_docstring_func', + 'is_class_method': False, 'is_public': True, 'is_static': False, 'name': 'epydoc_docstring_func', @@ -1400,6 +1416,7 @@ 'full_docstring': '', }), 'id': 'test_package/test_docstrings/GoogleDocstringClass/__init__', + 'is_class_method': False, 'is_public': True, 'is_static': False, 'name': '__init__', @@ -1444,6 +1461,7 @@ ''', }), 'id': 'test_package/test_docstrings/GoogleDocstringClass/google_docstring_func', + 'is_class_method': False, 'is_public': True, 'is_static': False, 'name': 'google_docstring_func', @@ -1464,6 +1482,7 @@ 'full_docstring': '', }), 'id': 'test_package/test_docstrings/NumpyDocstringClass/__init__', + 'is_class_method': False, 'is_public': True, 'is_static': False, 'name': '__init__', @@ -1514,6 +1533,7 @@ ''', }), 'id': 'test_package/test_docstrings/NumpyDocstringClass/numpy_docstring_func', + 'is_class_method': False, 'is_public': True, 'is_static': False, 'name': 'numpy_docstring_func', @@ -1534,6 +1554,7 @@ 'full_docstring': '', }), 'id': 'test_package/test_docstrings/RestDocstringClass/__init__', + 'is_class_method': False, 'is_public': True, 'is_static': False, 'name': '__init__', @@ -1572,6 +1593,7 @@ ''', }), 'id': 'test_package/test_docstrings/RestDocstringClass/rest_docstring_func', + 'is_class_method': False, 'is_public': True, 'is_static': False, 'name': 'rest_docstring_func', @@ -1592,6 +1614,7 @@ 'full_docstring': '', }), 'id': 'test_package/test_module/SomeClass/NestedClass/nested_class_function', + 'is_class_method': False, 'is_public': True, 'is_static': False, 'name': 'nested_class_function', @@ -1619,6 +1642,7 @@ ''', }), 'id': 'test_package/test_module/SomeClass/__init__', + 'is_class_method': False, 'is_public': True, 'is_static': False, 'name': '__init__', @@ -1645,6 +1669,7 @@ ''', }), 'id': 'test_package/test_module/SomeClass/_some_function', + 'is_class_method': False, 'is_public': False, 'is_static': False, 'name': '_some_function', @@ -1659,12 +1684,51 @@ 'test_package/test_module/SomeClass/_some_function/result_1', ]), }), + dict({ + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_package/test_module/SomeClass/class_method', + 'is_class_method': True, + 'is_public': True, + 'is_static': False, + 'name': 'class_method', + 'parameters': list([ + 'test_package/test_module/SomeClass/class_method/cls', + ]), + 'reexported_by': list([ + ]), + 'results': list([ + ]), + }), + dict({ + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_package/test_module/SomeClass/class_method_params', + 'is_class_method': True, + 'is_public': True, + 'is_static': False, + 'name': 'class_method_params', + 'parameters': list([ + 'test_package/test_module/SomeClass/class_method_params/cls', + 'test_package/test_module/SomeClass/class_method_params/param_1', + ]), + 'reexported_by': list([ + ]), + 'results': list([ + 'test_package/test_module/SomeClass/class_method_params/result_1', + ]), + }), dict({ 'docstring': dict({ 'description': 'Function Docstring.', 'full_docstring': 'Function Docstring.', }), 'id': 'test_package/test_module/SomeClass/multiple_results', + 'is_class_method': False, 'is_public': True, 'is_static': True, 'name': 'multiple_results', @@ -1683,6 +1747,7 @@ 'full_docstring': '', }), 'id': 'test_package/test_module/SomeClass/no_return_1', + 'is_class_method': False, 'is_public': True, 'is_static': False, 'name': 'no_return_1', @@ -1700,6 +1765,7 @@ 'full_docstring': '', }), 'id': 'test_package/test_module/SomeClass/no_return_2', + 'is_class_method': False, 'is_public': True, 'is_static': False, 'name': 'no_return_2', @@ -1717,6 +1783,7 @@ 'full_docstring': 'Function Docstring.', }), 'id': 'test_package/test_module/SomeClass/static_function', + 'is_class_method': False, 'is_public': True, 'is_static': True, 'name': 'static_function', @@ -1737,6 +1804,7 @@ 'full_docstring': '', }), 'id': 'test_package/test_module/SomeClass/test_params', + 'is_class_method': False, 'is_public': True, 'is_static': True, 'name': 'test_params', @@ -1755,6 +1823,7 @@ 'full_docstring': 'Function Docstring.', }), 'id': 'test_package/test_module/SomeClass/test_position', + 'is_class_method': False, 'is_public': True, 'is_static': False, 'name': 'test_position', @@ -1778,6 +1847,7 @@ 'full_docstring': '', }), 'id': 'test_package/test_module/_PrivateClass/NestedPrivateClass/static_nested_private_class_function', + 'is_class_method': False, 'is_public': False, 'is_static': True, 'name': 'static_nested_private_class_function', @@ -1794,6 +1864,7 @@ 'full_docstring': '', }), 'id': 'test_package/test_module/_PrivateClass/__init__', + 'is_class_method': False, 'is_public': False, 'is_static': False, 'name': '__init__', @@ -1811,6 +1882,7 @@ 'full_docstring': '', }), 'id': 'test_package/test_module/_PrivateClass/public_func_in_private_class', + 'is_class_method': False, 'is_public': False, 'is_static': False, 'name': 'public_func_in_private_class', @@ -1828,6 +1900,7 @@ 'full_docstring': '', }), 'id': 'test_package/test_module/_private_global_func', + 'is_class_method': False, 'is_public': False, 'is_static': False, 'name': '_private_global_func', @@ -1853,6 +1926,7 @@ ''', }), 'id': 'test_package/test_module/global_func', + 'is_class_method': False, 'is_public': True, 'is_static': False, 'name': 'global_func', @@ -2534,6 +2608,54 @@ 'name': 'SomeClass', }), }), + dict({ + 'assigned_by': 'IMPLICIT', + 'default_value': None, + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_package/test_module/SomeClass/class_method/cls', + 'is_optional': False, + 'name': 'cls', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'SomeClass', + }), + }), + dict({ + 'assigned_by': 'IMPLICIT', + 'default_value': None, + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_package/test_module/SomeClass/class_method_params/cls', + 'is_optional': False, + 'name': 'cls', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'SomeClass', + }), + }), + dict({ + 'assigned_by': 'POSITION_OR_NAME', + 'default_value': None, + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_package/test_module/SomeClass/class_method_params/param_1', + 'is_optional': False, + 'name': 'param_1', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'int', + }), + }), dict({ 'assigned_by': 'POSITION_OR_NAME', 'default_value': None, @@ -2924,6 +3046,18 @@ 'name': 'AnotherClass', }), }), + dict({ + 'docstring': dict({ + 'description': '', + 'type': '', + }), + 'id': 'test_package/test_module/SomeClass/class_method_params/result_1', + 'name': 'result_1', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'bool', + }), + }), dict({ 'docstring': dict({ 'description': '', diff --git a/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr b/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr index ba8c7f61..c63bbb69 100644 --- a/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr +++ b/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr @@ -637,6 +637,7 @@ ''', }), 'id': 'test_package/test_docstrings/EpydocDocstringClass/epydoc_docstring_func', + 'is_class_method': False, 'is_public': True, 'is_static': False, 'name': 'epydoc_docstring_func', @@ -679,6 +680,7 @@ ''', }), 'id': 'test_package/test_docstrings/GoogleDocstringClass/google_docstring_func', + 'is_class_method': False, 'is_public': True, 'is_static': False, 'name': 'google_docstring_func', @@ -703,6 +705,7 @@ 'full_docstring': '', }), 'id': 'test_package/test_module/SomeClass/NestedClass/nested_class_function', + 'is_class_method': False, 'is_public': True, 'is_static': False, 'name': 'nested_class_function', @@ -730,6 +733,7 @@ 'full_docstring': '', }), 'id': 'test_package/test_module/_PrivateClass/NestedPrivateClass/static_nested_private_class_function', + 'is_class_method': False, 'is_public': False, 'is_static': True, 'name': 'static_nested_private_class_function', @@ -770,6 +774,7 @@ ''', }), 'id': 'test_package/test_docstrings/NumpyDocstringClass/numpy_docstring_func', + 'is_class_method': False, 'is_public': True, 'is_static': False, 'name': 'numpy_docstring_func', @@ -794,6 +799,7 @@ 'full_docstring': '', }), 'id': 'test_package/_reexport_module_1/ReexportClass/_private_class_method_of_reexported_class', + 'is_class_method': False, 'is_public': False, 'is_static': True, 'name': '_private_class_method_of_reexported_class', @@ -829,6 +835,7 @@ ''', }), 'id': 'test_package/test_docstrings/RestDocstringClass/rest_docstring_func', + 'is_class_method': False, 'is_public': True, 'is_static': False, 'name': 'rest_docstring_func', @@ -861,6 +868,7 @@ ''', }), 'id': 'test_package/test_module/SomeClass/_some_function', + 'is_class_method': False, 'is_public': False, 'is_static': False, 'name': '_some_function', @@ -875,12 +883,51 @@ 'test_package/test_module/SomeClass/_some_function/result_1', ]), }), + dict({ + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_package/test_module/SomeClass/class_method', + 'is_class_method': True, + 'is_public': True, + 'is_static': False, + 'name': 'class_method', + 'parameters': list([ + 'test_package/test_module/SomeClass/class_method/cls', + ]), + 'reexported_by': list([ + ]), + 'results': list([ + ]), + }), + dict({ + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_package/test_module/SomeClass/class_method_params', + 'is_class_method': True, + 'is_public': True, + 'is_static': False, + 'name': 'class_method_params', + 'parameters': list([ + 'test_package/test_module/SomeClass/class_method_params/cls', + 'test_package/test_module/SomeClass/class_method_params/param_1', + ]), + 'reexported_by': list([ + ]), + 'results': list([ + 'test_package/test_module/SomeClass/class_method_params/result_1', + ]), + }), dict({ 'docstring': dict({ 'description': 'Function Docstring.', 'full_docstring': 'Function Docstring.', }), 'id': 'test_package/test_module/SomeClass/multiple_results', + 'is_class_method': False, 'is_public': True, 'is_static': True, 'name': 'multiple_results', @@ -899,6 +946,7 @@ 'full_docstring': '', }), 'id': 'test_package/test_module/SomeClass/no_return_1', + 'is_class_method': False, 'is_public': True, 'is_static': False, 'name': 'no_return_1', @@ -916,6 +964,7 @@ 'full_docstring': '', }), 'id': 'test_package/test_module/SomeClass/no_return_2', + 'is_class_method': False, 'is_public': True, 'is_static': False, 'name': 'no_return_2', @@ -933,6 +982,7 @@ 'full_docstring': 'Function Docstring.', }), 'id': 'test_package/test_module/SomeClass/static_function', + 'is_class_method': False, 'is_public': True, 'is_static': True, 'name': 'static_function', @@ -953,6 +1003,7 @@ 'full_docstring': '', }), 'id': 'test_package/test_module/SomeClass/test_params', + 'is_class_method': False, 'is_public': True, 'is_static': True, 'name': 'test_params', @@ -971,6 +1022,7 @@ 'full_docstring': 'Function Docstring.', }), 'id': 'test_package/test_module/SomeClass/test_position', + 'is_class_method': False, 'is_public': True, 'is_static': False, 'name': 'test_position', @@ -998,6 +1050,7 @@ 'full_docstring': '', }), 'id': 'test_package/test_module/_PrivateClass/public_func_in_private_class', + 'is_class_method': False, 'is_public': False, 'is_static': False, 'name': 'public_func_in_private_class', @@ -1046,6 +1099,7 @@ 'full_docstring': '', }), 'id': 'test_package/test_docstrings/EpydocDocstringClass/__init__', + 'is_class_method': False, 'is_public': True, 'is_static': False, 'name': '__init__', @@ -1117,6 +1171,7 @@ 'full_docstring': '', }), 'id': 'test_package/test_docstrings/GoogleDocstringClass/__init__', + 'is_class_method': False, 'is_public': True, 'is_static': False, 'name': '__init__', @@ -1243,6 +1298,7 @@ 'full_docstring': '', }), 'id': 'test_package/test_docstrings/NumpyDocstringClass/__init__', + 'is_class_method': False, 'is_public': True, 'is_static': False, 'name': '__init__', @@ -1326,6 +1382,7 @@ 'full_docstring': '', }), 'id': 'test_package/test_docstrings/RestDocstringClass/__init__', + 'is_class_method': False, 'is_public': True, 'is_static': False, 'name': '__init__', @@ -1409,6 +1466,7 @@ ''', }), 'id': 'test_package/test_module/SomeClass/__init__', + 'is_class_method': False, 'is_public': True, 'is_static': False, 'name': '__init__', @@ -1443,6 +1501,8 @@ 'test_package/test_module/SomeClass/multiple_results', 'test_package/test_module/SomeClass/no_return_1', 'test_package/test_module/SomeClass/no_return_2', + 'test_package/test_module/SomeClass/class_method', + 'test_package/test_module/SomeClass/class_method_params', ]), 'name': 'SomeClass', 'reexported_by': list([ @@ -1467,6 +1527,7 @@ 'full_docstring': '', }), 'id': 'test_package/test_module/_PrivateClass/__init__', + 'is_class_method': False, 'is_public': False, 'is_static': False, 'name': '__init__', @@ -2489,6 +2550,7 @@ 'full_docstring': '', }), 'id': 'test_package/_reexport_module_1/reexported_function', + 'is_class_method': False, 'is_public': False, 'is_static': False, 'name': 'reexported_function', @@ -2509,6 +2571,7 @@ 'full_docstring': '', }), 'id': 'test_package/_reexport_module_2/reexported_function_2', + 'is_class_method': False, 'is_public': True, 'is_static': False, 'name': 'reexported_function_2', @@ -2530,6 +2593,7 @@ 'full_docstring': '', }), 'id': 'test_package/_reexport_module_3/reexported_function_3', + 'is_class_method': False, 'is_public': False, 'is_static': False, 'name': 'reexported_function_3', @@ -2551,6 +2615,7 @@ 'full_docstring': '', }), 'id': 'test_package/_reexport_module_4/_reexported_function_4', + 'is_class_method': False, 'is_public': False, 'is_static': False, 'name': '_reexported_function_4', @@ -2568,6 +2633,7 @@ 'full_docstring': '', }), 'id': 'test_package/_reexport_module_4/_unreexported_function', + 'is_class_method': False, 'is_public': False, 'is_static': False, 'name': '_unreexported_function', @@ -2588,6 +2654,7 @@ 'full_docstring': '', }), 'id': 'test_package/test_module/_private_global_func', + 'is_class_method': False, 'is_public': False, 'is_static': False, 'name': '_private_global_func', @@ -2613,6 +2680,7 @@ ''', }), 'id': 'test_package/test_module/global_func', + 'is_class_method': False, 'is_public': True, 'is_static': False, 'name': 'global_func', diff --git a/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr b/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr index 233fb243..71283bb8 100644 --- a/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr +++ b/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr @@ -17,14 +17,14 @@ static attr tupleAttr1: Tuple // TODO Safe-DS does not support tuple types. @PythonName("tuple_attr_2") - static attr tupleAttr2: Tuple> + static attr tupleAttr2: Tuple> // TODO Safe-DS does not support tuple types. @PythonName("tuple_attr_3") static attr tupleAttr3: Tuple @PythonName("list_attr_1") static attr listAttr1: List @PythonName("list_attr_2") - static attr listAttr2: List> + static attr listAttr2: List> // TODO List type has to many type arguments. @PythonName("list_attr_3") static attr listAttr3: List @@ -36,7 +36,7 @@ @PythonName("dict_attr_2") static attr dictAttr2: Map @PythonName("dict_attr_3") - static attr dictAttr3: Map, A?> + static attr dictAttr3: Map, A?> @PythonName("bool_attr") static attr boolAttr: Boolean @PythonName("none_attr") @@ -44,7 +44,7 @@ @PythonName("flaot_attr") static attr flaotAttr: Float @PythonName("int_or_bool_attr") - static attr intOrBoolAttr: union + static attr intOrBoolAttr: union @PythonName("str_attr_with_none_value") static attr strAttrWithNoneValue: String @PythonName("multi_attr_1") @@ -128,32 +128,39 @@ ''' package test_stub_generation.function_module + from typing import Callable + @PythonName("public_no_params_no_result") fun publicNoParamsNoResult() fun params( i: Int, - `union`: union, + `union`: union, lst: List, obj: A - ) -> result_1: Any + ) -> result1: Any - // TODO Safe-DS does not support tuple types. // TODO List type has to many type arguments. + // TODO Safe-DS does not support tuple types. @PythonName("illegal_params") fun illegalParams( lst: List, - @PythonName("lst_2") lst2: List, + @PythonName("lst_2") lst2: List, tpl: Tuple, - _: Int = String - ) -> result_1: Any + `_`: Int = String + ) -> result1: Any @PythonName("special_params") fun specialParams( - @PythonName("none_bool_union") noneBoolUnion: Boolean?, @PythonName("none_union") noneUnion: Nothing?, + @PythonName("none_bool_union") noneBoolUnion: Boolean?, + @PythonName("bool_none_union") boolNoneUnion: Boolean?, + @PythonName("none_bool_none_union") noneBoolNoneUnion: Boolean?, + @PythonName("none_bool_int_union") noneBoolIntUnion: union, + @PythonName("none_none_bool_none_union") noneNoneBoolNoneUnion: Boolean?, + @PythonName("none_list_union_none_none") noneListUnionNoneNone: List?, none: Nothing? - ) -> result_1: Any + ) -> result1: Any @PythonName("param_position") fun paramPosition( @@ -163,7 +170,7 @@ c: Any = 1, d: Any, e: Int = 1 - ) -> result_1: Any + ) -> result1: Any // TODO Safe-DS does not support optional but position only parameter assignments. @PythonName("opt_pos_only") @@ -190,13 +197,18 @@ fun argsType( args: List, kwargs: Map - ) -> result_1: Any + ) -> result1: Any @PythonName("one_result") - fun oneResult() -> result_1: Int + fun oneResult() -> result1: Int @PythonName("multiple_results") - fun multipleResults() -> (result_1: String, result_2: Int, result_3: Boolean, result_4: A) + fun multipleResults() -> (result1: String, result2: Int, result3: Boolean, result4: A) + + @PythonName("callable_type") + fun callableType( + param: (a: String) -> (b: Int, c: String) + ) -> result1: (a: Int, b: Int) -> c: Int class A() @@ -206,13 +218,14 @@ @PythonName("instance_method") fun instanceMethod( a: A - ) -> result_1: A + ) -> result1: A - @PythonName("static_class_method") - static fun staticClassMethod() + @PythonName("static_method") + static fun staticMethod() + // TODO Safe-DS does not support class methods @PythonName("class_method") - fun classMethod() + static fun classMethod() } ''' From 6cd1892121541b6c68500f460f3ab14c6cba19f3 Mon Sep 17 00:00:00 2001 From: Arsam Date: Fri, 17 Nov 2023 22:29:53 +0100 Subject: [PATCH 039/109] Updated test snapshots --- .../stubs_generator/__snapshots__/test_generate_stubs.ambr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr b/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr index 71283bb8..b5d10963 100644 --- a/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr +++ b/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr @@ -145,7 +145,7 @@ @PythonName("illegal_params") fun illegalParams( lst: List, - @PythonName("lst_2") lst2: List, + @PythonName("lst_2") lst2: List, tpl: Tuple, `_`: Int = String ) -> result1: Any From d29d3d46ef760078ff3a0408e7af0c3ef15709a7 Mon Sep 17 00:00:00 2001 From: Arsam Date: Sat, 18 Nov 2023 17:48:55 +0100 Subject: [PATCH 040/109] Issue #34: Added inference for return, parameter and attribute types. --- src/safeds_stubgen/api_analyzer/_api.py | 10 +- .../api_analyzer/_ast_visitor.py | 224 ++++--- .../api_analyzer/_mypy_helpers.py | 24 +- .../stubs_generator/_generate_stubs.py | 53 +- tests/data/test_package/test_module.py | 44 +- .../test_stub_generation/function_module.py | 1 + .../infer_types_module.py | 38 ++ .../__snapshots__/test_main.ambr | 569 ++++++++++++++---- .../__snapshots__/test__get_api.ambr | 245 +++++--- .../safeds_stubgen/api_analyzer/test_types.py | 1 + .../__snapshots__/test_generate_stubs.ambr | 66 +- .../stubs_generator/test_generate_stubs.py | 5 + 12 files changed, 921 insertions(+), 359 deletions(-) create mode 100644 tests/data/test_stub_generation/infer_types_module.py diff --git a/src/safeds_stubgen/api_analyzer/_api.py b/src/safeds_stubgen/api_analyzer/_api.py index 16e34157..52908d36 100644 --- a/src/safeds_stubgen/api_analyzer/_api.py +++ b/src/safeds_stubgen/api_analyzer/_api.py @@ -210,6 +210,7 @@ class Attribute: is_static: bool type: AbstractType | None docstring: AttributeDocstring + is_type_inferred: bool def to_dict(self) -> dict[str, Any]: return { @@ -219,6 +220,7 @@ def to_dict(self) -> dict[str, Any]: "is_public": self.is_public, "is_static": self.is_static, "type": self.type.to_dict() if self.type is not None else None, + "is_type_inferred": self.is_type_inferred, } @@ -256,7 +258,8 @@ class Parameter: default_value: str | bool | int | float | None assigned_by: ParameterAssignment docstring: ParameterDocstring - type: AbstractType + type: AbstractType | None + is_type_inferred: bool @property def is_required(self) -> bool: @@ -277,7 +280,8 @@ def to_dict(self) -> dict[str, Any]: "is_optional": self.is_optional, "default_value": self.default_value, "assigned_by": self.assigned_by.name, - "type": self.type.to_dict(), + "type": self.type.to_dict() if self.type is not None else None, + "is_type_inferred": self.is_type_inferred, } @@ -304,6 +308,7 @@ class Result: id: str name: str type: AbstractType | None + is_type_inferred: bool docstring: ResultDocstring def to_dict(self) -> dict[str, Any]: @@ -312,6 +317,7 @@ def to_dict(self) -> dict[str, Any]: "name": self.name, "docstring": self.docstring.to_dict(), "type": self.type.to_dict() if self.type is not None else None, + "is_type_inferred": self.is_type_inferred, } diff --git a/src/safeds_stubgen/api_analyzer/_ast_visitor.py b/src/safeds_stubgen/api_analyzer/_ast_visitor.py index 4e2d75b4..70a07cea 100644 --- a/src/safeds_stubgen/api_analyzer/_ast_visitor.py +++ b/src/safeds_stubgen/api_analyzer/_ast_visitor.py @@ -4,23 +4,7 @@ from typing import TYPE_CHECKING import mypy.types as mp_types -from mypy.nodes import ( - AssignmentStmt, - CallExpr, - ClassDef, - Expression, - ExpressionStmt, - FuncDef, - Import, - ImportAll, - ImportFrom, - MemberExpr, - MypyFile, - NameExpr, - StrExpr, - TupleExpr, - Var, -) +from mypy import nodes as mp_nodes import safeds_stubgen.api_analyzer._types as sds_types @@ -38,8 +22,10 @@ WildcardImport, ) from ._mypy_helpers import ( + find_return_stmts_recursive, get_argument_kind, get_classdef_definitions, + get_funcdef_definitions, get_mypyfile_definitions, mypy_type_to_abstract_type, ) @@ -55,7 +41,7 @@ def __init__(self, docstring_parser: AbstractDocstringParser, api: API) -> None: self.api: API = api self.__declaration_stack: list[Module | Class | Function | Enum | list[Attribute | EnumInstance]] = [] - def enter_moduledef(self, node: MypyFile) -> None: + def enter_moduledef(self, node: mp_nodes.MypyFile) -> None: is_package = node.path.endswith("__init__.py") qualified_imports: list[QualifiedImport] = [] @@ -71,13 +57,13 @@ def enter_moduledef(self, node: MypyFile) -> None: for definition in child_definitions: # Imports - if isinstance(definition, Import): + if isinstance(definition, mp_nodes.Import): for import_name, import_alias in definition.ids: qualified_imports.append( QualifiedImport(import_name, import_alias), ) - elif isinstance(definition, ImportFrom): + elif isinstance(definition, mp_nodes.ImportFrom): for import_name, import_alias in definition.names: qualified_imports.append( QualifiedImport( @@ -86,13 +72,13 @@ def enter_moduledef(self, node: MypyFile) -> None: ), ) - elif isinstance(definition, ImportAll): + elif isinstance(definition, mp_nodes.ImportAll): wildcard_imports.append( WildcardImport(definition.id), ) # Docstring - elif isinstance(definition, ExpressionStmt) and isinstance(definition.expr, StrExpr): + elif isinstance(definition, mp_nodes.ExpressionStmt) and isinstance(definition.expr, mp_nodes.StrExpr): docstring = definition.expr.value # Create module id to get the full path @@ -116,20 +102,20 @@ def enter_moduledef(self, node: MypyFile) -> None: ) if is_package: - self.add_reexports(module) + self._add_reexports(module) self.__declaration_stack.append(module) - def leave_moduledef(self, _: MypyFile) -> None: + def leave_moduledef(self, _: mp_nodes.MypyFile) -> None: module = self.__declaration_stack.pop() if not isinstance(module, Module): # pragma: no cover raise AssertionError("Imbalanced push/pop on stack") # noqa: TRY004 self.api.add_module(module) - def enter_classdef(self, node: ClassDef) -> None: - id_ = self._create_id_from_stack(node.name) + def enter_classdef(self, node: mp_nodes.ClassDef) -> None: name = node.name + id_ = self._create_id_from_stack(name) # Get docstring docstring = self.docstring_parser.get_class_documentation(node) @@ -139,13 +125,13 @@ def enter_classdef(self, node: ClassDef) -> None: superclasses = [superclass.fullname for superclass in node.base_type_exprs if hasattr(superclass, "fullname")] # Get reexported data - reexported_by = self.get_reexported_by(name) + reexported_by = self._get_reexported_by(name) # Get constructor docstring definitions = get_classdef_definitions(node) constructor_fulldocstring = "" for definition in definitions: - if isinstance(definition, FuncDef) and definition.name == "__init__": + if isinstance(definition, mp_nodes.FuncDef) and definition.name == "__init__": constructor_docstring = self.docstring_parser.get_function_documentation(definition) constructor_fulldocstring = constructor_docstring.full_docstring @@ -154,14 +140,14 @@ def enter_classdef(self, node: ClassDef) -> None: id=id_, name=name, superclasses=superclasses, - is_public=self.is_public(node.name, name), + is_public=self._is_public(node.name, name), docstring=docstring, reexported_by=reexported_by, constructor_fulldocstring=constructor_fulldocstring, ) self.__declaration_stack.append(class_) - def leave_classdef(self, _: ClassDef) -> None: + def leave_classdef(self, _: mp_nodes.ClassDef) -> None: class_ = self.__declaration_stack.pop() if not isinstance(class_, Class): # pragma: no cover raise AssertionError("Imbalanced push/pop on stack") # noqa: TRY004 @@ -173,11 +159,11 @@ def leave_classdef(self, _: ClassDef) -> None: self.api.add_class(class_) parent.add_class(class_) - def enter_funcdef(self, node: FuncDef) -> None: + def enter_funcdef(self, node: mp_nodes.FuncDef) -> None: name = node.name function_id = self._create_id_from_stack(name) - is_public = self.is_public(name, node.fullname) + is_public = self._is_public(name, node.fullname) is_static = node.is_static # Get docstring @@ -186,13 +172,13 @@ def enter_funcdef(self, node: FuncDef) -> None: # Function args arguments: list[Parameter] = [] if getattr(node, "arguments", None) is not None: - arguments = self.parse_parameter_data(node, function_id) + arguments = self._parse_parameter_data(node, function_id) # Create results - results = self.create_result(node, function_id) + results = self._create_result(node, function_id) # Get reexported data - reexported_by = self.get_reexported_by(name) + reexported_by = self._get_reexported_by(name) # Create and add Function to stack function = Function( @@ -208,7 +194,7 @@ def enter_funcdef(self, node: FuncDef) -> None: ) self.__declaration_stack.append(function) - def leave_funcdef(self, _: FuncDef) -> None: + def leave_funcdef(self, _: mp_nodes.FuncDef) -> None: function = self.__declaration_stack.pop() if not isinstance(function, Function): # pragma: no cover raise AssertionError("Imbalanced push/pop on stack") # noqa: TRY004 @@ -232,7 +218,7 @@ def leave_funcdef(self, _: FuncDef) -> None: else: parent.add_method(function) - def enter_enumdef(self, node: ClassDef) -> None: + def enter_enumdef(self, node: mp_nodes.ClassDef) -> None: id_ = self._create_id_from_stack(node.name) self.__declaration_stack.append( Enum( @@ -242,7 +228,7 @@ def enter_enumdef(self, node: ClassDef) -> None: ), ) - def leave_enumdef(self, _: ClassDef) -> None: + def leave_enumdef(self, _: mp_nodes.ClassDef) -> None: enum = self.__declaration_stack.pop() if not isinstance(enum, Enum): # pragma: no cover raise AssertionError("Imbalanced push/pop on stack") # noqa: TRY004 @@ -255,21 +241,21 @@ def leave_enumdef(self, _: ClassDef) -> None: self.api.add_enum(enum) parent.add_enum(enum) - def enter_assignmentstmt(self, node: AssignmentStmt) -> None: + def enter_assignmentstmt(self, node: mp_nodes.AssignmentStmt) -> None: # Assignments are attributes or enum instances parent = self.__declaration_stack[-1] assignments: list[Attribute | EnumInstance] = [] for lvalue in node.lvalues: if isinstance(parent, Class): - for assignment in self.parse_attributes(lvalue, node.unanalyzed_type, is_static=True): + for assignment in self._parse_attributes(lvalue, node.unanalyzed_type, is_static=True): assignments.append(assignment) elif isinstance(parent, Function) and parent.name == "__init__": grand_parent = self.__declaration_stack[-2] # If the grandparent is not a class we ignore the attributes - if isinstance(grand_parent, Class) and not isinstance(lvalue, NameExpr): + if isinstance(grand_parent, Class) and not isinstance(lvalue, mp_nodes.NameExpr): # Ignore non instance attributes in __init__ classes - for assignment in self.parse_attributes(lvalue, node.unanalyzed_type, is_static=False): + for assignment in self._parse_attributes(lvalue, node.unanalyzed_type, is_static=False): assignments.append(assignment) elif isinstance(parent, Enum): @@ -292,7 +278,7 @@ def enter_assignmentstmt(self, node: AssignmentStmt) -> None: self.__declaration_stack.append(assignments) - def leave_assignmentstmt(self, _: AssignmentStmt) -> None: + def leave_assignmentstmt(self, _: mp_nodes.AssignmentStmt) -> None: # Assignments are attributes or enum instances assignments = self.__declaration_stack.pop() @@ -330,44 +316,75 @@ def leave_assignmentstmt(self, _: AssignmentStmt) -> None: # #### Result utilities - def create_result(self, node: FuncDef, function_id: str) -> list[Result]: + @staticmethod + def _get_types_from_return_stmts(return_stmts: list[mp_nodes.ReturnStmt]) -> list[sds_types.AbstractType]: + types = [] + for return_stmt in return_stmts: + expr = return_stmt.expr + if isinstance(expr, mp_nodes.NameExpr): + if expr.name in {"False", "True"}: + types.append(sds_types.NamedType(name="bool")) + else: + types.append(sds_types.NamedType(name=expr.name)) + elif isinstance(expr, mp_nodes.IntExpr): + types.append(sds_types.NamedType(name="int")) + elif isinstance(expr, mp_nodes.FloatExpr): + types.append(sds_types.NamedType(name="float")) + elif isinstance(expr, mp_nodes.StrExpr): + types.append(sds_types.NamedType(name="str")) + else: # pragma: no cover + raise TypeError("Unexpected expression type for return type.") + return types + + def _create_result(self, node: mp_nodes.FuncDef, function_id: str) -> list[Result]: # __init__ functions aren't supposed to have returns, so we can ignore them if node.name == "__init__": return [] ret_type = None + is_type_inferred = False if getattr(node, "type", None): node_type = node.type if node_type is not None and hasattr(node_type, "ret_type"): node_ret_type = node_type.ret_type else: # pragma: no cover raise AttributeError("Result has no return type information.") + if not isinstance(node_ret_type, mp_types.NoneType): - ret_type = mypy_type_to_abstract_type(node_ret_type) + # In Mypy AnyTypes can occur because of different reasons (see TypeOfAny Class) + if (isinstance(node_ret_type, mp_types.AnyType) and + node_ret_type.type_of_any == mp_types.TypeOfAny.unannotated): + # In this case, the "Any" type was given, because there was no annotation, therefore we have to + # either infer the type or set no type at all. To infer the type, we iterate through all return + # statements + func_defn = get_funcdef_definitions(node) + return_stmts = find_return_stmts_recursive(func_defn) + if return_stmts: + is_type_inferred = True + return_stmt_types = self._get_types_from_return_stmts(return_stmts) + if len(return_stmt_types) >= 2: + ret_type = sds_types.TupleType(types=return_stmt_types) + else: + ret_type = return_stmt_types[0] + + else: + ret_type = mypy_type_to_abstract_type(node_ret_type) if ret_type is None: return [] results = [] - docstring = self.docstring_parser.get_result_documentation(node) - if isinstance(ret_type, sds_types.TupleType): - for i, type_ in enumerate(ret_type.types): - name = f"result_{i + 1}" - results.append( - Result( - id=f"{function_id}/{name}", - type=type_, - name=name, - docstring=docstring, - ), - ) - else: - name = "result_1" + + # Results that are tuples will be split into multiple results + ret_types = ret_type.types if isinstance(ret_type, sds_types.TupleType) else [ret_type] + for i, type_ in enumerate(ret_types): + name = f"result_{i + 1}" results.append( Result( id=f"{function_id}/{name}", - type=ret_type, + type=type_, + is_type_inferred=is_type_inferred, name=name, docstring=docstring, ), @@ -377,13 +394,13 @@ def create_result(self, node: FuncDef, function_id: str) -> list[Result]: # #### Attribute utilities - def parse_attributes( + def _parse_attributes( self, - lvalue: Expression, + lvalue: mp_nodes.Expression, unanalyzed_type: mp_types.Type | None, is_static: bool = True, ) -> list[Attribute]: - assert isinstance(lvalue, NameExpr | MemberExpr | TupleExpr) + assert isinstance(lvalue, mp_nodes.NameExpr | mp_nodes.MemberExpr | mp_nodes.TupleExpr) attributes: list[Attribute] = [] if hasattr(lvalue, "name"): @@ -391,7 +408,7 @@ def parse_attributes( return attributes attributes.append( - self.create_attribute(lvalue, unanalyzed_type, is_static), + self._create_attribute(lvalue, unanalyzed_type, is_static), ) elif hasattr(lvalue, "items"): @@ -404,13 +421,13 @@ def parse_attributes( continue attributes.append( - self.create_attribute(lvalue_, unanalyzed_type, is_static), + self._create_attribute(lvalue_, unanalyzed_type, is_static), ) return attributes - def check_attribute_already_defined(self, lvalue: Expression, value_name: str) -> bool: - assert isinstance(lvalue, NameExpr | MemberExpr | TupleExpr) + def check_attribute_already_defined(self, lvalue: mp_nodes.Expression, value_name: str) -> bool: + assert isinstance(lvalue, mp_nodes.NameExpr | mp_nodes.MemberExpr | mp_nodes.TupleExpr) if hasattr(lvalue, "node"): node = lvalue.node else: # pragma: no cover @@ -432,46 +449,56 @@ def check_attribute_already_defined(self, lvalue: Expression, value_name: str) - raise ValueError(f"The attribute {value_name} has no value.") return False - def create_attribute( + def _create_attribute( self, - attribute: Expression, + attribute: mp_nodes.Expression, unanalyzed_type: mp_types.Type | None, is_static: bool, ) -> Attribute: + # Get name and qname if hasattr(attribute, "name"): name = attribute.name else: # pragma: no cover raise AttributeError("Expected attribute to have attribute 'name'.") qname = getattr(attribute, "fullname", "") + # Get node information if hasattr(attribute, "node"): - if not isinstance(attribute.node, Var): # pragma: no cover + if not isinstance(attribute.node, mp_nodes.Var): # pragma: no cover raise TypeError("node has wrong type") - node: Var = attribute.node + node: mp_nodes.Var = attribute.node else: # pragma: no cover raise AttributeError("Expected attribute to have attribute 'node'.") + # Sometimes the qname is not in the attribute.fullname field, in that case we have to get it from the node if qname in (name, "") and node is not None: qname = node.fullname - # Check if there is a type hint and get its value attribute_type = None - if isinstance(attribute, MemberExpr): - # Sometimes the is_inferred value is True even thoght has_explicit_value is False, thus the second check - if not node.is_inferred or (node.is_inferred and not node.has_explicit_value): - attribute_type = node.type - elif isinstance(attribute, NameExpr): - if not node.explicit_self_type and not node.is_inferred: + is_type_inferred = False + + # MemberExpr are constructor (__init__) attributes + if isinstance(attribute, mp_nodes.MemberExpr): + attribute_type = node.type + # Sometimes the is_inferred value is True even thoght has_explicit_value is False, thus we HAVE to check + # has_explicit_value, too. + is_type_inferred = node.is_inferred and node.has_explicit_value + + # NameExpr are class attributes + elif isinstance(attribute, mp_nodes.NameExpr): + if not node.explicit_self_type: attribute_type = node.type + is_type_inferred = node.is_inferred - # We need to get the unanalyzed_type for lists, since mypy is not able to check information regarding - # list item types + # We need to get the unanalyzed_type for lists, since mypy is not able to check type hint information + # regarding list item types if ( attribute_type is not None and hasattr(attribute_type, "type") and hasattr(attribute_type, "args") and attribute_type.type.fullname == "builtins.list" + and not is_type_inferred ): if unanalyzed_type is not None and hasattr(unanalyzed_type, "args"): attribute_type.args = unanalyzed_type.args @@ -499,19 +526,23 @@ def create_attribute( id=id_, name=name, type=type_, - is_public=self.is_public(name, qname), + is_type_inferred=is_type_inferred, + is_public=self._is_public(name, qname), is_static=is_static, docstring=docstring, ) # #### Parameter utilities - def parse_parameter_data(self, node: FuncDef, function_id: str) -> list[Parameter]: + def _parse_parameter_data(self, node: mp_nodes.FuncDef, function_id: str) -> list[Parameter]: arguments: list[Parameter] = [] for argument in node.arguments: arg_name = argument.variable.name mypy_type = argument.variable.type + is_type_inferred = False + arg_kind = get_argument_kind(argument) + if mypy_type is None: # pragma: no cover raise ValueError("Argument has no type.") @@ -523,17 +554,19 @@ def parse_parameter_data(self, node: FuncDef, function_id: str) -> list[Paramete # b/c something like list[int, str] is not allowed according to PEP and therefore not handled the normal # way in Mypy. arg_type = mypy_type_to_abstract_type(type_annotation) - else: + elif type_annotation is not None: arg_type = mypy_type_to_abstract_type(mypy_type) + else: + # We try to infer the type through the default value later, if possible + arg_type = None - arg_kind = get_argument_kind(argument) - + # Get default value information default_value = None is_optional = False initializer = argument.initializer if initializer is not None: if not hasattr(initializer, "value"): - if isinstance(initializer, CallExpr): + if isinstance(initializer, mp_nodes.CallExpr): # Special case when the default is a call expression value = None elif hasattr(initializer, "name"): @@ -554,6 +587,18 @@ def parse_parameter_data(self, node: FuncDef, function_id: str) -> list[Paramete default_value = value is_optional = True + # Infer the type, if no type hint was found + if arg_type is None: + value_type_name = { + str: "str", + bool: "bool", + int: "int", + float: "float", + NoneType: "None", + }[type(value)] + arg_type = sds_types.NamedType(name=value_type_name) + is_type_inferred = True + parent = self.__declaration_stack[-1] docstring = self.docstring_parser.get_parameter_documentation( function_node=node, @@ -571,6 +616,7 @@ def parse_parameter_data(self, node: FuncDef, function_id: str) -> list[Paramete assigned_by=arg_kind, docstring=docstring, type=arg_type, + is_type_inferred=is_type_inferred, ), ) @@ -578,7 +624,7 @@ def parse_parameter_data(self, node: FuncDef, function_id: str) -> list[Paramete # #### Reexport utilities - def get_reexported_by(self, name: str) -> list[Module]: + def _get_reexported_by(self, name: str) -> list[Module]: # Get the uppermost module and the path to the current node parents = [] parent = None @@ -601,7 +647,7 @@ def get_reexported_by(self, name: str) -> list[Module]: return list(reexported_by) - def add_reexports(self, module: Module) -> None: + def _add_reexports(self, module: Module) -> None: for qualified_import in module.qualified_imports: name = qualified_import.qualified_name if name in self.reexported: @@ -651,7 +697,7 @@ def _create_module_id(self, qname: str) -> str: module_id = f"/{module_id.replace('.', '/')}" if module_id else "" return f"{package_name}{module_id}" - def is_public(self, name: str, qualified_name: str) -> bool: + def _is_public(self, name: str, qualified_name: str) -> bool: if name.startswith("_") and not name.endswith("__"): return False diff --git a/src/safeds_stubgen/api_analyzer/_mypy_helpers.py b/src/safeds_stubgen/api_analyzer/_mypy_helpers.py index 616800e3..18f6988a 100644 --- a/src/safeds_stubgen/api_analyzer/_mypy_helpers.py +++ b/src/safeds_stubgen/api_analyzer/_mypy_helpers.py @@ -3,7 +3,8 @@ from typing import TYPE_CHECKING import mypy.types as mp_types -from mypy.nodes import ArgKind, Argument +from mypy import nodes as mp_nodes +from mypy.nodes import ArgKind from mypy.types import Instance import safeds_stubgen.api_analyzer._types as sds_types @@ -106,7 +107,7 @@ def mypy_type_to_abstract_type(mypy_type: Instance | ProperType | MypyType) -> A raise ValueError("Unexpected type.") -def get_argument_kind(arg: Argument) -> ParameterAssignment: +def get_argument_kind(arg: mp_nodes.Argument) -> ParameterAssignment: if arg.variable.is_self or arg.variable.is_cls: return ParameterAssignment.IMPLICIT elif arg.kind in {ArgKind.ARG_POS, ArgKind.ARG_OPT} and arg.pos_only: @@ -121,3 +122,22 @@ def get_argument_kind(arg: Argument) -> ParameterAssignment: return ParameterAssignment.NAMED_VARARG else: raise ValueError("Could not find an appropriate parameter assignment.") + + +def find_return_stmts_recursive(stmts: list[mp_nodes.Statement]) -> list[mp_nodes.ReturnStmt]: + return_stmts = [] + for stmt in stmts: + if isinstance(stmt, mp_nodes.IfStmt): + return_stmts += find_return_stmts_recursive(stmt.body) + if stmt.else_body: + return_stmts += find_return_stmts_recursive(stmt.else_body.body) + elif isinstance(stmt, mp_nodes.Block | mp_nodes.TryStmt): + return_stmts += find_return_stmts_recursive(stmt.body) + elif isinstance(stmt, mp_nodes.MatchStmt): + return_stmts += find_return_stmts_recursive(stmt.bodies) + elif isinstance(stmt, mp_nodes.WhileStmt | mp_nodes.WithStmt | mp_nodes.ForStmt): + return_stmts += find_return_stmts_recursive(stmt.body.body) + elif isinstance(stmt, mp_nodes.ReturnStmt): + return_stmts.append(stmt) + + return return_stmts diff --git a/src/safeds_stubgen/stubs_generator/_generate_stubs.py b/src/safeds_stubgen/stubs_generator/_generate_stubs.py index 29bca90f..17fab906 100644 --- a/src/safeds_stubgen/stubs_generator/_generate_stubs.py +++ b/src/safeds_stubgen/stubs_generator/_generate_stubs.py @@ -285,45 +285,48 @@ def _create_parameter_string( first_loop_skipped = True continue - # Default value + assigned_by = parameter.assigned_by + type_string = "" param_value = "" - param_default_value = parameter.default_value - parameter_type_data = parameter.type.to_dict() - if param_default_value is not None: - if isinstance(param_default_value, str): - if parameter_type_data["kind"] == "NamedType" and parameter_type_data["name"] != "str": - if param_default_value == "False": - default_value = "false" - elif param_default_value == "True": - default_value = "true" + + # Default value + if parameter.type is not None: + param_default_value = parameter.default_value + parameter_type_data = parameter.type.to_dict() + if param_default_value is not None: + if isinstance(param_default_value, str): + if parameter_type_data["kind"] == "NamedType" and parameter_type_data["name"] != "str": + if param_default_value == "False": + default_value = "false" + elif param_default_value == "True": + default_value = "true" + else: + default_value = f"{param_default_value}" else: - default_value = f"{param_default_value}" + default_value = f'"{param_default_value}"' else: - default_value = f'"{param_default_value}"' - else: - default_value = param_default_value - param_value = f" = {default_value}" + default_value = param_default_value + param_value = f" = {default_value}" + + # Mypy assignes *args parameters the tuple type, which is not supported in Safe-DS. Therefor we + # overwrite it and set the type to a list. + if assigned_by == ParameterAssignment.POSITIONAL_VARARG: + parameter_type_data["kind"] = "ListType" + + # Parameter type + param_type = self._create_type_string(parameter_type_data) + type_string = f": {param_type}" if param_type else "" # Check if assigned_by is not illegal - assigned_by = parameter.assigned_by if assigned_by == ParameterAssignment.POSITION_ONLY and parameter.default_value is not None: self._current_todo_msgs.add("OPT_POS_ONLY") elif assigned_by == ParameterAssignment.NAME_ONLY and not parameter.is_optional: self._current_todo_msgs.add("REQ_NAME_ONLY") - # Mypy assignes *args parameters the tuple type, which is not supported in Safe-DS. Therefor we overwrite it - # and set the type to a list. - if assigned_by == ParameterAssignment.POSITIONAL_VARARG: - parameter_type_data["kind"] = "ListType" - # Safe-DS does not support variadic parameters. if assigned_by in {ParameterAssignment.POSITIONAL_VARARG, ParameterAssignment.NAMED_VARARG}: self._current_todo_msgs.add("variadic") - # Parameter type - param_type = self._create_type_string(parameter_type_data) - type_string = f": {param_type}" if param_type else "" - # Convert to camelCase if necessary name = parameter.name camel_case_name = _convert_snake_to_camel_case(name) diff --git a/tests/data/test_package/test_module.py b/tests/data/test_package/test_module.py index e4ee31f0..41cd9114 100644 --- a/tests/data/test_package/test_module.py +++ b/tests/data/test_package/test_module.py @@ -62,8 +62,8 @@ class SomeClass(AcDoubleAlias): int_or_bool_attr: int | bool str_attr_with_none_value: str = None - mulit_attr_1, _mulit_attr_2_private = (123456, "I am a String") - mulit_attr_3 = _mulit_attr_4_private = ["I am some", "kind of list"] + multi_attr_1, _multi_attr_2_private = (123456, "I am a String") + multi_attr_3 = _multi_attr_4_private = ["I am some", "kind of list"] # noinspection PyUnusedLocal def __init__(self, init_param_1): @@ -134,3 +134,43 @@ def static_nested_private_class_function(): class NestedNestedPrivateClass: pass + + +class InferMyTypes: + infer_attr = 1 + + def __init__(self, init_param=1): + self.init_infer = 3 + + @staticmethod + def infer_function(infer_param=1, infer_param_2: int = "Something"): + if infer_param_2: + return False + elif infer_param: + if infer_param: + return 12 + else: + return bool + + match infer_param: + case 1: + if 4: + return InferMyTypes + case _: + return None + + while infer_param_2: + if infer_param_2: + return 1.23 + else: + infer_param_2 = 0 + + with open("no path", "r") as _: + if infer_param_2: + return "Some String" + + for _ in (1, 2): + if infer_param_2: + return SomeClass + + return int diff --git a/tests/data/test_stub_generation/function_module.py b/tests/data/test_stub_generation/function_module.py index cc1d5e9c..82488a42 100644 --- a/tests/data/test_stub_generation/function_module.py +++ b/tests/data/test_stub_generation/function_module.py @@ -60,6 +60,7 @@ def opt_pos_only(required, optional=1, /): ... def req_name_only(*, required, optional=1): ... +# Todo Frage: Welche type hints sollten hier erstellt werden? Aktuell werden gar keine erstellt def arg(*args, **kwargs): ... diff --git a/tests/data/test_stub_generation/infer_types_module.py b/tests/data/test_stub_generation/infer_types_module.py new file mode 100644 index 00000000..9b962c62 --- /dev/null +++ b/tests/data/test_stub_generation/infer_types_module.py @@ -0,0 +1,38 @@ +class InferMyTypes: + infer_attr = 1 + + def __init__(self, init_param=1): + self.init_infer = 3 + + @staticmethod + def infer_function(infer_param=1, infer_param_2: int = "Something"): + if infer_param_2: + return False + elif infer_param: + if infer_param: + return 12 + else: + return bool + + match infer_param: + case 1: + if 4: + return InferMyTypes + case _: + return None + + while infer_param_2: + if infer_param_2: + return 1.23 + else: + infer_param_2 = 0 + + with open("no path", "r") as _: + if infer_param_2: + return "Some String" + + for _ in (1, 2): + if infer_param_2: + return SomeClass + + return int diff --git a/tests/safeds_stubgen/__snapshots__/test_main.ambr b/tests/safeds_stubgen/__snapshots__/test_main.ambr index bf1a98c9..d58967af 100644 --- a/tests/safeds_stubgen/__snapshots__/test_main.ambr +++ b/tests/safeds_stubgen/__snapshots__/test_main.ambr @@ -11,6 +11,7 @@ 'id': 'test_package/test_docstrings/EpydocDocstringClass/attr_1', 'is_public': True, 'is_static': True, + 'is_type_inferred': False, 'name': 'attr_1', 'type': dict({ 'kind': 'NamedType', @@ -26,6 +27,7 @@ 'id': 'test_package/test_docstrings/GoogleDocstringClass/attr_1', 'is_public': True, 'is_static': True, + 'is_type_inferred': False, 'name': 'attr_1', 'type': dict({ 'kind': 'NamedType', @@ -41,6 +43,7 @@ 'id': 'test_package/test_docstrings/NumpyDocstringClass/attr_1', 'is_public': True, 'is_static': True, + 'is_type_inferred': False, 'name': 'attr_1', 'type': dict({ 'kind': 'NamedType', @@ -56,12 +59,45 @@ 'id': 'test_package/test_docstrings/RestDocstringClass/attr_1', 'is_public': True, 'is_static': True, + 'is_type_inferred': False, 'name': 'attr_1', 'type': dict({ 'kind': 'NamedType', 'name': 'str', }), }), + dict({ + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_package/test_module/InferMyTypes/infer_attr', + 'is_public': True, + 'is_static': True, + 'is_type_inferred': True, + 'name': 'arsam', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'int', + }), + }), + dict({ + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_package/test_module/InferMyTypes/init_infer', + 'is_public': True, + 'is_static': False, + 'is_type_inferred': True, + 'name': 'init_infer', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'int', + }), + }), dict({ 'docstring': dict({ 'default_value': '', @@ -71,6 +107,7 @@ 'id': 'test_package/test_module/SomeClass/_init_attr_private', 'is_public': False, 'is_static': False, + 'is_type_inferred': False, 'name': '_init_attr_private', 'type': dict({ 'kind': 'NamedType', @@ -83,11 +120,15 @@ 'description': '', 'type': '', }), - 'id': 'test_package/test_module/SomeClass/_mulit_attr_2_private', + 'id': 'test_package/test_module/SomeClass/_multi_attr_2_private', 'is_public': False, 'is_static': True, - 'name': '_mulit_attr_2_private', - 'type': None, + 'is_type_inferred': True, + 'name': '_multi_attr_2_private', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'str', + }), }), dict({ 'docstring': dict({ @@ -95,11 +136,20 @@ 'description': '', 'type': '', }), - 'id': 'test_package/test_module/SomeClass/_mulit_attr_4_private', + 'id': 'test_package/test_module/SomeClass/_multi_attr_4_private', 'is_public': False, 'is_static': True, - 'name': '_mulit_attr_4_private', - 'type': None, + 'is_type_inferred': True, + 'name': '_multi_attr_4_private', + 'type': dict({ + 'kind': 'ListType', + 'types': list([ + dict({ + 'kind': 'NamedType', + 'name': 'str', + }), + ]), + }), }), dict({ 'docstring': dict({ @@ -110,8 +160,12 @@ 'id': 'test_package/test_module/SomeClass/_no_type_hint_private', 'is_public': False, 'is_static': True, + 'is_type_inferred': True, 'name': '_no_type_hint_private', - 'type': None, + 'type': dict({ + 'kind': 'NamedType', + 'name': 'int', + }), }), dict({ 'docstring': dict({ @@ -122,6 +176,7 @@ 'id': 'test_package/test_module/SomeClass/_type_hint_private', 'is_public': False, 'is_static': True, + 'is_type_inferred': False, 'name': '_type_hint_private', 'type': dict({ 'kind': 'NamedType', @@ -137,6 +192,7 @@ 'id': 'test_package/test_module/SomeClass/bool_attr', 'is_public': True, 'is_static': True, + 'is_type_inferred': False, 'name': 'bool_attr', 'type': dict({ 'kind': 'NamedType', @@ -152,6 +208,7 @@ 'id': 'test_package/test_module/SomeClass/dict_attr_1', 'is_public': True, 'is_static': True, + 'is_type_inferred': False, 'name': 'dict_attr_1', 'type': dict({ 'key_type': dict({ @@ -174,6 +231,7 @@ 'id': 'test_package/test_module/SomeClass/dict_attr_2', 'is_public': True, 'is_static': True, + 'is_type_inferred': False, 'name': 'dict_attr_2', 'type': dict({ 'key_type': dict({ @@ -196,6 +254,7 @@ 'id': 'test_package/test_module/SomeClass/dict_attr_3', 'is_public': True, 'is_static': True, + 'is_type_inferred': False, 'name': 'dict_attr_3', 'type': dict({ 'key_type': dict({ @@ -236,6 +295,7 @@ 'id': 'test_package/test_module/SomeClass/flaot_attr', 'is_public': True, 'is_static': True, + 'is_type_inferred': False, 'name': 'flaot_attr', 'type': dict({ 'kind': 'NamedType', @@ -251,6 +311,7 @@ 'id': 'test_package/test_module/SomeClass/init_attr', 'is_public': True, 'is_static': False, + 'is_type_inferred': False, 'name': 'init_attr', 'type': dict({ 'kind': 'NamedType', @@ -266,6 +327,7 @@ 'id': 'test_package/test_module/SomeClass/int_or_bool_attr', 'is_public': True, 'is_static': True, + 'is_type_inferred': False, 'name': 'int_or_bool_attr', 'type': dict({ 'kind': 'UnionType', @@ -290,6 +352,7 @@ 'id': 'test_package/test_module/SomeClass/list_attr_1', 'is_public': True, 'is_static': True, + 'is_type_inferred': False, 'name': 'list_attr_1', 'type': dict({ 'kind': 'ListType', @@ -306,6 +369,7 @@ 'id': 'test_package/test_module/SomeClass/list_attr_2', 'is_public': True, 'is_static': True, + 'is_type_inferred': False, 'name': 'list_attr_2', 'type': dict({ 'kind': 'ListType', @@ -335,6 +399,7 @@ 'id': 'test_package/test_module/SomeClass/list_attr_3', 'is_public': True, 'is_static': True, + 'is_type_inferred': False, 'name': 'list_attr_3', 'type': dict({ 'kind': 'ListType', @@ -359,6 +424,7 @@ 'id': 'test_package/test_module/SomeClass/list_attr_4', 'is_public': True, 'is_static': True, + 'is_type_inferred': False, 'name': 'list_attr_4', 'type': dict({ 'kind': 'ListType', @@ -389,11 +455,15 @@ 'description': '', 'type': '', }), - 'id': 'test_package/test_module/SomeClass/mulit_attr_1', + 'id': 'test_package/test_module/SomeClass/multi_attr_1', 'is_public': True, 'is_static': True, - 'name': 'mulit_attr_1', - 'type': None, + 'is_type_inferred': True, + 'name': 'multi_attr_1', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'int', + }), }), dict({ 'docstring': dict({ @@ -401,11 +471,20 @@ 'description': '', 'type': '', }), - 'id': 'test_package/test_module/SomeClass/mulit_attr_3', + 'id': 'test_package/test_module/SomeClass/multi_attr_3', 'is_public': True, 'is_static': True, - 'name': 'mulit_attr_3', - 'type': None, + 'is_type_inferred': True, + 'name': 'multi_attr_3', + 'type': dict({ + 'kind': 'ListType', + 'types': list([ + dict({ + 'kind': 'NamedType', + 'name': 'str', + }), + ]), + }), }), dict({ 'docstring': dict({ @@ -416,8 +495,12 @@ 'id': 'test_package/test_module/SomeClass/no_type_hint_public', 'is_public': True, 'is_static': True, + 'is_type_inferred': True, 'name': 'no_type_hint_public', - 'type': None, + 'type': dict({ + 'kind': 'NamedType', + 'name': 'int', + }), }), dict({ 'docstring': dict({ @@ -428,6 +511,7 @@ 'id': 'test_package/test_module/SomeClass/none_attr', 'is_public': True, 'is_static': True, + 'is_type_inferred': False, 'name': 'none_attr', 'type': dict({ 'kind': 'NamedType', @@ -443,6 +527,7 @@ 'id': 'test_package/test_module/SomeClass/object_attr', 'is_public': True, 'is_static': True, + 'is_type_inferred': False, 'name': 'object_attr', 'type': dict({ 'kind': 'NamedType', @@ -458,6 +543,7 @@ 'id': 'test_package/test_module/SomeClass/object_attr_2', 'is_public': True, 'is_static': True, + 'is_type_inferred': False, 'name': 'object_attr_2', 'type': dict({ 'kind': 'NamedType', @@ -473,6 +559,7 @@ 'id': 'test_package/test_module/SomeClass/str_attr_with_none_value', 'is_public': True, 'is_static': True, + 'is_type_inferred': False, 'name': 'str_attr_with_none_value', 'type': dict({ 'kind': 'NamedType', @@ -488,6 +575,7 @@ 'id': 'test_package/test_module/SomeClass/tuple_attr_1', 'is_public': True, 'is_static': True, + 'is_type_inferred': False, 'name': 'tuple_attr_1', 'type': dict({ 'kind': 'TupleType', @@ -508,6 +596,7 @@ 'id': 'test_package/test_module/SomeClass/tuple_attr_2', 'is_public': True, 'is_static': True, + 'is_type_inferred': False, 'name': 'tuple_attr_2', 'type': dict({ 'kind': 'TupleType', @@ -537,6 +626,7 @@ 'id': 'test_package/test_module/SomeClass/tuple_attr_3', 'is_public': True, 'is_static': True, + 'is_type_inferred': False, 'name': 'tuple_attr_3', 'type': dict({ 'kind': 'TupleType', @@ -561,6 +651,7 @@ 'id': 'test_package/test_module/SomeClass/type_hint_public', 'is_public': True, 'is_static': True, + 'is_type_inferred': False, 'name': 'type_hint_public', 'type': dict({ 'kind': 'NamedType', @@ -576,8 +667,12 @@ 'id': 'test_package/test_module/_PrivateClass/NestedPrivateClass/nested_class_attr', 'is_public': False, 'is_static': True, + 'is_type_inferred': True, 'name': 'nested_class_attr', - 'type': None, + 'type': dict({ + 'kind': 'NamedType', + 'name': 'int', + }), }), dict({ 'docstring': dict({ @@ -588,8 +683,12 @@ 'id': 'test_package/test_module/_PrivateClass/public_attr_in_private_class', 'is_public': False, 'is_static': True, + 'is_type_inferred': True, 'name': 'public_attr_in_private_class', - 'type': None, + 'type': dict({ + 'kind': 'NamedType', + 'name': 'int', + }), }), dict({ 'docstring': dict({ @@ -600,6 +699,7 @@ 'id': 'test_package/test_module/_PrivateClass/public_init_attr_in_private_class', 'is_public': False, 'is_static': False, + 'is_type_inferred': False, 'name': 'public_init_attr_in_private_class', 'type': dict({ 'kind': 'NamedType', @@ -948,6 +1048,47 @@ 'superclasses': list([ ]), }), + dict({ + 'attributes': list([ + 'test_package/test_module/InferMyTypes/arsam', + 'test_package/test_module/InferMyTypes/init_infer', + ]), + 'classes': list([ + ]), + 'constructor': dict({ + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_package/test_module/InferMyTypes/__init__', + 'is_class_method': False, + 'is_public': True, + 'is_static': False, + 'name': '__init__', + 'parameters': list([ + 'test_package/test_module/InferMyTypes/__init__/self', + 'test_package/test_module/InferMyTypes/__init__/init_param', + ]), + 'reexported_by': list([ + ]), + 'results': list([ + ]), + }), + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_package/test_module/InferMyTypes', + 'is_public': True, + 'methods': list([ + 'test_package/test_module/InferMyTypes/arsam_function', + ]), + 'name': 'InferMyTypes', + 'reexported_by': list([ + ]), + 'superclasses': list([ + ]), + }), dict({ 'attributes': list([ 'test_package/test_module/SomeClass/type_hint_public', @@ -971,10 +1112,10 @@ 'test_package/test_module/SomeClass/flaot_attr', 'test_package/test_module/SomeClass/int_or_bool_attr', 'test_package/test_module/SomeClass/str_attr_with_none_value', - 'test_package/test_module/SomeClass/mulit_attr_1', - 'test_package/test_module/SomeClass/_mulit_attr_2_private', - 'test_package/test_module/SomeClass/mulit_attr_3', - 'test_package/test_module/SomeClass/_mulit_attr_4_private', + 'test_package/test_module/SomeClass/multi_attr_1', + 'test_package/test_module/SomeClass/_multi_attr_2_private', + 'test_package/test_module/SomeClass/multi_attr_3', + 'test_package/test_module/SomeClass/_multi_attr_4_private', 'test_package/test_module/SomeClass/init_attr', 'test_package/test_module/SomeClass/_init_attr_private', ]), @@ -1608,6 +1749,51 @@ 'test_package/test_docstrings/RestDocstringClass/rest_docstring_func/result_1', ]), }), + dict({ + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_package/test_module/InferMyTypes/__init__', + 'is_class_method': False, + 'is_public': True, + 'is_static': False, + 'name': '__init__', + 'parameters': list([ + 'test_package/test_module/InferMyTypes/__init__/self', + 'test_package/test_module/InferMyTypes/__init__/init_param', + ]), + 'reexported_by': list([ + ]), + 'results': list([ + ]), + }), + dict({ + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_package/test_module/InferMyTypes/infer_function', + 'is_class_method': False, + 'is_public': True, + 'is_static': True, + 'name': 'arsam_function', + 'parameters': list([ + 'test_package/test_module/InferMyTypes/infer_function/infer_param', + 'test_package/test_module/InferMyTypes/infer_function/infer_param_2', + ]), + 'reexported_by': list([ + ]), + 'results': list([ + 'test_package/test_module/InferMyTypes/arsam_function/result_1', + 'test_package/test_module/InferMyTypes/arsam_function/result_2', + 'test_package/test_module/InferMyTypes/arsam_function/result_3', + 'test_package/test_module/InferMyTypes/arsam_function/result_4', + 'test_package/test_module/InferMyTypes/arsam_function/result_5', + 'test_package/test_module/InferMyTypes/arsam_function/result_6', + 'test_package/test_module/InferMyTypes/arsam_function/result_7', + ]), + }), dict({ 'docstring': dict({ 'description': '', @@ -2136,6 +2322,7 @@ 'classes': list([ 'test_package/test_module/SomeClass', 'test_package/test_module/_PrivateClass', + 'test_package/test_module/InferMyTypes', ]), 'docstring': 'Docstring of the some_class.py module.', 'enums': list([ @@ -2186,6 +2373,7 @@ }), 'id': 'test_package/test_docstrings/EpydocDocstringClass/__init__/param_1', 'is_optional': False, + 'is_type_inferred': False, 'name': 'param_1', 'type': dict({ 'kind': 'NamedType', @@ -2202,11 +2390,9 @@ }), 'id': 'test_package/test_docstrings/EpydocDocstringClass/__init__/self', 'is_optional': False, + 'is_type_inferred': False, 'name': 'self', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'EpydocDocstringClass', - }), + 'type': None, }), dict({ 'assigned_by': 'IMPLICIT', @@ -2218,11 +2404,9 @@ }), 'id': 'test_package/test_docstrings/EpydocDocstringClass/epydoc_docstring_func/self', 'is_optional': False, + 'is_type_inferred': False, 'name': 'self', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'EpydocDocstringClass', - }), + 'type': None, }), dict({ 'assigned_by': 'POSITION_OR_NAME', @@ -2234,6 +2418,7 @@ }), 'id': 'test_package/test_docstrings/EpydocDocstringClass/epydoc_docstring_func/x', 'is_optional': False, + 'is_type_inferred': False, 'name': 'x', 'type': dict({ 'kind': 'NamedType', @@ -2250,6 +2435,7 @@ }), 'id': 'test_package/test_docstrings/EpydocDocstringClass/epydoc_docstring_func/y', 'is_optional': False, + 'is_type_inferred': False, 'name': 'y', 'type': dict({ 'kind': 'NamedType', @@ -2266,6 +2452,7 @@ }), 'id': 'test_package/test_docstrings/GoogleDocstringClass/__init__/param_1', 'is_optional': False, + 'is_type_inferred': False, 'name': 'param_1', 'type': dict({ 'kind': 'NamedType', @@ -2282,11 +2469,9 @@ }), 'id': 'test_package/test_docstrings/GoogleDocstringClass/__init__/self', 'is_optional': False, + 'is_type_inferred': False, 'name': 'self', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'GoogleDocstringClass', - }), + 'type': None, }), dict({ 'assigned_by': 'IMPLICIT', @@ -2298,11 +2483,9 @@ }), 'id': 'test_package/test_docstrings/GoogleDocstringClass/google_docstring_func/self', 'is_optional': False, + 'is_type_inferred': False, 'name': 'self', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'GoogleDocstringClass', - }), + 'type': None, }), dict({ 'assigned_by': 'POSITION_OR_NAME', @@ -2314,6 +2497,7 @@ }), 'id': 'test_package/test_docstrings/GoogleDocstringClass/google_docstring_func/x', 'is_optional': False, + 'is_type_inferred': False, 'name': 'x', 'type': dict({ 'kind': 'NamedType', @@ -2330,6 +2514,7 @@ }), 'id': 'test_package/test_docstrings/GoogleDocstringClass/google_docstring_func/y', 'is_optional': False, + 'is_type_inferred': False, 'name': 'y', 'type': dict({ 'kind': 'NamedType', @@ -2346,6 +2531,7 @@ }), 'id': 'test_package/test_docstrings/NumpyDocstringClass/__init__/param_1', 'is_optional': False, + 'is_type_inferred': False, 'name': 'param_1', 'type': dict({ 'kind': 'NamedType', @@ -2362,11 +2548,9 @@ }), 'id': 'test_package/test_docstrings/NumpyDocstringClass/__init__/self', 'is_optional': False, + 'is_type_inferred': False, 'name': 'self', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'NumpyDocstringClass', - }), + 'type': None, }), dict({ 'assigned_by': 'IMPLICIT', @@ -2378,11 +2562,9 @@ }), 'id': 'test_package/test_docstrings/NumpyDocstringClass/numpy_docstring_func/self', 'is_optional': False, + 'is_type_inferred': False, 'name': 'self', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'NumpyDocstringClass', - }), + 'type': None, }), dict({ 'assigned_by': 'POSITION_OR_NAME', @@ -2394,6 +2576,7 @@ }), 'id': 'test_package/test_docstrings/NumpyDocstringClass/numpy_docstring_func/x', 'is_optional': False, + 'is_type_inferred': False, 'name': 'x', 'type': dict({ 'kind': 'NamedType', @@ -2410,6 +2593,7 @@ }), 'id': 'test_package/test_docstrings/NumpyDocstringClass/numpy_docstring_func/y', 'is_optional': False, + 'is_type_inferred': False, 'name': 'y', 'type': dict({ 'kind': 'NamedType', @@ -2426,6 +2610,7 @@ }), 'id': 'test_package/test_docstrings/RestDocstringClass/__init__/param_1', 'is_optional': False, + 'is_type_inferred': False, 'name': 'param_1', 'type': dict({ 'kind': 'NamedType', @@ -2442,11 +2627,9 @@ }), 'id': 'test_package/test_docstrings/RestDocstringClass/__init__/self', 'is_optional': False, + 'is_type_inferred': False, 'name': 'self', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'RestDocstringClass', - }), + 'type': None, }), dict({ 'assigned_by': 'IMPLICIT', @@ -2458,11 +2641,9 @@ }), 'id': 'test_package/test_docstrings/RestDocstringClass/rest_docstring_func/self', 'is_optional': False, + 'is_type_inferred': False, 'name': 'self', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'RestDocstringClass', - }), + 'type': None, }), dict({ 'assigned_by': 'POSITION_OR_NAME', @@ -2474,6 +2655,7 @@ }), 'id': 'test_package/test_docstrings/RestDocstringClass/rest_docstring_func/x', 'is_optional': False, + 'is_type_inferred': False, 'name': 'x', 'type': dict({ 'kind': 'NamedType', @@ -2490,12 +2672,78 @@ }), 'id': 'test_package/test_docstrings/RestDocstringClass/rest_docstring_func/y', 'is_optional': False, + 'is_type_inferred': False, 'name': 'y', 'type': dict({ 'kind': 'NamedType', 'name': 'int', }), }), + dict({ + 'assigned_by': 'POSITION_OR_NAME', + 'default_value': 1, + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_package/test_module/InferMyTypes/__init__/init_param', + 'is_optional': True, + 'is_type_inferred': True, + 'name': 'init_param', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'int', + }), + }), + dict({ + 'assigned_by': 'IMPLICIT', + 'default_value': None, + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_package/test_module/InferMyTypes/__init__/self', + 'is_optional': False, + 'is_type_inferred': False, + 'name': 'self', + 'type': None, + }), + dict({ + 'assigned_by': 'POSITION_OR_NAME', + 'default_value': 1, + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_package/test_module/InferMyTypes/infer_function/infer_param', + 'is_optional': True, + 'is_type_inferred': True, + 'name': 'infer_param', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'int', + }), + }), + dict({ + 'assigned_by': 'POSITION_OR_NAME', + 'default_value': 'Something', + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_package/test_module/InferMyTypes/infer_function/infer_param_2', + 'is_optional': True, + 'is_type_inferred': False, + 'name': 'infer_param_2', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'int', + }), + }), dict({ 'assigned_by': 'POSITION_OR_NAME', 'default_value': None, @@ -2506,6 +2754,7 @@ }), 'id': 'test_package/test_module/SomeClass/NestedClass/nested_class_function/param_1', 'is_optional': False, + 'is_type_inferred': False, 'name': 'param_1', 'type': dict({ 'kind': 'NamedType', @@ -2522,11 +2771,9 @@ }), 'id': 'test_package/test_module/SomeClass/NestedClass/nested_class_function/self', 'is_optional': False, + 'is_type_inferred': False, 'name': 'self', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'NestedClass', - }), + 'type': None, }), dict({ 'assigned_by': 'POSITION_OR_NAME', @@ -2538,11 +2785,9 @@ }), 'id': 'test_package/test_module/SomeClass/__init__/init_param_1', 'is_optional': False, + 'is_type_inferred': False, 'name': 'init_param_1', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'Any', - }), + 'type': None, }), dict({ 'assigned_by': 'IMPLICIT', @@ -2554,11 +2799,9 @@ }), 'id': 'test_package/test_module/SomeClass/__init__/self', 'is_optional': False, + 'is_type_inferred': False, 'name': 'self', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'SomeClass', - }), + 'type': None, }), dict({ 'assigned_by': 'POSITION_OR_NAME', @@ -2570,6 +2813,7 @@ }), 'id': 'test_package/test_module/SomeClass/_some_function/param_1', 'is_optional': False, + 'is_type_inferred': False, 'name': 'param_1', 'type': dict({ 'kind': 'NamedType', @@ -2586,6 +2830,7 @@ }), 'id': 'test_package/test_module/SomeClass/_some_function/param_2', 'is_optional': True, + 'is_type_inferred': False, 'name': 'param_2', 'type': dict({ 'kind': 'NamedType', @@ -2602,11 +2847,9 @@ }), 'id': 'test_package/test_module/SomeClass/_some_function/self', 'is_optional': False, + 'is_type_inferred': False, 'name': 'self', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'SomeClass', - }), + 'type': None, }), dict({ 'assigned_by': 'IMPLICIT', @@ -2618,11 +2861,9 @@ }), 'id': 'test_package/test_module/SomeClass/class_method/cls', 'is_optional': False, + 'is_type_inferred': False, 'name': 'cls', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'SomeClass', - }), + 'type': None, }), dict({ 'assigned_by': 'IMPLICIT', @@ -2634,11 +2875,9 @@ }), 'id': 'test_package/test_module/SomeClass/class_method_params/cls', 'is_optional': False, + 'is_type_inferred': False, 'name': 'cls', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'SomeClass', - }), + 'type': None, }), dict({ 'assigned_by': 'POSITION_OR_NAME', @@ -2650,6 +2889,7 @@ }), 'id': 'test_package/test_module/SomeClass/class_method_params/param_1', 'is_optional': False, + 'is_type_inferred': False, 'name': 'param_1', 'type': dict({ 'kind': 'NamedType', @@ -2666,6 +2906,7 @@ }), 'id': 'test_package/test_module/SomeClass/multiple_results/param_1', 'is_optional': False, + 'is_type_inferred': False, 'name': 'param_1', 'type': dict({ 'kind': 'NamedType', @@ -2682,11 +2923,9 @@ }), 'id': 'test_package/test_module/SomeClass/no_return_1/self', 'is_optional': False, + 'is_type_inferred': False, 'name': 'self', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'SomeClass', - }), + 'type': None, }), dict({ 'assigned_by': 'IMPLICIT', @@ -2698,11 +2937,9 @@ }), 'id': 'test_package/test_module/SomeClass/no_return_2/self', 'is_optional': False, + 'is_type_inferred': False, 'name': 'self', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'SomeClass', - }), + 'type': None, }), dict({ 'assigned_by': 'POSITION_OR_NAME', @@ -2714,6 +2951,7 @@ }), 'id': 'test_package/test_module/SomeClass/static_function/param_1', 'is_optional': True, + 'is_type_inferred': False, 'name': 'param_1', 'type': dict({ 'kind': 'NamedType', @@ -2730,6 +2968,7 @@ }), 'id': 'test_package/test_module/SomeClass/static_function/param_2', 'is_optional': True, + 'is_type_inferred': False, 'name': 'param_2', 'type': dict({ 'kind': 'UnionType', @@ -2755,16 +2994,9 @@ }), 'id': 'test_package/test_module/SomeClass/test_params/args', 'is_optional': False, + 'is_type_inferred': False, 'name': 'args', - 'type': dict({ - 'kind': 'TupleType', - 'types': list([ - dict({ - 'kind': 'NamedType', - 'name': 'Any', - }), - ]), - }), + 'type': None, }), dict({ 'assigned_by': 'NAMED_VARARG', @@ -2776,18 +3008,9 @@ }), 'id': 'test_package/test_module/SomeClass/test_params/kwargs', 'is_optional': False, + 'is_type_inferred': False, 'name': 'kwargs', - 'type': dict({ - 'key_type': dict({ - 'kind': 'NamedType', - 'name': 'str', - }), - 'kind': 'DictType', - 'value_type': dict({ - 'kind': 'NamedType', - 'name': 'Any', - }), - }), + 'type': None, }), dict({ 'assigned_by': 'POSITION_ONLY', @@ -2799,11 +3022,9 @@ }), 'id': 'test_package/test_module/SomeClass/test_position/param1', 'is_optional': False, + 'is_type_inferred': False, 'name': 'param1', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'Any', - }), + 'type': None, }), dict({ 'assigned_by': 'POSITION_OR_NAME', @@ -2815,6 +3036,7 @@ }), 'id': 'test_package/test_module/SomeClass/test_position/param2', 'is_optional': False, + 'is_type_inferred': False, 'name': 'param2', 'type': dict({ 'kind': 'NamedType', @@ -2831,10 +3053,11 @@ }), 'id': 'test_package/test_module/SomeClass/test_position/param3', 'is_optional': True, + 'is_type_inferred': True, 'name': 'param3', 'type': dict({ 'kind': 'NamedType', - 'name': 'Any', + 'name': 'int', }), }), dict({ @@ -2847,10 +3070,11 @@ }), 'id': 'test_package/test_module/SomeClass/test_position/param4', 'is_optional': True, + 'is_type_inferred': True, 'name': 'param4', 'type': dict({ 'kind': 'NamedType', - 'name': 'Any', + 'name': 'None', }), }), dict({ @@ -2863,6 +3087,7 @@ }), 'id': 'test_package/test_module/SomeClass/test_position/param5', 'is_optional': True, + 'is_type_inferred': False, 'name': 'param5', 'type': dict({ 'kind': 'NamedType', @@ -2879,11 +3104,9 @@ }), 'id': 'test_package/test_module/SomeClass/test_position/self', 'is_optional': False, + 'is_type_inferred': False, 'name': 'self', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'SomeClass', - }), + 'type': None, }), dict({ 'assigned_by': 'IMPLICIT', @@ -2895,11 +3118,9 @@ }), 'id': 'test_package/test_module/_PrivateClass/__init__/self', 'is_optional': False, + 'is_type_inferred': False, 'name': 'self', - 'type': dict({ - 'kind': 'NamedType', - 'name': '_PrivateClass', - }), + 'type': None, }), dict({ 'assigned_by': 'IMPLICIT', @@ -2911,11 +3132,9 @@ }), 'id': 'test_package/test_module/_PrivateClass/public_func_in_private_class/self', 'is_optional': False, + 'is_type_inferred': False, 'name': 'self', - 'type': dict({ - 'kind': 'NamedType', - 'name': '_PrivateClass', - }), + 'type': None, }), dict({ 'assigned_by': 'POSITION_OR_NAME', @@ -2927,6 +3146,7 @@ }), 'id': 'test_package/test_module/global_func/param_1', 'is_optional': True, + 'is_type_inferred': False, 'name': 'param_1', 'type': dict({ 'kind': 'NamedType', @@ -2943,6 +3163,7 @@ }), 'id': 'test_package/test_module/global_func/param_2', 'is_optional': True, + 'is_type_inferred': False, 'name': 'param_2', 'type': dict({ 'kind': 'UnionType', @@ -2966,6 +3187,7 @@ 'type': '', }), 'id': 'test_package/test_docstrings/EpydocDocstringClass/epydoc_docstring_func/result_1', + 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ 'kind': 'NamedType', @@ -2978,6 +3200,7 @@ 'type': '', }), 'id': 'test_package/test_docstrings/GoogleDocstringClass/google_docstring_func/result_1', + 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ 'kind': 'NamedType', @@ -2990,6 +3213,7 @@ 'type': '', }), 'id': 'test_package/test_docstrings/NumpyDocstringClass/numpy_docstring_func/result_1', + 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ 'kind': 'NamedType', @@ -3002,18 +3226,111 @@ 'type': '', }), 'id': 'test_package/test_docstrings/RestDocstringClass/rest_docstring_func/result_1', + 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ 'kind': 'NamedType', 'name': 'bool', }), }), + dict({ + 'docstring': dict({ + 'description': '', + 'type': '', + }), + 'id': 'test_package/test_module/InferMyTypes/infer_function/result_1', + 'is_type_inferred': True, + 'name': 'result_1', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'bool', + }), + }), + dict({ + 'docstring': dict({ + 'description': '', + 'type': '', + }), + 'id': 'test_package/test_module/InferMyTypes/infer_function/result_2', + 'is_type_inferred': True, + 'name': 'result_2', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'int', + }), + }), + dict({ + 'docstring': dict({ + 'description': '', + 'type': '', + }), + 'id': 'test_package/test_module/InferMyTypes/infer_function/result_4', + 'is_type_inferred': True, + 'name': 'result_3', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'InferMyTypes', + }), + }), + dict({ + 'docstring': dict({ + 'description': '', + 'type': '', + }), + 'id': 'test_package/test_module/InferMyTypes/infer_function/result_5', + 'is_type_inferred': True, + 'name': 'result_4', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'None', + }), + }), + dict({ + 'docstring': dict({ + 'description': '', + 'type': '', + }), + 'id': 'test_package/test_module/InferMyTypes/infer_function/result_6', + 'is_type_inferred': True, + 'name': 'result_5', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'float', + }), + }), + dict({ + 'docstring': dict({ + 'description': '', + 'type': '', + }), + 'id': 'test_package/test_module/InferMyTypes/infer_function/result_7', + 'is_type_inferred': True, + 'name': 'result_6', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'str', + }), + }), + dict({ + 'docstring': dict({ + 'description': '', + 'type': '', + }), + 'id': 'test_package/test_module/InferMyTypes/infer_function/result_8', + 'is_type_inferred': True, + 'name': 'result_7', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'SomeClass', + }), + }), dict({ 'docstring': dict({ 'description': '', 'type': '', }), 'id': 'test_package/test_module/SomeClass/NestedClass/nested_class_function/result_1', + 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ 'kind': 'SetType', @@ -3040,6 +3357,7 @@ 'type': '', }), 'id': 'test_package/test_module/SomeClass/_some_function/result_1', + 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ 'kind': 'NamedType', @@ -3052,6 +3370,7 @@ 'type': '', }), 'id': 'test_package/test_module/SomeClass/class_method_params/result_1', + 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ 'kind': 'NamedType', @@ -3064,6 +3383,7 @@ 'type': '', }), 'id': 'test_package/test_module/SomeClass/multiple_results/result_1', + 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ 'kind': 'UnionType', @@ -3094,6 +3414,7 @@ 'type': '', }), 'id': 'test_package/test_module/SomeClass/static_function/result_1', + 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ 'kind': 'NamedType', @@ -3106,6 +3427,7 @@ 'type': '', }), 'id': 'test_package/test_module/SomeClass/static_function/result_2', + 'is_type_inferred': False, 'name': 'result_2', 'type': dict({ 'kind': 'NamedType', @@ -3118,6 +3440,7 @@ 'type': '', }), 'id': 'test_package/test_module/SomeClass/test_position/result_1', + 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ 'kind': 'NamedType', @@ -3130,6 +3453,7 @@ 'type': '', }), 'id': 'test_package/test_module/_private_global_func/result_1', + 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ 'kind': 'UnionType', @@ -3155,6 +3479,7 @@ 'type': '', }), 'id': 'test_package/test_module/global_func/result_1', + 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ 'kind': 'NamedType', diff --git a/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr b/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr index c63bbb69..42ba433b 100644 --- a/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr +++ b/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr @@ -10,6 +10,7 @@ 'id': 'test_package/test_docstrings/GoogleDocstringClass/attr_1', 'is_public': True, 'is_static': True, + 'is_type_inferred': False, 'name': 'attr_1', 'type': dict({ 'kind': 'NamedType', @@ -37,8 +38,12 @@ 'id': 'test_package/test_module/_PrivateClass/NestedPrivateClass/nested_class_attr', 'is_public': False, 'is_static': True, + 'is_type_inferred': True, 'name': 'nested_class_attr', - 'type': None, + 'type': dict({ + 'kind': 'NamedType', + 'name': 'int', + }), }), ]) # --- @@ -53,6 +58,7 @@ 'id': 'test_package/test_docstrings/NumpyDocstringClass/attr_1', 'is_public': True, 'is_static': True, + 'is_type_inferred': False, 'name': 'attr_1', 'type': dict({ 'kind': 'NamedType', @@ -72,6 +78,7 @@ 'id': 'test_package/test_docstrings/RestDocstringClass/attr_1', 'is_public': True, 'is_static': True, + 'is_type_inferred': False, 'name': 'attr_1', 'type': dict({ 'kind': 'NamedType', @@ -91,6 +98,7 @@ 'id': 'test_package/test_module/SomeClass/_init_attr_private', 'is_public': False, 'is_static': False, + 'is_type_inferred': False, 'name': '_init_attr_private', 'type': dict({ 'kind': 'NamedType', @@ -103,11 +111,15 @@ 'description': '', 'type': '', }), - 'id': 'test_package/test_module/SomeClass/_mulit_attr_2_private', + 'id': 'test_package/test_module/SomeClass/_multi_attr_2_private', 'is_public': False, 'is_static': True, - 'name': '_mulit_attr_2_private', - 'type': None, + 'is_type_inferred': True, + 'name': '_multi_attr_2_private', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'str', + }), }), dict({ 'docstring': dict({ @@ -115,11 +127,20 @@ 'description': '', 'type': '', }), - 'id': 'test_package/test_module/SomeClass/_mulit_attr_4_private', + 'id': 'test_package/test_module/SomeClass/_multi_attr_4_private', 'is_public': False, 'is_static': True, - 'name': '_mulit_attr_4_private', - 'type': None, + 'is_type_inferred': True, + 'name': '_multi_attr_4_private', + 'type': dict({ + 'kind': 'ListType', + 'types': list([ + dict({ + 'kind': 'NamedType', + 'name': 'str', + }), + ]), + }), }), dict({ 'docstring': dict({ @@ -130,8 +151,12 @@ 'id': 'test_package/test_module/SomeClass/_no_type_hint_private', 'is_public': False, 'is_static': True, + 'is_type_inferred': True, 'name': '_no_type_hint_private', - 'type': None, + 'type': dict({ + 'kind': 'NamedType', + 'name': 'int', + }), }), dict({ 'docstring': dict({ @@ -142,6 +167,7 @@ 'id': 'test_package/test_module/SomeClass/_type_hint_private', 'is_public': False, 'is_static': True, + 'is_type_inferred': False, 'name': '_type_hint_private', 'type': dict({ 'kind': 'NamedType', @@ -157,6 +183,7 @@ 'id': 'test_package/test_module/SomeClass/bool_attr', 'is_public': True, 'is_static': True, + 'is_type_inferred': False, 'name': 'bool_attr', 'type': dict({ 'kind': 'NamedType', @@ -172,6 +199,7 @@ 'id': 'test_package/test_module/SomeClass/dict_attr_1', 'is_public': True, 'is_static': True, + 'is_type_inferred': False, 'name': 'dict_attr_1', 'type': dict({ 'key_type': dict({ @@ -194,6 +222,7 @@ 'id': 'test_package/test_module/SomeClass/dict_attr_2', 'is_public': True, 'is_static': True, + 'is_type_inferred': False, 'name': 'dict_attr_2', 'type': dict({ 'key_type': dict({ @@ -216,6 +245,7 @@ 'id': 'test_package/test_module/SomeClass/dict_attr_3', 'is_public': True, 'is_static': True, + 'is_type_inferred': False, 'name': 'dict_attr_3', 'type': dict({ 'key_type': dict({ @@ -256,6 +286,7 @@ 'id': 'test_package/test_module/SomeClass/flaot_attr', 'is_public': True, 'is_static': True, + 'is_type_inferred': False, 'name': 'flaot_attr', 'type': dict({ 'kind': 'NamedType', @@ -271,6 +302,7 @@ 'id': 'test_package/test_module/SomeClass/init_attr', 'is_public': True, 'is_static': False, + 'is_type_inferred': False, 'name': 'init_attr', 'type': dict({ 'kind': 'NamedType', @@ -286,6 +318,7 @@ 'id': 'test_package/test_module/SomeClass/int_or_bool_attr', 'is_public': True, 'is_static': True, + 'is_type_inferred': False, 'name': 'int_or_bool_attr', 'type': dict({ 'kind': 'UnionType', @@ -310,6 +343,7 @@ 'id': 'test_package/test_module/SomeClass/list_attr_1', 'is_public': True, 'is_static': True, + 'is_type_inferred': False, 'name': 'list_attr_1', 'type': dict({ 'kind': 'ListType', @@ -326,6 +360,7 @@ 'id': 'test_package/test_module/SomeClass/list_attr_2', 'is_public': True, 'is_static': True, + 'is_type_inferred': False, 'name': 'list_attr_2', 'type': dict({ 'kind': 'ListType', @@ -355,6 +390,7 @@ 'id': 'test_package/test_module/SomeClass/list_attr_3', 'is_public': True, 'is_static': True, + 'is_type_inferred': False, 'name': 'list_attr_3', 'type': dict({ 'kind': 'ListType', @@ -379,6 +415,7 @@ 'id': 'test_package/test_module/SomeClass/list_attr_4', 'is_public': True, 'is_static': True, + 'is_type_inferred': False, 'name': 'list_attr_4', 'type': dict({ 'kind': 'ListType', @@ -409,11 +446,15 @@ 'description': '', 'type': '', }), - 'id': 'test_package/test_module/SomeClass/mulit_attr_1', + 'id': 'test_package/test_module/SomeClass/multi_attr_1', 'is_public': True, 'is_static': True, - 'name': 'mulit_attr_1', - 'type': None, + 'is_type_inferred': True, + 'name': 'multi_attr_1', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'int', + }), }), dict({ 'docstring': dict({ @@ -421,11 +462,20 @@ 'description': '', 'type': '', }), - 'id': 'test_package/test_module/SomeClass/mulit_attr_3', + 'id': 'test_package/test_module/SomeClass/multi_attr_3', 'is_public': True, 'is_static': True, - 'name': 'mulit_attr_3', - 'type': None, + 'is_type_inferred': True, + 'name': 'multi_attr_3', + 'type': dict({ + 'kind': 'ListType', + 'types': list([ + dict({ + 'kind': 'NamedType', + 'name': 'str', + }), + ]), + }), }), dict({ 'docstring': dict({ @@ -436,8 +486,12 @@ 'id': 'test_package/test_module/SomeClass/no_type_hint_public', 'is_public': True, 'is_static': True, + 'is_type_inferred': True, 'name': 'no_type_hint_public', - 'type': None, + 'type': dict({ + 'kind': 'NamedType', + 'name': 'int', + }), }), dict({ 'docstring': dict({ @@ -448,6 +502,7 @@ 'id': 'test_package/test_module/SomeClass/none_attr', 'is_public': True, 'is_static': True, + 'is_type_inferred': False, 'name': 'none_attr', 'type': dict({ 'kind': 'NamedType', @@ -463,6 +518,7 @@ 'id': 'test_package/test_module/SomeClass/object_attr', 'is_public': True, 'is_static': True, + 'is_type_inferred': False, 'name': 'object_attr', 'type': dict({ 'kind': 'NamedType', @@ -478,6 +534,7 @@ 'id': 'test_package/test_module/SomeClass/object_attr_2', 'is_public': True, 'is_static': True, + 'is_type_inferred': False, 'name': 'object_attr_2', 'type': dict({ 'kind': 'NamedType', @@ -493,6 +550,7 @@ 'id': 'test_package/test_module/SomeClass/str_attr_with_none_value', 'is_public': True, 'is_static': True, + 'is_type_inferred': False, 'name': 'str_attr_with_none_value', 'type': dict({ 'kind': 'NamedType', @@ -508,6 +566,7 @@ 'id': 'test_package/test_module/SomeClass/tuple_attr_1', 'is_public': True, 'is_static': True, + 'is_type_inferred': False, 'name': 'tuple_attr_1', 'type': dict({ 'kind': 'TupleType', @@ -528,6 +587,7 @@ 'id': 'test_package/test_module/SomeClass/tuple_attr_2', 'is_public': True, 'is_static': True, + 'is_type_inferred': False, 'name': 'tuple_attr_2', 'type': dict({ 'kind': 'TupleType', @@ -557,6 +617,7 @@ 'id': 'test_package/test_module/SomeClass/tuple_attr_3', 'is_public': True, 'is_static': True, + 'is_type_inferred': False, 'name': 'tuple_attr_3', 'type': dict({ 'kind': 'TupleType', @@ -581,6 +642,7 @@ 'id': 'test_package/test_module/SomeClass/type_hint_public', 'is_public': True, 'is_static': True, + 'is_type_inferred': False, 'name': 'type_hint_public', 'type': dict({ 'kind': 'NamedType', @@ -600,8 +662,12 @@ 'id': 'test_package/test_module/_PrivateClass/public_attr_in_private_class', 'is_public': False, 'is_static': True, + 'is_type_inferred': True, 'name': 'public_attr_in_private_class', - 'type': None, + 'type': dict({ + 'kind': 'NamedType', + 'name': 'int', + }), }), dict({ 'docstring': dict({ @@ -612,6 +678,7 @@ 'id': 'test_package/test_module/_PrivateClass/public_init_attr_in_private_class', 'is_public': False, 'is_static': False, + 'is_type_inferred': False, 'name': 'public_init_attr_in_private_class', 'type': dict({ 'kind': 'NamedType', @@ -1442,10 +1509,10 @@ 'test_package/test_module/SomeClass/flaot_attr', 'test_package/test_module/SomeClass/int_or_bool_attr', 'test_package/test_module/SomeClass/str_attr_with_none_value', - 'test_package/test_module/SomeClass/mulit_attr_1', - 'test_package/test_module/SomeClass/_mulit_attr_2_private', - 'test_package/test_module/SomeClass/mulit_attr_3', - 'test_package/test_module/SomeClass/_mulit_attr_4_private', + 'test_package/test_module/SomeClass/multi_attr_1', + 'test_package/test_module/SomeClass/_multi_attr_2_private', + 'test_package/test_module/SomeClass/multi_attr_3', + 'test_package/test_module/SomeClass/_multi_attr_4_private', 'test_package/test_module/SomeClass/init_attr', 'test_package/test_module/SomeClass/_init_attr_private', ]), @@ -1701,6 +1768,7 @@ }), 'id': 'test_package/test_docstrings/EpydocDocstringClass/__init__/param_1', 'is_optional': False, + 'is_type_inferred': False, 'name': 'param_1', 'type': dict({ 'kind': 'NamedType', @@ -1717,11 +1785,9 @@ }), 'id': 'test_package/test_docstrings/EpydocDocstringClass/__init__/self', 'is_optional': False, + 'is_type_inferred': False, 'name': 'self', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'EpydocDocstringClass', - }), + 'type': None, }), ]) # --- @@ -1737,6 +1803,7 @@ }), 'id': 'test_package/test_docstrings/GoogleDocstringClass/__init__/param_1', 'is_optional': False, + 'is_type_inferred': False, 'name': 'param_1', 'type': dict({ 'kind': 'NamedType', @@ -1753,11 +1820,9 @@ }), 'id': 'test_package/test_docstrings/GoogleDocstringClass/__init__/self', 'is_optional': False, + 'is_type_inferred': False, 'name': 'self', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'GoogleDocstringClass', - }), + 'type': None, }), ]) # --- @@ -1773,6 +1838,7 @@ }), 'id': 'test_package/test_docstrings/NumpyDocstringClass/__init__/param_1', 'is_optional': False, + 'is_type_inferred': False, 'name': 'param_1', 'type': dict({ 'kind': 'NamedType', @@ -1789,11 +1855,9 @@ }), 'id': 'test_package/test_docstrings/NumpyDocstringClass/__init__/self', 'is_optional': False, + 'is_type_inferred': False, 'name': 'self', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'NumpyDocstringClass', - }), + 'type': None, }), ]) # --- @@ -1809,6 +1873,7 @@ }), 'id': 'test_package/test_docstrings/RestDocstringClass/__init__/param_1', 'is_optional': False, + 'is_type_inferred': False, 'name': 'param_1', 'type': dict({ 'kind': 'NamedType', @@ -1825,11 +1890,9 @@ }), 'id': 'test_package/test_docstrings/RestDocstringClass/__init__/self', 'is_optional': False, + 'is_type_inferred': False, 'name': 'self', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'RestDocstringClass', - }), + 'type': None, }), ]) # --- @@ -1845,11 +1908,9 @@ }), 'id': 'test_package/test_module/SomeClass/__init__/init_param_1', 'is_optional': False, + 'is_type_inferred': False, 'name': 'init_param_1', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'Any', - }), + 'type': None, }), dict({ 'assigned_by': 'IMPLICIT', @@ -1861,11 +1922,9 @@ }), 'id': 'test_package/test_module/SomeClass/__init__/self', 'is_optional': False, + 'is_type_inferred': False, 'name': 'self', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'SomeClass', - }), + 'type': None, }), ]) # --- @@ -1881,11 +1940,9 @@ }), 'id': 'test_package/test_docstrings/EpydocDocstringClass/epydoc_docstring_func/self', 'is_optional': False, + 'is_type_inferred': False, 'name': 'self', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'EpydocDocstringClass', - }), + 'type': None, }), dict({ 'assigned_by': 'POSITION_OR_NAME', @@ -1897,6 +1954,7 @@ }), 'id': 'test_package/test_docstrings/EpydocDocstringClass/epydoc_docstring_func/x', 'is_optional': False, + 'is_type_inferred': False, 'name': 'x', 'type': dict({ 'kind': 'NamedType', @@ -1913,6 +1971,7 @@ }), 'id': 'test_package/test_docstrings/EpydocDocstringClass/epydoc_docstring_func/y', 'is_optional': False, + 'is_type_inferred': False, 'name': 'y', 'type': dict({ 'kind': 'NamedType', @@ -1933,6 +1992,7 @@ }), 'id': 'test_package/test_module/global_func/param_1', 'is_optional': True, + 'is_type_inferred': False, 'name': 'param_1', 'type': dict({ 'kind': 'NamedType', @@ -1949,6 +2009,7 @@ }), 'id': 'test_package/test_module/global_func/param_2', 'is_optional': True, + 'is_type_inferred': False, 'name': 'param_2', 'type': dict({ 'kind': 'UnionType', @@ -1978,11 +2039,9 @@ }), 'id': 'test_package/test_docstrings/GoogleDocstringClass/google_docstring_func/self', 'is_optional': False, + 'is_type_inferred': False, 'name': 'self', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'GoogleDocstringClass', - }), + 'type': None, }), dict({ 'assigned_by': 'POSITION_OR_NAME', @@ -1994,6 +2053,7 @@ }), 'id': 'test_package/test_docstrings/GoogleDocstringClass/google_docstring_func/x', 'is_optional': False, + 'is_type_inferred': False, 'name': 'x', 'type': dict({ 'kind': 'NamedType', @@ -2010,6 +2070,7 @@ }), 'id': 'test_package/test_docstrings/GoogleDocstringClass/google_docstring_func/y', 'is_optional': False, + 'is_type_inferred': False, 'name': 'y', 'type': dict({ 'kind': 'NamedType', @@ -2030,6 +2091,7 @@ }), 'id': 'test_package/test_module/SomeClass/NestedClass/nested_class_function/param_1', 'is_optional': False, + 'is_type_inferred': False, 'name': 'param_1', 'type': dict({ 'kind': 'NamedType', @@ -2046,11 +2108,9 @@ }), 'id': 'test_package/test_module/SomeClass/NestedClass/nested_class_function/self', 'is_optional': False, + 'is_type_inferred': False, 'name': 'self', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'NestedClass', - }), + 'type': None, }), ]) # --- @@ -2066,11 +2126,9 @@ }), 'id': 'test_package/test_docstrings/NumpyDocstringClass/numpy_docstring_func/self', 'is_optional': False, + 'is_type_inferred': False, 'name': 'self', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'NumpyDocstringClass', - }), + 'type': None, }), dict({ 'assigned_by': 'POSITION_OR_NAME', @@ -2082,6 +2140,7 @@ }), 'id': 'test_package/test_docstrings/NumpyDocstringClass/numpy_docstring_func/x', 'is_optional': False, + 'is_type_inferred': False, 'name': 'x', 'type': dict({ 'kind': 'NamedType', @@ -2098,6 +2157,7 @@ }), 'id': 'test_package/test_docstrings/NumpyDocstringClass/numpy_docstring_func/y', 'is_optional': False, + 'is_type_inferred': False, 'name': 'y', 'type': dict({ 'kind': 'NamedType', @@ -2118,11 +2178,9 @@ }), 'id': 'test_package/test_docstrings/RestDocstringClass/rest_docstring_func/self', 'is_optional': False, + 'is_type_inferred': False, 'name': 'self', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'RestDocstringClass', - }), + 'type': None, }), dict({ 'assigned_by': 'POSITION_OR_NAME', @@ -2134,6 +2192,7 @@ }), 'id': 'test_package/test_docstrings/RestDocstringClass/rest_docstring_func/x', 'is_optional': False, + 'is_type_inferred': False, 'name': 'x', 'type': dict({ 'kind': 'NamedType', @@ -2150,6 +2209,7 @@ }), 'id': 'test_package/test_docstrings/RestDocstringClass/rest_docstring_func/y', 'is_optional': False, + 'is_type_inferred': False, 'name': 'y', 'type': dict({ 'kind': 'NamedType', @@ -2170,6 +2230,7 @@ }), 'id': 'test_package/test_module/SomeClass/static_function/param_1', 'is_optional': True, + 'is_type_inferred': False, 'name': 'param_1', 'type': dict({ 'kind': 'NamedType', @@ -2186,6 +2247,7 @@ }), 'id': 'test_package/test_module/SomeClass/static_function/param_2', 'is_optional': True, + 'is_type_inferred': False, 'name': 'param_2', 'type': dict({ 'kind': 'UnionType', @@ -2215,16 +2277,9 @@ }), 'id': 'test_package/test_module/SomeClass/test_params/args', 'is_optional': False, + 'is_type_inferred': False, 'name': 'args', - 'type': dict({ - 'kind': 'TupleType', - 'types': list([ - dict({ - 'kind': 'NamedType', - 'name': 'Any', - }), - ]), - }), + 'type': None, }), dict({ 'assigned_by': 'NAMED_VARARG', @@ -2236,18 +2291,9 @@ }), 'id': 'test_package/test_module/SomeClass/test_params/kwargs', 'is_optional': False, + 'is_type_inferred': False, 'name': 'kwargs', - 'type': dict({ - 'key_type': dict({ - 'kind': 'NamedType', - 'name': 'str', - }), - 'kind': 'DictType', - 'value_type': dict({ - 'kind': 'NamedType', - 'name': 'Any', - }), - }), + 'type': None, }), ]) # --- @@ -2263,11 +2309,9 @@ }), 'id': 'test_package/test_module/SomeClass/test_position/param1', 'is_optional': False, + 'is_type_inferred': False, 'name': 'param1', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'Any', - }), + 'type': None, }), dict({ 'assigned_by': 'POSITION_OR_NAME', @@ -2279,6 +2323,7 @@ }), 'id': 'test_package/test_module/SomeClass/test_position/param2', 'is_optional': False, + 'is_type_inferred': False, 'name': 'param2', 'type': dict({ 'kind': 'NamedType', @@ -2295,10 +2340,11 @@ }), 'id': 'test_package/test_module/SomeClass/test_position/param3', 'is_optional': True, + 'is_type_inferred': True, 'name': 'param3', 'type': dict({ 'kind': 'NamedType', - 'name': 'Any', + 'name': 'int', }), }), dict({ @@ -2311,10 +2357,11 @@ }), 'id': 'test_package/test_module/SomeClass/test_position/param4', 'is_optional': True, + 'is_type_inferred': True, 'name': 'param4', 'type': dict({ 'kind': 'NamedType', - 'name': 'Any', + 'name': 'None', }), }), dict({ @@ -2327,6 +2374,7 @@ }), 'id': 'test_package/test_module/SomeClass/test_position/param5', 'is_optional': True, + 'is_type_inferred': False, 'name': 'param5', 'type': dict({ 'kind': 'NamedType', @@ -2343,11 +2391,9 @@ }), 'id': 'test_package/test_module/SomeClass/test_position/self', 'is_optional': False, + 'is_type_inferred': False, 'name': 'self', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'SomeClass', - }), + 'type': None, }), ]) # --- @@ -2359,6 +2405,7 @@ 'type': 'bool', }), 'id': 'test_package/test_docstrings/EpydocDocstringClass/epydoc_docstring_func/result_1', + 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ 'kind': 'NamedType', @@ -2375,6 +2422,7 @@ 'type': '', }), 'id': 'test_package/test_module/global_func/result_1', + 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ 'kind': 'NamedType', @@ -2394,6 +2442,7 @@ 'type': 'bool', }), 'id': 'test_package/test_docstrings/GoogleDocstringClass/google_docstring_func/result_1', + 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ 'kind': 'NamedType', @@ -2410,6 +2459,7 @@ 'type': '', }), 'id': 'test_package/test_module/SomeClass/multiple_results/result_1', + 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ 'kind': 'UnionType', @@ -2444,6 +2494,7 @@ 'type': '', }), 'id': 'test_package/test_module/SomeClass/NestedClass/nested_class_function/result_1', + 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ 'kind': 'SetType', @@ -2474,6 +2525,7 @@ 'type': 'bool', }), 'id': 'test_package/test_docstrings/NumpyDocstringClass/numpy_docstring_func/result_1', + 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ 'kind': 'NamedType', @@ -2490,6 +2542,7 @@ 'type': 'bool', }), 'id': 'test_package/test_docstrings/RestDocstringClass/rest_docstring_func/result_1', + 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ 'kind': 'NamedType', @@ -2506,6 +2559,7 @@ 'type': '', }), 'id': 'test_package/test_module/SomeClass/static_function/result_1', + 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ 'kind': 'NamedType', @@ -2518,6 +2572,7 @@ 'type': '', }), 'id': 'test_package/test_module/SomeClass/static_function/result_2', + 'is_type_inferred': False, 'name': 'result_2', 'type': dict({ 'kind': 'NamedType', @@ -2534,6 +2589,7 @@ 'type': '', }), 'id': 'test_package/test_module/SomeClass/test_position/result_1', + 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ 'kind': 'NamedType', @@ -2919,6 +2975,7 @@ 'classes': list([ 'test_package/test_module/SomeClass', 'test_package/test_module/_PrivateClass', + 'test_package/test_module/InferMyTypes', ]), 'docstring': 'Docstring of the some_class.py module.', 'enums': list([ diff --git a/tests/safeds_stubgen/api_analyzer/test_types.py b/tests/safeds_stubgen/api_analyzer/test_types.py index 21c33c8e..03ff5b16 100644 --- a/tests/safeds_stubgen/api_analyzer/test_types.py +++ b/tests/safeds_stubgen/api_analyzer/test_types.py @@ -31,6 +31,7 @@ def test_correct_hash() -> None: assigned_by=ParameterAssignment.POSITION_OR_NAME, docstring=ParameterDocstring("'hashvalue'", "r", "r"), type=NamedType("str"), + is_type_inferred=False ) assert hash(parameter) == hash(deepcopy(parameter)) enum_values = frozenset({"a", "b", "c"}) diff --git a/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr b/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr index b5d10963..f44217da 100644 --- a/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr +++ b/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr @@ -9,7 +9,7 @@ @PythonName("type_hint_public") static attr typeHintPublic: Int @PythonName("no_type_hint_public") - static attr noTypeHintPublic + static attr noTypeHintPublic: Int @PythonName("object_attr") static attr objectAttr: A // TODO Safe-DS does not support tuple types. @@ -48,17 +48,17 @@ @PythonName("str_attr_with_none_value") static attr strAttrWithNoneValue: String @PythonName("multi_attr_1") - static attr multiAttr1 + static attr multiAttr1: Int @PythonName("multi_attr_3") - static attr multiAttr3 + static attr multiAttr3: List @PythonName("multi_attr_5") - static attr multiAttr5 + static attr multiAttr5: String @PythonName("multi_attr_6") - static attr multiAttr6 + static attr multiAttr6: String @PythonName("multi_attr_7") - static attr multiAttr7 + static attr multiAttr7: String @PythonName("multi_attr_8") - static attr multiAttr8 + static attr multiAttr8: String @PythonName("init_attr") attr initAttr: Boolean } @@ -138,7 +138,7 @@ `union`: union, lst: List, obj: A - ) -> result1: Any + ) // TODO List type has to many type arguments. // TODO Safe-DS does not support tuple types. @@ -148,7 +148,7 @@ @PythonName("lst_2") lst2: List, tpl: Tuple, `_`: Int = String - ) -> result1: Any + ) @PythonName("special_params") fun specialParams( @@ -160,36 +160,36 @@ @PythonName("none_none_bool_none_union") noneNoneBoolNoneUnion: Boolean?, @PythonName("none_list_union_none_none") noneListUnionNoneNone: List?, none: Nothing? - ) -> result1: Any + ) @PythonName("param_position") fun paramPosition( - self: Any, - a: Any, + self, + a, b: Boolean, - c: Any = 1, - d: Any, + c: Int = 1, + d: A, e: Int = 1 - ) -> result1: Any + ) // TODO Safe-DS does not support optional but position only parameter assignments. @PythonName("opt_pos_only") fun optPosOnly( - required: Any, - optional: Any = 1 + required, + optional: Int = 1 ) // TODO Safe-DS does not support required but name only parameter assignments. @PythonName("req_name_only") fun reqNameOnly( - required: Any, - optional: Any = 1 + required, + optional: Int = 1 ) // TODO Safe-DS does not support variadic parameters. fun arg( - args: List, - kwargs: Map + args, + kwargs ) // TODO Safe-DS does not support variadic parameters. @@ -197,7 +197,7 @@ fun argsType( args: List, kwargs: Map - ) -> result1: Any + ) @PythonName("one_result") fun oneResult() -> result1: Int @@ -213,7 +213,7 @@ class A() class B( - @PythonName("init_param") initParam: Any + @PythonName("init_param") initParam ) { @PythonName("instance_method") fun instanceMethod( @@ -240,3 +240,23 @@ ''' # --- +# name: test_type_inference + ''' + package test_stub_generation.infer_types_module + + class InferMyTypes( + @PythonName("init_param") initParam: Int = 1 + ) { + static attr infer_attr: Int + @PythonName("init_infer") + attr initInfer: Any + + @PythonName("infer_function") + static fun inferFunction( + @PythonName("infer_param") inferParam: Int = 1, + @PythonName("infer_param_2") inferParam2: Int = Something + ) -> (result1: Boolean, result2: Int, result3: InferMyTypes, result4: Nothing?, result5: Float, result6: String, result7: SomeClass) + } + + ''' +# --- diff --git a/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py b/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py index 61f11d40..eb1f09ab 100644 --- a/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py +++ b/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py @@ -89,6 +89,11 @@ def test_import_creation(snapshot: SnapshotAssertion) -> None: assert_stubs_snapshot("import_module", snapshot) +# Todo Check snapshot +def test_type_inference(snapshot: SnapshotAssertion) -> None: + assert_stubs_snapshot("infer_types_module", snapshot) + + # Todo def test_docstring_creation() -> None: ... From b6a7051833e0d995bc22b00b0fe5d1295f493350 Mon Sep 17 00:00:00 2001 From: Arsam Date: Sat, 18 Nov 2023 18:13:13 +0100 Subject: [PATCH 041/109] Issue #34: Test fixes --- .../__snapshots__/test_main.ambr | 22 +++++++++---------- .../safeds_stubgen/api_analyzer/test_types.py | 1 + 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/tests/safeds_stubgen/__snapshots__/test_main.ambr b/tests/safeds_stubgen/__snapshots__/test_main.ambr index d58967af..5d7be957 100644 --- a/tests/safeds_stubgen/__snapshots__/test_main.ambr +++ b/tests/safeds_stubgen/__snapshots__/test_main.ambr @@ -76,7 +76,7 @@ 'is_public': True, 'is_static': True, 'is_type_inferred': True, - 'name': 'arsam', + 'name': 'infer_attr', 'type': dict({ 'kind': 'NamedType', 'name': 'int', @@ -1050,7 +1050,7 @@ }), dict({ 'attributes': list([ - 'test_package/test_module/InferMyTypes/arsam', + 'test_package/test_module/InferMyTypes/infer_attr', 'test_package/test_module/InferMyTypes/init_infer', ]), 'classes': list([ @@ -1081,7 +1081,7 @@ 'id': 'test_package/test_module/InferMyTypes', 'is_public': True, 'methods': list([ - 'test_package/test_module/InferMyTypes/arsam_function', + 'test_package/test_module/InferMyTypes/infer_function', ]), 'name': 'InferMyTypes', 'reexported_by': list([ @@ -1777,7 +1777,7 @@ 'is_class_method': False, 'is_public': True, 'is_static': True, - 'name': 'arsam_function', + 'name': 'infer_function', 'parameters': list([ 'test_package/test_module/InferMyTypes/infer_function/infer_param', 'test_package/test_module/InferMyTypes/infer_function/infer_param_2', @@ -1785,13 +1785,13 @@ 'reexported_by': list([ ]), 'results': list([ - 'test_package/test_module/InferMyTypes/arsam_function/result_1', - 'test_package/test_module/InferMyTypes/arsam_function/result_2', - 'test_package/test_module/InferMyTypes/arsam_function/result_3', - 'test_package/test_module/InferMyTypes/arsam_function/result_4', - 'test_package/test_module/InferMyTypes/arsam_function/result_5', - 'test_package/test_module/InferMyTypes/arsam_function/result_6', - 'test_package/test_module/InferMyTypes/arsam_function/result_7', + 'test_package/test_module/InferMyTypes/infer_function/result_1', + 'test_package/test_module/InferMyTypes/infer_function/result_2', + 'test_package/test_module/InferMyTypes/infer_function/result_3', + 'test_package/test_module/InferMyTypes/infer_function/result_4', + 'test_package/test_module/InferMyTypes/infer_function/result_5', + 'test_package/test_module/InferMyTypes/infer_function/result_6', + 'test_package/test_module/InferMyTypes/infer_function/result_7', ]), }), dict({ diff --git a/tests/safeds_stubgen/api_analyzer/test_types.py b/tests/safeds_stubgen/api_analyzer/test_types.py index 03ff5b16..bb25fdf5 100644 --- a/tests/safeds_stubgen/api_analyzer/test_types.py +++ b/tests/safeds_stubgen/api_analyzer/test_types.py @@ -56,6 +56,7 @@ def test_correct_hash() -> None: min_inclusive=True, max_inclusive=True, ), + is_type_inferred=False, is_public=True, is_static=True, docstring=AttributeDocstring(), From 6b0e74ea81e76e73f348900fe93e97ba85aaca9f Mon Sep 17 00:00:00 2001 From: Arsam Date: Sat, 18 Nov 2023 18:46:20 +0100 Subject: [PATCH 042/109] Issue #34: Test and bug fixes --- .../api_analyzer/_ast_visitor.py | 21 +++++++++----- .../__snapshots__/test_main.ambr | 29 +++++++++---------- 2 files changed, 27 insertions(+), 23 deletions(-) diff --git a/src/safeds_stubgen/api_analyzer/_ast_visitor.py b/src/safeds_stubgen/api_analyzer/_ast_visitor.py index 70a07cea..08375b49 100644 --- a/src/safeds_stubgen/api_analyzer/_ast_visitor.py +++ b/src/safeds_stubgen/api_analyzer/_ast_visitor.py @@ -318,23 +318,27 @@ def leave_assignmentstmt(self, _: mp_nodes.AssignmentStmt) -> None: @staticmethod def _get_types_from_return_stmts(return_stmts: list[mp_nodes.ReturnStmt]) -> list[sds_types.AbstractType]: - types = [] + types = set() for return_stmt in return_stmts: expr = return_stmt.expr if isinstance(expr, mp_nodes.NameExpr): if expr.name in {"False", "True"}: - types.append(sds_types.NamedType(name="bool")) + types.add(sds_types.NamedType(name="bool")) else: - types.append(sds_types.NamedType(name=expr.name)) + types.add(sds_types.NamedType(name=expr.name)) elif isinstance(expr, mp_nodes.IntExpr): - types.append(sds_types.NamedType(name="int")) + types.add(sds_types.NamedType(name="int")) elif isinstance(expr, mp_nodes.FloatExpr): - types.append(sds_types.NamedType(name="float")) + types.add(sds_types.NamedType(name="float")) elif isinstance(expr, mp_nodes.StrExpr): - types.append(sds_types.NamedType(name="str")) + types.add(sds_types.NamedType(name="str")) else: # pragma: no cover raise TypeError("Unexpected expression type for return type.") - return types + + # We have to sort the list for the snapshot tests + return_types = list(types) + return_types.sort(key=lambda x: x.name) + return return_types def _create_result(self, node: mp_nodes.FuncDef, function_id: str) -> list[Result]: # __init__ functions aren't supposed to have returns, so we can ignore them @@ -481,6 +485,9 @@ def _create_attribute( # MemberExpr are constructor (__init__) attributes if isinstance(attribute, mp_nodes.MemberExpr): attribute_type = node.type + if isinstance(attribute_type, mp_types.AnyType) and mp_types.TypeOfAny.unannotated: + attribute_type = None + # Sometimes the is_inferred value is True even thoght has_explicit_value is False, thus we HAVE to check # has_explicit_value, too. is_type_inferred = node.is_inferred and node.has_explicit_value diff --git a/tests/safeds_stubgen/__snapshots__/test_main.ambr b/tests/safeds_stubgen/__snapshots__/test_main.ambr index 5d7be957..2ca23c95 100644 --- a/tests/safeds_stubgen/__snapshots__/test_main.ambr +++ b/tests/safeds_stubgen/__snapshots__/test_main.ambr @@ -91,12 +91,9 @@ 'id': 'test_package/test_module/InferMyTypes/init_infer', 'is_public': True, 'is_static': False, - 'is_type_inferred': True, + 'is_type_inferred': False, 'name': 'init_infer', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'int', - }), + 'type': None, }), dict({ 'docstring': dict({ @@ -3243,7 +3240,7 @@ 'name': 'result_1', 'type': dict({ 'kind': 'NamedType', - 'name': 'bool', + 'name': 'InferMyTypes', }), }), dict({ @@ -3256,7 +3253,7 @@ 'name': 'result_2', 'type': dict({ 'kind': 'NamedType', - 'name': 'int', + 'name': 'None', }), }), dict({ @@ -3264,12 +3261,12 @@ 'description': '', 'type': '', }), - 'id': 'test_package/test_module/InferMyTypes/infer_function/result_4', + 'id': 'test_package/test_module/InferMyTypes/infer_function/result_3', 'is_type_inferred': True, 'name': 'result_3', 'type': dict({ 'kind': 'NamedType', - 'name': 'InferMyTypes', + 'name': 'SomeClass', }), }), dict({ @@ -3277,12 +3274,12 @@ 'description': '', 'type': '', }), - 'id': 'test_package/test_module/InferMyTypes/infer_function/result_5', + 'id': 'test_package/test_module/InferMyTypes/infer_function/result_4', 'is_type_inferred': True, 'name': 'result_4', 'type': dict({ 'kind': 'NamedType', - 'name': 'None', + 'name': 'bool', }), }), dict({ @@ -3290,7 +3287,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/test_module/InferMyTypes/infer_function/result_6', + 'id': 'test_package/test_module/InferMyTypes/infer_function/result_5', 'is_type_inferred': True, 'name': 'result_5', 'type': dict({ @@ -3303,12 +3300,12 @@ 'description': '', 'type': '', }), - 'id': 'test_package/test_module/InferMyTypes/infer_function/result_7', + 'id': 'test_package/test_module/InferMyTypes/infer_function/result_6', 'is_type_inferred': True, 'name': 'result_6', 'type': dict({ 'kind': 'NamedType', - 'name': 'str', + 'name': 'int', }), }), dict({ @@ -3316,12 +3313,12 @@ 'description': '', 'type': '', }), - 'id': 'test_package/test_module/InferMyTypes/infer_function/result_8', + 'id': 'test_package/test_module/InferMyTypes/infer_function/result_7', 'is_type_inferred': True, 'name': 'result_7', 'type': dict({ 'kind': 'NamedType', - 'name': 'SomeClass', + 'name': 'str', }), }), dict({ From 46e75febbdff70361546b885e487cfdd47af430c Mon Sep 17 00:00:00 2001 From: Arsam Date: Sat, 18 Nov 2023 19:42:10 +0100 Subject: [PATCH 043/109] Issue #34: Test and bug fixes --- .../api_analyzer/_ast_visitor.py | 26 ++++++++++++------- .../__snapshots__/test_generate_stubs.ambr | 10 ++++--- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/safeds_stubgen/api_analyzer/_ast_visitor.py b/src/safeds_stubgen/api_analyzer/_ast_visitor.py index 08375b49..37f2438a 100644 --- a/src/safeds_stubgen/api_analyzer/_ast_visitor.py +++ b/src/safeds_stubgen/api_analyzer/_ast_visitor.py @@ -554,18 +554,19 @@ def _parse_parameter_data(self, node: mp_nodes.FuncDef, function_id: str) -> lis raise ValueError("Argument has no type.") type_annotation = argument.type_annotation - if (isinstance(type_annotation, mp_types.UnboundType) and - type_annotation.name == "list" and - len(type_annotation.args) >= 2): + arg_type = None + if isinstance(mypy_type, mp_types.AnyType) and mp_types.TypeOfAny.unannotated: + # We try to infer the type through the default value later, if possible + pass + elif (isinstance(type_annotation, mp_types.UnboundType) and + type_annotation.name == "list" and + len(type_annotation.args) >= 2): # A special case where the argument is a list with multiple types. We have to handle this case like this # b/c something like list[int, str] is not allowed according to PEP and therefore not handled the normal # way in Mypy. arg_type = mypy_type_to_abstract_type(type_annotation) elif type_annotation is not None: arg_type = mypy_type_to_abstract_type(mypy_type) - else: - # We try to infer the type through the default value later, if possible - arg_type = None # Get default value information default_value = None @@ -574,8 +575,9 @@ def _parse_parameter_data(self, node: mp_nodes.FuncDef, function_id: str) -> lis if initializer is not None: if not hasattr(initializer, "value"): if isinstance(initializer, mp_nodes.CallExpr): - # Special case when the default is a call expression - value = None + # Special case when the default is a call expression, we set the value to tuple, so that it will + # be ignored later on when creating the default_value + value = tuple elif hasattr(initializer, "name"): if initializer.name == "None": value = None @@ -583,8 +585,12 @@ def _parse_parameter_data(self, node: mp_nodes.FuncDef, function_id: str) -> lis value = True elif initializer.name == "False": value = False - else: # pragma: no cover - raise ValueError("No value found for parameter") + else: + # Todo Frage: We don't support other classes as type hints for parameters + # (Wenn z.B. ein Parameter eine Klasse als default value hat) + # Thus we set the value to tuple, so that it will be ignored later on when creating the + # default_value + value = tuple else: # pragma: no cover raise ValueError("No value found for parameter") else: diff --git a/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr b/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr index f44217da..67bc37fd 100644 --- a/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr +++ b/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr @@ -162,13 +162,14 @@ none: Nothing? ) + // TODO Safe-DS does not support required but name only parameter assignments. @PythonName("param_position") fun paramPosition( self, a, b: Boolean, c: Int = 1, - d: A, + d, e: Int = 1 ) @@ -247,15 +248,16 @@ class InferMyTypes( @PythonName("init_param") initParam: Int = 1 ) { - static attr infer_attr: Int + @PythonName("infer_attr") + static attr inferAttr: Int @PythonName("init_infer") - attr initInfer: Any + attr initInfer @PythonName("infer_function") static fun inferFunction( @PythonName("infer_param") inferParam: Int = 1, @PythonName("infer_param_2") inferParam2: Int = Something - ) -> (result1: Boolean, result2: Int, result3: InferMyTypes, result4: Nothing?, result5: Float, result6: String, result7: SomeClass) + ) -> (result1: InferMyTypes, result2: Nothing?, result3: SomeClass, result4: Boolean, result5: Float, result6: Int, result7: String) } ''' From fa6c5ab20f7564d33efbbe2b45206ff54b510da8 Mon Sep 17 00:00:00 2001 From: Arsam Date: Sat, 18 Nov 2023 19:44:57 +0100 Subject: [PATCH 044/109] Issue #34: Test and bug fixes --- tests/safeds_stubgen/__snapshots__/test_main.ambr | 9 +++------ .../api_analyzer/__snapshots__/test__get_api.ambr | 9 +++------ 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/tests/safeds_stubgen/__snapshots__/test_main.ambr b/tests/safeds_stubgen/__snapshots__/test_main.ambr index 2ca23c95..07b0f576 100644 --- a/tests/safeds_stubgen/__snapshots__/test_main.ambr +++ b/tests/safeds_stubgen/__snapshots__/test_main.ambr @@ -3066,13 +3066,10 @@ 'type': '', }), 'id': 'test_package/test_module/SomeClass/test_position/param4', - 'is_optional': True, - 'is_type_inferred': True, + 'is_optional': False, + 'is_type_inferred': False, 'name': 'param4', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'None', - }), + 'type': None, }), dict({ 'assigned_by': 'NAME_ONLY', diff --git a/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr b/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr index 42ba433b..5c08c6c1 100644 --- a/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr +++ b/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr @@ -2356,13 +2356,10 @@ 'type': '', }), 'id': 'test_package/test_module/SomeClass/test_position/param4', - 'is_optional': True, - 'is_type_inferred': True, + 'is_optional': False, + 'is_type_inferred': False, 'name': 'param4', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'None', - }), + 'type': None, }), dict({ 'assigned_by': 'NAME_ONLY', From 9eb19f584a468577bac5d9d7b83a1b1e0b368cf6 Mon Sep 17 00:00:00 2001 From: Arsam Date: Mon, 20 Nov 2023 19:02:32 +0100 Subject: [PATCH 045/109] Issue #34: Added TODOs for the stub generator if parameters, attributes or results have no type information. --- .../stubs_generator/_generate_stubs.py | 14 +++++++++++-- .../__snapshots__/test_generate_stubs.ambr | 21 ++++++++++++++++++- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/safeds_stubgen/stubs_generator/_generate_stubs.py b/src/safeds_stubgen/stubs_generator/_generate_stubs.py index 17fab906..cbb65df2 100644 --- a/src/safeds_stubgen/stubs_generator/_generate_stubs.py +++ b/src/safeds_stubgen/stubs_generator/_generate_stubs.py @@ -166,6 +166,8 @@ def _create_class_string(self, class_: Class, class_indentation: str = "") -> st attribute_type = None if attribute.type: attribute_type = attribute.type.to_dict() + else: + self._current_todo_msgs.add("attr without type") static_string = "static " if attribute.is_static else "" @@ -247,12 +249,14 @@ def _create_function_string(self, function: Function, indentations: str = "", is if camel_case_name != name: function_name_annotation = f"{indentations}{self._create_name_annotation(name)}\n" + result_string = self._create_result_string(function.results) + # Create string and return return ( f"{self._create_todo_msg(indentations)}" f"{function_name_annotation}" f"{indentations}{static}fun {camel_case_name}({func_params})" - f"{self._create_result_string(function.results)}" + f"{result_string}" ) def _create_result_string(self, function_results: list[Result]) -> str: @@ -272,6 +276,7 @@ def _create_result_string(self, function_results: list[Result]) -> str: if len(results) == 1: return f" -> {results[0]}" return f" -> ({', '.join(results)})" + self._current_todo_msgs.add("result without type") return "" def _create_parameter_string( @@ -316,6 +321,8 @@ def _create_parameter_string( # Parameter type param_type = self._create_type_string(parameter_type_data) type_string = f": {param_type}" if param_type else "" + else: + self._current_todo_msgs.add("param without type") # Check if assigned_by is not illegal if assigned_by == ParameterAssignment.POSITION_ONLY and parameter.default_value is not None: @@ -546,7 +553,10 @@ def _create_todo_msg(self, indentations: str) -> str: "REQ_NAME_ONLY": "Safe-DS does not support required but name only parameter assignments.", "multiple_inheritance": "Safe-DS does not support multiple inheritance.", "variadic": "Safe-DS does not support variadic parameters.", - "class_method": "Safe-DS does not support class methods", + "class_method": "Safe-DS does not support class methods.", + "param without type": "Some parameter have no type information.", + "attr without type": "Attribute has no type information.", + "result without type": "Result type information missing.", }[msg] for msg in self._current_todo_msgs ] diff --git a/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr b/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr index 67bc37fd..2835bd93 100644 --- a/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr +++ b/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr @@ -75,6 +75,7 @@ a: Int, b: A? ) sub A { + // TODO Result type information missing. fun f() } @@ -85,6 +86,7 @@ @PythonName("attr_2") static attr attr2: Int + // TODO Result type information missing. fun f1() } @@ -130,9 +132,11 @@ from typing import Callable + // TODO Result type information missing. @PythonName("public_no_params_no_result") fun publicNoParamsNoResult() + // TODO Result type information missing. fun params( i: Int, `union`: union, @@ -141,6 +145,7 @@ ) // TODO List type has to many type arguments. + // TODO Result type information missing. // TODO Safe-DS does not support tuple types. @PythonName("illegal_params") fun illegalParams( @@ -150,6 +155,7 @@ `_`: Int = String ) + // TODO Result type information missing. @PythonName("special_params") fun specialParams( @PythonName("none_union") noneUnion: Nothing?, @@ -162,7 +168,9 @@ none: Nothing? ) + // TODO Result type information missing. // TODO Safe-DS does not support required but name only parameter assignments. + // TODO Some parameter have no type information. @PythonName("param_position") fun paramPosition( self, @@ -173,26 +181,33 @@ e: Int = 1 ) + // TODO Result type information missing. // TODO Safe-DS does not support optional but position only parameter assignments. + // TODO Some parameter have no type information. @PythonName("opt_pos_only") fun optPosOnly( required, optional: Int = 1 ) + // TODO Result type information missing. // TODO Safe-DS does not support required but name only parameter assignments. + // TODO Some parameter have no type information. @PythonName("req_name_only") fun reqNameOnly( required, optional: Int = 1 ) + // TODO Result type information missing. // TODO Safe-DS does not support variadic parameters. + // TODO Some parameter have no type information. fun arg( args, kwargs ) + // TODO Result type information missing. // TODO Safe-DS does not support variadic parameters. @PythonName("args_type") fun argsType( @@ -213,6 +228,7 @@ class A() + // TODO Some parameter have no type information. class B( @PythonName("init_param") initParam ) { @@ -221,10 +237,12 @@ a: A ) -> result1: A + // TODO Result type information missing. @PythonName("static_method") static fun staticMethod() - // TODO Safe-DS does not support class methods + // TODO Result type information missing. + // TODO Safe-DS does not support class methods. @PythonName("class_method") static fun classMethod() } @@ -250,6 +268,7 @@ ) { @PythonName("infer_attr") static attr inferAttr: Int + // TODO Attribute has no type information. @PythonName("init_infer") attr initInfer From 69d421f5f2fa17ab94af9c658df883c84849e94d Mon Sep 17 00:00:00 2001 From: Arsam Date: Tue, 21 Nov 2023 00:35:15 +0100 Subject: [PATCH 046/109] Issue #35 & #36 added variance parsing api_analyzer; added variance and constraints to stubs generator --- src/safeds_stubgen/api_analyzer/__init__.py | 2 + src/safeds_stubgen/api_analyzer/_api.py | 22 ++ .../api_analyzer/_ast_visitor.py | 39 +++ .../api_analyzer/_mypy_helpers.py | 18 +- src/safeds_stubgen/api_analyzer/_types.py | 9 +- .../stubs_generator/_generate_stubs.py | 48 +++- tests/data/test_package/test_module.py | 13 + .../test_stub_generation/variance_module.py | 18 ++ .../__snapshots__/test_main.ambr | 144 ++++++++++ .../__snapshots__/test__get_api.ambr | 269 ++++++++++++++++++ .../api_analyzer/test__get_api.py | 20 ++ .../safeds_stubgen/api_analyzer/test_types.py | 12 +- .../__snapshots__/test_generate_stubs.ambr | 19 ++ .../stubs_generator/test_generate_stubs.py | 5 + 14 files changed, 622 insertions(+), 16 deletions(-) create mode 100644 tests/data/test_stub_generation/variance_module.py diff --git a/src/safeds_stubgen/api_analyzer/__init__.py b/src/safeds_stubgen/api_analyzer/__init__.py index 45471b33..5f10161b 100644 --- a/src/safeds_stubgen/api_analyzer/__init__.py +++ b/src/safeds_stubgen/api_analyzer/__init__.py @@ -12,6 +12,7 @@ ParameterAssignment, QualifiedImport, Result, + VarianceType, WildcardImport, ) from ._get_api import get_api @@ -64,5 +65,6 @@ "SetType", "TupleType", "UnionType", + "VarianceType", "WildcardImport", ] diff --git a/src/safeds_stubgen/api_analyzer/_api.py b/src/safeds_stubgen/api_analyzer/_api.py index 52908d36..2934c9e4 100644 --- a/src/safeds_stubgen/api_analyzer/_api.py +++ b/src/safeds_stubgen/api_analyzer/_api.py @@ -174,6 +174,7 @@ class Class: attributes: list[Attribute] = field(default_factory=list) methods: list[Function] = field(default_factory=list) classes: list[Class] = field(default_factory=list) + variances: list[Variance] = field(default_factory=list) def to_dict(self) -> dict[str, Any]: return { @@ -187,6 +188,7 @@ def to_dict(self) -> dict[str, Any]: "attributes": [attribute.id for attribute in self.attributes], "methods": [method.id for method in self.methods], "classes": [class_.id for class_ in self.classes], + "variances": [variance.to_dict() for variance in self.variances], } def add_method(self, method: Function) -> None: @@ -303,6 +305,26 @@ class ParameterAssignment(PythonEnum): NAMED_VARARG = "NAMED_VARARG" +@dataclass(frozen=True) +class Variance: + name: str + type: AbstractType + variance_type: VarianceType + + def to_dict(self): + return { + "name": self.name, + "type": self.type.to_dict(), + "variance_type": self.variance_type.name + } + + +class VarianceType(PythonEnum): + CONTRAVARIANT = "CONTRAVARIANT" + COVARIANT = "COVARIANT" + INVARIANT = "INVARIANT" + + @dataclass(frozen=True) class Result: id: str diff --git a/src/safeds_stubgen/api_analyzer/_ast_visitor.py b/src/safeds_stubgen/api_analyzer/_ast_visitor.py index 37f2438a..a85a13d1 100644 --- a/src/safeds_stubgen/api_analyzer/_ast_visitor.py +++ b/src/safeds_stubgen/api_analyzer/_ast_visitor.py @@ -19,6 +19,8 @@ Parameter, QualifiedImport, Result, + Variance, + VarianceType, WildcardImport, ) from ._mypy_helpers import ( @@ -28,6 +30,7 @@ get_funcdef_definitions, get_mypyfile_definitions, mypy_type_to_abstract_type, + mypy_variance_parser, ) if TYPE_CHECKING: @@ -120,6 +123,41 @@ def enter_classdef(self, node: mp_nodes.ClassDef) -> None: # Get docstring docstring = self.docstring_parser.get_class_documentation(node) + # Variance + # Special base classes like Generic[...] get moved to "removed_base_type_expr" during semantic analysis of mypy + generic_exprs = [ + removed_base_type_expr + for removed_base_type_expr in node.removed_base_type_exprs + if removed_base_type_expr.base.name == "Generic" + ] + variances = [] + if generic_exprs: + # Can only be one, since a class can inherit "Generic" only one time + generic_expr = generic_exprs[0].index + + if isinstance(generic_expr, mp_nodes.TupleExpr): + generic_types = [item.node for item in generic_expr.items] + elif isinstance(generic_expr, mp_nodes.NameExpr): + generic_types = [generic_expr.node] + else: # pragma: no cover + raise TypeError("Unexpected type while parsing generic type.") + + for generic_type in generic_types: + variance_type = mypy_variance_parser(generic_type.variance) + if variance_type == VarianceType.INVARIANT: + variance_values = sds_types.UnionType([ + mypy_type_to_abstract_type(value) + for value in generic_type.values + ]) + else: + variance_values = mypy_type_to_abstract_type(generic_type.upper_bound) + + variances.append(Variance( + name=generic_type.name, + type=variance_values, + variance_type=variance_type + )) + # superclasses # Todo Aliasing: Werden noch nicht aufgelöst superclasses = [superclass.fullname for superclass in node.base_type_exprs if hasattr(superclass, "fullname")] @@ -144,6 +182,7 @@ def enter_classdef(self, node: mp_nodes.ClassDef) -> None: docstring=docstring, reexported_by=reexported_by, constructor_fulldocstring=constructor_fulldocstring, + variances=variances ) self.__declaration_stack.append(class_) diff --git a/src/safeds_stubgen/api_analyzer/_mypy_helpers.py b/src/safeds_stubgen/api_analyzer/_mypy_helpers.py index 18f6988a..da16b14b 100644 --- a/src/safeds_stubgen/api_analyzer/_mypy_helpers.py +++ b/src/safeds_stubgen/api_analyzer/_mypy_helpers.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, Literal import mypy.types as mp_types from mypy import nodes as mp_nodes @@ -9,7 +9,7 @@ import safeds_stubgen.api_analyzer._types as sds_types -from ._api import ParameterAssignment +from ._api import ParameterAssignment, VarianceType if TYPE_CHECKING: from mypy.nodes import ClassDef, FuncDef, MypyFile @@ -57,6 +57,8 @@ def mypy_type_to_abstract_type(mypy_type: Instance | ProperType | MypyType) -> A return sds_types.NamedType(name="Any") elif isinstance(mypy_type, mp_types.NoneType): return sds_types.NamedType(name="None") + elif isinstance(mypy_type, mp_types.LiteralType): + return sds_types.LiteralType(literal=mypy_type.value) elif isinstance(mypy_type, mp_types.UnboundType): if mypy_type.name == "list": return sds_types.ListType(types=[ @@ -141,3 +143,15 @@ def find_return_stmts_recursive(stmts: list[mp_nodes.Statement]) -> list[mp_node return_stmts.append(stmt) return return_stmts + + +def mypy_variance_parser(mypy_variance_type: Literal[0, 1, 2]) -> VarianceType: + match mypy_variance_type: + case 0: + return VarianceType.INVARIANT + case 1: + return VarianceType.COVARIANT + case 2: + return VarianceType.CONTRAVARIANT + case _: # pragma: no cover + raise ValueError("Mypy variance parser received an illegal parameter value.") diff --git a/src/safeds_stubgen/api_analyzer/_types.py b/src/safeds_stubgen/api_analyzer/_types.py index 43be968a..714edce0 100644 --- a/src/safeds_stubgen/api_analyzer/_types.py +++ b/src/safeds_stubgen/api_analyzer/_types.py @@ -349,18 +349,17 @@ def __hash__(self) -> int: @dataclass(frozen=True) class LiteralType(AbstractType): - literals: list[str | int | float | bool] + literal: str | int | float | bool @classmethod def from_dict(cls, d: dict[str, Any]) -> LiteralType: - literals = list(d["literals"]) - return LiteralType(literals) + return LiteralType(d["literal"]) def to_dict(self) -> dict[str, Any]: - return {"kind": self.__class__.__name__, "literals": self.literals} + return {"kind": self.__class__.__name__, "literal": self.literal} def __hash__(self) -> int: - return hash(frozenset(self.literals)) + return hash(frozenset([self.literal])) @dataclass(frozen=True) diff --git a/src/safeds_stubgen/stubs_generator/_generate_stubs.py b/src/safeds_stubgen/stubs_generator/_generate_stubs.py index cbb65df2..50265274 100644 --- a/src/safeds_stubgen/stubs_generator/_generate_stubs.py +++ b/src/safeds_stubgen/stubs_generator/_generate_stubs.py @@ -2,7 +2,7 @@ import string from pathlib import Path -from typing import Generator +from typing import TYPE_CHECKING from safeds_stubgen.api_analyzer import ( API, @@ -14,9 +14,13 @@ ParameterAssignment, QualifiedImport, Result, + VarianceType, WildcardImport, ) +if TYPE_CHECKING: + from collections.abc import Generator + def generate_stubs(api: API, out_path: Path) -> None: """Generate Safe-DS stubs. @@ -151,10 +155,48 @@ def _create_class_string(self, class_: Class, class_indentation: str = "") -> st if len(superclasses) > 1: self._current_todo_msgs.add("multiple_inheritance") + # Variance & Constrains + constraints_info = "" + variance_info = "" + if class_.variances: + constraints = [] + variances = [] + for variance in class_.variances: + match variance.variance_type.name: + case VarianceType.INVARIANT.name: + variance_inheritance = "" + variance_direction = "" + case VarianceType.COVARIANT.name: + variance_inheritance = "sub" + variance_direction = "out " + case VarianceType.CONTRAVARIANT.name: + variance_inheritance = "super" + variance_direction = "in " + case _: # pragma: no cover + raise ValueError(f"Expected variance kind, got {variance.variance_type.name}.") + + # Convert name to camelCase and check for keywords + variance_name_camel_case = _convert_snake_to_camel_case(variance.name) + variance_name_camel_case = self._replace_if_safeds_keyword(variance_name_camel_case) + + variances.append(f"{variance_direction}{variance_name_camel_case}") + if variance_inheritance: + constraints.append( + f"{variance_name_camel_case} {variance_inheritance} " + f"{self._create_type_string(variance.type.to_dict())}" + ) + + if variances: + variance_info = f"<{', '.join(variances)}>" + + if constraints: + constraints_info_inner = f",\n{inner_indentations}".join(constraints) + constraints_info = f" where {{\n{inner_indentations}{constraints_info_inner}\n}}" + # Class signature line class_signature = ( f"{class_indentation}{self._create_todo_msg(class_indentation)}class " - f"{class_.name}({parameter_info}){superclass_info}" + f"{class_.name}{variance_info}({parameter_info}){superclass_info}{constraints_info}" ) # Attributes @@ -524,7 +566,7 @@ def _create_type_string(self, type_data: dict | None) -> str: return f"Map<{key_data}>" return "Map" elif kind == "LiteralType": - return f"literal<{', '.join(type_data['literals'])}>" + return f"literal<{type_data['literal']}>" raise ValueError(f"Unexpected type: {kind}") diff --git a/tests/data/test_package/test_module.py b/tests/data/test_package/test_module.py index 41cd9114..f1afd76f 100644 --- a/tests/data/test_package/test_module.py +++ b/tests/data/test_package/test_module.py @@ -174,3 +174,16 @@ def infer_function(infer_param=1, infer_param_2: int = "Something"): return SomeClass return int + + +_T_co = TypeVar("_T_co", covariant=True, bound=str) +_T_con = TypeVar("_T_con", contravariant=True, bound=SomeClass) +_T_in = TypeVar("_T_in", int, Literal[1, 2]) + + +class VarianceClassAll(Generic[_T_co, _T_con, _T_in]): + ... + + +class VarianceClassOnlyInvariance(Generic[_T_in]): + ... diff --git a/tests/data/test_stub_generation/variance_module.py b/tests/data/test_stub_generation/variance_module.py new file mode 100644 index 00000000..acbac3ef --- /dev/null +++ b/tests/data/test_stub_generation/variance_module.py @@ -0,0 +1,18 @@ +from typing import Generic, TypeVar, Literal + + +class A: + ... + + +_T_co = TypeVar("_T_co", covariant=True, bound=str) +_T_con = TypeVar("_T_con", contravariant=True, bound=A) +_T_in = TypeVar("_T_in", int, Literal[1, 2]) + + +class VarianceClassAll(Generic[_T_co, _T_con, _T_in]): + ... + + +class VarianceClassOnlyInvariance(Generic[_T_in]): + ... diff --git a/tests/safeds_stubgen/__snapshots__/test_main.ambr b/tests/safeds_stubgen/__snapshots__/test_main.ambr index 07b0f576..cef46b96 100644 --- a/tests/safeds_stubgen/__snapshots__/test_main.ambr +++ b/tests/safeds_stubgen/__snapshots__/test_main.ambr @@ -726,6 +726,8 @@ ]), 'superclasses': list([ ]), + 'variances': list([ + ]), }), dict({ 'attributes': list([ @@ -746,6 +748,8 @@ ]), 'superclasses': list([ ]), + 'variances': list([ + ]), }), dict({ 'attributes': list([ @@ -767,6 +771,8 @@ ]), 'superclasses': list([ ]), + 'variances': list([ + ]), }), dict({ 'attributes': list([ @@ -788,6 +794,8 @@ ]), 'superclasses': list([ ]), + 'variances': list([ + ]), }), dict({ 'attributes': list([ @@ -808,6 +816,8 @@ ]), 'superclasses': list([ ]), + 'variances': list([ + ]), }), dict({ 'attributes': list([ @@ -862,6 +872,8 @@ ]), 'superclasses': list([ ]), + 'variances': list([ + ]), }), dict({ 'attributes': list([ @@ -922,6 +934,8 @@ ]), 'superclasses': list([ ]), + 'variances': list([ + ]), }), dict({ 'attributes': list([ @@ -990,6 +1004,8 @@ ]), 'superclasses': list([ ]), + 'variances': list([ + ]), }), dict({ 'attributes': list([ @@ -1044,6 +1060,8 @@ ]), 'superclasses': list([ ]), + 'variances': list([ + ]), }), dict({ 'attributes': list([ @@ -1085,6 +1103,8 @@ ]), 'superclasses': list([ ]), + 'variances': list([ + ]), }), dict({ 'attributes': list([ @@ -1177,6 +1197,8 @@ 'superclasses': list([ 'tests.data.test_package.test_module.AcDoubleAlias', ]), + 'variances': list([ + ]), }), dict({ 'attributes': list([ @@ -1199,6 +1221,120 @@ 'superclasses': list([ 'tests.data.test_package.another_path.another_module.AnotherClass', ]), + 'variances': list([ + ]), + }), + dict({ + 'attributes': list([ + ]), + 'classes': list([ + ]), + 'constructor': None, + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_package/test_module/VarianceClassAll', + 'is_public': True, + 'methods': list([ + ]), + 'name': 'VarianceClassAll', + 'reexported_by': list([ + ]), + 'superclasses': list([ + ]), + 'variances': list([ + dict({ + 'name': '_T_co', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'str', + }), + 'variance_type': 'COVARIANT', + }), + dict({ + 'name': '_T_con', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'SomeClass', + }), + 'variance_type': 'CONTRAVARIANT', + }), + dict({ + 'name': '_T_in', + 'type': dict({ + 'kind': 'UnionType', + 'types': list([ + dict({ + 'kind': 'NamedType', + 'name': 'int', + }), + dict({ + 'kind': 'UnionType', + 'types': list([ + dict({ + 'kind': 'LiteralType', + 'literal': 1, + }), + dict({ + 'kind': 'LiteralType', + 'literal': 2, + }), + ]), + }), + ]), + }), + 'variance_type': 'INVARIANT', + }), + ]), + }), + dict({ + 'attributes': list([ + ]), + 'classes': list([ + ]), + 'constructor': None, + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_package/test_module/VarianceClassOnlyInvariance', + 'is_public': True, + 'methods': list([ + ]), + 'name': 'VarianceClassOnlyInvariance', + 'reexported_by': list([ + ]), + 'superclasses': list([ + ]), + 'variances': list([ + dict({ + 'name': '_T_in', + 'type': dict({ + 'kind': 'UnionType', + 'types': list([ + dict({ + 'kind': 'NamedType', + 'name': 'int', + }), + dict({ + 'kind': 'UnionType', + 'types': list([ + dict({ + 'kind': 'LiteralType', + 'literal': 1, + }), + dict({ + 'kind': 'LiteralType', + 'literal': 2, + }), + ]), + }), + ]), + }), + 'variance_type': 'INVARIANT', + }), + ]), }), dict({ 'attributes': list([ @@ -1240,6 +1376,8 @@ ]), 'superclasses': list([ ]), + 'variances': list([ + ]), }), dict({ 'attributes': list([ @@ -1263,6 +1401,8 @@ ]), 'superclasses': list([ ]), + 'variances': list([ + ]), }), dict({ 'attributes': list([ @@ -1283,6 +1423,8 @@ ]), 'superclasses': list([ ]), + 'variances': list([ + ]), }), ]), 'distribution': '', @@ -2320,6 +2462,8 @@ 'test_package/test_module/SomeClass', 'test_package/test_module/_PrivateClass', 'test_package/test_module/InferMyTypes', + 'test_package/test_module/VarianceClassAll', + 'test_package/test_module/VarianceClassOnlyInvariance', ]), 'docstring': 'Docstring of the some_class.py module.', 'enums': list([ diff --git a/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr b/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr index 5c08c6c1..f89871dc 100644 --- a/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr +++ b/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr @@ -764,6 +764,36 @@ }), ]) # --- +# name: test_class_methods_InferMyTypes + list([ + dict({ + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_package/test_module/InferMyTypes/infer_function', + 'is_class_method': False, + 'is_public': True, + 'is_static': True, + 'name': 'infer_function', + 'parameters': list([ + 'test_package/test_module/InferMyTypes/infer_function/infer_param', + 'test_package/test_module/InferMyTypes/infer_function/infer_param_2', + ]), + 'reexported_by': list([ + ]), + 'results': list([ + 'test_package/test_module/InferMyTypes/infer_function/result_1', + 'test_package/test_module/InferMyTypes/infer_function/result_2', + 'test_package/test_module/InferMyTypes/infer_function/result_3', + 'test_package/test_module/InferMyTypes/infer_function/result_4', + 'test_package/test_module/InferMyTypes/infer_function/result_5', + 'test_package/test_module/InferMyTypes/infer_function/result_6', + 'test_package/test_module/InferMyTypes/infer_function/result_7', + ]), + }), + ]) +# --- # name: test_class_methods_NestedClass list([ dict({ @@ -1151,6 +1181,8 @@ ]), 'superclasses': list([ ]), + 'variances': list([ + ]), }) # --- # name: test_classes_EpydocDocstringClass @@ -1200,6 +1232,8 @@ ]), 'superclasses': list([ ]), + 'variances': list([ + ]), }) # --- # name: test_classes_FourthReexportClass @@ -1223,6 +1257,8 @@ ]), 'superclasses': list([ ]), + 'variances': list([ + ]), }) # --- # name: test_classes_GoogleDocstringClass @@ -1279,6 +1315,8 @@ ]), 'superclasses': list([ ]), + 'variances': list([ + ]), }) # --- # name: test_classes_NestedClass @@ -1303,6 +1341,8 @@ 'superclasses': list([ 'tests.data.test_package.another_path.another_module.AnotherClass', ]), + 'variances': list([ + ]), }) # --- # name: test_classes_NestedNestedPrivateClass @@ -1325,6 +1365,8 @@ ]), 'superclasses': list([ ]), + 'variances': list([ + ]), }) # --- # name: test_classes_NestedPrivateClass @@ -1350,6 +1392,8 @@ ]), 'superclasses': list([ ]), + 'variances': list([ + ]), }) # --- # name: test_classes_NumpyDocstringClass @@ -1410,6 +1454,8 @@ ]), 'superclasses': list([ ]), + 'variances': list([ + ]), }) # --- # name: test_classes_ReexportClass @@ -1434,6 +1480,8 @@ ]), 'superclasses': list([ ]), + 'variances': list([ + ]), }) # --- # name: test_classes_RestDocstringClass @@ -1483,6 +1531,8 @@ ]), 'superclasses': list([ ]), + 'variances': list([ + ]), }) # --- # name: test_classes_SomeClass @@ -1577,6 +1627,124 @@ 'superclasses': list([ 'tests.data.test_package.test_module.AcDoubleAlias', ]), + 'variances': list([ + ]), + }) +# --- +# name: test_classes_VarianceClassAll + dict({ + 'attributes': list([ + ]), + 'classes': list([ + ]), + 'constructor': None, + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_package/test_module/VarianceClassAll', + 'is_public': True, + 'methods': list([ + ]), + 'name': 'VarianceClassAll', + 'reexported_by': list([ + ]), + 'superclasses': list([ + ]), + 'variances': list([ + dict({ + 'name': '_T_co', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'str', + }), + 'variance_type': 'COVARIANT', + }), + dict({ + 'name': '_T_con', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'SomeClass', + }), + 'variance_type': 'CONTRAVARIANT', + }), + dict({ + 'name': '_T_in', + 'type': dict({ + 'kind': 'UnionType', + 'types': list([ + dict({ + 'kind': 'NamedType', + 'name': 'int', + }), + dict({ + 'kind': 'UnionType', + 'types': list([ + dict({ + 'kind': 'LiteralType', + 'literal': 1, + }), + dict({ + 'kind': 'LiteralType', + 'literal': 2, + }), + ]), + }), + ]), + }), + 'variance_type': 'INVARIANT', + }), + ]), + }) +# --- +# name: test_classes_VarianceClassOnlyInvariance + dict({ + 'attributes': list([ + ]), + 'classes': list([ + ]), + 'constructor': None, + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_package/test_module/VarianceClassOnlyInvariance', + 'is_public': True, + 'methods': list([ + ]), + 'name': 'VarianceClassOnlyInvariance', + 'reexported_by': list([ + ]), + 'superclasses': list([ + ]), + 'variances': list([ + dict({ + 'name': '_T_in', + 'type': dict({ + 'kind': 'UnionType', + 'types': list([ + dict({ + 'kind': 'NamedType', + 'name': 'int', + }), + dict({ + 'kind': 'UnionType', + 'types': list([ + dict({ + 'kind': 'LiteralType', + 'literal': 1, + }), + dict({ + 'kind': 'LiteralType', + 'literal': 2, + }), + ]), + }), + ]), + }), + 'variance_type': 'INVARIANT', + }), + ]), }) # --- # name: test_classes__PrivateClass @@ -1620,6 +1788,8 @@ ]), 'superclasses': list([ ]), + 'variances': list([ + ]), }) # --- # name: test_classes__ThirdReexportClass @@ -1643,6 +1813,8 @@ ]), 'superclasses': list([ ]), + 'variances': list([ + ]), }) # --- # name: test_enum_instances_AnotherTestEnum @@ -2448,6 +2620,101 @@ }), ]) # --- +# name: test_function_results_infer_function + list([ + dict({ + 'docstring': dict({ + 'description': '', + 'type': '', + }), + 'id': 'test_package/test_module/InferMyTypes/infer_function/result_1', + 'is_type_inferred': True, + 'name': 'result_1', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'InferMyTypes', + }), + }), + dict({ + 'docstring': dict({ + 'description': '', + 'type': '', + }), + 'id': 'test_package/test_module/InferMyTypes/infer_function/result_2', + 'is_type_inferred': True, + 'name': 'result_2', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'None', + }), + }), + dict({ + 'docstring': dict({ + 'description': '', + 'type': '', + }), + 'id': 'test_package/test_module/InferMyTypes/infer_function/result_3', + 'is_type_inferred': True, + 'name': 'result_3', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'SomeClass', + }), + }), + dict({ + 'docstring': dict({ + 'description': '', + 'type': '', + }), + 'id': 'test_package/test_module/InferMyTypes/infer_function/result_4', + 'is_type_inferred': True, + 'name': 'result_4', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'bool', + }), + }), + dict({ + 'docstring': dict({ + 'description': '', + 'type': '', + }), + 'id': 'test_package/test_module/InferMyTypes/infer_function/result_5', + 'is_type_inferred': True, + 'name': 'result_5', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'float', + }), + }), + dict({ + 'docstring': dict({ + 'description': '', + 'type': '', + }), + 'id': 'test_package/test_module/InferMyTypes/infer_function/result_6', + 'is_type_inferred': True, + 'name': 'result_6', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'int', + }), + }), + dict({ + 'docstring': dict({ + 'description': '', + 'type': '', + }), + 'id': 'test_package/test_module/InferMyTypes/infer_function/result_7', + 'is_type_inferred': True, + 'name': 'result_7', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'str', + }), + }), + ]) +# --- # name: test_function_results_multiple_results list([ dict({ @@ -2973,6 +3240,8 @@ 'test_package/test_module/SomeClass', 'test_package/test_module/_PrivateClass', 'test_package/test_module/InferMyTypes', + 'test_package/test_module/VarianceClassAll', + 'test_package/test_module/VarianceClassOnlyInvariance', ]), 'docstring': 'Docstring of the some_class.py module.', 'enums': list([ diff --git a/tests/safeds_stubgen/api_analyzer/test__get_api.py b/tests/safeds_stubgen/api_analyzer/test__get_api.py index 68024ceb..3837c93b 100644 --- a/tests/safeds_stubgen/api_analyzer/test__get_api.py +++ b/tests/safeds_stubgen/api_analyzer/test__get_api.py @@ -183,6 +183,16 @@ def test_classes_NestedNestedPrivateClass(snapshot: SnapshotAssertion) -> None: assert class_data == snapshot +def test_classes_VarianceClassAll(snapshot: SnapshotAssertion) -> None: # noqa: N802 + class_data = _get_specific_class_data("VarianceClassAll", "plaintext") + assert class_data == snapshot + + +def test_classes_VarianceClassOnlyInvariance(snapshot: SnapshotAssertion) -> None: # noqa: N802 + class_data = _get_specific_class_data("VarianceClassOnlyInvariance", "plaintext") + assert class_data == snapshot + + def test_classes_EpydocDocstringClass(snapshot: SnapshotAssertion) -> None: # noqa: N802 class_data = _get_specific_class_data("EpydocDocstringClass", "epydoc") assert class_data == snapshot @@ -377,6 +387,11 @@ def test_class_methods_SomeClass(snapshot: SnapshotAssertion) -> None: # noqa: assert class_methods_data == snapshot +def test_class_methods_InferMyTypes(snapshot: SnapshotAssertion) -> None: # noqa: N802 + class_methods_data = get_class_methods_data("InferMyTypes", "plaintext") + assert class_methods_data == snapshot + + def test_class_methods_NestedClass(snapshot: SnapshotAssertion) -> None: # noqa: N802 class_methods_data = get_class_methods_data("NestedClass", "plaintext") assert class_methods_data == snapshot @@ -526,6 +541,11 @@ def test_function_results_multiple_results(snapshot: SnapshotAssertion) -> None: assert function_result_data == snapshot +def test_function_results_infer_function(snapshot: SnapshotAssertion) -> None: + function_result_data = get_function_result_data("infer_function", "InferMyTypes", "plaintext") + assert function_result_data == snapshot + + def test_function_results_static_function(snapshot: SnapshotAssertion) -> None: function_result_data = get_function_result_data("static_function", "SomeClass", "plaintext") assert function_result_data == snapshot diff --git a/tests/safeds_stubgen/api_analyzer/test_types.py b/tests/safeds_stubgen/api_analyzer/test_types.py index bb25fdf5..53ddc329 100644 --- a/tests/safeds_stubgen/api_analyzer/test_types.py +++ b/tests/safeds_stubgen/api_analyzer/test_types.py @@ -229,20 +229,20 @@ def test_optional_type() -> None: def test_literal_type() -> None: - type_ = LiteralType(["Literal_1", 2]) + type_ = LiteralType("Literal_1") type_dict = { "kind": "LiteralType", - "literals": ["Literal_1", 2], + "literal": "Literal_1", } assert AbstractType.from_dict(type_dict) == type_ assert LiteralType.from_dict(type_dict) == type_ assert type_.to_dict() == type_dict - assert LiteralType(["a"]) == LiteralType(["a"]) - assert hash(LiteralType(["a"])) == hash(LiteralType(["a"])) - assert LiteralType(["a"]) != LiteralType(["b"]) - assert hash(LiteralType(["a"])) != hash(LiteralType(["b"])) + assert LiteralType("a") == LiteralType("a") + assert hash(LiteralType("a")) == hash(LiteralType("a")) + assert LiteralType("a") != LiteralType("b") + assert hash(LiteralType("a")) != hash(LiteralType("b")) def test_final_type() -> None: diff --git a/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr b/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr index 2835bd93..aefae482 100644 --- a/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr +++ b/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr @@ -281,3 +281,22 @@ ''' # --- +# name: test_variance_creation + ''' + package test_stub_generation.variance_module + + from typing import Generic + from typing import TypeVar + from typing import Literal + + class A() + + class VarianceClassAll() where { + TCo sub String, + TCon super A + } + + class VarianceClassOnlyInvariance() + + ''' +# --- diff --git a/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py b/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py index eb1f09ab..7740fdb4 100644 --- a/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py +++ b/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py @@ -94,6 +94,11 @@ def test_type_inference(snapshot: SnapshotAssertion) -> None: assert_stubs_snapshot("infer_types_module", snapshot) +# Todo Check snapshot +def test_variance_creation(snapshot: SnapshotAssertion) -> None: + assert_stubs_snapshot("variance_module", snapshot) + + # Todo def test_docstring_creation() -> None: ... From 477a3860e524e50ae906a66da3e4e03435b610fa Mon Sep 17 00:00:00 2001 From: Arsam Date: Tue, 21 Nov 2023 17:33:17 +0100 Subject: [PATCH 047/109] Fixed a bug for the stubs generator --- src/safeds_stubgen/stubs_generator/_generate_stubs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/safeds_stubgen/stubs_generator/_generate_stubs.py b/src/safeds_stubgen/stubs_generator/_generate_stubs.py index 50265274..44c8c939 100644 --- a/src/safeds_stubgen/stubs_generator/_generate_stubs.py +++ b/src/safeds_stubgen/stubs_generator/_generate_stubs.py @@ -54,7 +54,7 @@ def generate_stubs(api: API, out_path: Path) -> None: # the file would look like this: "package path.to.package\n". With the split we can check if the module # has enough information, if not, we won't create it in the first place. if len(module_text.split("\n")) <= 2: - return + continue # Create module dir module_dir = Path(out_path / module.id) From f1bf09fd80d4daff312cfd762955554c94a30f57 Mon Sep 17 00:00:00 2001 From: Arsam Date: Tue, 21 Nov 2023 17:35:46 +0100 Subject: [PATCH 048/109] Big overhaul of the tests: Removed redundant test data files and merged test data packages. Added some new tests and removed redundant tests. --- .../test_main/another_path/another_module.py | 8 + tests/data/test_main/main_test_module.py | 76 + tests/data/test_package/__init__.py | 2 +- .../attribute_module.py | 14 +- tests/data/test_package/class_module.py | 31 + ...test_docstrings.py => docstring_module.py} | 0 .../{test_enums.py => enum_module.py} | 16 +- .../function_module.py | 27 +- .../import_module.py | 0 .../infer_types_module.py | 2 +- .../test_file_creation/__init__.py | 0 .../test_file_creation/_module_2.py | 0 .../test_file_creation/_module_3.py | 0 .../test_file_creation/_module_4.py | 0 .../test_file_creation/_module_6.py | 0 .../test_file_creation/module_1.py | 0 .../test_file_creation/package_1/module_5.py | 0 tests/data/test_package/test_module.py | 189 - .../variance_module.py | 0 .../data/test_stub_generation/class_module.py | 21 - .../data/test_stub_generation/enum_module.py | 23 - .../__snapshots__/test_main.ambr | 3647 ++--------------- .../__snapshots__/test__get_api.ambr | 2883 ++++++++----- .../api_analyzer/test__get_api.py | 447 +- .../__snapshots__/test_generate_stubs.ambr | 90 +- .../stubs_generator/test_generate_stubs.py | 6 +- tests/safeds_stubgen/test_main.py | 2 +- 27 files changed, 2793 insertions(+), 4691 deletions(-) create mode 100644 tests/data/test_main/another_path/another_module.py create mode 100644 tests/data/test_main/main_test_module.py rename tests/data/{test_stub_generation => test_package}/attribute_module.py (71%) create mode 100644 tests/data/test_package/class_module.py rename tests/data/test_package/{test_docstrings.py => docstring_module.py} (100%) rename tests/data/test_package/{test_enums.py => enum_module.py} (80%) rename tests/data/{test_stub_generation => test_package}/function_module.py (63%) rename tests/data/{test_stub_generation => test_package}/import_module.py (100%) rename tests/data/{test_stub_generation => test_package}/infer_types_module.py (96%) rename tests/data/{test_stub_generation => test_package}/test_file_creation/__init__.py (100%) rename tests/data/{test_stub_generation => test_package}/test_file_creation/_module_2.py (100%) rename tests/data/{test_stub_generation => test_package}/test_file_creation/_module_3.py (100%) rename tests/data/{test_stub_generation => test_package}/test_file_creation/_module_4.py (100%) rename tests/data/{test_stub_generation => test_package}/test_file_creation/_module_6.py (100%) rename tests/data/{test_stub_generation => test_package}/test_file_creation/module_1.py (100%) rename tests/data/{test_stub_generation => test_package}/test_file_creation/package_1/module_5.py (100%) delete mode 100644 tests/data/test_package/test_module.py rename tests/data/{test_stub_generation => test_package}/variance_module.py (100%) delete mode 100644 tests/data/test_stub_generation/class_module.py delete mode 100644 tests/data/test_stub_generation/enum_module.py diff --git a/tests/data/test_main/another_path/another_module.py b/tests/data/test_main/another_path/another_module.py new file mode 100644 index 00000000..0d53fe84 --- /dev/null +++ b/tests/data/test_main/another_path/another_module.py @@ -0,0 +1,8 @@ +"""Another Module Docstring. + +Full Docstring Description +""" + + +class AnotherClass: + pass diff --git a/tests/data/test_main/main_test_module.py b/tests/data/test_main/main_test_module.py new file mode 100644 index 00000000..23c7a231 --- /dev/null +++ b/tests/data/test_main/main_test_module.py @@ -0,0 +1,76 @@ +"""Docstring of the some_class.py module.""" +# noinspection PyUnresolvedReferences +import math as mathematics + +# noinspection PyUnresolvedReferences +import mypy + +# noinspection PyUnresolvedReferences +from docstring_parser import * + +from .another_path.another_module import AnotherClass +from .another_path.another_module import AnotherClass as _AcImportAlias + +AcDoubleAlias = _AcImportAlias +ac_alias = AnotherClass + + +# noinspection PyUnusedLocal +def global_func(param_1: str = "first param", param_2: ac_alias | None = None) -> ac_alias: + """Docstring 1. + + Docstring 2. + """ + + +def _private_global_func() -> _AcImportAlias | AcDoubleAlias | ac_alias: + pass + + +class ModuleClass(AcDoubleAlias): + """Summary of the description. + + Full description + """ + attr_1: int = 3 + + # noinspection PyUnusedLocal + def __init__(self, init_param_1): + """Summary of the init description. + + Full init description. + """ + self.init_attr: bool + # noinspection PyTypeChecker + self._init_attr_private: float = "I'm a string" + no_class_attr: bool + + def _some_function(self, param_1: ac_alias, param_2: bool = False) -> ac_alias: + """Function Docstring. + + param_2: bool. + """ + + class NestedClass(_AcImportAlias): + def nested_class_function(self, param_1: int) -> set[bool | None]: + pass + + +class _PrivateClass: + public_attr_in_private_class = 0 + + def __init__(self): + self.public_init_attr_in_private_class: int = 0 + + def public_func_in_private_class(self): + pass + + class NestedPrivateClass: + nested_class_attr = 0 + + @staticmethod + def static_nested_private_class_function(): + pass + + class NestedNestedPrivateClass: + pass diff --git a/tests/data/test_package/__init__.py b/tests/data/test_package/__init__.py index d2c2476b..8c01e4eb 100644 --- a/tests/data/test_package/__init__.py +++ b/tests/data/test_package/__init__.py @@ -4,7 +4,7 @@ from ._reexport_module_3 import * from ._reexport_module_4 import FourthReexportClass from ._reexport_module_4 import _reexported_function_4 -from .test_enums import _ReexportedEmptyEnum +from .enum_module import _ReexportedEmptyEnum __all__ = [ "reex_1", diff --git a/tests/data/test_stub_generation/attribute_module.py b/tests/data/test_package/attribute_module.py similarity index 71% rename from tests/data/test_stub_generation/attribute_module.py rename to tests/data/test_package/attribute_module.py index 931eb7c9..885e1d56 100644 --- a/tests/data/test_stub_generation/attribute_module.py +++ b/tests/data/test_package/attribute_module.py @@ -1,28 +1,28 @@ -class A: +class AttributesClassA: ... -class B: +class AttributesClassB: type_hint_public: int _type_hint_private: int no_type_hint_public = 1 _no_type_hint_private = 1 - object_attr: A + object_attr: AttributesClassA tuple_attr_1: tuple tuple_attr_2: tuple[str | int] tuple_attr_3: tuple[str, int] list_attr_1: list - list_attr_2: list[str | A] - list_attr_3: list[str, A] - list_attr_4: list[str, A | int] + list_attr_2: list[str | AttributesClassA] + list_attr_3: list[str, AttributesClassA] + list_attr_4: list[str, AttributesClassA | int] dict_attr_1: dict dict_attr_2: dict[str, int] - dict_attr_3: dict[str | int, None | A] + dict_attr_3: dict[str | int, None | AttributesClassA] bool_attr: bool none_attr: None diff --git a/tests/data/test_package/class_module.py b/tests/data/test_package/class_module.py new file mode 100644 index 00000000..fdc1de62 --- /dev/null +++ b/tests/data/test_package/class_module.py @@ -0,0 +1,31 @@ +class ClassModuleEmptyClassA: + ... + + +class ClassModuleClassB(ClassModuleEmptyClassA): + def __init__(self, a: int, b: ClassModuleEmptyClassA | None): ... + + def f(self): ... + + +class ClassModuleClassC(ClassModuleEmptyClassA, ClassModuleClassB): + attr_1: int + attr_2: int + + def f1(self): ... + + +class ClassModuleClassD: + class ClassModuleNestedClassE: + nested_attr_1: None + _nested_attr_2: None + + def class_e_func(self): ... + + class _ClassModulePrivateDoubleNestedClassF: + def _class_f_func(self): ... + + +class _ClassModulePrivateClassG: + _attr_1: float + _attr_2: bool diff --git a/tests/data/test_package/test_docstrings.py b/tests/data/test_package/docstring_module.py similarity index 100% rename from tests/data/test_package/test_docstrings.py rename to tests/data/test_package/docstring_module.py diff --git a/tests/data/test_package/test_enums.py b/tests/data/test_package/enum_module.py similarity index 80% rename from tests/data/test_package/test_enums.py rename to tests/data/test_package/enum_module.py index 1d1b74c0..f42c0661 100644 --- a/tests/data/test_package/test_enums.py +++ b/tests/data/test_package/enum_module.py @@ -4,24 +4,30 @@ from .another_path.another_module import AnotherClass as _AcImportAlias +class _ReexportedEmptyEnum(_Enum): + """Nothing's here.""" + + class EnumTest(Enum): """Enum Docstring. Full Docstring Description """ - ONE = "first" TWO = (2, 2) THREE = 3 FOUR = FIVE = "forth and fifth" SIX, SEVEN = ("sixth", 7) EIGHT, NINE = "89" + + +class EnumTest2(_Enum): TEN = _AcImportAlias() -class _ReexportedEmptyEnum(_Enum): - """Nothing's here.""" +class EnumTest3(IntEnum): + ELEVEN = 11 -class AnotherTestEnum(IntEnum): - number_eleven = 11 +class EmptyEnum(Enum, IntEnum): + ... diff --git a/tests/data/test_stub_generation/function_module.py b/tests/data/test_package/function_module.py similarity index 63% rename from tests/data/test_stub_generation/function_module.py rename to tests/data/test_package/function_module.py index 82488a42..02a1cbbc 100644 --- a/tests/data/test_stub_generation/function_module.py +++ b/tests/data/test_package/function_module.py @@ -1,21 +1,34 @@ from typing import Callable -class A: +class FunctionModuleClassA: ... -class B: +class FunctionModuleClassB: def __init__(self, init_param): ... - def instance_method(self, a: A) -> A: ... + def instance_method(self, a: FunctionModuleClassA) -> FunctionModuleClassA: ... @staticmethod - def static_method() -> None: ... + def static_method(): ... + + @staticmethod + def static_method_params(param_1: int) -> None: ... @classmethod def class_method(cls): ... + @classmethod + def class_method_params(cls, param_1: int) -> bool: + pass + + class FunctionModuleClassC: + def nested_class_function(self, param1: int) -> bool: ... + + class FunctionModuleClassD: + ... + def _private(a): ... @@ -27,7 +40,7 @@ def params( i: int, union: int | bool, lst: list[int], - obj: A, + obj: FunctionModuleClassA, ): ... @@ -51,7 +64,7 @@ def special_params( ): ... -def param_position(self, a, /, b: bool, c=1, *, d=A(), e: int = 1): ... +def param_position(self, a, /, b: bool, c=1, *, d=FunctionModuleClassA(), e: int = 1): ... def opt_pos_only(required, optional=1, /): ... @@ -70,7 +83,7 @@ def args_type(*args: int, **kwargs: int): ... def one_result() -> int: ... -def multiple_results() -> tuple[str, int, bool, A]: ... +def multiple_results() -> tuple[str, int, bool, FunctionModuleClassA]: ... def callable_type(param: Callable[[str], tuple[int, str]]) -> Callable[[int, int], int]: ... diff --git a/tests/data/test_stub_generation/import_module.py b/tests/data/test_package/import_module.py similarity index 100% rename from tests/data/test_stub_generation/import_module.py rename to tests/data/test_package/import_module.py diff --git a/tests/data/test_stub_generation/infer_types_module.py b/tests/data/test_package/infer_types_module.py similarity index 96% rename from tests/data/test_stub_generation/infer_types_module.py rename to tests/data/test_package/infer_types_module.py index 9b962c62..b5e67caf 100644 --- a/tests/data/test_stub_generation/infer_types_module.py +++ b/tests/data/test_package/infer_types_module.py @@ -33,6 +33,6 @@ def infer_function(infer_param=1, infer_param_2: int = "Something"): for _ in (1, 2): if infer_param_2: - return SomeClass + return ModuleClass return int diff --git a/tests/data/test_stub_generation/test_file_creation/__init__.py b/tests/data/test_package/test_file_creation/__init__.py similarity index 100% rename from tests/data/test_stub_generation/test_file_creation/__init__.py rename to tests/data/test_package/test_file_creation/__init__.py diff --git a/tests/data/test_stub_generation/test_file_creation/_module_2.py b/tests/data/test_package/test_file_creation/_module_2.py similarity index 100% rename from tests/data/test_stub_generation/test_file_creation/_module_2.py rename to tests/data/test_package/test_file_creation/_module_2.py diff --git a/tests/data/test_stub_generation/test_file_creation/_module_3.py b/tests/data/test_package/test_file_creation/_module_3.py similarity index 100% rename from tests/data/test_stub_generation/test_file_creation/_module_3.py rename to tests/data/test_package/test_file_creation/_module_3.py diff --git a/tests/data/test_stub_generation/test_file_creation/_module_4.py b/tests/data/test_package/test_file_creation/_module_4.py similarity index 100% rename from tests/data/test_stub_generation/test_file_creation/_module_4.py rename to tests/data/test_package/test_file_creation/_module_4.py diff --git a/tests/data/test_stub_generation/test_file_creation/_module_6.py b/tests/data/test_package/test_file_creation/_module_6.py similarity index 100% rename from tests/data/test_stub_generation/test_file_creation/_module_6.py rename to tests/data/test_package/test_file_creation/_module_6.py diff --git a/tests/data/test_stub_generation/test_file_creation/module_1.py b/tests/data/test_package/test_file_creation/module_1.py similarity index 100% rename from tests/data/test_stub_generation/test_file_creation/module_1.py rename to tests/data/test_package/test_file_creation/module_1.py diff --git a/tests/data/test_stub_generation/test_file_creation/package_1/module_5.py b/tests/data/test_package/test_file_creation/package_1/module_5.py similarity index 100% rename from tests/data/test_stub_generation/test_file_creation/package_1/module_5.py rename to tests/data/test_package/test_file_creation/package_1/module_5.py diff --git a/tests/data/test_package/test_module.py b/tests/data/test_package/test_module.py deleted file mode 100644 index f1afd76f..00000000 --- a/tests/data/test_package/test_module.py +++ /dev/null @@ -1,189 +0,0 @@ -"""Docstring of the some_class.py module.""" -# noinspection PyUnresolvedReferences -import math as mathematics -from typing import * - -# noinspection PyUnresolvedReferences -import mypy - -# noinspection PyUnresolvedReferences -from docstring_parser import * - -from .another_path.another_module import AnotherClass -from .another_path.another_module import AnotherClass as _AcImportAlias - -AcDoubleAlias = _AcImportAlias -ac_alias = AnotherClass - - -# noinspection PyUnusedLocal -def global_func(param_1: str = "first param", param_2: ac_alias | None = None) -> ac_alias: - """Docstring 1. - - Docstring 2. - """ - - -def _private_global_func() -> _AcImportAlias | AcDoubleAlias | ac_alias: - pass - - -class SomeClass(AcDoubleAlias): - """Summary of the description. - - Full description - """ - - type_hint_public: int - _type_hint_private: int - - no_type_hint_public = 1 - _no_type_hint_private = 1 - - object_attr: _AcImportAlias - object_attr_2: AcDoubleAlias - - tuple_attr_1: tuple - tuple_attr_2: tuple[str | int] - tuple_attr_3: tuple[str, int] - - list_attr_1: list - list_attr_2: list[str | _AcImportAlias] - list_attr_3: list[str, AcDoubleAlias] - list_attr_4: list[str, _AcImportAlias | int] - - dict_attr_1: dict - dict_attr_2: dict[str, int] - dict_attr_3: dict[str | int, None | _AcImportAlias] - - bool_attr: bool - none_attr: None - flaot_attr: float - int_or_bool_attr: int | bool - str_attr_with_none_value: str = None - - multi_attr_1, _multi_attr_2_private = (123456, "I am a String") - multi_attr_3 = _multi_attr_4_private = ["I am some", "kind of list"] - - # noinspection PyUnusedLocal - def __init__(self, init_param_1): - """Summary of the init description. - - Full init description. - """ - self.init_attr: bool - # noinspection PyTypeChecker - self._init_attr_private: float = "I'm a string" - no_class_attr: bool - - def _some_function(self, param_1: ac_alias, param_2: bool = False) -> ac_alias: - """Function Docstring. - - param_2: bool. - """ - - @staticmethod - def static_function(param_1: bool = True, param_2: int | bool = 123456) -> tuple[bool, int]: - """Function Docstring.""" - - def test_position(self, param1, /, param2: bool, param3=1, *, param4=AcDoubleAlias(), param5: int = 1) -> Any: - """Function Docstring.""" - - @staticmethod - def test_params(*args, **kwargs): - pass - - @staticmethod - def multiple_results(param_1: int) -> Any | tuple[int, str]: - """Function Docstring.""" - - def no_return_1(self): - pass - - def no_return_2(self) -> None: - pass - - @classmethod - def class_method(cls) -> None: - pass - - @classmethod - def class_method_params(cls, param_1: int) -> bool: - pass - - class NestedClass(_AcImportAlias): - def nested_class_function(self, param_1: int) -> set[bool | None]: - pass - - -class _PrivateClass: - public_attr_in_private_class = 0 - - def __init__(self): - self.public_init_attr_in_private_class: int = 0 - - def public_func_in_private_class(self): - pass - - class NestedPrivateClass: - nested_class_attr = 0 - - @staticmethod - def static_nested_private_class_function(): - pass - - class NestedNestedPrivateClass: - pass - - -class InferMyTypes: - infer_attr = 1 - - def __init__(self, init_param=1): - self.init_infer = 3 - - @staticmethod - def infer_function(infer_param=1, infer_param_2: int = "Something"): - if infer_param_2: - return False - elif infer_param: - if infer_param: - return 12 - else: - return bool - - match infer_param: - case 1: - if 4: - return InferMyTypes - case _: - return None - - while infer_param_2: - if infer_param_2: - return 1.23 - else: - infer_param_2 = 0 - - with open("no path", "r") as _: - if infer_param_2: - return "Some String" - - for _ in (1, 2): - if infer_param_2: - return SomeClass - - return int - - -_T_co = TypeVar("_T_co", covariant=True, bound=str) -_T_con = TypeVar("_T_con", contravariant=True, bound=SomeClass) -_T_in = TypeVar("_T_in", int, Literal[1, 2]) - - -class VarianceClassAll(Generic[_T_co, _T_con, _T_in]): - ... - - -class VarianceClassOnlyInvariance(Generic[_T_in]): - ... diff --git a/tests/data/test_stub_generation/variance_module.py b/tests/data/test_package/variance_module.py similarity index 100% rename from tests/data/test_stub_generation/variance_module.py rename to tests/data/test_package/variance_module.py diff --git a/tests/data/test_stub_generation/class_module.py b/tests/data/test_stub_generation/class_module.py deleted file mode 100644 index 7b491fa7..00000000 --- a/tests/data/test_stub_generation/class_module.py +++ /dev/null @@ -1,21 +0,0 @@ -class A: - ... - - -class B(A): - def __init__(self, a: int, b: A | None): ... - - def f(self): ... - - -class C(A, B): - attr_1: int - attr_2: int - - def f1(self): ... - - -class D: - class E: - class F: - ... diff --git a/tests/data/test_stub_generation/enum_module.py b/tests/data/test_stub_generation/enum_module.py deleted file mode 100644 index 34520ec0..00000000 --- a/tests/data/test_stub_generation/enum_module.py +++ /dev/null @@ -1,23 +0,0 @@ -from enum import Enum, IntEnum -from enum import Enum as _Enum - - -class EnumTest(Enum): - ONE = "first" - TWO = (2, 2) - THREE = 3 - FOUR = FIVE = "forth and fifth" - SIX, SEVEN = ("sixth", 7) - EIGHT, NINE = "89" - - -class EnumTest2(_Enum): - TEN = "TEN" - - -class EnumTest3(IntEnum): - ELEVEN = 11 - - -class EmptyEnum(Enum, IntEnum): - ... diff --git a/tests/safeds_stubgen/__snapshots__/test_main.ambr b/tests/safeds_stubgen/__snapshots__/test_main.ambr index cef46b96..8e8060b3 100644 --- a/tests/safeds_stubgen/__snapshots__/test_main.ambr +++ b/tests/safeds_stubgen/__snapshots__/test_main.ambr @@ -8,14 +8,14 @@ 'description': '', 'type': '', }), - 'id': 'test_package/test_docstrings/EpydocDocstringClass/attr_1', - 'is_public': True, - 'is_static': True, + 'id': 'test_main/main_test_module/ModuleClass/_init_attr_private', + 'is_public': False, + 'is_static': False, 'is_type_inferred': False, - 'name': 'attr_1', + 'name': '_init_attr_private', 'type': dict({ 'kind': 'NamedType', - 'name': 'str', + 'name': 'float', }), }), dict({ @@ -24,14 +24,14 @@ 'description': '', 'type': '', }), - 'id': 'test_package/test_docstrings/GoogleDocstringClass/attr_1', + 'id': 'test_main/main_test_module/ModuleClass/attr_1', 'is_public': True, 'is_static': True, 'is_type_inferred': False, 'name': 'attr_1', 'type': dict({ 'kind': 'NamedType', - 'name': 'str', + 'name': 'int', }), }), dict({ @@ -40,14 +40,14 @@ 'description': '', 'type': '', }), - 'id': 'test_package/test_docstrings/NumpyDocstringClass/attr_1', + 'id': 'test_main/main_test_module/ModuleClass/init_attr', 'is_public': True, - 'is_static': True, + 'is_static': False, 'is_type_inferred': False, - 'name': 'attr_1', + 'name': 'init_attr', 'type': dict({ 'kind': 'NamedType', - 'name': 'str', + 'name': 'bool', }), }), dict({ @@ -56,14 +56,14 @@ 'description': '', 'type': '', }), - 'id': 'test_package/test_docstrings/RestDocstringClass/attr_1', - 'is_public': True, + 'id': 'test_main/main_test_module/_PrivateClass/NestedPrivateClass/nested_class_attr', + 'is_public': False, 'is_static': True, - 'is_type_inferred': False, - 'name': 'attr_1', + 'is_type_inferred': True, + 'name': 'nested_class_attr', 'type': dict({ 'kind': 'NamedType', - 'name': 'str', + 'name': 'int', }), }), dict({ @@ -72,11 +72,11 @@ 'description': '', 'type': '', }), - 'id': 'test_package/test_module/InferMyTypes/infer_attr', - 'is_public': True, + 'id': 'test_main/main_test_module/_PrivateClass/public_attr_in_private_class', + 'is_public': False, 'is_static': True, 'is_type_inferred': True, - 'name': 'infer_attr', + 'name': 'public_attr_in_private_class', 'type': dict({ 'kind': 'NamedType', 'name': 'int', @@ -88,3083 +88,519 @@ 'description': '', 'type': '', }), - 'id': 'test_package/test_module/InferMyTypes/init_infer', - 'is_public': True, - 'is_static': False, - 'is_type_inferred': False, - 'name': 'init_infer', - 'type': None, - }), - dict({ - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_module/SomeClass/_init_attr_private', + 'id': 'test_main/main_test_module/_PrivateClass/public_init_attr_in_private_class', 'is_public': False, 'is_static': False, 'is_type_inferred': False, - 'name': '_init_attr_private', + 'name': 'public_init_attr_in_private_class', 'type': dict({ 'kind': 'NamedType', - 'name': 'float', + 'name': 'int', }), }), + ]), + 'classes': list([ dict({ + 'attributes': list([ + ]), + 'classes': list([ + ]), + 'constructor': None, 'docstring': dict({ - 'default_value': '', 'description': '', - 'type': '', - }), - 'id': 'test_package/test_module/SomeClass/_multi_attr_2_private', - 'is_public': False, - 'is_static': True, - 'is_type_inferred': True, - 'name': '_multi_attr_2_private', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'str', + 'full_docstring': '', }), + 'id': 'test_main/another_path/another_module/AnotherClass', + 'is_public': True, + 'methods': list([ + ]), + 'name': 'AnotherClass', + 'reexported_by': list([ + ]), + 'superclasses': list([ + ]), + 'variances': list([ + ]), }), dict({ - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_module/SomeClass/_multi_attr_4_private', - 'is_public': False, - 'is_static': True, - 'is_type_inferred': True, - 'name': '_multi_attr_4_private', - 'type': dict({ - 'kind': 'ListType', - 'types': list([ - dict({ - 'kind': 'NamedType', - 'name': 'str', - }), + 'attributes': list([ + 'test_main/main_test_module/ModuleClass/attr_1', + 'test_main/main_test_module/ModuleClass/init_attr', + 'test_main/main_test_module/ModuleClass/_init_attr_private', + ]), + 'classes': list([ + 'test_main/main_test_module/ModuleClass/NestedClass', + ]), + 'constructor': dict({ + 'docstring': dict({ + 'description': ''' + Summary of the init description. + + Full init description. + ''', + 'full_docstring': ''' + Summary of the init description. + + Full init description. + ''', + }), + 'id': 'test_main/main_test_module/ModuleClass/__init__', + 'is_class_method': False, + 'is_public': True, + 'is_static': False, + 'name': '__init__', + 'parameters': list([ + 'test_main/main_test_module/ModuleClass/__init__/self', + 'test_main/main_test_module/ModuleClass/__init__/init_param_1', ]), + 'reexported_by': list([ + ]), + 'results': list([ + ]), + }), + 'docstring': dict({ + 'description': ''' + Summary of the description. + + Full description + ''', + 'full_docstring': ''' + Summary of the description. + + Full description + ''', }), + 'id': 'test_main/main_test_module/ModuleClass', + 'is_public': True, + 'methods': list([ + 'test_main/main_test_module/ModuleClass/_some_function', + ]), + 'name': 'ModuleClass', + 'reexported_by': list([ + ]), + 'superclasses': list([ + 'tests.data.test_main.main_test_module.AcDoubleAlias', + ]), + 'variances': list([ + ]), }), dict({ + 'attributes': list([ + ]), + 'classes': list([ + ]), + 'constructor': None, 'docstring': dict({ - 'default_value': '', 'description': '', - 'type': '', - }), - 'id': 'test_package/test_module/SomeClass/_no_type_hint_private', - 'is_public': False, - 'is_static': True, - 'is_type_inferred': True, - 'name': '_no_type_hint_private', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'int', + 'full_docstring': '', }), + 'id': 'test_main/main_test_module/ModuleClass/NestedClass', + 'is_public': True, + 'methods': list([ + 'test_main/main_test_module/ModuleClass/NestedClass/nested_class_function', + ]), + 'name': 'NestedClass', + 'reexported_by': list([ + ]), + 'superclasses': list([ + 'tests.data.test_main.another_path.another_module.AnotherClass', + ]), + 'variances': list([ + ]), }), dict({ + 'attributes': list([ + 'test_main/main_test_module/_PrivateClass/public_attr_in_private_class', + 'test_main/main_test_module/_PrivateClass/public_init_attr_in_private_class', + ]), + 'classes': list([ + 'test_main/main_test_module/_PrivateClass/NestedPrivateClass', + ]), + 'constructor': dict({ + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_main/main_test_module/_PrivateClass/__init__', + 'is_class_method': False, + 'is_public': False, + 'is_static': False, + 'name': '__init__', + 'parameters': list([ + 'test_main/main_test_module/_PrivateClass/__init__/self', + ]), + 'reexported_by': list([ + ]), + 'results': list([ + ]), + }), 'docstring': dict({ - 'default_value': '', 'description': '', - 'type': '', + 'full_docstring': '', }), - 'id': 'test_package/test_module/SomeClass/_type_hint_private', + 'id': 'test_main/main_test_module/_PrivateClass', 'is_public': False, - 'is_static': True, - 'is_type_inferred': False, - 'name': '_type_hint_private', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'int', - }), + 'methods': list([ + 'test_main/main_test_module/_PrivateClass/public_func_in_private_class', + ]), + 'name': '_PrivateClass', + 'reexported_by': list([ + ]), + 'superclasses': list([ + ]), + 'variances': list([ + ]), }), dict({ + 'attributes': list([ + 'test_main/main_test_module/_PrivateClass/NestedPrivateClass/nested_class_attr', + ]), + 'classes': list([ + 'test_main/main_test_module/_PrivateClass/NestedPrivateClass/NestedNestedPrivateClass', + ]), + 'constructor': None, 'docstring': dict({ - 'default_value': '', 'description': '', - 'type': '', + 'full_docstring': '', }), - 'id': 'test_package/test_module/SomeClass/bool_attr', + 'id': 'test_main/main_test_module/_PrivateClass/NestedPrivateClass', 'is_public': True, - 'is_static': True, - 'is_type_inferred': False, - 'name': 'bool_attr', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'bool', - }), + 'methods': list([ + 'test_main/main_test_module/_PrivateClass/NestedPrivateClass/static_nested_private_class_function', + ]), + 'name': 'NestedPrivateClass', + 'reexported_by': list([ + ]), + 'superclasses': list([ + ]), + 'variances': list([ + ]), }), dict({ + 'attributes': list([ + ]), + 'classes': list([ + ]), + 'constructor': None, 'docstring': dict({ - 'default_value': '', 'description': '', - 'type': '', + 'full_docstring': '', }), - 'id': 'test_package/test_module/SomeClass/dict_attr_1', + 'id': 'test_main/main_test_module/_PrivateClass/NestedPrivateClass/NestedNestedPrivateClass', 'is_public': True, - 'is_static': True, - 'is_type_inferred': False, - 'name': 'dict_attr_1', - 'type': dict({ - 'key_type': dict({ - 'kind': 'NamedType', - 'name': 'Any', - }), - 'kind': 'DictType', - 'value_type': dict({ - 'kind': 'NamedType', - 'name': 'Any', - }), - }), + 'methods': list([ + ]), + 'name': 'NestedNestedPrivateClass', + 'reexported_by': list([ + ]), + 'superclasses': list([ + ]), + 'variances': list([ + ]), }), + ]), + 'distribution': '', + 'enum_instances': list([ + ]), + 'enums': list([ + ]), + 'functions': list([ dict({ 'docstring': dict({ - 'default_value': '', 'description': '', - 'type': '', + 'full_docstring': '', }), - 'id': 'test_package/test_module/SomeClass/dict_attr_2', + 'id': 'test_main/main_test_module/ModuleClass/NestedClass/nested_class_function', + 'is_class_method': False, 'is_public': True, - 'is_static': True, - 'is_type_inferred': False, - 'name': 'dict_attr_2', - 'type': dict({ - 'key_type': dict({ - 'kind': 'NamedType', - 'name': 'str', - }), - 'kind': 'DictType', - 'value_type': dict({ - 'kind': 'NamedType', - 'name': 'int', - }), - }), - }), - dict({ - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_module/SomeClass/dict_attr_3', - 'is_public': True, - 'is_static': True, - 'is_type_inferred': False, - 'name': 'dict_attr_3', - 'type': dict({ - 'key_type': dict({ - 'kind': 'UnionType', - 'types': list([ - dict({ - 'kind': 'NamedType', - 'name': 'str', - }), - dict({ - 'kind': 'NamedType', - 'name': 'int', - }), - ]), - }), - 'kind': 'DictType', - 'value_type': dict({ - 'kind': 'UnionType', - 'types': list([ - dict({ - 'kind': 'NamedType', - 'name': 'None', - }), - dict({ - 'kind': 'NamedType', - 'name': 'AnotherClass', - }), - ]), - }), - }), + 'is_static': False, + 'name': 'nested_class_function', + 'parameters': list([ + 'test_main/main_test_module/ModuleClass/NestedClass/nested_class_function/self', + 'test_main/main_test_module/ModuleClass/NestedClass/nested_class_function/param_1', + ]), + 'reexported_by': list([ + ]), + 'results': list([ + 'test_main/main_test_module/ModuleClass/NestedClass/nested_class_function/result_1', + ]), }), dict({ 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', + 'description': ''' + Summary of the init description. + + Full init description. + ''', + 'full_docstring': ''' + Summary of the init description. + + Full init description. + ''', }), - 'id': 'test_package/test_module/SomeClass/flaot_attr', + 'id': 'test_main/main_test_module/ModuleClass/__init__', + 'is_class_method': False, 'is_public': True, - 'is_static': True, - 'is_type_inferred': False, - 'name': 'flaot_attr', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'float', - }), + 'is_static': False, + 'name': '__init__', + 'parameters': list([ + 'test_main/main_test_module/ModuleClass/__init__/self', + 'test_main/main_test_module/ModuleClass/__init__/init_param_1', + ]), + 'reexported_by': list([ + ]), + 'results': list([ + ]), }), dict({ 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', + 'description': ''' + Function Docstring. + + param_2: bool. + ''', + 'full_docstring': ''' + Function Docstring. + + param_2: bool. + ''', }), - 'id': 'test_package/test_module/SomeClass/init_attr', - 'is_public': True, + 'id': 'test_main/main_test_module/ModuleClass/_some_function', + 'is_class_method': False, + 'is_public': False, 'is_static': False, - 'is_type_inferred': False, - 'name': 'init_attr', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'bool', - }), + 'name': '_some_function', + 'parameters': list([ + 'test_main/main_test_module/ModuleClass/_some_function/self', + 'test_main/main_test_module/ModuleClass/_some_function/param_1', + 'test_main/main_test_module/ModuleClass/_some_function/param_2', + ]), + 'reexported_by': list([ + ]), + 'results': list([ + 'test_main/main_test_module/ModuleClass/_some_function/result_1', + ]), }), dict({ 'docstring': dict({ - 'default_value': '', 'description': '', - 'type': '', + 'full_docstring': '', }), - 'id': 'test_package/test_module/SomeClass/int_or_bool_attr', - 'is_public': True, + 'id': 'test_main/main_test_module/_PrivateClass/NestedPrivateClass/static_nested_private_class_function', + 'is_class_method': False, + 'is_public': False, 'is_static': True, - 'is_type_inferred': False, - 'name': 'int_or_bool_attr', - 'type': dict({ - 'kind': 'UnionType', - 'types': list([ - dict({ - 'kind': 'NamedType', - 'name': 'int', - }), - dict({ - 'kind': 'NamedType', - 'name': 'bool', - }), - ]), - }), + 'name': 'static_nested_private_class_function', + 'parameters': list([ + ]), + 'reexported_by': list([ + ]), + 'results': list([ + ]), }), dict({ 'docstring': dict({ - 'default_value': '', 'description': '', - 'type': '', - }), - 'id': 'test_package/test_module/SomeClass/list_attr_1', - 'is_public': True, - 'is_static': True, - 'is_type_inferred': False, - 'name': 'list_attr_1', - 'type': dict({ - 'kind': 'ListType', - 'types': list([ - ]), + 'full_docstring': '', }), + 'id': 'test_main/main_test_module/_PrivateClass/__init__', + 'is_class_method': False, + 'is_public': False, + 'is_static': False, + 'name': '__init__', + 'parameters': list([ + 'test_main/main_test_module/_PrivateClass/__init__/self', + ]), + 'reexported_by': list([ + ]), + 'results': list([ + ]), }), dict({ 'docstring': dict({ - 'default_value': '', 'description': '', - 'type': '', - }), - 'id': 'test_package/test_module/SomeClass/list_attr_2', - 'is_public': True, - 'is_static': True, - 'is_type_inferred': False, - 'name': 'list_attr_2', - 'type': dict({ - 'kind': 'ListType', - 'types': list([ - dict({ - 'kind': 'UnionType', - 'types': list([ - dict({ - 'kind': 'NamedType', - 'name': 'str', - }), - dict({ - 'kind': 'NamedType', - 'name': '_AcImportAlias', - }), - ]), - }), - ]), + 'full_docstring': '', }), + 'id': 'test_main/main_test_module/_PrivateClass/public_func_in_private_class', + 'is_class_method': False, + 'is_public': False, + 'is_static': False, + 'name': 'public_func_in_private_class', + 'parameters': list([ + 'test_main/main_test_module/_PrivateClass/public_func_in_private_class/self', + ]), + 'reexported_by': list([ + ]), + 'results': list([ + ]), }), dict({ 'docstring': dict({ - 'default_value': '', 'description': '', - 'type': '', - }), - 'id': 'test_package/test_module/SomeClass/list_attr_3', - 'is_public': True, - 'is_static': True, - 'is_type_inferred': False, - 'name': 'list_attr_3', - 'type': dict({ - 'kind': 'ListType', - 'types': list([ - dict({ - 'kind': 'NamedType', - 'name': 'str', - }), - dict({ - 'kind': 'NamedType', - 'name': 'AcDoubleAlias', - }), - ]), + 'full_docstring': '', }), + 'id': 'test_main/main_test_module/_private_global_func', + 'is_class_method': False, + 'is_public': False, + 'is_static': False, + 'name': '_private_global_func', + 'parameters': list([ + ]), + 'reexported_by': list([ + ]), + 'results': list([ + 'test_main/main_test_module/_private_global_func/result_1', + ]), }), dict({ 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', + 'description': ''' + Docstring 1. + + Docstring 2. + ''', + 'full_docstring': ''' + Docstring 1. + + Docstring 2. + ''', }), - 'id': 'test_package/test_module/SomeClass/list_attr_4', + 'id': 'test_main/main_test_module/global_func', + 'is_class_method': False, 'is_public': True, - 'is_static': True, - 'is_type_inferred': False, - 'name': 'list_attr_4', - 'type': dict({ - 'kind': 'ListType', - 'types': list([ - dict({ - 'kind': 'NamedType', - 'name': 'str', - }), - dict({ - 'kind': 'UnionType', - 'types': list([ - dict({ - 'kind': 'NamedType', - 'name': '_AcImportAlias', - }), - dict({ - 'kind': 'NamedType', - 'name': 'int', - }), - ]), - }), - ]), - }), + 'is_static': False, + 'name': 'global_func', + 'parameters': list([ + 'test_main/main_test_module/global_func/param_1', + 'test_main/main_test_module/global_func/param_2', + ]), + 'reexported_by': list([ + ]), + 'results': list([ + 'test_main/main_test_module/global_func/result_1', + ]), }), + ]), + 'modules': list([ dict({ - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_module/SomeClass/multi_attr_1', - 'is_public': True, - 'is_static': True, - 'is_type_inferred': True, - 'name': 'multi_attr_1', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'int', - }), + 'classes': list([ + 'test_main/another_path/another_module/AnotherClass', + ]), + 'docstring': ''' + Another Module Docstring. + + Full Docstring Description + + ''', + 'enums': list([ + ]), + 'functions': list([ + ]), + 'id': 'test_main/another_path/another_module', + 'name': 'another_module', + 'qualified_imports': list([ + ]), + 'wildcard_imports': list([ + ]), }), dict({ - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_module/SomeClass/multi_attr_3', - 'is_public': True, - 'is_static': True, - 'is_type_inferred': True, - 'name': 'multi_attr_3', - 'type': dict({ - 'kind': 'ListType', - 'types': list([ - dict({ - 'kind': 'NamedType', - 'name': 'str', - }), - ]), - }), - }), - dict({ - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_module/SomeClass/no_type_hint_public', - 'is_public': True, - 'is_static': True, - 'is_type_inferred': True, - 'name': 'no_type_hint_public', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'int', - }), - }), - dict({ - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_module/SomeClass/none_attr', - 'is_public': True, - 'is_static': True, - 'is_type_inferred': False, - 'name': 'none_attr', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'None', - }), - }), - dict({ - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_module/SomeClass/object_attr', - 'is_public': True, - 'is_static': True, - 'is_type_inferred': False, - 'name': 'object_attr', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'AnotherClass', - }), - }), - dict({ - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_module/SomeClass/object_attr_2', - 'is_public': True, - 'is_static': True, - 'is_type_inferred': False, - 'name': 'object_attr_2', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'AnotherClass', - }), - }), - dict({ - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_module/SomeClass/str_attr_with_none_value', - 'is_public': True, - 'is_static': True, - 'is_type_inferred': False, - 'name': 'str_attr_with_none_value', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'str', - }), - }), - dict({ - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_module/SomeClass/tuple_attr_1', - 'is_public': True, - 'is_static': True, - 'is_type_inferred': False, - 'name': 'tuple_attr_1', - 'type': dict({ - 'kind': 'TupleType', - 'types': list([ - dict({ - 'kind': 'NamedType', - 'name': 'Any', - }), - ]), - }), - }), - dict({ - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_module/SomeClass/tuple_attr_2', - 'is_public': True, - 'is_static': True, - 'is_type_inferred': False, - 'name': 'tuple_attr_2', - 'type': dict({ - 'kind': 'TupleType', - 'types': list([ - dict({ - 'kind': 'UnionType', - 'types': list([ - dict({ - 'kind': 'NamedType', - 'name': 'str', - }), - dict({ - 'kind': 'NamedType', - 'name': 'int', - }), - ]), - }), - ]), - }), - }), - dict({ - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_module/SomeClass/tuple_attr_3', - 'is_public': True, - 'is_static': True, - 'is_type_inferred': False, - 'name': 'tuple_attr_3', - 'type': dict({ - 'kind': 'TupleType', - 'types': list([ - dict({ - 'kind': 'NamedType', - 'name': 'str', - }), - dict({ - 'kind': 'NamedType', - 'name': 'int', - }), - ]), - }), - }), - dict({ - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_module/SomeClass/type_hint_public', - 'is_public': True, - 'is_static': True, - 'is_type_inferred': False, - 'name': 'type_hint_public', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'int', - }), - }), - dict({ - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_module/_PrivateClass/NestedPrivateClass/nested_class_attr', - 'is_public': False, - 'is_static': True, - 'is_type_inferred': True, - 'name': 'nested_class_attr', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'int', - }), - }), - dict({ - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_module/_PrivateClass/public_attr_in_private_class', - 'is_public': False, - 'is_static': True, - 'is_type_inferred': True, - 'name': 'public_attr_in_private_class', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'int', - }), - }), - dict({ - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_module/_PrivateClass/public_init_attr_in_private_class', - 'is_public': False, - 'is_static': False, - 'is_type_inferred': False, - 'name': 'public_init_attr_in_private_class', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'int', - }), - }), - ]), - 'classes': list([ - dict({ - 'attributes': list([ - ]), - 'classes': list([ - ]), - 'constructor': None, - 'docstring': dict({ - 'description': '', - 'full_docstring': '', - }), - 'id': 'test_package/_reexport_module_1/ReexportClass', - 'is_public': True, - 'methods': list([ - 'test_package/_reexport_module_1/ReexportClass/_private_class_method_of_reexported_class', - ]), - 'name': 'ReexportClass', - 'reexported_by': list([ - 'test_package/__init__', - ]), - 'superclasses': list([ - ]), - 'variances': list([ - ]), - }), - dict({ - 'attributes': list([ - ]), 'classes': list([ + 'test_main/main_test_module/ModuleClass', + 'test_main/main_test_module/_PrivateClass', ]), - 'constructor': None, - 'docstring': dict({ - 'description': '', - 'full_docstring': '', - }), - 'id': 'test_package/_reexport_module_2/AnotherReexportClass', - 'is_public': True, - 'methods': list([ - ]), - 'name': 'AnotherReexportClass', - 'reexported_by': list([ - ]), - 'superclasses': list([ - ]), - 'variances': list([ - ]), - }), - dict({ - 'attributes': list([ + 'docstring': 'Docstring of the some_class.py module.', + 'enums': list([ ]), - 'classes': list([ + 'functions': list([ + 'test_main/main_test_module/global_func', + 'test_main/main_test_module/_private_global_func', ]), - 'constructor': None, - 'docstring': dict({ - 'description': '', - 'full_docstring': '', - }), - 'id': 'test_package/_reexport_module_3/_ThirdReexportClass', - 'is_public': False, - 'methods': list([ - ]), - 'name': '_ThirdReexportClass', - 'reexported_by': list([ - 'test_package/__init__', - ]), - 'superclasses': list([ - ]), - 'variances': list([ - ]), - }), - dict({ - 'attributes': list([ - ]), - 'classes': list([ - ]), - 'constructor': None, - 'docstring': dict({ - 'description': '', - 'full_docstring': '', - }), - 'id': 'test_package/_reexport_module_4/FourthReexportClass', - 'is_public': True, - 'methods': list([ - ]), - 'name': 'FourthReexportClass', - 'reexported_by': list([ - 'test_package/__init__', - ]), - 'superclasses': list([ - ]), - 'variances': list([ - ]), - }), - dict({ - 'attributes': list([ - ]), - 'classes': list([ - ]), - 'constructor': None, - 'docstring': dict({ - 'description': '', - 'full_docstring': '', - }), - 'id': 'test_package/another_path/another_module/AnotherClass', - 'is_public': True, - 'methods': list([ - ]), - 'name': 'AnotherClass', - 'reexported_by': list([ - ]), - 'superclasses': list([ - ]), - 'variances': list([ - ]), - }), - dict({ - 'attributes': list([ - 'test_package/test_docstrings/EpydocDocstringClass/attr_1', - ]), - 'classes': list([ - ]), - 'constructor': dict({ - 'docstring': dict({ - 'description': '', - 'full_docstring': '', - }), - 'id': 'test_package/test_docstrings/EpydocDocstringClass/__init__', - 'is_class_method': False, - 'is_public': True, - 'is_static': False, - 'name': '__init__', - 'parameters': list([ - 'test_package/test_docstrings/EpydocDocstringClass/__init__/self', - 'test_package/test_docstrings/EpydocDocstringClass/__init__/param_1', - ]), - 'reexported_by': list([ - ]), - 'results': list([ - ]), - }), - 'docstring': dict({ - 'description': ''' - A class with a variety of different methods for calculations. (Epydoc). - - @ivar attr_1: Attribute of the calculator. (Epydoc) - @type attr_1: str - @param param_1: Parameter of the calculator. (Epydoc) - @type param_1: str - ''', - 'full_docstring': ''' - A class with a variety of different methods for calculations. (Epydoc). - - @ivar attr_1: Attribute of the calculator. (Epydoc) - @type attr_1: str - @param param_1: Parameter of the calculator. (Epydoc) - @type param_1: str - ''', - }), - 'id': 'test_package/test_docstrings/EpydocDocstringClass', - 'is_public': True, - 'methods': list([ - 'test_package/test_docstrings/EpydocDocstringClass/epydoc_docstring_func', - ]), - 'name': 'EpydocDocstringClass', - 'reexported_by': list([ - ]), - 'superclasses': list([ - ]), - 'variances': list([ - ]), - }), - dict({ - 'attributes': list([ - 'test_package/test_docstrings/GoogleDocstringClass/attr_1', - ]), - 'classes': list([ - ]), - 'constructor': dict({ - 'docstring': dict({ - 'description': '', - 'full_docstring': '', + 'id': 'test_main/main_test_module', + 'name': 'main_test_module', + 'qualified_imports': list([ + dict({ + 'alias': 'mathematics', + 'qualified_name': 'math', }), - 'id': 'test_package/test_docstrings/GoogleDocstringClass/__init__', - 'is_class_method': False, - 'is_public': True, - 'is_static': False, - 'name': '__init__', - 'parameters': list([ - 'test_package/test_docstrings/GoogleDocstringClass/__init__/self', - 'test_package/test_docstrings/GoogleDocstringClass/__init__/param_1', - ]), - 'reexported_by': list([ - ]), - 'results': list([ - ]), - }), - 'docstring': dict({ - 'description': ''' - A class that calculates stuff. (Google Style). - - A class with a variety of different methods for calculations. (Google Style) - - Attributes: - attr_1 (str): Attribute of the calculator. (Google Style) - - Args: - param_1 (str): Parameter of the calculator. (Google Style) - ''', - 'full_docstring': ''' - A class that calculates stuff. (Google Style). - - A class with a variety of different methods for calculations. (Google Style) - - Attributes: - attr_1 (str): Attribute of the calculator. (Google Style) - - Args: - param_1 (str): Parameter of the calculator. (Google Style) - ''', - }), - 'id': 'test_package/test_docstrings/GoogleDocstringClass', - 'is_public': True, - 'methods': list([ - 'test_package/test_docstrings/GoogleDocstringClass/google_docstring_func', - ]), - 'name': 'GoogleDocstringClass', - 'reexported_by': list([ - ]), - 'superclasses': list([ - ]), - 'variances': list([ - ]), - }), - dict({ - 'attributes': list([ - 'test_package/test_docstrings/NumpyDocstringClass/attr_1', - ]), - 'classes': list([ - ]), - 'constructor': dict({ - 'docstring': dict({ - 'description': '', - 'full_docstring': '', + dict({ + 'alias': None, + 'qualified_name': 'mypy', }), - 'id': 'test_package/test_docstrings/NumpyDocstringClass/__init__', - 'is_class_method': False, - 'is_public': True, - 'is_static': False, - 'name': '__init__', - 'parameters': list([ - 'test_package/test_docstrings/NumpyDocstringClass/__init__/self', - 'test_package/test_docstrings/NumpyDocstringClass/__init__/param_1', - ]), - 'reexported_by': list([ - ]), - 'results': list([ - ]), - }), - 'docstring': dict({ - 'description': ''' - A class that calculates stuff. (Numpy). - - A class with a variety of different methods for calculations. (Numpy) - - Attributes - ---------- - attr_1 : str - Attribute of the calculator. (Numpy) - - Parameters - ---------- - param_1 : str - Parameter of the calculator. (Numpy) - ''', - 'full_docstring': ''' - A class that calculates stuff. (Numpy). - - A class with a variety of different methods for calculations. (Numpy) - - Attributes - ---------- - attr_1 : str - Attribute of the calculator. (Numpy) - - Parameters - ---------- - param_1 : str - Parameter of the calculator. (Numpy) - ''', - }), - 'id': 'test_package/test_docstrings/NumpyDocstringClass', - 'is_public': True, - 'methods': list([ - 'test_package/test_docstrings/NumpyDocstringClass/numpy_docstring_func', - ]), - 'name': 'NumpyDocstringClass', - 'reexported_by': list([ - ]), - 'superclasses': list([ - ]), - 'variances': list([ - ]), - }), - dict({ - 'attributes': list([ - 'test_package/test_docstrings/RestDocstringClass/attr_1', - ]), - 'classes': list([ - ]), - 'constructor': dict({ - 'docstring': dict({ - 'description': '', - 'full_docstring': '', + dict({ + 'alias': None, + 'qualified_name': 'another_path.another_module.AnotherClass', }), - 'id': 'test_package/test_docstrings/RestDocstringClass/__init__', - 'is_class_method': False, - 'is_public': True, - 'is_static': False, - 'name': '__init__', - 'parameters': list([ - 'test_package/test_docstrings/RestDocstringClass/__init__/self', - 'test_package/test_docstrings/RestDocstringClass/__init__/param_1', - ]), - 'reexported_by': list([ - ]), - 'results': list([ - ]), - }), - 'docstring': dict({ - 'description': ''' - A class with a variety of different methods for calculations. (ReST). - - :param attr_1: Attribute of the calculator. (ReST) - :type attr_1: str - :param param_1: Parameter of the calculator. (ReST) - :type param_1: str - ''', - 'full_docstring': ''' - A class with a variety of different methods for calculations. (ReST). - - :param attr_1: Attribute of the calculator. (ReST) - :type attr_1: str - :param param_1: Parameter of the calculator. (ReST) - :type param_1: str - ''', - }), - 'id': 'test_package/test_docstrings/RestDocstringClass', - 'is_public': True, - 'methods': list([ - 'test_package/test_docstrings/RestDocstringClass/rest_docstring_func', - ]), - 'name': 'RestDocstringClass', - 'reexported_by': list([ - ]), - 'superclasses': list([ - ]), - 'variances': list([ - ]), - }), - dict({ - 'attributes': list([ - 'test_package/test_module/InferMyTypes/infer_attr', - 'test_package/test_module/InferMyTypes/init_infer', - ]), - 'classes': list([ - ]), - 'constructor': dict({ - 'docstring': dict({ - 'description': '', - 'full_docstring': '', + dict({ + 'alias': '_AcImportAlias', + 'qualified_name': 'another_path.another_module.AnotherClass', }), - 'id': 'test_package/test_module/InferMyTypes/__init__', - 'is_class_method': False, - 'is_public': True, - 'is_static': False, - 'name': '__init__', - 'parameters': list([ - 'test_package/test_module/InferMyTypes/__init__/self', - 'test_package/test_module/InferMyTypes/__init__/init_param', - ]), - 'reexported_by': list([ - ]), - 'results': list([ - ]), - }), - 'docstring': dict({ - 'description': '', - 'full_docstring': '', - }), - 'id': 'test_package/test_module/InferMyTypes', - 'is_public': True, - 'methods': list([ - 'test_package/test_module/InferMyTypes/infer_function', - ]), - 'name': 'InferMyTypes', - 'reexported_by': list([ - ]), - 'superclasses': list([ - ]), - 'variances': list([ - ]), - }), - dict({ - 'attributes': list([ - 'test_package/test_module/SomeClass/type_hint_public', - 'test_package/test_module/SomeClass/_type_hint_private', - 'test_package/test_module/SomeClass/no_type_hint_public', - 'test_package/test_module/SomeClass/_no_type_hint_private', - 'test_package/test_module/SomeClass/object_attr', - 'test_package/test_module/SomeClass/object_attr_2', - 'test_package/test_module/SomeClass/tuple_attr_1', - 'test_package/test_module/SomeClass/tuple_attr_2', - 'test_package/test_module/SomeClass/tuple_attr_3', - 'test_package/test_module/SomeClass/list_attr_1', - 'test_package/test_module/SomeClass/list_attr_2', - 'test_package/test_module/SomeClass/list_attr_3', - 'test_package/test_module/SomeClass/list_attr_4', - 'test_package/test_module/SomeClass/dict_attr_1', - 'test_package/test_module/SomeClass/dict_attr_2', - 'test_package/test_module/SomeClass/dict_attr_3', - 'test_package/test_module/SomeClass/bool_attr', - 'test_package/test_module/SomeClass/none_attr', - 'test_package/test_module/SomeClass/flaot_attr', - 'test_package/test_module/SomeClass/int_or_bool_attr', - 'test_package/test_module/SomeClass/str_attr_with_none_value', - 'test_package/test_module/SomeClass/multi_attr_1', - 'test_package/test_module/SomeClass/_multi_attr_2_private', - 'test_package/test_module/SomeClass/multi_attr_3', - 'test_package/test_module/SomeClass/_multi_attr_4_private', - 'test_package/test_module/SomeClass/init_attr', - 'test_package/test_module/SomeClass/_init_attr_private', - ]), - 'classes': list([ - 'test_package/test_module/SomeClass/NestedClass', - ]), - 'constructor': dict({ - 'docstring': dict({ - 'description': ''' - Summary of the init description. - - Full init description. - ''', - 'full_docstring': ''' - Summary of the init description. - - Full init description. - ''', - }), - 'id': 'test_package/test_module/SomeClass/__init__', - 'is_class_method': False, - 'is_public': True, - 'is_static': False, - 'name': '__init__', - 'parameters': list([ - 'test_package/test_module/SomeClass/__init__/self', - 'test_package/test_module/SomeClass/__init__/init_param_1', - ]), - 'reexported_by': list([ - ]), - 'results': list([ - ]), - }), - 'docstring': dict({ - 'description': ''' - Summary of the description. - - Full description - ''', - 'full_docstring': ''' - Summary of the description. - - Full description - ''', - }), - 'id': 'test_package/test_module/SomeClass', - 'is_public': True, - 'methods': list([ - 'test_package/test_module/SomeClass/_some_function', - 'test_package/test_module/SomeClass/static_function', - 'test_package/test_module/SomeClass/test_position', - 'test_package/test_module/SomeClass/test_params', - 'test_package/test_module/SomeClass/multiple_results', - 'test_package/test_module/SomeClass/no_return_1', - 'test_package/test_module/SomeClass/no_return_2', - 'test_package/test_module/SomeClass/class_method', - 'test_package/test_module/SomeClass/class_method_params', - ]), - 'name': 'SomeClass', - 'reexported_by': list([ - ]), - 'superclasses': list([ - 'tests.data.test_package.test_module.AcDoubleAlias', - ]), - 'variances': list([ - ]), - }), - dict({ - 'attributes': list([ - ]), - 'classes': list([ - ]), - 'constructor': None, - 'docstring': dict({ - 'description': '', - 'full_docstring': '', - }), - 'id': 'test_package/test_module/SomeClass/NestedClass', - 'is_public': True, - 'methods': list([ - 'test_package/test_module/SomeClass/NestedClass/nested_class_function', - ]), - 'name': 'NestedClass', - 'reexported_by': list([ - ]), - 'superclasses': list([ - 'tests.data.test_package.another_path.another_module.AnotherClass', - ]), - 'variances': list([ - ]), - }), - dict({ - 'attributes': list([ - ]), - 'classes': list([ - ]), - 'constructor': None, - 'docstring': dict({ - 'description': '', - 'full_docstring': '', - }), - 'id': 'test_package/test_module/VarianceClassAll', - 'is_public': True, - 'methods': list([ - ]), - 'name': 'VarianceClassAll', - 'reexported_by': list([ - ]), - 'superclasses': list([ - ]), - 'variances': list([ - dict({ - 'name': '_T_co', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'str', - }), - 'variance_type': 'COVARIANT', - }), - dict({ - 'name': '_T_con', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'SomeClass', - }), - 'variance_type': 'CONTRAVARIANT', - }), - dict({ - 'name': '_T_in', - 'type': dict({ - 'kind': 'UnionType', - 'types': list([ - dict({ - 'kind': 'NamedType', - 'name': 'int', - }), - dict({ - 'kind': 'UnionType', - 'types': list([ - dict({ - 'kind': 'LiteralType', - 'literal': 1, - }), - dict({ - 'kind': 'LiteralType', - 'literal': 2, - }), - ]), - }), - ]), - }), - 'variance_type': 'INVARIANT', - }), - ]), - }), - dict({ - 'attributes': list([ - ]), - 'classes': list([ - ]), - 'constructor': None, - 'docstring': dict({ - 'description': '', - 'full_docstring': '', - }), - 'id': 'test_package/test_module/VarianceClassOnlyInvariance', - 'is_public': True, - 'methods': list([ - ]), - 'name': 'VarianceClassOnlyInvariance', - 'reexported_by': list([ - ]), - 'superclasses': list([ - ]), - 'variances': list([ - dict({ - 'name': '_T_in', - 'type': dict({ - 'kind': 'UnionType', - 'types': list([ - dict({ - 'kind': 'NamedType', - 'name': 'int', - }), - dict({ - 'kind': 'UnionType', - 'types': list([ - dict({ - 'kind': 'LiteralType', - 'literal': 1, - }), - dict({ - 'kind': 'LiteralType', - 'literal': 2, - }), - ]), - }), - ]), - }), - 'variance_type': 'INVARIANT', - }), - ]), - }), - dict({ - 'attributes': list([ - 'test_package/test_module/_PrivateClass/public_attr_in_private_class', - 'test_package/test_module/_PrivateClass/public_init_attr_in_private_class', - ]), - 'classes': list([ - 'test_package/test_module/_PrivateClass/NestedPrivateClass', - ]), - 'constructor': dict({ - 'docstring': dict({ - 'description': '', - 'full_docstring': '', - }), - 'id': 'test_package/test_module/_PrivateClass/__init__', - 'is_class_method': False, - 'is_public': False, - 'is_static': False, - 'name': '__init__', - 'parameters': list([ - 'test_package/test_module/_PrivateClass/__init__/self', - ]), - 'reexported_by': list([ - ]), - 'results': list([ - ]), - }), - 'docstring': dict({ - 'description': '', - 'full_docstring': '', - }), - 'id': 'test_package/test_module/_PrivateClass', - 'is_public': False, - 'methods': list([ - 'test_package/test_module/_PrivateClass/public_func_in_private_class', - ]), - 'name': '_PrivateClass', - 'reexported_by': list([ - ]), - 'superclasses': list([ - ]), - 'variances': list([ - ]), - }), - dict({ - 'attributes': list([ - 'test_package/test_module/_PrivateClass/NestedPrivateClass/nested_class_attr', - ]), - 'classes': list([ - 'test_package/test_module/_PrivateClass/NestedPrivateClass/NestedNestedPrivateClass', - ]), - 'constructor': None, - 'docstring': dict({ - 'description': '', - 'full_docstring': '', - }), - 'id': 'test_package/test_module/_PrivateClass/NestedPrivateClass', - 'is_public': True, - 'methods': list([ - 'test_package/test_module/_PrivateClass/NestedPrivateClass/static_nested_private_class_function', - ]), - 'name': 'NestedPrivateClass', - 'reexported_by': list([ - ]), - 'superclasses': list([ - ]), - 'variances': list([ - ]), - }), - dict({ - 'attributes': list([ - ]), - 'classes': list([ - ]), - 'constructor': None, - 'docstring': dict({ - 'description': '', - 'full_docstring': '', - }), - 'id': 'test_package/test_module/_PrivateClass/NestedPrivateClass/NestedNestedPrivateClass', - 'is_public': True, - 'methods': list([ - ]), - 'name': 'NestedNestedPrivateClass', - 'reexported_by': list([ - ]), - 'superclasses': list([ - ]), - 'variances': list([ - ]), - }), - ]), - 'distribution': '', - 'enum_instances': list([ - dict({ - 'id': 'test_package/test_enums/AnotherTestEnum/number_eleven', - 'name': 'number_eleven', - }), - dict({ - 'id': 'test_package/test_enums/EnumTest/EIGHT', - 'name': 'EIGHT', - }), - dict({ - 'id': 'test_package/test_enums/EnumTest/FIVE', - 'name': 'FIVE', - }), - dict({ - 'id': 'test_package/test_enums/EnumTest/FOUR', - 'name': 'FOUR', - }), - dict({ - 'id': 'test_package/test_enums/EnumTest/NINE', - 'name': 'NINE', - }), - dict({ - 'id': 'test_package/test_enums/EnumTest/ONE', - 'name': 'ONE', - }), - dict({ - 'id': 'test_package/test_enums/EnumTest/SEVEN', - 'name': 'SEVEN', - }), - dict({ - 'id': 'test_package/test_enums/EnumTest/SIX', - 'name': 'SIX', - }), - dict({ - 'id': 'test_package/test_enums/EnumTest/TEN', - 'name': 'TEN', - }), - dict({ - 'id': 'test_package/test_enums/EnumTest/THREE', - 'name': 'THREE', - }), - dict({ - 'id': 'test_package/test_enums/EnumTest/TWO', - 'name': 'TWO', - }), - ]), - 'enums': list([ - dict({ - 'docstring': dict({ - 'description': '', - 'full_docstring': '', - }), - 'id': 'test_package/test_enums/AnotherTestEnum', - 'instances': list([ - 'test_package/test_enums/AnotherTestEnum/number_eleven', - ]), - 'name': 'AnotherTestEnum', - }), - dict({ - 'docstring': dict({ - 'description': ''' - Enum Docstring. - - Full Docstring Description - ''', - 'full_docstring': ''' - Enum Docstring. - - Full Docstring Description - ''', - }), - 'id': 'test_package/test_enums/EnumTest', - 'instances': list([ - 'test_package/test_enums/EnumTest/ONE', - 'test_package/test_enums/EnumTest/TWO', - 'test_package/test_enums/EnumTest/THREE', - 'test_package/test_enums/EnumTest/FOUR', - 'test_package/test_enums/EnumTest/FIVE', - 'test_package/test_enums/EnumTest/SIX', - 'test_package/test_enums/EnumTest/SEVEN', - 'test_package/test_enums/EnumTest/EIGHT', - 'test_package/test_enums/EnumTest/NINE', - 'test_package/test_enums/EnumTest/TEN', - ]), - 'name': 'EnumTest', - }), - dict({ - 'docstring': dict({ - 'description': "Nothing's here.", - 'full_docstring': "Nothing's here.", - }), - 'id': 'test_package/test_enums/_ReexportedEmptyEnum', - 'instances': list([ - ]), - 'name': '_ReexportedEmptyEnum', - }), - ]), - 'functions': list([ - dict({ - 'docstring': dict({ - 'description': '', - 'full_docstring': '', - }), - 'id': 'test_package/_reexport_module_1/ReexportClass/_private_class_method_of_reexported_class', - 'is_class_method': False, - 'is_public': False, - 'is_static': True, - 'name': '_private_class_method_of_reexported_class', - 'parameters': list([ - ]), - 'reexported_by': list([ - 'test_package/__init__', - ]), - 'results': list([ - ]), - }), - dict({ - 'docstring': dict({ - 'description': '', - 'full_docstring': '', - }), - 'id': 'test_package/_reexport_module_1/reexported_function', - 'is_class_method': False, - 'is_public': False, - 'is_static': False, - 'name': 'reexported_function', - 'parameters': list([ - ]), - 'reexported_by': list([ - ]), - 'results': list([ - ]), - }), - dict({ - 'docstring': dict({ - 'description': '', - 'full_docstring': '', - }), - 'id': 'test_package/_reexport_module_2/reexported_function_2', - 'is_class_method': False, - 'is_public': True, - 'is_static': False, - 'name': 'reexported_function_2', - 'parameters': list([ - ]), - 'reexported_by': list([ - 'test_package/__init__', - ]), - 'results': list([ - ]), - }), - dict({ - 'docstring': dict({ - 'description': '', - 'full_docstring': '', - }), - 'id': 'test_package/_reexport_module_3/reexported_function_3', - 'is_class_method': False, - 'is_public': False, - 'is_static': False, - 'name': 'reexported_function_3', - 'parameters': list([ - ]), - 'reexported_by': list([ - 'test_package/__init__', - ]), - 'results': list([ - ]), - }), - dict({ - 'docstring': dict({ - 'description': '', - 'full_docstring': '', - }), - 'id': 'test_package/_reexport_module_4/_reexported_function_4', - 'is_class_method': False, - 'is_public': False, - 'is_static': False, - 'name': '_reexported_function_4', - 'parameters': list([ - ]), - 'reexported_by': list([ - 'test_package/__init__', - ]), - 'results': list([ - ]), - }), - dict({ - 'docstring': dict({ - 'description': '', - 'full_docstring': '', - }), - 'id': 'test_package/_reexport_module_4/_unreexported_function', - 'is_class_method': False, - 'is_public': False, - 'is_static': False, - 'name': '_unreexported_function', - 'parameters': list([ - ]), - 'reexported_by': list([ - ]), - 'results': list([ - ]), - }), - dict({ - 'docstring': dict({ - 'description': '', - 'full_docstring': '', - }), - 'id': 'test_package/test_docstrings/EpydocDocstringClass/__init__', - 'is_class_method': False, - 'is_public': True, - 'is_static': False, - 'name': '__init__', - 'parameters': list([ - 'test_package/test_docstrings/EpydocDocstringClass/__init__/self', - 'test_package/test_docstrings/EpydocDocstringClass/__init__/param_1', - ]), - 'reexported_by': list([ - ]), - 'results': list([ - ]), - }), - dict({ - 'docstring': dict({ - 'description': ''' - This function checks if the sum of x and y is less than the value 10 and returns True if it is. (Epydoc). - - @param x: First integer value for the calculation. (Epydoc) - @type x: int - @param y: Second integer value for the calculation. (Epydoc) - @type y: int - @return: Checks if the sum of x and y is greater than 10. (Epydoc) - @rtype: bool - ''', - 'full_docstring': ''' - This function checks if the sum of x and y is less than the value 10 and returns True if it is. (Epydoc). - - @param x: First integer value for the calculation. (Epydoc) - @type x: int - @param y: Second integer value for the calculation. (Epydoc) - @type y: int - @return: Checks if the sum of x and y is greater than 10. (Epydoc) - @rtype: bool - ''', - }), - 'id': 'test_package/test_docstrings/EpydocDocstringClass/epydoc_docstring_func', - 'is_class_method': False, - 'is_public': True, - 'is_static': False, - 'name': 'epydoc_docstring_func', - 'parameters': list([ - 'test_package/test_docstrings/EpydocDocstringClass/epydoc_docstring_func/self', - 'test_package/test_docstrings/EpydocDocstringClass/epydoc_docstring_func/x', - 'test_package/test_docstrings/EpydocDocstringClass/epydoc_docstring_func/y', - ]), - 'reexported_by': list([ - ]), - 'results': list([ - 'test_package/test_docstrings/EpydocDocstringClass/epydoc_docstring_func/result_1', - ]), - }), - dict({ - 'docstring': dict({ - 'description': '', - 'full_docstring': '', - }), - 'id': 'test_package/test_docstrings/GoogleDocstringClass/__init__', - 'is_class_method': False, - 'is_public': True, - 'is_static': False, - 'name': '__init__', - 'parameters': list([ - 'test_package/test_docstrings/GoogleDocstringClass/__init__/self', - 'test_package/test_docstrings/GoogleDocstringClass/__init__/param_1', - ]), - 'reexported_by': list([ - ]), - 'results': list([ - ]), - }), - dict({ - 'docstring': dict({ - 'description': ''' - Checks if the sum of two variables is over the value of 10. (Google Style). - - This function checks if the sum of x and y is less than the value 10 - and returns True if it is. (Google Style) - - Args: - x (int): First integer value for the calculation. (Google Style) - y (int): Second integer value for the calculation. (Google Style) - - Returns: - bool: Checks if the sum of x and y is greater than 10 and returns - a boolean value. (Google Style) - ''', - 'full_docstring': ''' - Checks if the sum of two variables is over the value of 10. (Google Style). - - This function checks if the sum of x and y is less than the value 10 - and returns True if it is. (Google Style) - - Args: - x (int): First integer value for the calculation. (Google Style) - y (int): Second integer value for the calculation. (Google Style) - - Returns: - bool: Checks if the sum of x and y is greater than 10 and returns - a boolean value. (Google Style) - ''', - }), - 'id': 'test_package/test_docstrings/GoogleDocstringClass/google_docstring_func', - 'is_class_method': False, - 'is_public': True, - 'is_static': False, - 'name': 'google_docstring_func', - 'parameters': list([ - 'test_package/test_docstrings/GoogleDocstringClass/google_docstring_func/self', - 'test_package/test_docstrings/GoogleDocstringClass/google_docstring_func/x', - 'test_package/test_docstrings/GoogleDocstringClass/google_docstring_func/y', - ]), - 'reexported_by': list([ - ]), - 'results': list([ - 'test_package/test_docstrings/GoogleDocstringClass/google_docstring_func/result_1', - ]), - }), - dict({ - 'docstring': dict({ - 'description': '', - 'full_docstring': '', - }), - 'id': 'test_package/test_docstrings/NumpyDocstringClass/__init__', - 'is_class_method': False, - 'is_public': True, - 'is_static': False, - 'name': '__init__', - 'parameters': list([ - 'test_package/test_docstrings/NumpyDocstringClass/__init__/self', - 'test_package/test_docstrings/NumpyDocstringClass/__init__/param_1', - ]), - 'reexported_by': list([ - ]), - 'results': list([ - ]), - }), - dict({ - 'docstring': dict({ - 'description': ''' - Checks if the sum of two variables is over the value of 10. (Numpy). - - This function checks if the sum of `x` and `y` is less than the value 10 and returns True if it is. (Numpy) - - Parameters - ---------- - x : int - First integer value for the calculation. (Numpy) - y : int - Second integer value for the calculation. (Numpy) - - Returns - ------- - bool - Checks if the sum of `x` and `y` is greater than 10. (Numpy) - ''', - 'full_docstring': ''' - Checks if the sum of two variables is over the value of 10. (Numpy). - - This function checks if the sum of `x` and `y` is less than the value 10 and returns True if it is. (Numpy) - - Parameters - ---------- - x : int - First integer value for the calculation. (Numpy) - y : int - Second integer value for the calculation. (Numpy) - - Returns - ------- - bool - Checks if the sum of `x` and `y` is greater than 10. (Numpy) - ''', - }), - 'id': 'test_package/test_docstrings/NumpyDocstringClass/numpy_docstring_func', - 'is_class_method': False, - 'is_public': True, - 'is_static': False, - 'name': 'numpy_docstring_func', - 'parameters': list([ - 'test_package/test_docstrings/NumpyDocstringClass/numpy_docstring_func/self', - 'test_package/test_docstrings/NumpyDocstringClass/numpy_docstring_func/x', - 'test_package/test_docstrings/NumpyDocstringClass/numpy_docstring_func/y', - ]), - 'reexported_by': list([ - ]), - 'results': list([ - 'test_package/test_docstrings/NumpyDocstringClass/numpy_docstring_func/result_1', - ]), - }), - dict({ - 'docstring': dict({ - 'description': '', - 'full_docstring': '', - }), - 'id': 'test_package/test_docstrings/RestDocstringClass/__init__', - 'is_class_method': False, - 'is_public': True, - 'is_static': False, - 'name': '__init__', - 'parameters': list([ - 'test_package/test_docstrings/RestDocstringClass/__init__/self', - 'test_package/test_docstrings/RestDocstringClass/__init__/param_1', - ]), - 'reexported_by': list([ - ]), - 'results': list([ - ]), - }), - dict({ - 'docstring': dict({ - 'description': ''' - This function checks if the sum of x and y is less than the value 10 - and returns True if it is. (ReST). - - :param x: First integer value for the calculation. (ReST) - :type x: int - :param y: Second integer value for the calculation. (ReST) - :type y: int - :returns: Checks if the sum of x and y is greater than 10. (ReST) - :rtype: bool - ''', - 'full_docstring': ''' - This function checks if the sum of x and y is less than the value 10 - and returns True if it is. (ReST). - - :param x: First integer value for the calculation. (ReST) - :type x: int - :param y: Second integer value for the calculation. (ReST) - :type y: int - :returns: Checks if the sum of x and y is greater than 10. (ReST) - :rtype: bool - ''', - }), - 'id': 'test_package/test_docstrings/RestDocstringClass/rest_docstring_func', - 'is_class_method': False, - 'is_public': True, - 'is_static': False, - 'name': 'rest_docstring_func', - 'parameters': list([ - 'test_package/test_docstrings/RestDocstringClass/rest_docstring_func/self', - 'test_package/test_docstrings/RestDocstringClass/rest_docstring_func/x', - 'test_package/test_docstrings/RestDocstringClass/rest_docstring_func/y', - ]), - 'reexported_by': list([ - ]), - 'results': list([ - 'test_package/test_docstrings/RestDocstringClass/rest_docstring_func/result_1', - ]), - }), - dict({ - 'docstring': dict({ - 'description': '', - 'full_docstring': '', - }), - 'id': 'test_package/test_module/InferMyTypes/__init__', - 'is_class_method': False, - 'is_public': True, - 'is_static': False, - 'name': '__init__', - 'parameters': list([ - 'test_package/test_module/InferMyTypes/__init__/self', - 'test_package/test_module/InferMyTypes/__init__/init_param', - ]), - 'reexported_by': list([ - ]), - 'results': list([ - ]), - }), - dict({ - 'docstring': dict({ - 'description': '', - 'full_docstring': '', - }), - 'id': 'test_package/test_module/InferMyTypes/infer_function', - 'is_class_method': False, - 'is_public': True, - 'is_static': True, - 'name': 'infer_function', - 'parameters': list([ - 'test_package/test_module/InferMyTypes/infer_function/infer_param', - 'test_package/test_module/InferMyTypes/infer_function/infer_param_2', - ]), - 'reexported_by': list([ - ]), - 'results': list([ - 'test_package/test_module/InferMyTypes/infer_function/result_1', - 'test_package/test_module/InferMyTypes/infer_function/result_2', - 'test_package/test_module/InferMyTypes/infer_function/result_3', - 'test_package/test_module/InferMyTypes/infer_function/result_4', - 'test_package/test_module/InferMyTypes/infer_function/result_5', - 'test_package/test_module/InferMyTypes/infer_function/result_6', - 'test_package/test_module/InferMyTypes/infer_function/result_7', - ]), - }), - dict({ - 'docstring': dict({ - 'description': '', - 'full_docstring': '', - }), - 'id': 'test_package/test_module/SomeClass/NestedClass/nested_class_function', - 'is_class_method': False, - 'is_public': True, - 'is_static': False, - 'name': 'nested_class_function', - 'parameters': list([ - 'test_package/test_module/SomeClass/NestedClass/nested_class_function/self', - 'test_package/test_module/SomeClass/NestedClass/nested_class_function/param_1', - ]), - 'reexported_by': list([ - ]), - 'results': list([ - 'test_package/test_module/SomeClass/NestedClass/nested_class_function/result_1', - ]), - }), - dict({ - 'docstring': dict({ - 'description': ''' - Summary of the init description. - - Full init description. - ''', - 'full_docstring': ''' - Summary of the init description. - - Full init description. - ''', - }), - 'id': 'test_package/test_module/SomeClass/__init__', - 'is_class_method': False, - 'is_public': True, - 'is_static': False, - 'name': '__init__', - 'parameters': list([ - 'test_package/test_module/SomeClass/__init__/self', - 'test_package/test_module/SomeClass/__init__/init_param_1', - ]), - 'reexported_by': list([ - ]), - 'results': list([ - ]), - }), - dict({ - 'docstring': dict({ - 'description': ''' - Function Docstring. - - param_2: bool. - ''', - 'full_docstring': ''' - Function Docstring. - - param_2: bool. - ''', - }), - 'id': 'test_package/test_module/SomeClass/_some_function', - 'is_class_method': False, - 'is_public': False, - 'is_static': False, - 'name': '_some_function', - 'parameters': list([ - 'test_package/test_module/SomeClass/_some_function/self', - 'test_package/test_module/SomeClass/_some_function/param_1', - 'test_package/test_module/SomeClass/_some_function/param_2', - ]), - 'reexported_by': list([ - ]), - 'results': list([ - 'test_package/test_module/SomeClass/_some_function/result_1', - ]), - }), - dict({ - 'docstring': dict({ - 'description': '', - 'full_docstring': '', - }), - 'id': 'test_package/test_module/SomeClass/class_method', - 'is_class_method': True, - 'is_public': True, - 'is_static': False, - 'name': 'class_method', - 'parameters': list([ - 'test_package/test_module/SomeClass/class_method/cls', - ]), - 'reexported_by': list([ - ]), - 'results': list([ - ]), - }), - dict({ - 'docstring': dict({ - 'description': '', - 'full_docstring': '', - }), - 'id': 'test_package/test_module/SomeClass/class_method_params', - 'is_class_method': True, - 'is_public': True, - 'is_static': False, - 'name': 'class_method_params', - 'parameters': list([ - 'test_package/test_module/SomeClass/class_method_params/cls', - 'test_package/test_module/SomeClass/class_method_params/param_1', - ]), - 'reexported_by': list([ - ]), - 'results': list([ - 'test_package/test_module/SomeClass/class_method_params/result_1', - ]), - }), - dict({ - 'docstring': dict({ - 'description': 'Function Docstring.', - 'full_docstring': 'Function Docstring.', - }), - 'id': 'test_package/test_module/SomeClass/multiple_results', - 'is_class_method': False, - 'is_public': True, - 'is_static': True, - 'name': 'multiple_results', - 'parameters': list([ - 'test_package/test_module/SomeClass/multiple_results/param_1', - ]), - 'reexported_by': list([ - ]), - 'results': list([ - 'test_package/test_module/SomeClass/multiple_results/result_1', - ]), - }), - dict({ - 'docstring': dict({ - 'description': '', - 'full_docstring': '', - }), - 'id': 'test_package/test_module/SomeClass/no_return_1', - 'is_class_method': False, - 'is_public': True, - 'is_static': False, - 'name': 'no_return_1', - 'parameters': list([ - 'test_package/test_module/SomeClass/no_return_1/self', - ]), - 'reexported_by': list([ - ]), - 'results': list([ - ]), - }), - dict({ - 'docstring': dict({ - 'description': '', - 'full_docstring': '', - }), - 'id': 'test_package/test_module/SomeClass/no_return_2', - 'is_class_method': False, - 'is_public': True, - 'is_static': False, - 'name': 'no_return_2', - 'parameters': list([ - 'test_package/test_module/SomeClass/no_return_2/self', - ]), - 'reexported_by': list([ - ]), - 'results': list([ - ]), - }), - dict({ - 'docstring': dict({ - 'description': 'Function Docstring.', - 'full_docstring': 'Function Docstring.', - }), - 'id': 'test_package/test_module/SomeClass/static_function', - 'is_class_method': False, - 'is_public': True, - 'is_static': True, - 'name': 'static_function', - 'parameters': list([ - 'test_package/test_module/SomeClass/static_function/param_1', - 'test_package/test_module/SomeClass/static_function/param_2', - ]), - 'reexported_by': list([ - ]), - 'results': list([ - 'test_package/test_module/SomeClass/static_function/result_1', - 'test_package/test_module/SomeClass/static_function/result_2', - ]), - }), - dict({ - 'docstring': dict({ - 'description': '', - 'full_docstring': '', - }), - 'id': 'test_package/test_module/SomeClass/test_params', - 'is_class_method': False, - 'is_public': True, - 'is_static': True, - 'name': 'test_params', - 'parameters': list([ - 'test_package/test_module/SomeClass/test_params/args', - 'test_package/test_module/SomeClass/test_params/kwargs', - ]), - 'reexported_by': list([ - ]), - 'results': list([ - ]), - }), - dict({ - 'docstring': dict({ - 'description': 'Function Docstring.', - 'full_docstring': 'Function Docstring.', - }), - 'id': 'test_package/test_module/SomeClass/test_position', - 'is_class_method': False, - 'is_public': True, - 'is_static': False, - 'name': 'test_position', - 'parameters': list([ - 'test_package/test_module/SomeClass/test_position/self', - 'test_package/test_module/SomeClass/test_position/param1', - 'test_package/test_module/SomeClass/test_position/param2', - 'test_package/test_module/SomeClass/test_position/param3', - 'test_package/test_module/SomeClass/test_position/param4', - 'test_package/test_module/SomeClass/test_position/param5', - ]), - 'reexported_by': list([ - ]), - 'results': list([ - 'test_package/test_module/SomeClass/test_position/result_1', - ]), - }), - dict({ - 'docstring': dict({ - 'description': '', - 'full_docstring': '', - }), - 'id': 'test_package/test_module/_PrivateClass/NestedPrivateClass/static_nested_private_class_function', - 'is_class_method': False, - 'is_public': False, - 'is_static': True, - 'name': 'static_nested_private_class_function', - 'parameters': list([ - ]), - 'reexported_by': list([ - ]), - 'results': list([ - ]), - }), - dict({ - 'docstring': dict({ - 'description': '', - 'full_docstring': '', - }), - 'id': 'test_package/test_module/_PrivateClass/__init__', - 'is_class_method': False, - 'is_public': False, - 'is_static': False, - 'name': '__init__', - 'parameters': list([ - 'test_package/test_module/_PrivateClass/__init__/self', - ]), - 'reexported_by': list([ - ]), - 'results': list([ - ]), - }), - dict({ - 'docstring': dict({ - 'description': '', - 'full_docstring': '', - }), - 'id': 'test_package/test_module/_PrivateClass/public_func_in_private_class', - 'is_class_method': False, - 'is_public': False, - 'is_static': False, - 'name': 'public_func_in_private_class', - 'parameters': list([ - 'test_package/test_module/_PrivateClass/public_func_in_private_class/self', - ]), - 'reexported_by': list([ - ]), - 'results': list([ - ]), - }), - dict({ - 'docstring': dict({ - 'description': '', - 'full_docstring': '', - }), - 'id': 'test_package/test_module/_private_global_func', - 'is_class_method': False, - 'is_public': False, - 'is_static': False, - 'name': '_private_global_func', - 'parameters': list([ - ]), - 'reexported_by': list([ - ]), - 'results': list([ - 'test_package/test_module/_private_global_func/result_1', - ]), - }), - dict({ - 'docstring': dict({ - 'description': ''' - Docstring 1. - - Docstring 2. - ''', - 'full_docstring': ''' - Docstring 1. - - Docstring 2. - ''', - }), - 'id': 'test_package/test_module/global_func', - 'is_class_method': False, - 'is_public': True, - 'is_static': False, - 'name': 'global_func', - 'parameters': list([ - 'test_package/test_module/global_func/param_1', - 'test_package/test_module/global_func/param_2', - ]), - 'reexported_by': list([ - ]), - 'results': list([ - 'test_package/test_module/global_func/result_1', - ]), - }), - ]), - 'modules': list([ - dict({ - 'classes': list([ - ]), - 'docstring': '', - 'enums': list([ - ]), - 'functions': list([ - ]), - 'id': 'test_package/__init__', - 'name': '__init__', - 'qualified_imports': list([ - dict({ - 'alias': 'reex_1', - 'qualified_name': '._reexport_module_1', - }), - dict({ - 'alias': None, - 'qualified_name': '_reexport_module_1.ReexportClass', - }), - dict({ - 'alias': None, - 'qualified_name': '_reexport_module_2.reexported_function_2', - }), - dict({ - 'alias': None, - 'qualified_name': '_reexport_module_4.FourthReexportClass', - }), - dict({ - 'alias': None, - 'qualified_name': '_reexport_module_4._reexported_function_4', - }), - dict({ - 'alias': None, - 'qualified_name': 'test_enums._ReexportedEmptyEnum', - }), - ]), - 'wildcard_imports': list([ - dict({ - 'module_name': '_reexport_module_3', - }), - ]), - }), - dict({ - 'classes': list([ - 'test_package/_reexport_module_1/ReexportClass', - ]), - 'docstring': '', - 'enums': list([ - ]), - 'functions': list([ - 'test_package/_reexport_module_1/reexported_function', - ]), - 'id': 'test_package/_reexport_module_1', - 'name': '_reexport_module_1', - 'qualified_imports': list([ - ]), - 'wildcard_imports': list([ - ]), - }), - dict({ - 'classes': list([ - 'test_package/_reexport_module_2/AnotherReexportClass', - ]), - 'docstring': '', - 'enums': list([ - ]), - 'functions': list([ - 'test_package/_reexport_module_2/reexported_function_2', - ]), - 'id': 'test_package/_reexport_module_2', - 'name': '_reexport_module_2', - 'qualified_imports': list([ - ]), - 'wildcard_imports': list([ - ]), - }), - dict({ - 'classes': list([ - 'test_package/_reexport_module_3/_ThirdReexportClass', - ]), - 'docstring': '', - 'enums': list([ - ]), - 'functions': list([ - 'test_package/_reexport_module_3/reexported_function_3', - ]), - 'id': 'test_package/_reexport_module_3', - 'name': '_reexport_module_3', - 'qualified_imports': list([ - ]), - 'wildcard_imports': list([ - ]), - }), - dict({ - 'classes': list([ - 'test_package/_reexport_module_4/FourthReexportClass', - ]), - 'docstring': '', - 'enums': list([ - ]), - 'functions': list([ - 'test_package/_reexport_module_4/_unreexported_function', - 'test_package/_reexport_module_4/_reexported_function_4', - ]), - 'id': 'test_package/_reexport_module_4', - 'name': '_reexport_module_4', - 'qualified_imports': list([ - ]), - 'wildcard_imports': list([ - ]), - }), - dict({ - 'classes': list([ - 'test_package/another_path/another_module/AnotherClass', - ]), - 'docstring': ''' - Another Module Docstring. - - Full Docstring Description - - ''', - 'enums': list([ - ]), - 'functions': list([ - ]), - 'id': 'test_package/another_path/another_module', - 'name': 'another_module', - 'qualified_imports': list([ - ]), - 'wildcard_imports': list([ - ]), - }), - dict({ - 'classes': list([ - 'test_package/test_docstrings/EpydocDocstringClass', - 'test_package/test_docstrings/RestDocstringClass', - 'test_package/test_docstrings/NumpyDocstringClass', - 'test_package/test_docstrings/GoogleDocstringClass', - ]), - 'docstring': ''' - Test module for docstring tests. - - A module for testing the various docstring types. - - ''', - 'enums': list([ - ]), - 'functions': list([ - ]), - 'id': 'test_package/test_docstrings', - 'name': 'test_docstrings', - 'qualified_imports': list([ - ]), - 'wildcard_imports': list([ - ]), - }), - dict({ - 'classes': list([ - ]), - 'docstring': '', - 'enums': list([ - 'test_package/test_enums/EnumTest', - 'test_package/test_enums/_ReexportedEmptyEnum', - 'test_package/test_enums/AnotherTestEnum', - ]), - 'functions': list([ - ]), - 'id': 'test_package/test_enums', - 'name': 'test_enums', - 'qualified_imports': list([ - dict({ - 'alias': None, - 'qualified_name': 'enum.Enum', - }), - dict({ - 'alias': None, - 'qualified_name': 'enum.IntEnum', - }), - dict({ - 'alias': '_Enum', - 'qualified_name': 'enum.Enum', - }), - dict({ - 'alias': '_AcImportAlias', - 'qualified_name': 'another_path.another_module.AnotherClass', - }), - ]), - 'wildcard_imports': list([ - ]), - }), - dict({ - 'classes': list([ - 'test_package/test_module/SomeClass', - 'test_package/test_module/_PrivateClass', - 'test_package/test_module/InferMyTypes', - 'test_package/test_module/VarianceClassAll', - 'test_package/test_module/VarianceClassOnlyInvariance', - ]), - 'docstring': 'Docstring of the some_class.py module.', - 'enums': list([ - ]), - 'functions': list([ - 'test_package/test_module/global_func', - 'test_package/test_module/_private_global_func', - ]), - 'id': 'test_package/test_module', - 'name': 'test_module', - 'qualified_imports': list([ - dict({ - 'alias': 'mathematics', - 'qualified_name': 'math', - }), - dict({ - 'alias': None, - 'qualified_name': 'mypy', - }), - dict({ - 'alias': None, - 'qualified_name': 'another_path.another_module.AnotherClass', - }), - dict({ - 'alias': '_AcImportAlias', - 'qualified_name': 'another_path.another_module.AnotherClass', - }), - ]), - 'wildcard_imports': list([ - dict({ - 'module_name': 'typing', - }), - dict({ - 'module_name': 'docstring_parser', - }), - ]), - }), - ]), - 'package': 'test_package', - 'parameters': list([ - dict({ - 'assigned_by': 'POSITION_OR_NAME', - 'default_value': None, - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_docstrings/EpydocDocstringClass/__init__/param_1', - 'is_optional': False, - 'is_type_inferred': False, - 'name': 'param_1', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'str', - }), - }), - dict({ - 'assigned_by': 'IMPLICIT', - 'default_value': None, - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_docstrings/EpydocDocstringClass/__init__/self', - 'is_optional': False, - 'is_type_inferred': False, - 'name': 'self', - 'type': None, - }), - dict({ - 'assigned_by': 'IMPLICIT', - 'default_value': None, - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_docstrings/EpydocDocstringClass/epydoc_docstring_func/self', - 'is_optional': False, - 'is_type_inferred': False, - 'name': 'self', - 'type': None, - }), - dict({ - 'assigned_by': 'POSITION_OR_NAME', - 'default_value': None, - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_docstrings/EpydocDocstringClass/epydoc_docstring_func/x', - 'is_optional': False, - 'is_type_inferred': False, - 'name': 'x', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'int', - }), - }), - dict({ - 'assigned_by': 'POSITION_OR_NAME', - 'default_value': None, - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_docstrings/EpydocDocstringClass/epydoc_docstring_func/y', - 'is_optional': False, - 'is_type_inferred': False, - 'name': 'y', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'int', - }), - }), - dict({ - 'assigned_by': 'POSITION_OR_NAME', - 'default_value': None, - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_docstrings/GoogleDocstringClass/__init__/param_1', - 'is_optional': False, - 'is_type_inferred': False, - 'name': 'param_1', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'str', - }), - }), - dict({ - 'assigned_by': 'IMPLICIT', - 'default_value': None, - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_docstrings/GoogleDocstringClass/__init__/self', - 'is_optional': False, - 'is_type_inferred': False, - 'name': 'self', - 'type': None, - }), - dict({ - 'assigned_by': 'IMPLICIT', - 'default_value': None, - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_docstrings/GoogleDocstringClass/google_docstring_func/self', - 'is_optional': False, - 'is_type_inferred': False, - 'name': 'self', - 'type': None, - }), - dict({ - 'assigned_by': 'POSITION_OR_NAME', - 'default_value': None, - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_docstrings/GoogleDocstringClass/google_docstring_func/x', - 'is_optional': False, - 'is_type_inferred': False, - 'name': 'x', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'int', - }), - }), - dict({ - 'assigned_by': 'POSITION_OR_NAME', - 'default_value': None, - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_docstrings/GoogleDocstringClass/google_docstring_func/y', - 'is_optional': False, - 'is_type_inferred': False, - 'name': 'y', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'int', - }), - }), - dict({ - 'assigned_by': 'POSITION_OR_NAME', - 'default_value': None, - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_docstrings/NumpyDocstringClass/__init__/param_1', - 'is_optional': False, - 'is_type_inferred': False, - 'name': 'param_1', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'str', - }), - }), - dict({ - 'assigned_by': 'IMPLICIT', - 'default_value': None, - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_docstrings/NumpyDocstringClass/__init__/self', - 'is_optional': False, - 'is_type_inferred': False, - 'name': 'self', - 'type': None, - }), - dict({ - 'assigned_by': 'IMPLICIT', - 'default_value': None, - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_docstrings/NumpyDocstringClass/numpy_docstring_func/self', - 'is_optional': False, - 'is_type_inferred': False, - 'name': 'self', - 'type': None, - }), - dict({ - 'assigned_by': 'POSITION_OR_NAME', - 'default_value': None, - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_docstrings/NumpyDocstringClass/numpy_docstring_func/x', - 'is_optional': False, - 'is_type_inferred': False, - 'name': 'x', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'int', - }), - }), - dict({ - 'assigned_by': 'POSITION_OR_NAME', - 'default_value': None, - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_docstrings/NumpyDocstringClass/numpy_docstring_func/y', - 'is_optional': False, - 'is_type_inferred': False, - 'name': 'y', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'int', - }), - }), - dict({ - 'assigned_by': 'POSITION_OR_NAME', - 'default_value': None, - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_docstrings/RestDocstringClass/__init__/param_1', - 'is_optional': False, - 'is_type_inferred': False, - 'name': 'param_1', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'str', - }), - }), - dict({ - 'assigned_by': 'IMPLICIT', - 'default_value': None, - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_docstrings/RestDocstringClass/__init__/self', - 'is_optional': False, - 'is_type_inferred': False, - 'name': 'self', - 'type': None, - }), - dict({ - 'assigned_by': 'IMPLICIT', - 'default_value': None, - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_docstrings/RestDocstringClass/rest_docstring_func/self', - 'is_optional': False, - 'is_type_inferred': False, - 'name': 'self', - 'type': None, - }), - dict({ - 'assigned_by': 'POSITION_OR_NAME', - 'default_value': None, - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_docstrings/RestDocstringClass/rest_docstring_func/x', - 'is_optional': False, - 'is_type_inferred': False, - 'name': 'x', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'int', - }), - }), - dict({ - 'assigned_by': 'POSITION_OR_NAME', - 'default_value': None, - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_docstrings/RestDocstringClass/rest_docstring_func/y', - 'is_optional': False, - 'is_type_inferred': False, - 'name': 'y', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'int', - }), - }), - dict({ - 'assigned_by': 'POSITION_OR_NAME', - 'default_value': 1, - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_module/InferMyTypes/__init__/init_param', - 'is_optional': True, - 'is_type_inferred': True, - 'name': 'init_param', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'int', - }), - }), - dict({ - 'assigned_by': 'IMPLICIT', - 'default_value': None, - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_module/InferMyTypes/__init__/self', - 'is_optional': False, - 'is_type_inferred': False, - 'name': 'self', - 'type': None, - }), - dict({ - 'assigned_by': 'POSITION_OR_NAME', - 'default_value': 1, - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_module/InferMyTypes/infer_function/infer_param', - 'is_optional': True, - 'is_type_inferred': True, - 'name': 'infer_param', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'int', - }), - }), - dict({ - 'assigned_by': 'POSITION_OR_NAME', - 'default_value': 'Something', - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_module/InferMyTypes/infer_function/infer_param_2', - 'is_optional': True, - 'is_type_inferred': False, - 'name': 'infer_param_2', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'int', - }), - }), - dict({ - 'assigned_by': 'POSITION_OR_NAME', - 'default_value': None, - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_module/SomeClass/NestedClass/nested_class_function/param_1', - 'is_optional': False, - 'is_type_inferred': False, - 'name': 'param_1', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'int', - }), - }), - dict({ - 'assigned_by': 'IMPLICIT', - 'default_value': None, - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_module/SomeClass/NestedClass/nested_class_function/self', - 'is_optional': False, - 'is_type_inferred': False, - 'name': 'self', - 'type': None, - }), - dict({ - 'assigned_by': 'POSITION_OR_NAME', - 'default_value': None, - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_module/SomeClass/__init__/init_param_1', - 'is_optional': False, - 'is_type_inferred': False, - 'name': 'init_param_1', - 'type': None, - }), - dict({ - 'assigned_by': 'IMPLICIT', - 'default_value': None, - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_module/SomeClass/__init__/self', - 'is_optional': False, - 'is_type_inferred': False, - 'name': 'self', - 'type': None, - }), - dict({ - 'assigned_by': 'POSITION_OR_NAME', - 'default_value': None, - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_module/SomeClass/_some_function/param_1', - 'is_optional': False, - 'is_type_inferred': False, - 'name': 'param_1', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'AnotherClass', - }), - }), - dict({ - 'assigned_by': 'POSITION_OR_NAME', - 'default_value': False, - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_module/SomeClass/_some_function/param_2', - 'is_optional': True, - 'is_type_inferred': False, - 'name': 'param_2', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'bool', - }), - }), - dict({ - 'assigned_by': 'IMPLICIT', - 'default_value': None, - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_module/SomeClass/_some_function/self', - 'is_optional': False, - 'is_type_inferred': False, - 'name': 'self', - 'type': None, - }), - dict({ - 'assigned_by': 'IMPLICIT', - 'default_value': None, - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_module/SomeClass/class_method/cls', - 'is_optional': False, - 'is_type_inferred': False, - 'name': 'cls', - 'type': None, - }), - dict({ - 'assigned_by': 'IMPLICIT', - 'default_value': None, - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_module/SomeClass/class_method_params/cls', - 'is_optional': False, - 'is_type_inferred': False, - 'name': 'cls', - 'type': None, - }), - dict({ - 'assigned_by': 'POSITION_OR_NAME', - 'default_value': None, - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_module/SomeClass/class_method_params/param_1', - 'is_optional': False, - 'is_type_inferred': False, - 'name': 'param_1', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'int', - }), - }), - dict({ - 'assigned_by': 'POSITION_OR_NAME', - 'default_value': None, - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_module/SomeClass/multiple_results/param_1', - 'is_optional': False, - 'is_type_inferred': False, - 'name': 'param_1', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'int', - }), - }), - dict({ - 'assigned_by': 'IMPLICIT', - 'default_value': None, - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_module/SomeClass/no_return_1/self', - 'is_optional': False, - 'is_type_inferred': False, - 'name': 'self', - 'type': None, - }), - dict({ - 'assigned_by': 'IMPLICIT', - 'default_value': None, - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_module/SomeClass/no_return_2/self', - 'is_optional': False, - 'is_type_inferred': False, - 'name': 'self', - 'type': None, - }), - dict({ - 'assigned_by': 'POSITION_OR_NAME', - 'default_value': True, - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_module/SomeClass/static_function/param_1', - 'is_optional': True, - 'is_type_inferred': False, - 'name': 'param_1', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'bool', - }), + ]), + 'wildcard_imports': list([ + dict({ + 'module_name': 'docstring_parser', + }), + ]), }), + ]), + 'package': 'test_main', + 'parameters': list([ dict({ 'assigned_by': 'POSITION_OR_NAME', - 'default_value': 123456, + 'default_value': None, 'docstring': dict({ 'default_value': '', 'description': '', 'type': '', }), - 'id': 'test_package/test_module/SomeClass/static_function/param_2', - 'is_optional': True, + 'id': 'test_main/main_test_module/ModuleClass/NestedClass/nested_class_function/param_1', + 'is_optional': False, 'is_type_inferred': False, - 'name': 'param_2', + 'name': 'param_1', 'type': dict({ - 'kind': 'UnionType', - 'types': list([ - dict({ - 'kind': 'NamedType', - 'name': 'int', - }), - dict({ - 'kind': 'NamedType', - 'name': 'bool', - }), - ]), + 'kind': 'NamedType', + 'name': 'int', }), }), dict({ - 'assigned_by': 'POSITIONAL_VARARG', + 'assigned_by': 'IMPLICIT', 'default_value': None, 'docstring': dict({ 'default_value': '', 'description': '', 'type': '', }), - 'id': 'test_package/test_module/SomeClass/test_params/args', + 'id': 'test_main/main_test_module/ModuleClass/NestedClass/nested_class_function/self', 'is_optional': False, 'is_type_inferred': False, - 'name': 'args', + 'name': 'self', 'type': None, }), dict({ - 'assigned_by': 'NAMED_VARARG', + 'assigned_by': 'POSITION_OR_NAME', 'default_value': None, 'docstring': dict({ 'default_value': '', 'description': '', 'type': '', }), - 'id': 'test_package/test_module/SomeClass/test_params/kwargs', + 'id': 'test_main/main_test_module/ModuleClass/__init__/init_param_1', 'is_optional': False, 'is_type_inferred': False, - 'name': 'kwargs', + 'name': 'init_param_1', 'type': None, }), dict({ - 'assigned_by': 'POSITION_ONLY', + 'assigned_by': 'IMPLICIT', 'default_value': None, 'docstring': dict({ 'default_value': '', 'description': '', 'type': '', }), - 'id': 'test_package/test_module/SomeClass/test_position/param1', + 'id': 'test_main/main_test_module/ModuleClass/__init__/self', 'is_optional': False, 'is_type_inferred': False, - 'name': 'param1', + 'name': 'self', 'type': None, }), dict({ @@ -3175,61 +611,30 @@ 'description': '', 'type': '', }), - 'id': 'test_package/test_module/SomeClass/test_position/param2', + 'id': 'test_main/main_test_module/ModuleClass/_some_function/param_1', 'is_optional': False, 'is_type_inferred': False, - 'name': 'param2', + 'name': 'param_1', 'type': dict({ 'kind': 'NamedType', - 'name': 'bool', + 'name': 'AnotherClass', }), }), dict({ 'assigned_by': 'POSITION_OR_NAME', - 'default_value': 1, - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_module/SomeClass/test_position/param3', - 'is_optional': True, - 'is_type_inferred': True, - 'name': 'param3', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'int', - }), - }), - dict({ - 'assigned_by': 'NAME_ONLY', - 'default_value': None, - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_module/SomeClass/test_position/param4', - 'is_optional': False, - 'is_type_inferred': False, - 'name': 'param4', - 'type': None, - }), - dict({ - 'assigned_by': 'NAME_ONLY', - 'default_value': 1, + 'default_value': False, 'docstring': dict({ 'default_value': '', 'description': '', 'type': '', }), - 'id': 'test_package/test_module/SomeClass/test_position/param5', + 'id': 'test_main/main_test_module/ModuleClass/_some_function/param_2', 'is_optional': True, 'is_type_inferred': False, - 'name': 'param5', + 'name': 'param_2', 'type': dict({ 'kind': 'NamedType', - 'name': 'int', + 'name': 'bool', }), }), dict({ @@ -3240,7 +645,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/test_module/SomeClass/test_position/self', + 'id': 'test_main/main_test_module/ModuleClass/_some_function/self', 'is_optional': False, 'is_type_inferred': False, 'name': 'self', @@ -3254,7 +659,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/test_module/_PrivateClass/__init__/self', + 'id': 'test_main/main_test_module/_PrivateClass/__init__/self', 'is_optional': False, 'is_type_inferred': False, 'name': 'self', @@ -3268,7 +673,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/test_module/_PrivateClass/public_func_in_private_class/self', + 'id': 'test_main/main_test_module/_PrivateClass/public_func_in_private_class/self', 'is_optional': False, 'is_type_inferred': False, 'name': 'self', @@ -3282,7 +687,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/test_module/global_func/param_1', + 'id': 'test_main/main_test_module/global_func/param_1', 'is_optional': True, 'is_type_inferred': False, 'name': 'param_1', @@ -3299,7 +704,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/test_module/global_func/param_2', + 'id': 'test_main/main_test_module/global_func/param_2', 'is_optional': True, 'is_type_inferred': False, 'name': 'param_2', @@ -3324,150 +729,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/test_docstrings/EpydocDocstringClass/epydoc_docstring_func/result_1', - 'is_type_inferred': False, - 'name': 'result_1', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'bool', - }), - }), - dict({ - 'docstring': dict({ - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_docstrings/GoogleDocstringClass/google_docstring_func/result_1', - 'is_type_inferred': False, - 'name': 'result_1', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'bool', - }), - }), - dict({ - 'docstring': dict({ - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_docstrings/NumpyDocstringClass/numpy_docstring_func/result_1', - 'is_type_inferred': False, - 'name': 'result_1', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'bool', - }), - }), - dict({ - 'docstring': dict({ - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_docstrings/RestDocstringClass/rest_docstring_func/result_1', - 'is_type_inferred': False, - 'name': 'result_1', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'bool', - }), - }), - dict({ - 'docstring': dict({ - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_module/InferMyTypes/infer_function/result_1', - 'is_type_inferred': True, - 'name': 'result_1', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'InferMyTypes', - }), - }), - dict({ - 'docstring': dict({ - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_module/InferMyTypes/infer_function/result_2', - 'is_type_inferred': True, - 'name': 'result_2', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'None', - }), - }), - dict({ - 'docstring': dict({ - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_module/InferMyTypes/infer_function/result_3', - 'is_type_inferred': True, - 'name': 'result_3', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'SomeClass', - }), - }), - dict({ - 'docstring': dict({ - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_module/InferMyTypes/infer_function/result_4', - 'is_type_inferred': True, - 'name': 'result_4', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'bool', - }), - }), - dict({ - 'docstring': dict({ - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_module/InferMyTypes/infer_function/result_5', - 'is_type_inferred': True, - 'name': 'result_5', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'float', - }), - }), - dict({ - 'docstring': dict({ - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_module/InferMyTypes/infer_function/result_6', - 'is_type_inferred': True, - 'name': 'result_6', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'int', - }), - }), - dict({ - 'docstring': dict({ - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_module/InferMyTypes/infer_function/result_7', - 'is_type_inferred': True, - 'name': 'result_7', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'str', - }), - }), - dict({ - 'docstring': dict({ - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_module/SomeClass/NestedClass/nested_class_function/result_1', + 'id': 'test_main/main_test_module/ModuleClass/NestedClass/nested_class_function/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ @@ -3494,7 +756,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/test_module/SomeClass/_some_function/result_1', + 'id': 'test_main/main_test_module/ModuleClass/_some_function/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ @@ -3507,90 +769,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/test_module/SomeClass/class_method_params/result_1', - 'is_type_inferred': False, - 'name': 'result_1', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'bool', - }), - }), - dict({ - 'docstring': dict({ - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_module/SomeClass/multiple_results/result_1', - 'is_type_inferred': False, - 'name': 'result_1', - 'type': dict({ - 'kind': 'UnionType', - 'types': list([ - dict({ - 'kind': 'NamedType', - 'name': 'Any', - }), - dict({ - 'kind': 'TupleType', - 'types': list([ - dict({ - 'kind': 'NamedType', - 'name': 'int', - }), - dict({ - 'kind': 'NamedType', - 'name': 'str', - }), - ]), - }), - ]), - }), - }), - dict({ - 'docstring': dict({ - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_module/SomeClass/static_function/result_1', - 'is_type_inferred': False, - 'name': 'result_1', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'bool', - }), - }), - dict({ - 'docstring': dict({ - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_module/SomeClass/static_function/result_2', - 'is_type_inferred': False, - 'name': 'result_2', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'int', - }), - }), - dict({ - 'docstring': dict({ - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_module/SomeClass/test_position/result_1', - 'is_type_inferred': False, - 'name': 'result_1', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'Any', - }), - }), - dict({ - 'docstring': dict({ - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_module/_private_global_func/result_1', + 'id': 'test_main/main_test_module/_private_global_func/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ @@ -3616,7 +795,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/test_module/global_func/result_1', + 'id': 'test_main/main_test_module/global_func/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ diff --git a/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr b/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr index f89871dc..398c7615 100644 --- a/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr +++ b/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr @@ -1,93 +1,5 @@ # serializer version: 1 -# name: test_class_attributes_GoogleDocstringClass - list([ - dict({ - 'docstring': dict({ - 'default_value': '', - 'description': 'Attribute of the calculator. (Google Style)', - 'type': 'str', - }), - 'id': 'test_package/test_docstrings/GoogleDocstringClass/attr_1', - 'is_public': True, - 'is_static': True, - 'is_type_inferred': False, - 'name': 'attr_1', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'str', - }), - }), - ]) -# --- -# name: test_class_attributes_NestedClass - list([ - ]) -# --- -# name: test_class_attributes_NestedNestedPrivateClass - list([ - ]) -# --- -# name: test_class_attributes_NestedPrivateClass - list([ - dict({ - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_module/_PrivateClass/NestedPrivateClass/nested_class_attr', - 'is_public': False, - 'is_static': True, - 'is_type_inferred': True, - 'name': 'nested_class_attr', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'int', - }), - }), - ]) -# --- -# name: test_class_attributes_NumpyDocstringClass - list([ - dict({ - 'docstring': dict({ - 'default_value': '', - 'description': 'Attribute of the calculator. (Numpy)', - 'type': 'str', - }), - 'id': 'test_package/test_docstrings/NumpyDocstringClass/attr_1', - 'is_public': True, - 'is_static': True, - 'is_type_inferred': False, - 'name': 'attr_1', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'str', - }), - }), - ]) -# --- -# name: test_class_attributes_RestDocstringClass - list([ - dict({ - 'docstring': dict({ - 'default_value': '', - 'description': 'Attribute of the calculator. (ReST)', - 'type': 'str', - }), - 'id': 'test_package/test_docstrings/RestDocstringClass/attr_1', - 'is_public': True, - 'is_static': True, - 'is_type_inferred': False, - 'name': 'attr_1', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'str', - }), - }), - ]) -# --- -# name: test_class_attributes_SomeClass +# name: test_class_attributes_AttributesClassB list([ dict({ 'docstring': dict({ @@ -95,23 +7,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/test_module/SomeClass/_init_attr_private', - 'is_public': False, - 'is_static': False, - 'is_type_inferred': False, - 'name': '_init_attr_private', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'float', - }), - }), - dict({ - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_module/SomeClass/_multi_attr_2_private', + 'id': 'test_package/attribute_module/AttributesClassB/_multi_attr_2_private', 'is_public': False, 'is_static': True, 'is_type_inferred': True, @@ -127,7 +23,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/test_module/SomeClass/_multi_attr_4_private', + 'id': 'test_package/attribute_module/AttributesClassB/_multi_attr_4_private', 'is_public': False, 'is_static': True, 'is_type_inferred': True, @@ -148,7 +44,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/test_module/SomeClass/_no_type_hint_private', + 'id': 'test_package/attribute_module/AttributesClassB/_no_type_hint_private', 'is_public': False, 'is_static': True, 'is_type_inferred': True, @@ -164,7 +60,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/test_module/SomeClass/_type_hint_private', + 'id': 'test_package/attribute_module/AttributesClassB/_type_hint_private', 'is_public': False, 'is_static': True, 'is_type_inferred': False, @@ -180,7 +76,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/test_module/SomeClass/bool_attr', + 'id': 'test_package/attribute_module/AttributesClassB/bool_attr', 'is_public': True, 'is_static': True, 'is_type_inferred': False, @@ -196,7 +92,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/test_module/SomeClass/dict_attr_1', + 'id': 'test_package/attribute_module/AttributesClassB/dict_attr_1', 'is_public': True, 'is_static': True, 'is_type_inferred': False, @@ -219,7 +115,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/test_module/SomeClass/dict_attr_2', + 'id': 'test_package/attribute_module/AttributesClassB/dict_attr_2', 'is_public': True, 'is_static': True, 'is_type_inferred': False, @@ -242,7 +138,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/test_module/SomeClass/dict_attr_3', + 'id': 'test_package/attribute_module/AttributesClassB/dict_attr_3', 'is_public': True, 'is_static': True, 'is_type_inferred': False, @@ -271,7 +167,7 @@ }), dict({ 'kind': 'NamedType', - 'name': 'AnotherClass', + 'name': 'AttributesClassA', }), ]), }), @@ -283,7 +179,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/test_module/SomeClass/flaot_attr', + 'id': 'test_package/attribute_module/AttributesClassB/flaot_attr', 'is_public': True, 'is_static': True, 'is_type_inferred': False, @@ -299,7 +195,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/test_module/SomeClass/init_attr', + 'id': 'test_package/attribute_module/AttributesClassB/init_attr', 'is_public': True, 'is_static': False, 'is_type_inferred': False, @@ -315,7 +211,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/test_module/SomeClass/int_or_bool_attr', + 'id': 'test_package/attribute_module/AttributesClassB/int_or_bool_attr', 'is_public': True, 'is_static': True, 'is_type_inferred': False, @@ -340,7 +236,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/test_module/SomeClass/list_attr_1', + 'id': 'test_package/attribute_module/AttributesClassB/list_attr_1', 'is_public': True, 'is_static': True, 'is_type_inferred': False, @@ -357,7 +253,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/test_module/SomeClass/list_attr_2', + 'id': 'test_package/attribute_module/AttributesClassB/list_attr_2', 'is_public': True, 'is_static': True, 'is_type_inferred': False, @@ -374,7 +270,7 @@ }), dict({ 'kind': 'NamedType', - 'name': '_AcImportAlias', + 'name': 'AttributesClassA', }), ]), }), @@ -387,7 +283,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/test_module/SomeClass/list_attr_3', + 'id': 'test_package/attribute_module/AttributesClassB/list_attr_3', 'is_public': True, 'is_static': True, 'is_type_inferred': False, @@ -401,7 +297,7 @@ }), dict({ 'kind': 'NamedType', - 'name': 'AcDoubleAlias', + 'name': 'AttributesClassA', }), ]), }), @@ -412,7 +308,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/test_module/SomeClass/list_attr_4', + 'id': 'test_package/attribute_module/AttributesClassB/list_attr_4', 'is_public': True, 'is_static': True, 'is_type_inferred': False, @@ -429,7 +325,7 @@ 'types': list([ dict({ 'kind': 'NamedType', - 'name': '_AcImportAlias', + 'name': 'AttributesClassA', }), dict({ 'kind': 'NamedType', @@ -446,7 +342,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/test_module/SomeClass/multi_attr_1', + 'id': 'test_package/attribute_module/AttributesClassB/multi_attr_1', 'is_public': True, 'is_static': True, 'is_type_inferred': True, @@ -462,7 +358,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/test_module/SomeClass/multi_attr_3', + 'id': 'test_package/attribute_module/AttributesClassB/multi_attr_3', 'is_public': True, 'is_static': True, 'is_type_inferred': True, @@ -483,14 +379,14 @@ 'description': '', 'type': '', }), - 'id': 'test_package/test_module/SomeClass/no_type_hint_public', + 'id': 'test_package/attribute_module/AttributesClassB/multi_attr_5', 'is_public': True, 'is_static': True, 'is_type_inferred': True, - 'name': 'no_type_hint_public', + 'name': 'multi_attr_5', 'type': dict({ 'kind': 'NamedType', - 'name': 'int', + 'name': 'str', }), }), dict({ @@ -499,14 +395,62 @@ 'description': '', 'type': '', }), - 'id': 'test_package/test_module/SomeClass/none_attr', + 'id': 'test_package/attribute_module/AttributesClassB/multi_attr_6', 'is_public': True, 'is_static': True, - 'is_type_inferred': False, - 'name': 'none_attr', + 'is_type_inferred': True, + 'name': 'multi_attr_6', 'type': dict({ 'kind': 'NamedType', - 'name': 'None', + 'name': 'str', + }), + }), + dict({ + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_package/attribute_module/AttributesClassB/multi_attr_7', + 'is_public': True, + 'is_static': True, + 'is_type_inferred': True, + 'name': 'multi_attr_7', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'str', + }), + }), + dict({ + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_package/attribute_module/AttributesClassB/multi_attr_8', + 'is_public': True, + 'is_static': True, + 'is_type_inferred': True, + 'name': 'multi_attr_8', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'str', + }), + }), + dict({ + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_package/attribute_module/AttributesClassB/no_type_hint_public', + 'is_public': True, + 'is_static': True, + 'is_type_inferred': True, + 'name': 'no_type_hint_public', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'int', }), }), dict({ @@ -515,14 +459,14 @@ 'description': '', 'type': '', }), - 'id': 'test_package/test_module/SomeClass/object_attr', + 'id': 'test_package/attribute_module/AttributesClassB/none_attr', 'is_public': True, 'is_static': True, 'is_type_inferred': False, - 'name': 'object_attr', + 'name': 'none_attr', 'type': dict({ 'kind': 'NamedType', - 'name': 'AnotherClass', + 'name': 'None', }), }), dict({ @@ -531,14 +475,14 @@ 'description': '', 'type': '', }), - 'id': 'test_package/test_module/SomeClass/object_attr_2', + 'id': 'test_package/attribute_module/AttributesClassB/object_attr', 'is_public': True, 'is_static': True, 'is_type_inferred': False, - 'name': 'object_attr_2', + 'name': 'object_attr', 'type': dict({ 'kind': 'NamedType', - 'name': 'AnotherClass', + 'name': 'AttributesClassA', }), }), dict({ @@ -547,7 +491,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/test_module/SomeClass/str_attr_with_none_value', + 'id': 'test_package/attribute_module/AttributesClassB/str_attr_with_none_value', 'is_public': True, 'is_static': True, 'is_type_inferred': False, @@ -563,7 +507,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/test_module/SomeClass/tuple_attr_1', + 'id': 'test_package/attribute_module/AttributesClassB/tuple_attr_1', 'is_public': True, 'is_static': True, 'is_type_inferred': False, @@ -584,7 +528,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/test_module/SomeClass/tuple_attr_2', + 'id': 'test_package/attribute_module/AttributesClassB/tuple_attr_2', 'is_public': True, 'is_static': True, 'is_type_inferred': False, @@ -614,7 +558,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/test_module/SomeClass/tuple_attr_3', + 'id': 'test_package/attribute_module/AttributesClassB/tuple_attr_3', 'is_public': True, 'is_static': True, 'is_type_inferred': False, @@ -639,7 +583,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/test_module/SomeClass/type_hint_public', + 'id': 'test_package/attribute_module/AttributesClassB/type_hint_public', 'is_public': True, 'is_static': True, 'is_type_inferred': False, @@ -651,7 +595,7 @@ }), ]) # --- -# name: test_class_attributes__PrivateClass +# name: test_class_attributes_ClassModuleNestedClassE list([ dict({ 'docstring': dict({ @@ -659,14 +603,14 @@ 'description': '', 'type': '', }), - 'id': 'test_package/test_module/_PrivateClass/public_attr_in_private_class', + 'id': 'test_package/class_module/ClassModuleClassD/ClassModuleNestedClassE/_nested_attr_2', 'is_public': False, 'is_static': True, - 'is_type_inferred': True, - 'name': 'public_attr_in_private_class', + 'is_type_inferred': False, + 'name': '_nested_attr_2', 'type': dict({ 'kind': 'NamedType', - 'name': 'int', + 'name': 'None', }), }), dict({ @@ -675,170 +619,287 @@ 'description': '', 'type': '', }), - 'id': 'test_package/test_module/_PrivateClass/public_init_attr_in_private_class', - 'is_public': False, - 'is_static': False, + 'id': 'test_package/class_module/ClassModuleClassD/ClassModuleNestedClassE/nested_attr_1', + 'is_public': True, + 'is_static': True, 'is_type_inferred': False, - 'name': 'public_init_attr_in_private_class', + 'name': 'nested_attr_1', 'type': dict({ 'kind': 'NamedType', - 'name': 'int', + 'name': 'None', }), }), ]) # --- -# name: test_class_methods_EpydocDocstringClass +# name: test_class_attributes_GoogleDocstringClass list([ dict({ 'docstring': dict({ - 'description': 'This function checks if the sum of x and y is less than the value 10 and returns True if it is. (Epydoc).', - 'full_docstring': ''' - This function checks if the sum of x and y is less than the value 10 and returns True if it is. (Epydoc). - - @param x: First integer value for the calculation. (Epydoc) - @type x: int - @param y: Second integer value for the calculation. (Epydoc) - @type y: int - @return: Checks if the sum of x and y is greater than 10. (Epydoc) - @rtype: bool - ''', + 'default_value': '', + 'description': 'Attribute of the calculator. (Google Style)', + 'type': 'str', }), - 'id': 'test_package/test_docstrings/EpydocDocstringClass/epydoc_docstring_func', - 'is_class_method': False, + 'id': 'test_package/docstring_module/GoogleDocstringClass/attr_1', 'is_public': True, - 'is_static': False, - 'name': 'epydoc_docstring_func', - 'parameters': list([ - 'test_package/test_docstrings/EpydocDocstringClass/epydoc_docstring_func/self', - 'test_package/test_docstrings/EpydocDocstringClass/epydoc_docstring_func/x', - 'test_package/test_docstrings/EpydocDocstringClass/epydoc_docstring_func/y', - ]), - 'reexported_by': list([ - ]), - 'results': list([ - 'test_package/test_docstrings/EpydocDocstringClass/epydoc_docstring_func/result_1', - ]), + 'is_static': True, + 'is_type_inferred': False, + 'name': 'attr_1', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'str', + }), }), ]) # --- -# name: test_class_methods_GoogleDocstringClass +# name: test_class_attributes_NumpyDocstringClass list([ dict({ 'docstring': dict({ - 'description': ''' - Checks if the sum of two variables is over the value of 10. (Google Style). - - This function checks if the sum of x and y is less than the value 10 - and returns True if it is. (Google Style) - ''', - 'full_docstring': ''' - Checks if the sum of two variables is over the value of 10. (Google Style). - - This function checks if the sum of x and y is less than the value 10 - and returns True if it is. (Google Style) - - Args: - x (int): First integer value for the calculation. (Google Style) - y (int): Second integer value for the calculation. (Google Style) - - Returns: - bool: Checks if the sum of x and y is greater than 10 and returns - a boolean value. (Google Style) - ''', + 'default_value': '', + 'description': 'Attribute of the calculator. (Numpy)', + 'type': 'str', }), - 'id': 'test_package/test_docstrings/GoogleDocstringClass/google_docstring_func', - 'is_class_method': False, + 'id': 'test_package/docstring_module/NumpyDocstringClass/attr_1', 'is_public': True, - 'is_static': False, - 'name': 'google_docstring_func', - 'parameters': list([ - 'test_package/test_docstrings/GoogleDocstringClass/google_docstring_func/self', - 'test_package/test_docstrings/GoogleDocstringClass/google_docstring_func/x', - 'test_package/test_docstrings/GoogleDocstringClass/google_docstring_func/y', - ]), - 'reexported_by': list([ - ]), - 'results': list([ - 'test_package/test_docstrings/GoogleDocstringClass/google_docstring_func/result_1', - ]), + 'is_static': True, + 'is_type_inferred': False, + 'name': 'attr_1', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'str', + }), }), ]) # --- -# name: test_class_methods_InferMyTypes +# name: test_class_attributes_RestDocstringClass list([ dict({ 'docstring': dict({ - 'description': '', - 'full_docstring': '', + 'default_value': '', + 'description': 'Attribute of the calculator. (ReST)', + 'type': 'str', }), - 'id': 'test_package/test_module/InferMyTypes/infer_function', - 'is_class_method': False, + 'id': 'test_package/docstring_module/RestDocstringClass/attr_1', 'is_public': True, 'is_static': True, - 'name': 'infer_function', - 'parameters': list([ - 'test_package/test_module/InferMyTypes/infer_function/infer_param', - 'test_package/test_module/InferMyTypes/infer_function/infer_param_2', - ]), - 'reexported_by': list([ - ]), - 'results': list([ - 'test_package/test_module/InferMyTypes/infer_function/result_1', - 'test_package/test_module/InferMyTypes/infer_function/result_2', - 'test_package/test_module/InferMyTypes/infer_function/result_3', - 'test_package/test_module/InferMyTypes/infer_function/result_4', - 'test_package/test_module/InferMyTypes/infer_function/result_5', - 'test_package/test_module/InferMyTypes/infer_function/result_6', - 'test_package/test_module/InferMyTypes/infer_function/result_7', - ]), + 'is_type_inferred': False, + 'name': 'attr_1', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'str', + }), }), ]) # --- -# name: test_class_methods_NestedClass +# name: test_class_attributes__ClassModulePrivateClassG list([ dict({ 'docstring': dict({ + 'default_value': '', 'description': '', - 'full_docstring': '', + 'type': '', }), - 'id': 'test_package/test_module/SomeClass/NestedClass/nested_class_function', + 'id': 'test_package/class_module/_ClassModulePrivateClassG/_attr_1', + 'is_public': False, + 'is_static': True, + 'is_type_inferred': False, + 'name': '_attr_1', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'float', + }), + }), + dict({ + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_package/class_module/_ClassModulePrivateClassG/_attr_2', + 'is_public': False, + 'is_static': True, + 'is_type_inferred': False, + 'name': '_attr_2', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'bool', + }), + }), + ]) +# --- +# name: test_class_methods_ClassModuleClassB + list([ + dict({ + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_package/class_module/ClassModuleClassB/f', 'is_class_method': False, 'is_public': True, 'is_static': False, - 'name': 'nested_class_function', + 'name': 'f', + 'parameters': list([ + 'test_package/class_module/ClassModuleClassB/f/self', + ]), + 'reexported_by': list([ + ]), + 'results': list([ + ]), + }), + ]) +# --- +# name: test_class_methods_ClassModuleClassC + list([ + dict({ + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_package/class_module/ClassModuleClassC/f1', + 'is_class_method': False, + 'is_public': True, + 'is_static': False, + 'name': 'f1', 'parameters': list([ - 'test_package/test_module/SomeClass/NestedClass/nested_class_function/self', - 'test_package/test_module/SomeClass/NestedClass/nested_class_function/param_1', + 'test_package/class_module/ClassModuleClassC/f1/self', ]), 'reexported_by': list([ ]), 'results': list([ - 'test_package/test_module/SomeClass/NestedClass/nested_class_function/result_1', ]), }), ]) # --- -# name: test_class_methods_NestedNestedPrivateClass +# name: test_class_methods_ClassModuleEmptyClassA list([ ]) # --- -# name: test_class_methods_NestedPrivateClass +# name: test_class_methods_ClassModuleNestedClassE list([ dict({ 'docstring': dict({ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/test_module/_PrivateClass/NestedPrivateClass/static_nested_private_class_function', + 'id': 'test_package/class_module/ClassModuleClassD/ClassModuleNestedClassE/class_e_func', 'is_class_method': False, - 'is_public': False, + 'is_public': True, + 'is_static': False, + 'name': 'class_e_func', + 'parameters': list([ + 'test_package/class_module/ClassModuleClassD/ClassModuleNestedClassE/class_e_func/self', + ]), + 'reexported_by': list([ + ]), + 'results': list([ + ]), + }), + ]) +# --- +# name: test_class_methods_EpydocDocstringClass + list([ + dict({ + 'docstring': dict({ + 'description': 'This function checks if the sum of x and y is less than the value 10 and returns True if it is. (Epydoc).', + 'full_docstring': ''' + This function checks if the sum of x and y is less than the value 10 and returns True if it is. (Epydoc). + + @param x: First integer value for the calculation. (Epydoc) + @type x: int + @param y: Second integer value for the calculation. (Epydoc) + @type y: int + @return: Checks if the sum of x and y is greater than 10. (Epydoc) + @rtype: bool + ''', + }), + 'id': 'test_package/docstring_module/EpydocDocstringClass/epydoc_docstring_func', + 'is_class_method': False, + 'is_public': True, + 'is_static': False, + 'name': 'epydoc_docstring_func', + 'parameters': list([ + 'test_package/docstring_module/EpydocDocstringClass/epydoc_docstring_func/self', + 'test_package/docstring_module/EpydocDocstringClass/epydoc_docstring_func/x', + 'test_package/docstring_module/EpydocDocstringClass/epydoc_docstring_func/y', + ]), + 'reexported_by': list([ + ]), + 'results': list([ + 'test_package/docstring_module/EpydocDocstringClass/epydoc_docstring_func/result_1', + ]), + }), + ]) +# --- +# name: test_class_methods_GoogleDocstringClass + list([ + dict({ + 'docstring': dict({ + 'description': ''' + Checks if the sum of two variables is over the value of 10. (Google Style). + + This function checks if the sum of x and y is less than the value 10 + and returns True if it is. (Google Style) + ''', + 'full_docstring': ''' + Checks if the sum of two variables is over the value of 10. (Google Style). + + This function checks if the sum of x and y is less than the value 10 + and returns True if it is. (Google Style) + + Args: + x (int): First integer value for the calculation. (Google Style) + y (int): Second integer value for the calculation. (Google Style) + + Returns: + bool: Checks if the sum of x and y is greater than 10 and returns + a boolean value. (Google Style) + ''', + }), + 'id': 'test_package/docstring_module/GoogleDocstringClass/google_docstring_func', + 'is_class_method': False, + 'is_public': True, + 'is_static': False, + 'name': 'google_docstring_func', + 'parameters': list([ + 'test_package/docstring_module/GoogleDocstringClass/google_docstring_func/self', + 'test_package/docstring_module/GoogleDocstringClass/google_docstring_func/x', + 'test_package/docstring_module/GoogleDocstringClass/google_docstring_func/y', + ]), + 'reexported_by': list([ + ]), + 'results': list([ + 'test_package/docstring_module/GoogleDocstringClass/google_docstring_func/result_1', + ]), + }), + ]) +# --- +# name: test_class_methods_InferMyTypes + list([ + dict({ + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_package/infer_types_module/InferMyTypes/infer_function', + 'is_class_method': False, + 'is_public': True, 'is_static': True, - 'name': 'static_nested_private_class_function', + 'name': 'infer_function', 'parameters': list([ + 'test_package/infer_types_module/InferMyTypes/infer_function/infer_param', + 'test_package/infer_types_module/InferMyTypes/infer_function/infer_param_2', ]), 'reexported_by': list([ ]), 'results': list([ + 'test_package/infer_types_module/InferMyTypes/infer_function/result_1', + 'test_package/infer_types_module/InferMyTypes/infer_function/result_2', + 'test_package/infer_types_module/InferMyTypes/infer_function/result_3', + 'test_package/infer_types_module/InferMyTypes/infer_function/result_4', + 'test_package/infer_types_module/InferMyTypes/infer_function/result_5', + 'test_package/infer_types_module/InferMyTypes/infer_function/result_6', + 'test_package/infer_types_module/InferMyTypes/infer_function/result_7', ]), }), ]) @@ -870,20 +931,20 @@ Checks if the sum of `x` and `y` is greater than 10. (Numpy) ''', }), - 'id': 'test_package/test_docstrings/NumpyDocstringClass/numpy_docstring_func', + 'id': 'test_package/docstring_module/NumpyDocstringClass/numpy_docstring_func', 'is_class_method': False, 'is_public': True, 'is_static': False, 'name': 'numpy_docstring_func', 'parameters': list([ - 'test_package/test_docstrings/NumpyDocstringClass/numpy_docstring_func/self', - 'test_package/test_docstrings/NumpyDocstringClass/numpy_docstring_func/x', - 'test_package/test_docstrings/NumpyDocstringClass/numpy_docstring_func/y', + 'test_package/docstring_module/NumpyDocstringClass/numpy_docstring_func/self', + 'test_package/docstring_module/NumpyDocstringClass/numpy_docstring_func/x', + 'test_package/docstring_module/NumpyDocstringClass/numpy_docstring_func/y', ]), 'reexported_by': list([ ]), 'results': list([ - 'test_package/test_docstrings/NumpyDocstringClass/numpy_docstring_func/result_1', + 'test_package/docstring_module/NumpyDocstringClass/numpy_docstring_func/result_1', ]), }), ]) @@ -931,67 +992,60 @@ :rtype: bool ''', }), - 'id': 'test_package/test_docstrings/RestDocstringClass/rest_docstring_func', + 'id': 'test_package/docstring_module/RestDocstringClass/rest_docstring_func', 'is_class_method': False, 'is_public': True, 'is_static': False, 'name': 'rest_docstring_func', 'parameters': list([ - 'test_package/test_docstrings/RestDocstringClass/rest_docstring_func/self', - 'test_package/test_docstrings/RestDocstringClass/rest_docstring_func/x', - 'test_package/test_docstrings/RestDocstringClass/rest_docstring_func/y', + 'test_package/docstring_module/RestDocstringClass/rest_docstring_func/self', + 'test_package/docstring_module/RestDocstringClass/rest_docstring_func/x', + 'test_package/docstring_module/RestDocstringClass/rest_docstring_func/y', ]), 'reexported_by': list([ ]), 'results': list([ - 'test_package/test_docstrings/RestDocstringClass/rest_docstring_func/result_1', + 'test_package/docstring_module/RestDocstringClass/rest_docstring_func/result_1', ]), }), ]) # --- -# name: test_class_methods_SomeClass +# name: test_class_methods__ClassModulePrivateDoubleNestedClassF list([ dict({ 'docstring': dict({ - 'description': ''' - Function Docstring. - - param_2: bool. - ''', - 'full_docstring': ''' - Function Docstring. - - param_2: bool. - ''', + 'description': '', + 'full_docstring': '', }), - 'id': 'test_package/test_module/SomeClass/_some_function', + 'id': 'test_package/class_module/ClassModuleClassD/ClassModuleNestedClassE/_ClassModulePrivateDoubleNestedClassF/_class_f_func', 'is_class_method': False, 'is_public': False, 'is_static': False, - 'name': '_some_function', + 'name': '_class_f_func', 'parameters': list([ - 'test_package/test_module/SomeClass/_some_function/self', - 'test_package/test_module/SomeClass/_some_function/param_1', - 'test_package/test_module/SomeClass/_some_function/param_2', + 'test_package/class_module/ClassModuleClassD/ClassModuleNestedClassE/_ClassModulePrivateDoubleNestedClassF/_class_f_func/self', ]), 'reexported_by': list([ ]), 'results': list([ - 'test_package/test_module/SomeClass/_some_function/result_1', ]), }), + ]) +# --- +# name: test_class_methods_function_module_FunctionModuleClassB + list([ dict({ 'docstring': dict({ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/test_module/SomeClass/class_method', + 'id': 'test_package/function_module/FunctionModuleClassB/class_method', 'is_class_method': True, 'is_public': True, 'is_static': False, 'name': 'class_method', 'parameters': list([ - 'test_package/test_module/SomeClass/class_method/cls', + 'test_package/function_module/FunctionModuleClassB/class_method/cls', ]), 'reexported_by': list([ ]), @@ -1003,38 +1057,19 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/test_module/SomeClass/class_method_params', + 'id': 'test_package/function_module/FunctionModuleClassB/class_method_params', 'is_class_method': True, 'is_public': True, 'is_static': False, 'name': 'class_method_params', 'parameters': list([ - 'test_package/test_module/SomeClass/class_method_params/cls', - 'test_package/test_module/SomeClass/class_method_params/param_1', - ]), - 'reexported_by': list([ - ]), - 'results': list([ - 'test_package/test_module/SomeClass/class_method_params/result_1', - ]), - }), - dict({ - 'docstring': dict({ - 'description': 'Function Docstring.', - 'full_docstring': 'Function Docstring.', - }), - 'id': 'test_package/test_module/SomeClass/multiple_results', - 'is_class_method': False, - 'is_public': True, - 'is_static': True, - 'name': 'multiple_results', - 'parameters': list([ - 'test_package/test_module/SomeClass/multiple_results/param_1', + 'test_package/function_module/FunctionModuleClassB/class_method_params/cls', + 'test_package/function_module/FunctionModuleClassB/class_method_params/param_1', ]), 'reexported_by': list([ ]), 'results': list([ - 'test_package/test_module/SomeClass/multiple_results/result_1', + 'test_package/function_module/FunctionModuleClassB/class_method_params/result_1', ]), }), dict({ @@ -1042,17 +1077,19 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/test_module/SomeClass/no_return_1', + 'id': 'test_package/function_module/FunctionModuleClassB/instance_method', 'is_class_method': False, 'is_public': True, 'is_static': False, - 'name': 'no_return_1', + 'name': 'instance_method', 'parameters': list([ - 'test_package/test_module/SomeClass/no_return_1/self', + 'test_package/function_module/FunctionModuleClassB/instance_method/self', + 'test_package/function_module/FunctionModuleClassB/instance_method/a', ]), 'reexported_by': list([ ]), 'results': list([ + 'test_package/function_module/FunctionModuleClassB/instance_method/result_1', ]), }), dict({ @@ -1060,38 +1097,16 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/test_module/SomeClass/no_return_2', - 'is_class_method': False, - 'is_public': True, - 'is_static': False, - 'name': 'no_return_2', - 'parameters': list([ - 'test_package/test_module/SomeClass/no_return_2/self', - ]), - 'reexported_by': list([ - ]), - 'results': list([ - ]), - }), - dict({ - 'docstring': dict({ - 'description': 'Function Docstring.', - 'full_docstring': 'Function Docstring.', - }), - 'id': 'test_package/test_module/SomeClass/static_function', + 'id': 'test_package/function_module/FunctionModuleClassB/static_method', 'is_class_method': False, 'is_public': True, 'is_static': True, - 'name': 'static_function', + 'name': 'static_method', 'parameters': list([ - 'test_package/test_module/SomeClass/static_function/param_1', - 'test_package/test_module/SomeClass/static_function/param_2', ]), 'reexported_by': list([ ]), 'results': list([ - 'test_package/test_module/SomeClass/static_function/result_1', - 'test_package/test_module/SomeClass/static_function/result_2', ]), }), dict({ @@ -1099,64 +1114,41 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/test_module/SomeClass/test_params', + 'id': 'test_package/function_module/FunctionModuleClassB/static_method_params', 'is_class_method': False, 'is_public': True, 'is_static': True, - 'name': 'test_params', + 'name': 'static_method_params', 'parameters': list([ - 'test_package/test_module/SomeClass/test_params/args', - 'test_package/test_module/SomeClass/test_params/kwargs', + 'test_package/function_module/FunctionModuleClassB/static_method_params/param_1', ]), 'reexported_by': list([ ]), 'results': list([ ]), }), - dict({ - 'docstring': dict({ - 'description': 'Function Docstring.', - 'full_docstring': 'Function Docstring.', - }), - 'id': 'test_package/test_module/SomeClass/test_position', - 'is_class_method': False, - 'is_public': True, - 'is_static': False, - 'name': 'test_position', - 'parameters': list([ - 'test_package/test_module/SomeClass/test_position/self', - 'test_package/test_module/SomeClass/test_position/param1', - 'test_package/test_module/SomeClass/test_position/param2', - 'test_package/test_module/SomeClass/test_position/param3', - 'test_package/test_module/SomeClass/test_position/param4', - 'test_package/test_module/SomeClass/test_position/param5', - ]), - 'reexported_by': list([ - ]), - 'results': list([ - 'test_package/test_module/SomeClass/test_position/result_1', - ]), - }), ]) # --- -# name: test_class_methods__PrivateClass +# name: test_class_methods_function_module_FunctionModuleClassC list([ dict({ 'docstring': dict({ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/test_module/_PrivateClass/public_func_in_private_class', + 'id': 'test_package/function_module/FunctionModuleClassB/FunctionModuleClassC/nested_class_function', 'is_class_method': False, - 'is_public': False, + 'is_public': True, 'is_static': False, - 'name': 'public_func_in_private_class', + 'name': 'nested_class_function', 'parameters': list([ - 'test_package/test_module/_PrivateClass/public_func_in_private_class/self', + 'test_package/function_module/FunctionModuleClassB/FunctionModuleClassC/nested_class_function/self', + 'test_package/function_module/FunctionModuleClassB/FunctionModuleClassC/nested_class_function/param1', ]), 'reexported_by': list([ ]), 'results': list([ + 'test_package/function_module/FunctionModuleClassB/FunctionModuleClassC/nested_class_function/result_1', ]), }), ]) @@ -1185,10 +1177,9 @@ ]), }) # --- -# name: test_classes_EpydocDocstringClass +# name: test_classes_ClassModuleClassB dict({ 'attributes': list([ - 'test_package/test_docstrings/EpydocDocstringClass/attr_1', ]), 'classes': list([ ]), @@ -1197,14 +1188,15 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/test_docstrings/EpydocDocstringClass/__init__', + 'id': 'test_package/class_module/ClassModuleClassB/__init__', 'is_class_method': False, 'is_public': True, 'is_static': False, 'name': '__init__', 'parameters': list([ - 'test_package/test_docstrings/EpydocDocstringClass/__init__/self', - 'test_package/test_docstrings/EpydocDocstringClass/__init__/param_1', + 'test_package/class_module/ClassModuleClassB/__init__/self', + 'test_package/class_module/ClassModuleClassB/__init__/a', + 'test_package/class_module/ClassModuleClassB/__init__/b', ]), 'reexported_by': list([ ]), @@ -1212,33 +1204,29 @@ ]), }), 'docstring': dict({ - 'description': 'A class with a variety of different methods for calculations. (Epydoc).', - 'full_docstring': ''' - A class with a variety of different methods for calculations. (Epydoc). - - @ivar attr_1: Attribute of the calculator. (Epydoc) - @type attr_1: str - @param param_1: Parameter of the calculator. (Epydoc) - @type param_1: str - ''', + 'description': '', + 'full_docstring': '', }), - 'id': 'test_package/test_docstrings/EpydocDocstringClass', + 'id': 'test_package/class_module/ClassModuleClassB', 'is_public': True, 'methods': list([ - 'test_package/test_docstrings/EpydocDocstringClass/epydoc_docstring_func', + 'test_package/class_module/ClassModuleClassB/f', ]), - 'name': 'EpydocDocstringClass', + 'name': 'ClassModuleClassB', 'reexported_by': list([ ]), 'superclasses': list([ + 'tests.data.test_package.class_module.ClassModuleEmptyClassA', ]), 'variances': list([ ]), }) # --- -# name: test_classes_FourthReexportClass +# name: test_classes_ClassModuleClassC dict({ 'attributes': list([ + 'test_package/class_module/ClassModuleClassC/attr_1', + 'test_package/class_module/ClassModuleClassC/attr_2', ]), 'classes': list([ ]), @@ -1247,70 +1235,39 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/_reexport_module_4/FourthReexportClass', + 'id': 'test_package/class_module/ClassModuleClassC', 'is_public': True, 'methods': list([ + 'test_package/class_module/ClassModuleClassC/f1', ]), - 'name': 'FourthReexportClass', + 'name': 'ClassModuleClassC', 'reexported_by': list([ - 'test_package/__init__', ]), 'superclasses': list([ + 'tests.data.test_package.class_module.ClassModuleEmptyClassA', + 'tests.data.test_package.class_module.ClassModuleClassB', ]), 'variances': list([ ]), }) # --- -# name: test_classes_GoogleDocstringClass +# name: test_classes_ClassModuleClassD dict({ 'attributes': list([ - 'test_package/test_docstrings/GoogleDocstringClass/attr_1', ]), 'classes': list([ + 'test_package/class_module/ClassModuleClassD/ClassModuleNestedClassE', ]), - 'constructor': dict({ - 'docstring': dict({ - 'description': '', - 'full_docstring': '', - }), - 'id': 'test_package/test_docstrings/GoogleDocstringClass/__init__', - 'is_class_method': False, - 'is_public': True, - 'is_static': False, - 'name': '__init__', - 'parameters': list([ - 'test_package/test_docstrings/GoogleDocstringClass/__init__/self', - 'test_package/test_docstrings/GoogleDocstringClass/__init__/param_1', - ]), - 'reexported_by': list([ - ]), - 'results': list([ - ]), - }), + 'constructor': None, 'docstring': dict({ - 'description': ''' - A class that calculates stuff. (Google Style). - - A class with a variety of different methods for calculations. (Google Style) - ''', - 'full_docstring': ''' - A class that calculates stuff. (Google Style). - - A class with a variety of different methods for calculations. (Google Style) - - Attributes: - attr_1 (str): Attribute of the calculator. (Google Style) - - Args: - param_1 (str): Parameter of the calculator. (Google Style) - ''', + 'description': '', + 'full_docstring': '', }), - 'id': 'test_package/test_docstrings/GoogleDocstringClass', + 'id': 'test_package/class_module/ClassModuleClassD', 'is_public': True, 'methods': list([ - 'test_package/test_docstrings/GoogleDocstringClass/google_docstring_func', ]), - 'name': 'GoogleDocstringClass', + 'name': 'ClassModuleClassD', 'reexported_by': list([ ]), 'superclasses': list([ @@ -1319,7 +1276,7 @@ ]), }) # --- -# name: test_classes_NestedClass +# name: test_classes_ClassModuleEmptyClassA dict({ 'attributes': list([ ]), @@ -1330,37 +1287,39 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/test_module/SomeClass/NestedClass', + 'id': 'test_package/class_module/ClassModuleEmptyClassA', 'is_public': True, 'methods': list([ - 'test_package/test_module/SomeClass/NestedClass/nested_class_function', ]), - 'name': 'NestedClass', + 'name': 'ClassModuleEmptyClassA', 'reexported_by': list([ ]), 'superclasses': list([ - 'tests.data.test_package.another_path.another_module.AnotherClass', ]), 'variances': list([ ]), }) # --- -# name: test_classes_NestedNestedPrivateClass +# name: test_classes_ClassModuleNestedClassE dict({ 'attributes': list([ + 'test_package/class_module/ClassModuleClassD/ClassModuleNestedClassE/nested_attr_1', + 'test_package/class_module/ClassModuleClassD/ClassModuleNestedClassE/_nested_attr_2', ]), 'classes': list([ + 'test_package/class_module/ClassModuleClassD/ClassModuleNestedClassE/_ClassModulePrivateDoubleNestedClassF', ]), 'constructor': None, 'docstring': dict({ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/test_module/_PrivateClass/NestedPrivateClass/NestedNestedPrivateClass', + 'id': 'test_package/class_module/ClassModuleClassD/ClassModuleNestedClassE', 'is_public': True, 'methods': list([ + 'test_package/class_module/ClassModuleClassD/ClassModuleNestedClassE/class_e_func', ]), - 'name': 'NestedNestedPrivateClass', + 'name': 'ClassModuleNestedClassE', 'reexported_by': list([ ]), 'superclasses': list([ @@ -1369,26 +1328,50 @@ ]), }) # --- -# name: test_classes_NestedPrivateClass +# name: test_classes_EpydocDocstringClass dict({ 'attributes': list([ - 'test_package/test_module/_PrivateClass/NestedPrivateClass/nested_class_attr', + 'test_package/docstring_module/EpydocDocstringClass/attr_1', ]), 'classes': list([ - 'test_package/test_module/_PrivateClass/NestedPrivateClass/NestedNestedPrivateClass', - ]), - 'constructor': None, - 'docstring': dict({ - 'description': '', - 'full_docstring': '', - }), - 'id': 'test_package/test_module/_PrivateClass/NestedPrivateClass', - 'is_public': True, - 'methods': list([ - 'test_package/test_module/_PrivateClass/NestedPrivateClass/static_nested_private_class_function', ]), - 'name': 'NestedPrivateClass', - 'reexported_by': list([ + 'constructor': dict({ + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_package/docstring_module/EpydocDocstringClass/__init__', + 'is_class_method': False, + 'is_public': True, + 'is_static': False, + 'name': '__init__', + 'parameters': list([ + 'test_package/docstring_module/EpydocDocstringClass/__init__/self', + 'test_package/docstring_module/EpydocDocstringClass/__init__/param_1', + ]), + 'reexported_by': list([ + ]), + 'results': list([ + ]), + }), + 'docstring': dict({ + 'description': 'A class with a variety of different methods for calculations. (Epydoc).', + 'full_docstring': ''' + A class with a variety of different methods for calculations. (Epydoc). + + @ivar attr_1: Attribute of the calculator. (Epydoc) + @type attr_1: str + @param param_1: Parameter of the calculator. (Epydoc) + @type param_1: str + ''', + }), + 'id': 'test_package/docstring_module/EpydocDocstringClass', + 'is_public': True, + 'methods': list([ + 'test_package/docstring_module/EpydocDocstringClass/epydoc_docstring_func', + ]), + 'name': 'EpydocDocstringClass', + 'reexported_by': list([ ]), 'superclasses': list([ ]), @@ -1396,10 +1379,35 @@ ]), }) # --- -# name: test_classes_NumpyDocstringClass +# name: test_classes_FourthReexportClass + dict({ + 'attributes': list([ + ]), + 'classes': list([ + ]), + 'constructor': None, + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_package/_reexport_module_4/FourthReexportClass', + 'is_public': True, + 'methods': list([ + ]), + 'name': 'FourthReexportClass', + 'reexported_by': list([ + 'test_package/__init__', + ]), + 'superclasses': list([ + ]), + 'variances': list([ + ]), + }) +# --- +# name: test_classes_GoogleDocstringClass dict({ 'attributes': list([ - 'test_package/test_docstrings/NumpyDocstringClass/attr_1', + 'test_package/docstring_module/GoogleDocstringClass/attr_1', ]), 'classes': list([ ]), @@ -1408,14 +1416,14 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/test_docstrings/NumpyDocstringClass/__init__', + 'id': 'test_package/docstring_module/GoogleDocstringClass/__init__', 'is_class_method': False, 'is_public': True, 'is_static': False, 'name': '__init__', 'parameters': list([ - 'test_package/test_docstrings/NumpyDocstringClass/__init__/self', - 'test_package/test_docstrings/NumpyDocstringClass/__init__/param_1', + 'test_package/docstring_module/GoogleDocstringClass/__init__/self', + 'test_package/docstring_module/GoogleDocstringClass/__init__/param_1', ]), 'reexported_by': list([ ]), @@ -1424,32 +1432,28 @@ }), 'docstring': dict({ 'description': ''' - A class that calculates stuff. (Numpy). + A class that calculates stuff. (Google Style). - A class with a variety of different methods for calculations. (Numpy) + A class with a variety of different methods for calculations. (Google Style) ''', 'full_docstring': ''' - A class that calculates stuff. (Numpy). + A class that calculates stuff. (Google Style). - A class with a variety of different methods for calculations. (Numpy) + A class with a variety of different methods for calculations. (Google Style) - Attributes - ---------- - attr_1 : str - Attribute of the calculator. (Numpy) + Attributes: + attr_1 (str): Attribute of the calculator. (Google Style) - Parameters - ---------- - param_1 : str - Parameter of the calculator. (Numpy) + Args: + param_1 (str): Parameter of the calculator. (Google Style) ''', }), - 'id': 'test_package/test_docstrings/NumpyDocstringClass', + 'id': 'test_package/docstring_module/GoogleDocstringClass', 'is_public': True, 'methods': list([ - 'test_package/test_docstrings/NumpyDocstringClass/numpy_docstring_func', + 'test_package/docstring_module/GoogleDocstringClass/google_docstring_func', ]), - 'name': 'NumpyDocstringClass', + 'name': 'GoogleDocstringClass', 'reexported_by': list([ ]), 'superclasses': list([ @@ -1458,25 +1462,44 @@ ]), }) # --- -# name: test_classes_ReexportClass +# name: test_classes_InferMyTypes dict({ 'attributes': list([ + 'test_package/infer_types_module/InferMyTypes/infer_attr', + 'test_package/infer_types_module/InferMyTypes/init_infer', ]), 'classes': list([ ]), - 'constructor': None, + 'constructor': dict({ + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_package/infer_types_module/InferMyTypes/__init__', + 'is_class_method': False, + 'is_public': True, + 'is_static': False, + 'name': '__init__', + 'parameters': list([ + 'test_package/infer_types_module/InferMyTypes/__init__/self', + 'test_package/infer_types_module/InferMyTypes/__init__/init_param', + ]), + 'reexported_by': list([ + ]), + 'results': list([ + ]), + }), 'docstring': dict({ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/_reexport_module_1/ReexportClass', + 'id': 'test_package/infer_types_module/InferMyTypes', 'is_public': True, 'methods': list([ - 'test_package/_reexport_module_1/ReexportClass/_private_class_method_of_reexported_class', + 'test_package/infer_types_module/InferMyTypes/infer_function', ]), - 'name': 'ReexportClass', + 'name': 'InferMyTypes', 'reexported_by': list([ - 'test_package/__init__', ]), 'superclasses': list([ ]), @@ -1484,10 +1507,10 @@ ]), }) # --- -# name: test_classes_RestDocstringClass +# name: test_classes_NumpyDocstringClass dict({ 'attributes': list([ - 'test_package/test_docstrings/RestDocstringClass/attr_1', + 'test_package/docstring_module/NumpyDocstringClass/attr_1', ]), 'classes': list([ ]), @@ -1496,14 +1519,14 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/test_docstrings/RestDocstringClass/__init__', + 'id': 'test_package/docstring_module/NumpyDocstringClass/__init__', 'is_class_method': False, 'is_public': True, 'is_static': False, 'name': '__init__', 'parameters': list([ - 'test_package/test_docstrings/RestDocstringClass/__init__/self', - 'test_package/test_docstrings/RestDocstringClass/__init__/param_1', + 'test_package/docstring_module/NumpyDocstringClass/__init__/self', + 'test_package/docstring_module/NumpyDocstringClass/__init__/param_1', ]), 'reexported_by': list([ ]), @@ -1511,23 +1534,60 @@ ]), }), 'docstring': dict({ - 'description': 'A class with a variety of different methods for calculations. (ReST).', + 'description': ''' + A class that calculates stuff. (Numpy). + + A class with a variety of different methods for calculations. (Numpy) + ''', 'full_docstring': ''' - A class with a variety of different methods for calculations. (ReST). + A class that calculates stuff. (Numpy). - :param attr_1: Attribute of the calculator. (ReST) - :type attr_1: str - :param param_1: Parameter of the calculator. (ReST) - :type param_1: str + A class with a variety of different methods for calculations. (Numpy) + + Attributes + ---------- + attr_1 : str + Attribute of the calculator. (Numpy) + + Parameters + ---------- + param_1 : str + Parameter of the calculator. (Numpy) ''', }), - 'id': 'test_package/test_docstrings/RestDocstringClass', + 'id': 'test_package/docstring_module/NumpyDocstringClass', 'is_public': True, 'methods': list([ - 'test_package/test_docstrings/RestDocstringClass/rest_docstring_func', + 'test_package/docstring_module/NumpyDocstringClass/numpy_docstring_func', ]), - 'name': 'RestDocstringClass', + 'name': 'NumpyDocstringClass', + 'reexported_by': list([ + ]), + 'superclasses': list([ + ]), + 'variances': list([ + ]), + }) +# --- +# name: test_classes_ReexportClass + dict({ + 'attributes': list([ + ]), + 'classes': list([ + ]), + 'constructor': None, + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_package/_reexport_module_1/ReexportClass', + 'is_public': True, + 'methods': list([ + 'test_package/_reexport_module_1/ReexportClass/_private_class_method_of_reexported_class', + ]), + 'name': 'ReexportClass', 'reexported_by': list([ + 'test_package/__init__', ]), 'superclasses': list([ ]), @@ -1535,61 +1595,26 @@ ]), }) # --- -# name: test_classes_SomeClass +# name: test_classes_RestDocstringClass dict({ 'attributes': list([ - 'test_package/test_module/SomeClass/type_hint_public', - 'test_package/test_module/SomeClass/_type_hint_private', - 'test_package/test_module/SomeClass/no_type_hint_public', - 'test_package/test_module/SomeClass/_no_type_hint_private', - 'test_package/test_module/SomeClass/object_attr', - 'test_package/test_module/SomeClass/object_attr_2', - 'test_package/test_module/SomeClass/tuple_attr_1', - 'test_package/test_module/SomeClass/tuple_attr_2', - 'test_package/test_module/SomeClass/tuple_attr_3', - 'test_package/test_module/SomeClass/list_attr_1', - 'test_package/test_module/SomeClass/list_attr_2', - 'test_package/test_module/SomeClass/list_attr_3', - 'test_package/test_module/SomeClass/list_attr_4', - 'test_package/test_module/SomeClass/dict_attr_1', - 'test_package/test_module/SomeClass/dict_attr_2', - 'test_package/test_module/SomeClass/dict_attr_3', - 'test_package/test_module/SomeClass/bool_attr', - 'test_package/test_module/SomeClass/none_attr', - 'test_package/test_module/SomeClass/flaot_attr', - 'test_package/test_module/SomeClass/int_or_bool_attr', - 'test_package/test_module/SomeClass/str_attr_with_none_value', - 'test_package/test_module/SomeClass/multi_attr_1', - 'test_package/test_module/SomeClass/_multi_attr_2_private', - 'test_package/test_module/SomeClass/multi_attr_3', - 'test_package/test_module/SomeClass/_multi_attr_4_private', - 'test_package/test_module/SomeClass/init_attr', - 'test_package/test_module/SomeClass/_init_attr_private', + 'test_package/docstring_module/RestDocstringClass/attr_1', ]), 'classes': list([ - 'test_package/test_module/SomeClass/NestedClass', ]), 'constructor': dict({ 'docstring': dict({ - 'description': ''' - Summary of the init description. - - Full init description. - ''', - 'full_docstring': ''' - Summary of the init description. - - Full init description. - ''', + 'description': '', + 'full_docstring': '', }), - 'id': 'test_package/test_module/SomeClass/__init__', + 'id': 'test_package/docstring_module/RestDocstringClass/__init__', 'is_class_method': False, 'is_public': True, 'is_static': False, 'name': '__init__', 'parameters': list([ - 'test_package/test_module/SomeClass/__init__/self', - 'test_package/test_module/SomeClass/__init__/init_param_1', + 'test_package/docstring_module/RestDocstringClass/__init__/self', + 'test_package/docstring_module/RestDocstringClass/__init__/param_1', ]), 'reexported_by': list([ ]), @@ -1597,35 +1622,25 @@ ]), }), 'docstring': dict({ - 'description': ''' - Summary of the description. - - Full description - ''', + 'description': 'A class with a variety of different methods for calculations. (ReST).', 'full_docstring': ''' - Summary of the description. + A class with a variety of different methods for calculations. (ReST). - Full description + :param attr_1: Attribute of the calculator. (ReST) + :type attr_1: str + :param param_1: Parameter of the calculator. (ReST) + :type param_1: str ''', }), - 'id': 'test_package/test_module/SomeClass', + 'id': 'test_package/docstring_module/RestDocstringClass', 'is_public': True, 'methods': list([ - 'test_package/test_module/SomeClass/_some_function', - 'test_package/test_module/SomeClass/static_function', - 'test_package/test_module/SomeClass/test_position', - 'test_package/test_module/SomeClass/test_params', - 'test_package/test_module/SomeClass/multiple_results', - 'test_package/test_module/SomeClass/no_return_1', - 'test_package/test_module/SomeClass/no_return_2', - 'test_package/test_module/SomeClass/class_method', - 'test_package/test_module/SomeClass/class_method_params', - ]), - 'name': 'SomeClass', + 'test_package/docstring_module/RestDocstringClass/rest_docstring_func', + ]), + 'name': 'RestDocstringClass', 'reexported_by': list([ ]), 'superclasses': list([ - 'tests.data.test_package.test_module.AcDoubleAlias', ]), 'variances': list([ ]), @@ -1642,7 +1657,7 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/test_module/VarianceClassAll', + 'id': 'test_package/variance_module/VarianceClassAll', 'is_public': True, 'methods': list([ ]), @@ -1664,7 +1679,7 @@ 'name': '_T_con', 'type': dict({ 'kind': 'NamedType', - 'name': 'SomeClass', + 'name': 'A', }), 'variance_type': 'CONTRAVARIANT', }), @@ -1708,7 +1723,7 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/test_module/VarianceClassOnlyInvariance', + 'id': 'test_package/variance_module/VarianceClassOnlyInvariance', 'is_public': True, 'methods': list([ ]), @@ -1747,43 +1762,49 @@ ]), }) # --- -# name: test_classes__PrivateClass +# name: test_classes__ClassModulePrivateClassG dict({ 'attributes': list([ - 'test_package/test_module/_PrivateClass/public_attr_in_private_class', - 'test_package/test_module/_PrivateClass/public_init_attr_in_private_class', + 'test_package/class_module/_ClassModulePrivateClassG/_attr_1', + 'test_package/class_module/_ClassModulePrivateClassG/_attr_2', ]), 'classes': list([ - 'test_package/test_module/_PrivateClass/NestedPrivateClass', ]), - 'constructor': dict({ - 'docstring': dict({ - 'description': '', - 'full_docstring': '', - }), - 'id': 'test_package/test_module/_PrivateClass/__init__', - 'is_class_method': False, - 'is_public': False, - 'is_static': False, - 'name': '__init__', - 'parameters': list([ - 'test_package/test_module/_PrivateClass/__init__/self', - ]), - 'reexported_by': list([ - ]), - 'results': list([ - ]), + 'constructor': None, + 'docstring': dict({ + 'description': '', + 'full_docstring': '', }), + 'id': 'test_package/class_module/_ClassModulePrivateClassG', + 'is_public': False, + 'methods': list([ + ]), + 'name': '_ClassModulePrivateClassG', + 'reexported_by': list([ + ]), + 'superclasses': list([ + ]), + 'variances': list([ + ]), + }) +# --- +# name: test_classes__ClassModulePrivateDoubleNestedClassF + dict({ + 'attributes': list([ + ]), + 'classes': list([ + ]), + 'constructor': None, 'docstring': dict({ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/test_module/_PrivateClass', + 'id': 'test_package/class_module/ClassModuleClassD/ClassModuleNestedClassE/_ClassModulePrivateDoubleNestedClassF', 'is_public': False, 'methods': list([ - 'test_package/test_module/_PrivateClass/public_func_in_private_class', + 'test_package/class_module/ClassModuleClassD/ClassModuleNestedClassE/_ClassModulePrivateDoubleNestedClassF/_class_f_func', ]), - 'name': '_PrivateClass', + 'name': '_ClassModulePrivateDoubleNestedClassF', 'reexported_by': list([ ]), 'superclasses': list([ @@ -1817,74 +1838,57 @@ ]), }) # --- -# name: test_enum_instances_AnotherTestEnum - list([ - dict({ - 'id': 'test_package/test_enums/AnotherTestEnum/number_eleven', - 'name': 'number_eleven', - }), - ]) -# --- # name: test_enum_instances_EnumTest list([ dict({ - 'id': 'test_package/test_enums/EnumTest/EIGHT', + 'id': 'test_package/enum_module/EnumTest/EIGHT', 'name': 'EIGHT', }), dict({ - 'id': 'test_package/test_enums/EnumTest/FIVE', + 'id': 'test_package/enum_module/EnumTest/FIVE', 'name': 'FIVE', }), dict({ - 'id': 'test_package/test_enums/EnumTest/FOUR', + 'id': 'test_package/enum_module/EnumTest/FOUR', 'name': 'FOUR', }), dict({ - 'id': 'test_package/test_enums/EnumTest/NINE', + 'id': 'test_package/enum_module/EnumTest/NINE', 'name': 'NINE', }), dict({ - 'id': 'test_package/test_enums/EnumTest/ONE', + 'id': 'test_package/enum_module/EnumTest/ONE', 'name': 'ONE', }), dict({ - 'id': 'test_package/test_enums/EnumTest/SEVEN', + 'id': 'test_package/enum_module/EnumTest/SEVEN', 'name': 'SEVEN', }), dict({ - 'id': 'test_package/test_enums/EnumTest/SIX', + 'id': 'test_package/enum_module/EnumTest/SIX', 'name': 'SIX', }), dict({ - 'id': 'test_package/test_enums/EnumTest/TEN', - 'name': 'TEN', - }), - dict({ - 'id': 'test_package/test_enums/EnumTest/THREE', + 'id': 'test_package/enum_module/EnumTest/THREE', 'name': 'THREE', }), dict({ - 'id': 'test_package/test_enums/EnumTest/TWO', + 'id': 'test_package/enum_module/EnumTest/TWO', 'name': 'TWO', }), ]) # --- -# name: test_enum_instances__ReexportedEmptyEnum +# name: test_enum_instances_EnumTest3 list([ + dict({ + 'id': 'test_package/enum_module/EnumTest3/ELEVEN', + 'name': 'ELEVEN', + }), ]) # --- -# name: test_enums_AnotherTestEnum - dict({ - 'docstring': dict({ - 'description': '', - 'full_docstring': '', - }), - 'id': 'test_package/test_enums/AnotherTestEnum', - 'instances': list([ - 'test_package/test_enums/AnotherTestEnum/number_eleven', - ]), - 'name': 'AnotherTestEnum', - }) +# name: test_enum_instances__ReexportedEmptyEnum + list([ + ]) # --- # name: test_enums_EnumTest dict({ @@ -1900,29 +1904,54 @@ Full Docstring Description ''', }), - 'id': 'test_package/test_enums/EnumTest', + 'id': 'test_package/enum_module/EnumTest', 'instances': list([ - 'test_package/test_enums/EnumTest/ONE', - 'test_package/test_enums/EnumTest/TWO', - 'test_package/test_enums/EnumTest/THREE', - 'test_package/test_enums/EnumTest/FOUR', - 'test_package/test_enums/EnumTest/FIVE', - 'test_package/test_enums/EnumTest/SIX', - 'test_package/test_enums/EnumTest/SEVEN', - 'test_package/test_enums/EnumTest/EIGHT', - 'test_package/test_enums/EnumTest/NINE', - 'test_package/test_enums/EnumTest/TEN', + 'test_package/enum_module/EnumTest/ONE', + 'test_package/enum_module/EnumTest/TWO', + 'test_package/enum_module/EnumTest/THREE', + 'test_package/enum_module/EnumTest/FOUR', + 'test_package/enum_module/EnumTest/FIVE', + 'test_package/enum_module/EnumTest/SIX', + 'test_package/enum_module/EnumTest/SEVEN', + 'test_package/enum_module/EnumTest/EIGHT', + 'test_package/enum_module/EnumTest/NINE', ]), 'name': 'EnumTest', }) # --- +# name: test_enums_EnumTest2 + dict({ + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_package/enum_module/EnumTest2', + 'instances': list([ + 'test_package/enum_module/EnumTest2/TEN', + ]), + 'name': 'EnumTest2', + }) +# --- +# name: test_enums_EnumTest3 + dict({ + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_package/enum_module/EnumTest3', + 'instances': list([ + 'test_package/enum_module/EnumTest3/ELEVEN', + ]), + 'name': 'EnumTest3', + }) +# --- # name: test_enums__ReexportedEmptyEnum dict({ 'docstring': dict({ 'description': "Nothing's here.", 'full_docstring': "Nothing's here.", }), - 'id': 'test_package/test_enums/_ReexportedEmptyEnum', + 'id': 'test_package/enum_module/_ReexportedEmptyEnum', 'instances': list([ ]), 'name': '_ReexportedEmptyEnum', @@ -1938,7 +1967,7 @@ 'description': 'Parameter of the calculator. (Epydoc)', 'type': 'str', }), - 'id': 'test_package/test_docstrings/EpydocDocstringClass/__init__/param_1', + 'id': 'test_package/docstring_module/EpydocDocstringClass/__init__/param_1', 'is_optional': False, 'is_type_inferred': False, 'name': 'param_1', @@ -1955,7 +1984,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/test_docstrings/EpydocDocstringClass/__init__/self', + 'id': 'test_package/docstring_module/EpydocDocstringClass/__init__/self', 'is_optional': False, 'is_type_inferred': False, 'name': 'self', @@ -1973,7 +2002,7 @@ 'description': 'Parameter of the calculator. (Google Style)', 'type': 'str', }), - 'id': 'test_package/test_docstrings/GoogleDocstringClass/__init__/param_1', + 'id': 'test_package/docstring_module/GoogleDocstringClass/__init__/param_1', 'is_optional': False, 'is_type_inferred': False, 'name': 'param_1', @@ -1990,7 +2019,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/test_docstrings/GoogleDocstringClass/__init__/self', + 'id': 'test_package/docstring_module/GoogleDocstringClass/__init__/self', 'is_optional': False, 'is_type_inferred': False, 'name': 'self', @@ -2008,7 +2037,7 @@ 'description': 'Parameter of the calculator. (Numpy)', 'type': 'str', }), - 'id': 'test_package/test_docstrings/NumpyDocstringClass/__init__/param_1', + 'id': 'test_package/docstring_module/NumpyDocstringClass/__init__/param_1', 'is_optional': False, 'is_type_inferred': False, 'name': 'param_1', @@ -2025,7 +2054,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/test_docstrings/NumpyDocstringClass/__init__/self', + 'id': 'test_package/docstring_module/NumpyDocstringClass/__init__/self', 'is_optional': False, 'is_type_inferred': False, 'name': 'self', @@ -2043,7 +2072,7 @@ 'description': 'Parameter of the calculator. (ReST)', 'type': 'str', }), - 'id': 'test_package/test_docstrings/RestDocstringClass/__init__/param_1', + 'id': 'test_package/docstring_module/RestDocstringClass/__init__/param_1', 'is_optional': False, 'is_type_inferred': False, 'name': 'param_1', @@ -2060,7 +2089,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/test_docstrings/RestDocstringClass/__init__/self', + 'id': 'test_package/docstring_module/RestDocstringClass/__init__/self', 'is_optional': False, 'is_type_inferred': False, 'name': 'self', @@ -2068,31 +2097,83 @@ }), ]) # --- -# name: test_function_parameters_SomeClass___init__ +# name: test_function_parameters_epydoc_docstring_func list([ dict({ - 'assigned_by': 'POSITION_OR_NAME', + 'assigned_by': 'IMPLICIT', 'default_value': None, 'docstring': dict({ 'default_value': '', 'description': '', 'type': '', }), - 'id': 'test_package/test_module/SomeClass/__init__/init_param_1', + 'id': 'test_package/docstring_module/EpydocDocstringClass/epydoc_docstring_func/self', 'is_optional': False, 'is_type_inferred': False, - 'name': 'init_param_1', + 'name': 'self', 'type': None, }), dict({ - 'assigned_by': 'IMPLICIT', + 'assigned_by': 'POSITION_OR_NAME', + 'default_value': None, + 'docstring': dict({ + 'default_value': '', + 'description': 'First integer value for the calculation. (Epydoc)', + 'type': 'int', + }), + 'id': 'test_package/docstring_module/EpydocDocstringClass/epydoc_docstring_func/x', + 'is_optional': False, + 'is_type_inferred': False, + 'name': 'x', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'int', + }), + }), + dict({ + 'assigned_by': 'POSITION_OR_NAME', + 'default_value': None, + 'docstring': dict({ + 'default_value': '', + 'description': 'Second integer value for the calculation. (Epydoc)', + 'type': 'int', + }), + 'id': 'test_package/docstring_module/EpydocDocstringClass/epydoc_docstring_func/y', + 'is_optional': False, + 'is_type_inferred': False, + 'name': 'y', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'int', + }), + }), + ]) +# --- +# name: test_function_parameters_function_module_FunctionModuleClassB___init__ + list([ + dict({ + 'assigned_by': 'POSITION_OR_NAME', + 'default_value': None, + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_package/function_module/FunctionModuleClassB/__init__/init_param', + 'is_optional': False, + 'is_type_inferred': False, + 'name': 'init_param', + 'type': None, + }), + dict({ + 'assigned_by': 'IMPLICIT', 'default_value': None, 'docstring': dict({ 'default_value': '', 'description': '', 'type': '', }), - 'id': 'test_package/test_module/SomeClass/__init__/self', + 'id': 'test_package/function_module/FunctionModuleClassB/__init__/self', 'is_optional': False, 'is_type_inferred': False, 'name': 'self', @@ -2100,7 +2181,7 @@ }), ]) # --- -# name: test_function_parameters_epydoc_docstring_func +# name: test_function_parameters_function_module_FunctionModuleClassB_class_method list([ dict({ 'assigned_by': 'IMPLICIT', @@ -2110,10 +2191,28 @@ 'description': '', 'type': '', }), - 'id': 'test_package/test_docstrings/EpydocDocstringClass/epydoc_docstring_func/self', + 'id': 'test_package/function_module/FunctionModuleClassB/class_method/cls', 'is_optional': False, 'is_type_inferred': False, - 'name': 'self', + 'name': 'cls', + 'type': None, + }), + ]) +# --- +# name: test_function_parameters_function_module_FunctionModuleClassB_class_method_params + list([ + dict({ + 'assigned_by': 'IMPLICIT', + 'default_value': None, + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_package/function_module/FunctionModuleClassB/class_method_params/cls', + 'is_optional': False, + 'is_type_inferred': False, + 'name': 'cls', 'type': None, }), dict({ @@ -2121,54 +2220,790 @@ 'default_value': None, 'docstring': dict({ 'default_value': '', - 'description': 'First integer value for the calculation. (Epydoc)', - 'type': 'int', + 'description': '', + 'type': '', }), - 'id': 'test_package/test_docstrings/EpydocDocstringClass/epydoc_docstring_func/x', + 'id': 'test_package/function_module/FunctionModuleClassB/class_method_params/param_1', 'is_optional': False, 'is_type_inferred': False, - 'name': 'x', + 'name': 'param_1', 'type': dict({ 'kind': 'NamedType', 'name': 'int', }), }), + ]) +# --- +# name: test_function_parameters_function_module_FunctionModuleClassB_static_method_params + list([ dict({ 'assigned_by': 'POSITION_OR_NAME', 'default_value': None, 'docstring': dict({ 'default_value': '', - 'description': 'Second integer value for the calculation. (Epydoc)', - 'type': 'int', + 'description': '', + 'type': '', }), - 'id': 'test_package/test_docstrings/EpydocDocstringClass/epydoc_docstring_func/y', + 'id': 'test_package/function_module/FunctionModuleClassB/static_method_params/param_1', 'is_optional': False, 'is_type_inferred': False, - 'name': 'y', + 'name': 'param_1', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'int', + }), + }), + ]) +# --- +# name: test_function_parameters_function_module_FunctionModuleClassC_nested_class_function + list([ + dict({ + 'assigned_by': 'POSITION_OR_NAME', + 'default_value': None, + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_package/function_module/FunctionModuleClassB/FunctionModuleClassC/nested_class_function/param1', + 'is_optional': False, + 'is_type_inferred': False, + 'name': 'param1', 'type': dict({ 'kind': 'NamedType', 'name': 'int', }), }), + dict({ + 'assigned_by': 'IMPLICIT', + 'default_value': None, + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_package/function_module/FunctionModuleClassB/FunctionModuleClassC/nested_class_function/self', + 'is_optional': False, + 'is_type_inferred': False, + 'name': 'self', + 'type': None, + }), + ]) +# --- +# name: test_function_parameters_function_module__private + list([ + dict({ + 'assigned_by': 'POSITION_OR_NAME', + 'default_value': None, + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_package/function_module/_private/a', + 'is_optional': False, + 'is_type_inferred': False, + 'name': 'a', + 'type': None, + }), + ]) +# --- +# name: test_function_parameters_function_module_arg + list([ + dict({ + 'assigned_by': 'POSITIONAL_VARARG', + 'default_value': None, + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_package/function_module/arg/args', + 'is_optional': False, + 'is_type_inferred': False, + 'name': 'args', + 'type': None, + }), + dict({ + 'assigned_by': 'NAMED_VARARG', + 'default_value': None, + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_package/function_module/arg/kwargs', + 'is_optional': False, + 'is_type_inferred': False, + 'name': 'kwargs', + 'type': None, + }), + ]) +# --- +# name: test_function_parameters_function_module_args_type + list([ + dict({ + 'assigned_by': 'POSITIONAL_VARARG', + 'default_value': None, + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_package/function_module/args_type/args', + 'is_optional': False, + 'is_type_inferred': False, + 'name': 'args', + 'type': dict({ + 'kind': 'TupleType', + 'types': list([ + dict({ + 'kind': 'NamedType', + 'name': 'int', + }), + ]), + }), + }), + dict({ + 'assigned_by': 'NAMED_VARARG', + 'default_value': None, + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_package/function_module/args_type/kwargs', + 'is_optional': False, + 'is_type_inferred': False, + 'name': 'kwargs', + 'type': dict({ + 'key_type': dict({ + 'kind': 'NamedType', + 'name': 'str', + }), + 'kind': 'DictType', + 'value_type': dict({ + 'kind': 'NamedType', + 'name': 'int', + }), + }), + }), + ]) +# --- +# name: test_function_parameters_function_module_callable_type + list([ + dict({ + 'assigned_by': 'POSITION_OR_NAME', + 'default_value': None, + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_package/function_module/callable_type/param', + 'is_optional': False, + 'is_type_inferred': False, + 'name': 'param', + 'type': dict({ + 'kind': 'CallableType', + 'parameter_types': list([ + dict({ + 'kind': 'NamedType', + 'name': 'str', + }), + ]), + 'return_type': dict({ + 'kind': 'TupleType', + 'types': list([ + dict({ + 'kind': 'NamedType', + 'name': 'int', + }), + dict({ + 'kind': 'NamedType', + 'name': 'str', + }), + ]), + }), + }), + }), ]) # --- -# name: test_function_parameters_global_func +# name: test_function_parameters_function_module_illegal_params list([ dict({ 'assigned_by': 'POSITION_OR_NAME', - 'default_value': 'first param', + 'default_value': 'String', 'docstring': dict({ 'default_value': '', 'description': '', 'type': '', }), - 'id': 'test_package/test_module/global_func/param_1', + 'id': 'test_package/function_module/illegal_params/_', 'is_optional': True, 'is_type_inferred': False, - 'name': 'param_1', + 'name': '_', 'type': dict({ 'kind': 'NamedType', - 'name': 'str', + 'name': 'int', + }), + }), + dict({ + 'assigned_by': 'POSITION_OR_NAME', + 'default_value': None, + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_package/function_module/illegal_params/lst', + 'is_optional': False, + 'is_type_inferred': False, + 'name': 'lst', + 'type': dict({ + 'kind': 'ListType', + 'types': list([ + dict({ + 'kind': 'NamedType', + 'name': 'int', + }), + dict({ + 'kind': 'NamedType', + 'name': 'str', + }), + ]), + }), + }), + dict({ + 'assigned_by': 'POSITION_OR_NAME', + 'default_value': None, + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_package/function_module/illegal_params/lst_2', + 'is_optional': False, + 'is_type_inferred': False, + 'name': 'lst_2', + 'type': dict({ + 'kind': 'ListType', + 'types': list([ + dict({ + 'kind': 'NamedType', + 'name': 'int', + }), + dict({ + 'kind': 'NamedType', + 'name': 'str', + }), + dict({ + 'kind': 'NamedType', + 'name': 'int', + }), + ]), + }), + }), + dict({ + 'assigned_by': 'POSITION_OR_NAME', + 'default_value': None, + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_package/function_module/illegal_params/tpl', + 'is_optional': False, + 'is_type_inferred': False, + 'name': 'tpl', + 'type': dict({ + 'kind': 'TupleType', + 'types': list([ + dict({ + 'kind': 'NamedType', + 'name': 'int', + }), + dict({ + 'kind': 'NamedType', + 'name': 'str', + }), + dict({ + 'kind': 'NamedType', + 'name': 'bool', + }), + dict({ + 'kind': 'NamedType', + 'name': 'int', + }), + ]), + }), + }), + ]) +# --- +# name: test_function_parameters_function_module_opt_pos_only + list([ + dict({ + 'assigned_by': 'POSITION_ONLY', + 'default_value': 1, + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_package/function_module/opt_pos_only/optional', + 'is_optional': True, + 'is_type_inferred': True, + 'name': 'optional', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'int', + }), + }), + dict({ + 'assigned_by': 'POSITION_ONLY', + 'default_value': None, + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_package/function_module/opt_pos_only/required', + 'is_optional': False, + 'is_type_inferred': False, + 'name': 'required', + 'type': None, + }), + ]) +# --- +# name: test_function_parameters_function_module_param_position + list([ + dict({ + 'assigned_by': 'POSITION_ONLY', + 'default_value': None, + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_package/function_module/param_position/a', + 'is_optional': False, + 'is_type_inferred': False, + 'name': 'a', + 'type': None, + }), + dict({ + 'assigned_by': 'POSITION_OR_NAME', + 'default_value': None, + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_package/function_module/param_position/b', + 'is_optional': False, + 'is_type_inferred': False, + 'name': 'b', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'bool', + }), + }), + dict({ + 'assigned_by': 'POSITION_OR_NAME', + 'default_value': 1, + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_package/function_module/param_position/c', + 'is_optional': True, + 'is_type_inferred': True, + 'name': 'c', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'int', + }), + }), + dict({ + 'assigned_by': 'NAME_ONLY', + 'default_value': None, + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_package/function_module/param_position/d', + 'is_optional': False, + 'is_type_inferred': False, + 'name': 'd', + 'type': None, + }), + dict({ + 'assigned_by': 'NAME_ONLY', + 'default_value': 1, + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_package/function_module/param_position/e', + 'is_optional': True, + 'is_type_inferred': False, + 'name': 'e', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'int', + }), + }), + dict({ + 'assigned_by': 'POSITION_ONLY', + 'default_value': None, + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_package/function_module/param_position/self', + 'is_optional': False, + 'is_type_inferred': False, + 'name': 'self', + 'type': None, + }), + ]) +# --- +# name: test_function_parameters_function_module_params + list([ + dict({ + 'assigned_by': 'POSITION_OR_NAME', + 'default_value': None, + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_package/function_module/params/i', + 'is_optional': False, + 'is_type_inferred': False, + 'name': 'i', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'int', + }), + }), + dict({ + 'assigned_by': 'POSITION_OR_NAME', + 'default_value': None, + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_package/function_module/params/lst', + 'is_optional': False, + 'is_type_inferred': False, + 'name': 'lst', + 'type': dict({ + 'kind': 'ListType', + 'types': list([ + dict({ + 'kind': 'NamedType', + 'name': 'int', + }), + ]), + }), + }), + dict({ + 'assigned_by': 'POSITION_OR_NAME', + 'default_value': None, + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_package/function_module/params/obj', + 'is_optional': False, + 'is_type_inferred': False, + 'name': 'obj', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'FunctionModuleClassA', + }), + }), + dict({ + 'assigned_by': 'POSITION_OR_NAME', + 'default_value': None, + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_package/function_module/params/union', + 'is_optional': False, + 'is_type_inferred': False, + 'name': 'union', + 'type': dict({ + 'kind': 'UnionType', + 'types': list([ + dict({ + 'kind': 'NamedType', + 'name': 'int', + }), + dict({ + 'kind': 'NamedType', + 'name': 'bool', + }), + ]), + }), + }), + ]) +# --- +# name: test_function_parameters_function_module_public_no_params_no_result + list([ + ]) +# --- +# name: test_function_parameters_function_module_req_name_only + list([ + dict({ + 'assigned_by': 'NAME_ONLY', + 'default_value': 1, + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_package/function_module/req_name_only/optional', + 'is_optional': True, + 'is_type_inferred': True, + 'name': 'optional', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'int', + }), + }), + dict({ + 'assigned_by': 'NAME_ONLY', + 'default_value': None, + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_package/function_module/req_name_only/required', + 'is_optional': False, + 'is_type_inferred': False, + 'name': 'required', + 'type': None, + }), + ]) +# --- +# name: test_function_parameters_function_module_special_params + list([ + dict({ + 'assigned_by': 'POSITION_OR_NAME', + 'default_value': None, + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_package/function_module/special_params/bool_none_union', + 'is_optional': False, + 'is_type_inferred': False, + 'name': 'bool_none_union', + 'type': dict({ + 'kind': 'UnionType', + 'types': list([ + dict({ + 'kind': 'NamedType', + 'name': 'bool', + }), + dict({ + 'kind': 'NamedType', + 'name': 'None', + }), + ]), + }), + }), + dict({ + 'assigned_by': 'POSITION_OR_NAME', + 'default_value': None, + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_package/function_module/special_params/none', + 'is_optional': False, + 'is_type_inferred': False, + 'name': 'none', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'None', + }), + }), + dict({ + 'assigned_by': 'POSITION_OR_NAME', + 'default_value': None, + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_package/function_module/special_params/none_bool_int_union', + 'is_optional': False, + 'is_type_inferred': False, + 'name': 'none_bool_int_union', + 'type': dict({ + 'kind': 'UnionType', + 'types': list([ + dict({ + 'kind': 'NamedType', + 'name': 'None', + }), + dict({ + 'kind': 'NamedType', + 'name': 'bool', + }), + dict({ + 'kind': 'NamedType', + 'name': 'int', + }), + ]), + }), + }), + dict({ + 'assigned_by': 'POSITION_OR_NAME', + 'default_value': None, + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_package/function_module/special_params/none_bool_none_union', + 'is_optional': False, + 'is_type_inferred': False, + 'name': 'none_bool_none_union', + 'type': dict({ + 'kind': 'UnionType', + 'types': list([ + dict({ + 'kind': 'NamedType', + 'name': 'None', + }), + dict({ + 'kind': 'NamedType', + 'name': 'bool', + }), + dict({ + 'kind': 'NamedType', + 'name': 'None', + }), + ]), + }), + }), + dict({ + 'assigned_by': 'POSITION_OR_NAME', + 'default_value': None, + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_package/function_module/special_params/none_bool_union', + 'is_optional': False, + 'is_type_inferred': False, + 'name': 'none_bool_union', + 'type': dict({ + 'kind': 'UnionType', + 'types': list([ + dict({ + 'kind': 'NamedType', + 'name': 'None', + }), + dict({ + 'kind': 'NamedType', + 'name': 'bool', + }), + ]), + }), + }), + dict({ + 'assigned_by': 'POSITION_OR_NAME', + 'default_value': None, + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_package/function_module/special_params/none_list_union_none_none', + 'is_optional': False, + 'is_type_inferred': False, + 'name': 'none_list_union_none_none', + 'type': dict({ + 'kind': 'UnionType', + 'types': list([ + dict({ + 'kind': 'NamedType', + 'name': 'None', + }), + dict({ + 'kind': 'ListType', + 'types': list([ + dict({ + 'kind': 'UnionType', + 'types': list([ + dict({ + 'kind': 'NamedType', + 'name': 'None', + }), + dict({ + 'kind': 'NamedType', + 'name': 'None', + }), + ]), + }), + ]), + }), + dict({ + 'kind': 'NamedType', + 'name': 'None', + }), + ]), + }), + }), + dict({ + 'assigned_by': 'POSITION_OR_NAME', + 'default_value': None, + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_package/function_module/special_params/none_none_bool_none_union', + 'is_optional': False, + 'is_type_inferred': False, + 'name': 'none_none_bool_none_union', + 'type': dict({ + 'kind': 'UnionType', + 'types': list([ + dict({ + 'kind': 'NamedType', + 'name': 'None', + }), + dict({ + 'kind': 'NamedType', + 'name': 'None', + }), + dict({ + 'kind': 'NamedType', + 'name': 'bool', + }), + dict({ + 'kind': 'NamedType', + 'name': 'None', + }), + ]), }), }), dict({ @@ -2179,16 +3014,16 @@ 'description': '', 'type': '', }), - 'id': 'test_package/test_module/global_func/param_2', - 'is_optional': True, + 'id': 'test_package/function_module/special_params/none_union', + 'is_optional': False, 'is_type_inferred': False, - 'name': 'param_2', + 'name': 'none_union', 'type': dict({ 'kind': 'UnionType', 'types': list([ dict({ 'kind': 'NamedType', - 'name': 'AnotherClass', + 'name': 'None', }), dict({ 'kind': 'NamedType', @@ -2209,7 +3044,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/test_docstrings/GoogleDocstringClass/google_docstring_func/self', + 'id': 'test_package/docstring_module/GoogleDocstringClass/google_docstring_func/self', 'is_optional': False, 'is_type_inferred': False, 'name': 'self', @@ -2223,7 +3058,7 @@ 'description': 'First integer value for the calculation. (Google Style)', 'type': 'int', }), - 'id': 'test_package/test_docstrings/GoogleDocstringClass/google_docstring_func/x', + 'id': 'test_package/docstring_module/GoogleDocstringClass/google_docstring_func/x', 'is_optional': False, 'is_type_inferred': False, 'name': 'x', @@ -2240,7 +3075,7 @@ 'description': 'Second integer value for the calculation. (Google Style)', 'type': 'int', }), - 'id': 'test_package/test_docstrings/GoogleDocstringClass/google_docstring_func/y', + 'id': 'test_package/docstring_module/GoogleDocstringClass/google_docstring_func/y', 'is_optional': False, 'is_type_inferred': False, 'name': 'y', @@ -2251,41 +3086,6 @@ }), ]) # --- -# name: test_function_parameters_nested_class_function - list([ - dict({ - 'assigned_by': 'POSITION_OR_NAME', - 'default_value': None, - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_module/SomeClass/NestedClass/nested_class_function/param_1', - 'is_optional': False, - 'is_type_inferred': False, - 'name': 'param_1', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'int', - }), - }), - dict({ - 'assigned_by': 'IMPLICIT', - 'default_value': None, - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_module/SomeClass/NestedClass/nested_class_function/self', - 'is_optional': False, - 'is_type_inferred': False, - 'name': 'self', - 'type': None, - }), - ]) -# --- # name: test_function_parameters_numpy_docstring_func list([ dict({ @@ -2296,7 +3096,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/test_docstrings/NumpyDocstringClass/numpy_docstring_func/self', + 'id': 'test_package/docstring_module/NumpyDocstringClass/numpy_docstring_func/self', 'is_optional': False, 'is_type_inferred': False, 'name': 'self', @@ -2310,7 +3110,7 @@ 'description': 'First integer value for the calculation. (Numpy)', 'type': 'int', }), - 'id': 'test_package/test_docstrings/NumpyDocstringClass/numpy_docstring_func/x', + 'id': 'test_package/docstring_module/NumpyDocstringClass/numpy_docstring_func/x', 'is_optional': False, 'is_type_inferred': False, 'name': 'x', @@ -2327,7 +3127,7 @@ 'description': 'Second integer value for the calculation. (Numpy)', 'type': 'int', }), - 'id': 'test_package/test_docstrings/NumpyDocstringClass/numpy_docstring_func/y', + 'id': 'test_package/docstring_module/NumpyDocstringClass/numpy_docstring_func/y', 'is_optional': False, 'is_type_inferred': False, 'name': 'y', @@ -2348,7 +3148,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/test_docstrings/RestDocstringClass/rest_docstring_func/self', + 'id': 'test_package/docstring_module/RestDocstringClass/rest_docstring_func/self', 'is_optional': False, 'is_type_inferred': False, 'name': 'self', @@ -2362,7 +3162,7 @@ 'description': 'First integer value for the calculation. (ReST)', 'type': 'int', }), - 'id': 'test_package/test_docstrings/RestDocstringClass/rest_docstring_func/x', + 'id': 'test_package/docstring_module/RestDocstringClass/rest_docstring_func/x', 'is_optional': False, 'is_type_inferred': False, 'name': 'x', @@ -2379,7 +3179,7 @@ 'description': 'Second integer value for the calculation. (ReST)', 'type': 'int', }), - 'id': 'test_package/test_docstrings/RestDocstringClass/rest_docstring_func/y', + 'id': 'test_package/docstring_module/RestDocstringClass/rest_docstring_func/y', 'is_optional': False, 'is_type_inferred': False, 'name': 'y', @@ -2390,180 +3190,51 @@ }), ]) # --- -# name: test_function_parameters_static_function +# name: test_function_results_callable_type list([ dict({ - 'assigned_by': 'POSITION_OR_NAME', - 'default_value': True, - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_module/SomeClass/static_function/param_1', - 'is_optional': True, - 'is_type_inferred': False, - 'name': 'param_1', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'bool', - }), - }), - dict({ - 'assigned_by': 'POSITION_OR_NAME', - 'default_value': 123456, 'docstring': dict({ - 'default_value': '', 'description': '', 'type': '', }), - 'id': 'test_package/test_module/SomeClass/static_function/param_2', - 'is_optional': True, + 'id': 'test_package/function_module/callable_type/result_1', 'is_type_inferred': False, - 'name': 'param_2', + 'name': 'result_1', 'type': dict({ - 'kind': 'UnionType', - 'types': list([ + 'kind': 'CallableType', + 'parameter_types': list([ dict({ 'kind': 'NamedType', 'name': 'int', }), dict({ 'kind': 'NamedType', - 'name': 'bool', + 'name': 'int', }), ]), + 'return_type': dict({ + 'kind': 'NamedType', + 'name': 'int', + }), }), }), ]) # --- -# name: test_function_parameters_test_params - list([ - dict({ - 'assigned_by': 'POSITIONAL_VARARG', - 'default_value': None, - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_module/SomeClass/test_params/args', - 'is_optional': False, - 'is_type_inferred': False, - 'name': 'args', - 'type': None, - }), - dict({ - 'assigned_by': 'NAMED_VARARG', - 'default_value': None, - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_module/SomeClass/test_params/kwargs', - 'is_optional': False, - 'is_type_inferred': False, - 'name': 'kwargs', - 'type': None, - }), - ]) -# --- -# name: test_function_parameters_test_position +# name: test_function_results_class_method_params list([ dict({ - 'assigned_by': 'POSITION_ONLY', - 'default_value': None, - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_module/SomeClass/test_position/param1', - 'is_optional': False, - 'is_type_inferred': False, - 'name': 'param1', - 'type': None, - }), - dict({ - 'assigned_by': 'POSITION_OR_NAME', - 'default_value': None, 'docstring': dict({ - 'default_value': '', 'description': '', 'type': '', }), - 'id': 'test_package/test_module/SomeClass/test_position/param2', - 'is_optional': False, + 'id': 'test_package/function_module/FunctionModuleClassB/class_method_params/result_1', 'is_type_inferred': False, - 'name': 'param2', + 'name': 'result_1', 'type': dict({ 'kind': 'NamedType', 'name': 'bool', }), }), - dict({ - 'assigned_by': 'POSITION_OR_NAME', - 'default_value': 1, - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_module/SomeClass/test_position/param3', - 'is_optional': True, - 'is_type_inferred': True, - 'name': 'param3', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'int', - }), - }), - dict({ - 'assigned_by': 'NAME_ONLY', - 'default_value': None, - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_module/SomeClass/test_position/param4', - 'is_optional': False, - 'is_type_inferred': False, - 'name': 'param4', - 'type': None, - }), - dict({ - 'assigned_by': 'NAME_ONLY', - 'default_value': 1, - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_module/SomeClass/test_position/param5', - 'is_optional': True, - 'is_type_inferred': False, - 'name': 'param5', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'int', - }), - }), - dict({ - 'assigned_by': 'IMPLICIT', - 'default_value': None, - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_module/SomeClass/test_position/self', - 'is_optional': False, - 'is_type_inferred': False, - 'name': 'self', - 'type': None, - }), ]) # --- # name: test_function_results_epydoc_docstring_func @@ -2573,7 +3244,7 @@ 'description': 'Checks if the sum of x and y is greater than 10. (Epydoc)', 'type': 'bool', }), - 'id': 'test_package/test_docstrings/EpydocDocstringClass/epydoc_docstring_func/result_1', + 'id': 'test_package/docstring_module/EpydocDocstringClass/epydoc_docstring_func/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ @@ -2583,23 +3254,6 @@ }), ]) # --- -# name: test_function_results_global_func - list([ - dict({ - 'docstring': dict({ - 'description': '', - 'type': '', - }), - 'id': 'test_package/test_module/global_func/result_1', - 'is_type_inferred': False, - 'name': 'result_1', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'AnotherClass', - }), - }), - ]) -# --- # name: test_function_results_google_docstring_func list([ dict({ @@ -2610,7 +3264,7 @@ ''', 'type': 'bool', }), - 'id': 'test_package/test_docstrings/GoogleDocstringClass/google_docstring_func/result_1', + 'id': 'test_package/docstring_module/GoogleDocstringClass/google_docstring_func/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ @@ -2627,7 +3281,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/test_module/InferMyTypes/infer_function/result_1', + 'id': 'test_package/infer_types_module/InferMyTypes/infer_function/result_1', 'is_type_inferred': True, 'name': 'result_1', 'type': dict({ @@ -2640,12 +3294,12 @@ 'description': '', 'type': '', }), - 'id': 'test_package/test_module/InferMyTypes/infer_function/result_2', + 'id': 'test_package/infer_types_module/InferMyTypes/infer_function/result_2', 'is_type_inferred': True, 'name': 'result_2', 'type': dict({ 'kind': 'NamedType', - 'name': 'None', + 'name': 'ModuleClass', }), }), dict({ @@ -2653,12 +3307,12 @@ 'description': '', 'type': '', }), - 'id': 'test_package/test_module/InferMyTypes/infer_function/result_3', + 'id': 'test_package/infer_types_module/InferMyTypes/infer_function/result_3', 'is_type_inferred': True, 'name': 'result_3', 'type': dict({ 'kind': 'NamedType', - 'name': 'SomeClass', + 'name': 'None', }), }), dict({ @@ -2666,7 +3320,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/test_module/InferMyTypes/infer_function/result_4', + 'id': 'test_package/infer_types_module/InferMyTypes/infer_function/result_4', 'is_type_inferred': True, 'name': 'result_4', 'type': dict({ @@ -2679,7 +3333,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/test_module/InferMyTypes/infer_function/result_5', + 'id': 'test_package/infer_types_module/InferMyTypes/infer_function/result_5', 'is_type_inferred': True, 'name': 'result_5', 'type': dict({ @@ -2692,7 +3346,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/test_module/InferMyTypes/infer_function/result_6', + 'id': 'test_package/infer_types_module/InferMyTypes/infer_function/result_6', 'is_type_inferred': True, 'name': 'result_6', 'type': dict({ @@ -2705,7 +3359,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/test_module/InferMyTypes/infer_function/result_7', + 'id': 'test_package/infer_types_module/InferMyTypes/infer_function/result_7', 'is_type_inferred': True, 'name': 'result_7', 'type': dict({ @@ -2715,114 +3369,87 @@ }), ]) # --- -# name: test_function_results_multiple_results +# name: test_function_results_instance_method list([ dict({ 'docstring': dict({ 'description': '', 'type': '', }), - 'id': 'test_package/test_module/SomeClass/multiple_results/result_1', + 'id': 'test_package/function_module/FunctionModuleClassB/instance_method/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ - 'kind': 'UnionType', - 'types': list([ - dict({ - 'kind': 'NamedType', - 'name': 'Any', - }), - dict({ - 'kind': 'TupleType', - 'types': list([ - dict({ - 'kind': 'NamedType', - 'name': 'int', - }), - dict({ - 'kind': 'NamedType', - 'name': 'str', - }), - ]), - }), - ]), + 'kind': 'NamedType', + 'name': 'FunctionModuleClassA', }), }), ]) # --- -# name: test_function_results_nested_class_function +# name: test_function_results_multiple_results list([ dict({ 'docstring': dict({ 'description': '', 'type': '', }), - 'id': 'test_package/test_module/SomeClass/NestedClass/nested_class_function/result_1', + 'id': 'test_package/function_module/multiple_results/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ - 'kind': 'SetType', - 'types': list([ - dict({ - 'kind': 'UnionType', - 'types': list([ - dict({ - 'kind': 'NamedType', - 'name': 'bool', - }), - dict({ - 'kind': 'NamedType', - 'name': 'None', - }), - ]), - }), - ]), + 'kind': 'NamedType', + 'name': 'str', }), }), - ]) -# --- -# name: test_function_results_numpy_docstring_func - list([ dict({ 'docstring': dict({ - 'description': 'Checks if the sum of `x` and `y` is greater than 10. (Numpy)', - 'type': 'bool', + 'description': '', + 'type': '', }), - 'id': 'test_package/test_docstrings/NumpyDocstringClass/numpy_docstring_func/result_1', + 'id': 'test_package/function_module/multiple_results/result_2', 'is_type_inferred': False, - 'name': 'result_1', + 'name': 'result_2', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'int', + }), + }), + dict({ + 'docstring': dict({ + 'description': '', + 'type': '', + }), + 'id': 'test_package/function_module/multiple_results/result_3', + 'is_type_inferred': False, + 'name': 'result_3', 'type': dict({ 'kind': 'NamedType', 'name': 'bool', }), }), - ]) -# --- -# name: test_function_results_rest_docstring_func - list([ dict({ 'docstring': dict({ - 'description': 'Checks if the sum of x and y is greater than 10. (ReST)', - 'type': 'bool', + 'description': '', + 'type': '', }), - 'id': 'test_package/test_docstrings/RestDocstringClass/rest_docstring_func/result_1', + 'id': 'test_package/function_module/multiple_results/result_4', 'is_type_inferred': False, - 'name': 'result_1', + 'name': 'result_4', 'type': dict({ 'kind': 'NamedType', - 'name': 'bool', + 'name': 'FunctionModuleClassA', }), }), ]) # --- -# name: test_function_results_static_function +# name: test_function_results_nested_class_function list([ dict({ 'docstring': dict({ 'description': '', 'type': '', }), - 'id': 'test_package/test_module/SomeClass/static_function/result_1', + 'id': 'test_package/function_module/FunctionModuleClassB/FunctionModuleClassC/nested_class_function/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ @@ -2830,38 +3457,46 @@ 'name': 'bool', }), }), + ]) +# --- +# name: test_function_results_numpy_docstring_func + list([ dict({ 'docstring': dict({ - 'description': '', - 'type': '', + 'description': 'Checks if the sum of `x` and `y` is greater than 10. (Numpy)', + 'type': 'bool', }), - 'id': 'test_package/test_module/SomeClass/static_function/result_2', + 'id': 'test_package/docstring_module/NumpyDocstringClass/numpy_docstring_func/result_1', 'is_type_inferred': False, - 'name': 'result_2', + 'name': 'result_1', 'type': dict({ 'kind': 'NamedType', - 'name': 'int', + 'name': 'bool', }), }), ]) # --- -# name: test_function_results_test_position +# name: test_function_results_rest_docstring_func list([ dict({ 'docstring': dict({ - 'description': '', - 'type': '', + 'description': 'Checks if the sum of x and y is greater than 10. (ReST)', + 'type': 'bool', }), - 'id': 'test_package/test_module/SomeClass/test_position/result_1', + 'id': 'test_package/docstring_module/RestDocstringClass/rest_docstring_func/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ 'kind': 'NamedType', - 'name': 'Any', + 'name': 'bool', }), }), ]) # --- +# name: test_function_results_static_method_params + list([ + ]) +# --- # name: test_global_functions__reexport_module_1 list([ dict({ @@ -2966,52 +3601,265 @@ }), ]) # --- -# name: test_global_functions_test_module +# name: test_global_functions_function_module list([ dict({ 'docstring': dict({ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/test_module/_private_global_func', + 'id': 'test_package/function_module/_private', 'is_class_method': False, 'is_public': False, 'is_static': False, - 'name': '_private_global_func', + 'name': '_private', 'parameters': list([ + 'test_package/function_module/_private/a', ]), 'reexported_by': list([ ]), 'results': list([ - 'test_package/test_module/_private_global_func/result_1', ]), }), dict({ 'docstring': dict({ - 'description': ''' - Docstring 1. - - Docstring 2. - ''', - 'full_docstring': ''' - Docstring 1. - - Docstring 2. - ''', + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_package/function_module/arg', + 'is_class_method': False, + 'is_public': True, + 'is_static': False, + 'name': 'arg', + 'parameters': list([ + 'test_package/function_module/arg/args', + 'test_package/function_module/arg/kwargs', + ]), + 'reexported_by': list([ + ]), + 'results': list([ + ]), + }), + dict({ + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_package/function_module/args_type', + 'is_class_method': False, + 'is_public': True, + 'is_static': False, + 'name': 'args_type', + 'parameters': list([ + 'test_package/function_module/args_type/args', + 'test_package/function_module/args_type/kwargs', + ]), + 'reexported_by': list([ + ]), + 'results': list([ + ]), + }), + dict({ + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_package/function_module/callable_type', + 'is_class_method': False, + 'is_public': True, + 'is_static': False, + 'name': 'callable_type', + 'parameters': list([ + 'test_package/function_module/callable_type/param', + ]), + 'reexported_by': list([ + ]), + 'results': list([ + 'test_package/function_module/callable_type/result_1', + ]), + }), + dict({ + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_package/function_module/illegal_params', + 'is_class_method': False, + 'is_public': True, + 'is_static': False, + 'name': 'illegal_params', + 'parameters': list([ + 'test_package/function_module/illegal_params/lst', + 'test_package/function_module/illegal_params/lst_2', + 'test_package/function_module/illegal_params/tpl', + 'test_package/function_module/illegal_params/_', + ]), + 'reexported_by': list([ + ]), + 'results': list([ + ]), + }), + dict({ + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_package/function_module/multiple_results', + 'is_class_method': False, + 'is_public': True, + 'is_static': False, + 'name': 'multiple_results', + 'parameters': list([ + ]), + 'reexported_by': list([ + ]), + 'results': list([ + 'test_package/function_module/multiple_results/result_1', + 'test_package/function_module/multiple_results/result_2', + 'test_package/function_module/multiple_results/result_3', + 'test_package/function_module/multiple_results/result_4', + ]), + }), + dict({ + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_package/function_module/one_result', + 'is_class_method': False, + 'is_public': True, + 'is_static': False, + 'name': 'one_result', + 'parameters': list([ + ]), + 'reexported_by': list([ + ]), + 'results': list([ + 'test_package/function_module/one_result/result_1', + ]), + }), + dict({ + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_package/function_module/opt_pos_only', + 'is_class_method': False, + 'is_public': True, + 'is_static': False, + 'name': 'opt_pos_only', + 'parameters': list([ + 'test_package/function_module/opt_pos_only/required', + 'test_package/function_module/opt_pos_only/optional', + ]), + 'reexported_by': list([ + ]), + 'results': list([ + ]), + }), + dict({ + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_package/function_module/param_position', + 'is_class_method': False, + 'is_public': True, + 'is_static': False, + 'name': 'param_position', + 'parameters': list([ + 'test_package/function_module/param_position/self', + 'test_package/function_module/param_position/a', + 'test_package/function_module/param_position/b', + 'test_package/function_module/param_position/c', + 'test_package/function_module/param_position/d', + 'test_package/function_module/param_position/e', + ]), + 'reexported_by': list([ + ]), + 'results': list([ + ]), + }), + dict({ + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_package/function_module/params', + 'is_class_method': False, + 'is_public': True, + 'is_static': False, + 'name': 'params', + 'parameters': list([ + 'test_package/function_module/params/i', + 'test_package/function_module/params/union', + 'test_package/function_module/params/lst', + 'test_package/function_module/params/obj', + ]), + 'reexported_by': list([ + ]), + 'results': list([ + ]), + }), + dict({ + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_package/function_module/public_no_params_no_result', + 'is_class_method': False, + 'is_public': True, + 'is_static': False, + 'name': 'public_no_params_no_result', + 'parameters': list([ + ]), + 'reexported_by': list([ + ]), + 'results': list([ + ]), + }), + dict({ + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_package/function_module/req_name_only', + 'is_class_method': False, + 'is_public': True, + 'is_static': False, + 'name': 'req_name_only', + 'parameters': list([ + 'test_package/function_module/req_name_only/required', + 'test_package/function_module/req_name_only/optional', + ]), + 'reexported_by': list([ + ]), + 'results': list([ + ]), + }), + dict({ + 'docstring': dict({ + 'description': '', + 'full_docstring': '', }), - 'id': 'test_package/test_module/global_func', + 'id': 'test_package/function_module/special_params', 'is_class_method': False, 'is_public': True, 'is_static': False, - 'name': 'global_func', + 'name': 'special_params', 'parameters': list([ - 'test_package/test_module/global_func/param_1', - 'test_package/test_module/global_func/param_2', + 'test_package/function_module/special_params/none_union', + 'test_package/function_module/special_params/none_bool_union', + 'test_package/function_module/special_params/bool_none_union', + 'test_package/function_module/special_params/none_bool_none_union', + 'test_package/function_module/special_params/none_bool_int_union', + 'test_package/function_module/special_params/none_none_bool_none_union', + 'test_package/function_module/special_params/none_list_union_none_none', + 'test_package/function_module/special_params/none', ]), 'reexported_by': list([ ]), 'results': list([ - 'test_package/test_module/global_func/result_1', ]), }), ]) @@ -3040,7 +3888,7 @@ }), dict({ 'alias': None, - 'qualified_name': 'test_enums._ReexportedEmptyEnum', + 'qualified_name': 'enum_module._ReexportedEmptyEnum', }), ]) # --- @@ -3051,7 +3899,7 @@ }), ]) # --- -# name: test_imports_test_emums_qualified_imports +# name: test_imports_enum_module_qualified_imports list([ dict({ 'alias': None, @@ -3071,37 +3919,30 @@ }), ]) # --- -# name: test_imports_test_enums_wildcard_imports +# name: test_imports_enum_module_wildcard_imports list([ ]) # --- -# name: test_imports_test_module_qualified_imports +# name: test_imports_module_qualified_imports list([ - dict({ - 'alias': 'mathematics', - 'qualified_name': 'math', - }), dict({ 'alias': None, - 'qualified_name': 'mypy', + 'qualified_name': 'enum.IntEnum', }), dict({ - 'alias': None, - 'qualified_name': 'another_path.another_module.AnotherClass', + 'alias': '_Enum', + 'qualified_name': 'enum.Enum', }), dict({ - 'alias': '_AcImportAlias', - 'qualified_name': 'another_path.another_module.AnotherClass', + 'alias': 'static', + 'qualified_name': 'mypy', }), ]) # --- -# name: test_imports_test_module_wildcard_imports +# name: test_imports_module_wildcard_imports list([ dict({ - 'module_name': 'typing', - }), - dict({ - 'module_name': 'docstring_parser', + 'module_name': 'math', }), ]) # --- @@ -3139,7 +3980,7 @@ }), dict({ 'alias': None, - 'qualified_name': 'test_enums._ReexportedEmptyEnum', + 'qualified_name': 'enum_module._ReexportedEmptyEnum', }), ]), 'wildcard_imports': list([ @@ -3172,98 +4013,82 @@ ]), }) # --- -# name: test_modules_test_docstrings +# name: test_modules_class_module dict({ 'classes': list([ - 'test_package/test_docstrings/EpydocDocstringClass', - 'test_package/test_docstrings/RestDocstringClass', - 'test_package/test_docstrings/NumpyDocstringClass', - 'test_package/test_docstrings/GoogleDocstringClass', + 'test_package/class_module/ClassModuleEmptyClassA', + 'test_package/class_module/ClassModuleClassB', + 'test_package/class_module/ClassModuleClassC', + 'test_package/class_module/ClassModuleClassD', + 'test_package/class_module/_ClassModulePrivateClassG', ]), - 'docstring': ''' - Test module for docstring tests. - - A module for testing the various docstring types. - - ''', + 'docstring': '', 'enums': list([ ]), 'functions': list([ ]), - 'id': 'test_package/test_docstrings', - 'name': 'test_docstrings', + 'id': 'test_package/class_module', + 'name': 'class_module', 'qualified_imports': list([ ]), 'wildcard_imports': list([ ]), }) # --- -# name: test_modules_test_enums +# name: test_modules_docstring_module dict({ 'classes': list([ + 'test_package/docstring_module/EpydocDocstringClass', + 'test_package/docstring_module/RestDocstringClass', + 'test_package/docstring_module/NumpyDocstringClass', + 'test_package/docstring_module/GoogleDocstringClass', ]), - 'docstring': '', + 'docstring': ''' + Test module for docstring tests. + + A module for testing the various docstring types. + + ''', 'enums': list([ - 'test_package/test_enums/EnumTest', - 'test_package/test_enums/_ReexportedEmptyEnum', - 'test_package/test_enums/AnotherTestEnum', ]), 'functions': list([ ]), - 'id': 'test_package/test_enums', - 'name': 'test_enums', + 'id': 'test_package/docstring_module', + 'name': 'docstring_module', 'qualified_imports': list([ - dict({ - 'alias': None, - 'qualified_name': 'enum.Enum', - }), - dict({ - 'alias': None, - 'qualified_name': 'enum.IntEnum', - }), - dict({ - 'alias': '_Enum', - 'qualified_name': 'enum.Enum', - }), - dict({ - 'alias': '_AcImportAlias', - 'qualified_name': 'another_path.another_module.AnotherClass', - }), ]), 'wildcard_imports': list([ ]), }) # --- -# name: test_modules_test_module +# name: test_modules_enum_module dict({ 'classes': list([ - 'test_package/test_module/SomeClass', - 'test_package/test_module/_PrivateClass', - 'test_package/test_module/InferMyTypes', - 'test_package/test_module/VarianceClassAll', - 'test_package/test_module/VarianceClassOnlyInvariance', ]), - 'docstring': 'Docstring of the some_class.py module.', + 'docstring': '', 'enums': list([ + 'test_package/enum_module/_ReexportedEmptyEnum', + 'test_package/enum_module/EnumTest', + 'test_package/enum_module/EnumTest2', + 'test_package/enum_module/EnumTest3', + 'test_package/enum_module/EmptyEnum', ]), 'functions': list([ - 'test_package/test_module/global_func', - 'test_package/test_module/_private_global_func', ]), - 'id': 'test_package/test_module', - 'name': 'test_module', + 'id': 'test_package/enum_module', + 'name': 'enum_module', 'qualified_imports': list([ dict({ - 'alias': 'mathematics', - 'qualified_name': 'math', + 'alias': None, + 'qualified_name': 'enum.Enum', }), dict({ 'alias': None, - 'qualified_name': 'mypy', + 'qualified_name': 'enum.IntEnum', }), dict({ - 'alias': None, - 'qualified_name': 'another_path.another_module.AnotherClass', + 'alias': '_Enum', + 'qualified_name': 'enum.Enum', }), dict({ 'alias': '_AcImportAlias', @@ -3271,12 +4096,6 @@ }), ]), 'wildcard_imports': list([ - dict({ - 'module_name': 'typing', - }), - dict({ - 'module_name': 'docstring_parser', - }), ]), }) # --- diff --git a/tests/safeds_stubgen/api_analyzer/test__get_api.py b/tests/safeds_stubgen/api_analyzer/test__get_api.py index 3837c93b..6326ee17 100644 --- a/tests/safeds_stubgen/api_analyzer/test__get_api.py +++ b/tests/safeds_stubgen/api_analyzer/test__get_api.py @@ -12,7 +12,6 @@ # Setup: API data _test_dir = Path(__file__).parent.parent.parent _test_package_name = "test_package" -_main_test_module_name = "test_module" api_data_paintext = get_api( package_name=_test_package_name, @@ -59,11 +58,16 @@ def _get_specific_module_data(module_name: str, docstring_style: str = "plaintex raise AssertionError -def _get_specific_class_data(class_name: str, docstring_style: str = "plaintext", is_enum: bool = False) -> dict: +def _get_specific_class_data( + module_name: str, + class_name: str, + docstring_style: str = "plaintext", + is_enum: bool = False +) -> dict: data_type = "enums" if is_enum else "classes" api_data = get_api_data(docstring_style) for class_ in api_data[data_type]: - if class_["id"].endswith(f"/{class_name}"): + if module_name in class_["id"] and class_["id"].endswith(f"/{class_name}"): return class_ raise AssertionError @@ -79,15 +83,15 @@ def get_api_data(docstring_style: str) -> dict: def _get_specific_function_data( + module_name: str, function_name: str, parent_class_name: str = "", - test_module_name: str = _main_test_module_name, docstring_style: str = "plaintext", ) -> dict: api_data = get_api_data(docstring_style) if parent_class_name == "": - parent_class_name = test_module_name + parent_class_name = module_name for function in api_data["functions"]: if function["id"].endswith(f"{parent_class_name}/{function_name}"): @@ -96,8 +100,8 @@ def _get_specific_function_data( # ############################## Module ############################## # -def test_modules_test_module(snapshot: SnapshotAssertion) -> None: - module_data = _get_specific_module_data(_main_test_module_name) +def test_modules_class_module(snapshot: SnapshotAssertion) -> None: + module_data = _get_specific_module_data("class_module") assert module_data == snapshot @@ -106,8 +110,8 @@ def test_modules_another_module(snapshot: SnapshotAssertion) -> None: assert module_data == snapshot -def test_modules_test_enums(snapshot: SnapshotAssertion) -> None: - module_data = _get_specific_module_data("test_enums") +def test_modules_enum_module(snapshot: SnapshotAssertion) -> None: + module_data = _get_specific_module_data("enum_module") assert module_data == snapshot @@ -116,34 +120,34 @@ def test_modules___init__(snapshot: SnapshotAssertion) -> None: assert module_data == snapshot -def test_modules_test_docstrings(snapshot: SnapshotAssertion) -> None: - module_data = _get_specific_module_data("test_docstrings") +def test_modules_docstring_module(snapshot: SnapshotAssertion) -> None: + module_data = _get_specific_module_data("docstring_module") assert module_data == snapshot -# ############################## Imports ############################## # +# ############################## Imports ############################## # Todo new tests after issue #38 def get_import_data(module_name: str, import_type: str) -> list[dict]: module_data = _get_specific_module_data(module_name) return module_data.get(import_type, []) -def test_imports_test_module_qualified_imports(snapshot: SnapshotAssertion) -> None: - import_data = get_import_data(_main_test_module_name, "qualified_imports") +def test_imports_module_qualified_imports(snapshot: SnapshotAssertion) -> None: + import_data = get_import_data("import_module", "qualified_imports") assert import_data == snapshot -def test_imports_test_module_wildcard_imports(snapshot: SnapshotAssertion) -> None: - import_data = get_import_data(_main_test_module_name, "wildcard_imports") +def test_imports_module_wildcard_imports(snapshot: SnapshotAssertion) -> None: + import_data = get_import_data("import_module", "wildcard_imports") assert import_data == snapshot -def test_imports_test_emums_qualified_imports(snapshot: SnapshotAssertion) -> None: - import_data = get_import_data("test_enums", "qualified_imports") +def test_imports_enum_module_qualified_imports(snapshot: SnapshotAssertion) -> None: + import_data = get_import_data("enum_module", "qualified_imports") assert import_data == snapshot -def test_imports_test_enums_wildcard_imports(snapshot: SnapshotAssertion) -> None: - import_data = get_import_data("test_enums", "wildcard_imports") +def test_imports_enum_module_wildcard_imports(snapshot: SnapshotAssertion) -> None: + import_data = get_import_data("enum_module", "wildcard_imports") assert import_data == snapshot @@ -158,84 +162,99 @@ def test_imports___init___wildcard_imports(snapshot: SnapshotAssertion) -> None: # ############################## Classes ############################## # -def test_classes_SomeClass(snapshot: SnapshotAssertion) -> None: # noqa: N802 - class_data = _get_specific_class_data("SomeClass", "plaintext") +def test_classes_ClassModuleEmptyClassA(snapshot: SnapshotAssertion) -> None: # noqa: N802 + class_data = _get_specific_class_data("class_module", "ClassModuleEmptyClassA") + assert class_data == snapshot + + +def test_classes_ClassModuleClassB(snapshot: SnapshotAssertion) -> None: # noqa: N802 + class_data = _get_specific_class_data("class_module", "ClassModuleClassB") assert class_data == snapshot -def test_classes_NestedClass(snapshot: SnapshotAssertion) -> None: # noqa: N802 - class_data = _get_specific_class_data("NestedClass", "plaintext") +def test_classes_ClassModuleClassC(snapshot: SnapshotAssertion) -> None: # noqa: N802 + class_data = _get_specific_class_data("class_module", "ClassModuleClassC") assert class_data == snapshot -def test_classes__PrivateClass(snapshot: SnapshotAssertion) -> None: # noqa: N802 - class_data = _get_specific_class_data("_PrivateClass", "plaintext") +def test_classes_ClassModuleClassD(snapshot: SnapshotAssertion) -> None: # noqa: N802 + class_data = _get_specific_class_data("class_module", "ClassModuleClassD") assert class_data == snapshot -def test_classes_NestedPrivateClass(snapshot: SnapshotAssertion) -> None: # noqa: N802 - class_data = _get_specific_class_data("NestedPrivateClass", "plaintext") +def test_classes_ClassModuleNestedClassE(snapshot: SnapshotAssertion) -> None: # noqa: N802 + class_data = _get_specific_class_data("class_module", "ClassModuleNestedClassE") assert class_data == snapshot -def test_classes_NestedNestedPrivateClass(snapshot: SnapshotAssertion) -> None: # noqa: N802 - class_data = _get_specific_class_data("NestedNestedPrivateClass", "plaintext") +def test_classes__ClassModulePrivateDoubleNestedClassF(snapshot: SnapshotAssertion) -> None: # noqa: N802 + class_data = _get_specific_class_data("class_module", "_ClassModulePrivateDoubleNestedClassF") + assert class_data == snapshot + + +def test_classes__ClassModulePrivateClassG(snapshot: SnapshotAssertion) -> None: # noqa: N802 + class_data = _get_specific_class_data("class_module", "_ClassModulePrivateClassG") assert class_data == snapshot def test_classes_VarianceClassAll(snapshot: SnapshotAssertion) -> None: # noqa: N802 - class_data = _get_specific_class_data("VarianceClassAll", "plaintext") + class_data = _get_specific_class_data("variance_module", "VarianceClassAll") assert class_data == snapshot def test_classes_VarianceClassOnlyInvariance(snapshot: SnapshotAssertion) -> None: # noqa: N802 - class_data = _get_specific_class_data("VarianceClassOnlyInvariance", "plaintext") + class_data = _get_specific_class_data("variance_module", "VarianceClassOnlyInvariance") + assert class_data == snapshot + + +def test_classes_InferMyTypes(snapshot: SnapshotAssertion) -> None: # noqa: N802 + class_data = _get_specific_class_data("infer_types_module", "InferMyTypes") assert class_data == snapshot def test_classes_EpydocDocstringClass(snapshot: SnapshotAssertion) -> None: # noqa: N802 - class_data = _get_specific_class_data("EpydocDocstringClass", "epydoc") + class_data = _get_specific_class_data("docstring_module", "EpydocDocstringClass", "epydoc") assert class_data == snapshot def test_classes_RestDocstringClass(snapshot: SnapshotAssertion) -> None: # noqa: N802 - class_data = _get_specific_class_data("RestDocstringClass", "rest") + class_data = _get_specific_class_data("docstring_module", "RestDocstringClass", "rest") assert class_data == snapshot def test_classes_NumpyDocstringClass(snapshot: SnapshotAssertion) -> None: # noqa: N802 - class_data = _get_specific_class_data("NumpyDocstringClass", "numpydoc") + class_data = _get_specific_class_data("docstring_module", "NumpyDocstringClass", "numpydoc") assert class_data == snapshot def test_classes_GoogleDocstringClass(snapshot: SnapshotAssertion) -> None: # noqa: N802 - class_data = _get_specific_class_data("GoogleDocstringClass", "google") + class_data = _get_specific_class_data("docstring_module", "GoogleDocstringClass", "google") assert class_data == snapshot def test_classes_ReexportClass(snapshot: SnapshotAssertion) -> None: # noqa: N802 - class_data = _get_specific_class_data("ReexportClass", "plaintext") + class_data = _get_specific_class_data("_reexport_module_1", "ReexportClass") assert class_data == snapshot def test_classes_AnotherReexportClass(snapshot: SnapshotAssertion) -> None: # noqa: N802 - class_data = _get_specific_class_data("AnotherReexportClass", "plaintext") + class_data = _get_specific_class_data("_reexport_module_2", "AnotherReexportClass") assert class_data == snapshot def test_classes__ThirdReexportClass(snapshot: SnapshotAssertion) -> None: # noqa: N802 - class_data = _get_specific_class_data("_ThirdReexportClass", "plaintext") + class_data = _get_specific_class_data("_reexport_module_3", "_ThirdReexportClass") assert class_data == snapshot def test_classes_FourthReexportClass(snapshot: SnapshotAssertion) -> None: # noqa: N802 - class_data = _get_specific_class_data("FourthReexportClass", "plaintext") + class_data = _get_specific_class_data("_reexport_module_4", "FourthReexportClass") assert class_data == snapshot # ############################## Class Attributes ############################## # -def get_class_attribute_data(class_name: str, docstring_style: str) -> list: - class_data: dict = _get_specific_class_data(class_name) +def get_class_attribute_data(module_name: str, class_name: str, docstring_style: str) -> list: + class_data: dict = _get_specific_class_data(module_name, class_name, docstring_style) class_attr_ids: list[str] = class_data["attributes"] # Sort out the class attribute data we need and return @@ -243,79 +262,76 @@ def get_class_attribute_data(class_name: str, docstring_style: str) -> list: return [attr for attr in api_data["attributes"] if attr["id"] in class_attr_ids] -def test_class_attributes_SomeClass(snapshot: SnapshotAssertion) -> None: # noqa: N802 - class_data = get_class_attribute_data("SomeClass", "plaintext") - assert class_data == snapshot - - -def test_class_attributes_NestedClass(snapshot: SnapshotAssertion) -> None: # noqa: N802 - class_data = get_class_attribute_data("NestedClass", "plaintext") +def test_class_attributes_AttributesClassB(snapshot: SnapshotAssertion) -> None: # noqa: N802 + class_data = get_class_attribute_data("attribute_module", "AttributesClassB", "plaintext") assert class_data == snapshot -def test_class_attributes__PrivateClass(snapshot: SnapshotAssertion) -> None: # noqa: N802 - class_data = get_class_attribute_data("_PrivateClass", "plaintext") +def test_class_attributes_ClassModuleNestedClassE(snapshot: SnapshotAssertion) -> None: # noqa: N802 + class_data = get_class_attribute_data("class_module", "ClassModuleNestedClassE", "plaintext") assert class_data == snapshot -def test_class_attributes_NestedPrivateClass(snapshot: SnapshotAssertion) -> None: # noqa: N802 - class_data = get_class_attribute_data("NestedPrivateClass", "plaintext") - assert class_data == snapshot - - -def test_class_attributes_NestedNestedPrivateClass(snapshot: SnapshotAssertion) -> None: # noqa: N802 - class_data = get_class_attribute_data("NestedNestedPrivateClass", "plaintext") +def test_class_attributes__ClassModulePrivateClassG(snapshot: SnapshotAssertion) -> None: # noqa: N802 + class_data = get_class_attribute_data("class_module", "_ClassModulePrivateClassG", "plaintext") assert class_data == snapshot # Todo Epydoc Tests are deactivated right now, since attribute handling is not implemented yet in the # docstring_parser library def xtest_class_attributes_EpydocDocstringClass(snapshot: SnapshotAssertion) -> None: # noqa: N802 - class_data = get_class_attribute_data("EpydocDocstringClass", "epydoc") + class_data = get_class_attribute_data("docstring_module", "EpydocDocstringClass", "epydoc") assert class_data == snapshot def test_class_attributes_RestDocstringClass(snapshot: SnapshotAssertion) -> None: # noqa: N802 - class_data = get_class_attribute_data("RestDocstringClass", "rest") + class_data = get_class_attribute_data("docstring_module", "RestDocstringClass", "rest") assert class_data == snapshot def test_class_attributes_NumpyDocstringClass(snapshot: SnapshotAssertion) -> None: # noqa: N802 - class_data = get_class_attribute_data("NumpyDocstringClass", "numpydoc") + class_data = get_class_attribute_data("docstring_module", "NumpyDocstringClass", "numpydoc") assert class_data == snapshot def test_class_attributes_GoogleDocstringClass(snapshot: SnapshotAssertion) -> None: # noqa: N802 - class_data = get_class_attribute_data("GoogleDocstringClass", "google") + class_data = get_class_attribute_data("docstring_module", "GoogleDocstringClass", "google") assert class_data == snapshot # ############################## Enums ############################## # def test_enums_EnumTest(snapshot: SnapshotAssertion) -> None: # noqa: N802 - enum_data = _get_specific_class_data("EnumTest", is_enum=True) + enum_data = _get_specific_class_data("enum_module", "EnumTest", is_enum=True) assert enum_data == snapshot def test_enums__ReexportedEmptyEnum(snapshot: SnapshotAssertion) -> None: # noqa: N802 - enum_data = _get_specific_class_data("_ReexportedEmptyEnum", is_enum=True) + enum_data = _get_specific_class_data("enum_module", "_ReexportedEmptyEnum", is_enum=True) assert enum_data == snapshot -def test_enums_AnotherTestEnum(snapshot: SnapshotAssertion) -> None: # noqa: N802 - enum_data = _get_specific_class_data("AnotherTestEnum", is_enum=True) +def test_enums_EnumTest2(snapshot: SnapshotAssertion) -> None: # noqa: N802 + enum_data = _get_specific_class_data("enum_module", "EnumTest2", is_enum=True) + assert enum_data == snapshot + + +def test_enums_EnumTest3(snapshot: SnapshotAssertion) -> None: # noqa: N802 + enum_data = _get_specific_class_data("enum_module", "EnumTest3", is_enum=True) assert enum_data == snapshot # ############################## Enum Instances ############################## # -def get_enum_instance_data(enum_name: str) -> list: +def get_enum_instance_data(enum_name: str, module_name: str = "enum_module") -> list: # Get enum data - enum_data = _get_specific_class_data(enum_name, is_enum=True) + enum_data = _get_specific_class_data(module_name, enum_name, is_enum=True) enum_instance_ids = enum_data["instances"] - all_enum_instances = api_data_paintext["enum_instances"] - # Sort out the enum instances we need and return - return [enum_instance for enum_instance in all_enum_instances if enum_instance["id"] in enum_instance_ids] + return [ + enum_instance + for enum_instance in api_data_paintext["enum_instances"] + if enum_instance["id"] in enum_instance_ids + ] def test_enum_instances_EnumTest(snapshot: SnapshotAssertion) -> None: # noqa: N802 @@ -328,8 +344,8 @@ def test_enum_instances__ReexportedEmptyEnum(snapshot: SnapshotAssertion) -> Non assert enum_instance_data == snapshot -def test_enum_instances_AnotherTestEnum(snapshot: SnapshotAssertion) -> None: # noqa: N802 - enum_instance_data = get_enum_instance_data("AnotherTestEnum") +def test_enum_instances_EnumTest3(snapshot: SnapshotAssertion) -> None: # noqa: N802 + enum_instance_data = get_enum_instance_data("EnumTest3") assert enum_instance_data == snapshot @@ -345,8 +361,8 @@ def get_global_function_data(module_name: str) -> list: return [function for function in all_functions if function["id"] in global_function_ids] -def test_global_functions_test_module(snapshot: SnapshotAssertion) -> None: - global_function_data = get_global_function_data(_main_test_module_name) +def test_global_functions_function_module(snapshot: SnapshotAssertion) -> None: + global_function_data = get_global_function_data("function_module") assert global_function_data == snapshot @@ -371,8 +387,8 @@ def test_global_functions__reexport_module_4(snapshot: SnapshotAssertion) -> Non # ############################## Class Methods ############################## # -def get_class_methods_data(class_name: str, docstring_style: str) -> list: - class_data: dict = _get_specific_class_data(class_name) +def get_class_methods_data(module_name: str, class_name: str, docstring_style: str = "plaintext") -> list: + class_data: dict = _get_specific_class_data(module_name, class_name) class_method_ids: list[str] = class_data["methods"] api_data = get_api_data(docstring_style) @@ -382,200 +398,355 @@ def get_class_methods_data(class_name: str, docstring_style: str) -> list: return [method for method in all_functions if method["id"] in class_method_ids] -def test_class_methods_SomeClass(snapshot: SnapshotAssertion) -> None: # noqa: N802 - class_methods_data = get_class_methods_data("SomeClass", "plaintext") +def test_class_methods_ClassModuleEmptyClassA(snapshot: SnapshotAssertion) -> None: # noqa: N802 + class_methods_data = get_class_methods_data("class_module", "ClassModuleEmptyClassA") assert class_methods_data == snapshot -def test_class_methods_InferMyTypes(snapshot: SnapshotAssertion) -> None: # noqa: N802 - class_methods_data = get_class_methods_data("InferMyTypes", "plaintext") +def test_class_methods_ClassModuleClassB(snapshot: SnapshotAssertion) -> None: # noqa: N802 + class_methods_data = get_class_methods_data("class_module", "ClassModuleClassB") assert class_methods_data == snapshot -def test_class_methods_NestedClass(snapshot: SnapshotAssertion) -> None: # noqa: N802 - class_methods_data = get_class_methods_data("NestedClass", "plaintext") +def test_class_methods_ClassModuleClassC(snapshot: SnapshotAssertion) -> None: # noqa: N802 + class_methods_data = get_class_methods_data("class_module", "ClassModuleClassC") assert class_methods_data == snapshot -def test_class_methods__PrivateClass(snapshot: SnapshotAssertion) -> None: # noqa: N802 - class_methods_data = get_class_methods_data("_PrivateClass", "plaintext") +def test_class_methods_function_module_FunctionModuleClassB(snapshot: SnapshotAssertion) -> None: # noqa: N802 + class_methods_data = get_class_methods_data("function_module", "FunctionModuleClassB") assert class_methods_data == snapshot -def test_class_methods_NestedPrivateClass(snapshot: SnapshotAssertion) -> None: # noqa: N802 - class_methods_data = get_class_methods_data("NestedPrivateClass", "plaintext") +def test_class_methods_function_module_FunctionModuleClassC(snapshot: SnapshotAssertion) -> None: # noqa: N802 + class_methods_data = get_class_methods_data("function_module", "FunctionModuleClassC") assert class_methods_data == snapshot -def test_class_methods_NestedNestedPrivateClass(snapshot: SnapshotAssertion) -> None: # noqa: N802 - class_methods_data = get_class_methods_data("NestedNestedPrivateClass", "plaintext") +def test_class_methods_InferMyTypes(snapshot: SnapshotAssertion) -> None: # noqa: N802 + class_methods_data = get_class_methods_data("infer_types_module", "InferMyTypes") + assert class_methods_data == snapshot + + +def test_class_methods_ClassModuleNestedClassE(snapshot: SnapshotAssertion) -> None: # noqa: N802 + class_methods_data = get_class_methods_data("class_module", "ClassModuleNestedClassE") + assert class_methods_data == snapshot + + +def test_class_methods__ClassModulePrivateDoubleNestedClassF(snapshot: SnapshotAssertion) -> None: # noqa: N802 + class_methods_data = get_class_methods_data("class_module", "_ClassModulePrivateDoubleNestedClassF") assert class_methods_data == snapshot def test_class_methods_ReexportClass(snapshot: SnapshotAssertion) -> None: # noqa: N802 - class_methods_data = get_class_methods_data("ReexportClass", "plaintext") + class_methods_data = get_class_methods_data("_reexport_module_1", "ReexportClass") assert class_methods_data == snapshot def test_class_methods_EpydocDocstringClass(snapshot: SnapshotAssertion) -> None: # noqa: N802 - class_methods_data = get_class_methods_data("EpydocDocstringClass", "epydoc") + class_methods_data = get_class_methods_data("docstring_module", "EpydocDocstringClass", "epydoc") assert class_methods_data == snapshot def test_class_methods_RestDocstringClass(snapshot: SnapshotAssertion) -> None: # noqa: N802 - class_methods_data = get_class_methods_data("RestDocstringClass", "rest") + class_methods_data = get_class_methods_data("docstring_module", "RestDocstringClass", "rest") assert class_methods_data == snapshot def test_class_methods_NumpyDocstringClass(snapshot: SnapshotAssertion) -> None: # noqa: N802 - class_methods_data = get_class_methods_data("NumpyDocstringClass", "numpydoc") + class_methods_data = get_class_methods_data("docstring_module", "NumpyDocstringClass", "numpydoc") assert class_methods_data == snapshot def test_class_methods_GoogleDocstringClass(snapshot: SnapshotAssertion) -> None: # noqa: N802 - class_methods_data = get_class_methods_data("GoogleDocstringClass", "google") + class_methods_data = get_class_methods_data("docstring_module", "GoogleDocstringClass", "google") assert class_methods_data == snapshot # ############################## Function Parameters ############################## # -def get_function_parameter_data(function_name: str, parent_class_name: str, docstring_style: str) -> list: - function_data: dict = _get_specific_function_data(function_name, parent_class_name) +def get_function_parameter_data( + function_name: str, + module_name: str = "function_module", + parent_class_name: str = "", + docstring_style: str = "plaintext" +) -> list: + function_data: dict = _get_specific_function_data(module_name, function_name, parent_class_name, docstring_style) function_parameter_ids: list[str] = function_data["parameters"] api_data = get_api_data(docstring_style) - all_parameters: list[dict] = api_data["parameters"] # Sort out the parameters we need and return - return [parameter for parameter in all_parameters if parameter["id"] in function_parameter_ids] + return [ + parameter + for parameter in api_data["parameters"] + if parameter["id"] in function_parameter_ids + ] + + +def test_function_parameters_function_module_FunctionModuleClassB___init__(snapshot: SnapshotAssertion) -> None: # noqa: N802 + function_parameter_data = get_function_parameter_data( + function_name="__init__", + parent_class_name="FunctionModuleClassB" + ) + assert function_parameter_data == snapshot + + +def test_function_parameters_function_module_FunctionModuleClassB_static_method_params(snapshot: SnapshotAssertion) -> None: # noqa: N802 + function_parameter_data = get_function_parameter_data( + function_name="static_method_params", + parent_class_name="FunctionModuleClassB" + ) + assert function_parameter_data == snapshot -def test_function_parameters_global_func(snapshot: SnapshotAssertion) -> None: - function_parameter_data = get_function_parameter_data("global_func", "", "plaintext") +def test_function_parameters_function_module_FunctionModuleClassB_class_method(snapshot: SnapshotAssertion) -> None: # noqa: N802 + function_parameter_data = get_function_parameter_data( + function_name="class_method", + parent_class_name="FunctionModuleClassB" + ) assert function_parameter_data == snapshot -def test_function_parameters_SomeClass___init__(snapshot: SnapshotAssertion) -> None: # noqa: N802 - function_parameter_data = get_function_parameter_data("__init__", "SomeClass", "plaintext") +def test_function_parameters_function_module_FunctionModuleClassB_class_method_params(snapshot: SnapshotAssertion) -> None: # noqa: N802 + function_parameter_data = get_function_parameter_data( + function_name="class_method_params", + parent_class_name="FunctionModuleClassB" + ) assert function_parameter_data == snapshot -def test_function_parameters_static_function(snapshot: SnapshotAssertion) -> None: - function_parameter_data = get_function_parameter_data("static_function", "SomeClass", "plaintext") +def test_function_parameters_function_module_FunctionModuleClassC_nested_class_function(snapshot: SnapshotAssertion) -> None: # noqa: N802 + function_parameter_data = get_function_parameter_data( + function_name="nested_class_function", + parent_class_name="FunctionModuleClassC" + ) assert function_parameter_data == snapshot -def test_function_parameters_test_position(snapshot: SnapshotAssertion) -> None: - function_parameter_data = get_function_parameter_data("test_position", "SomeClass", "plaintext") +def test_function_parameters_function_module__private(snapshot: SnapshotAssertion) -> None: + function_parameter_data = get_function_parameter_data(function_name="_private") assert function_parameter_data == snapshot -def test_function_parameters_test_params(snapshot: SnapshotAssertion) -> None: - function_parameter_data = get_function_parameter_data("test_params", "SomeClass", "plaintext") +def test_function_parameters_function_module_public_no_params_no_result(snapshot: SnapshotAssertion) -> None: + function_parameter_data = get_function_parameter_data(function_name="public_no_params_no_result") assert function_parameter_data == snapshot -def test_function_parameters_nested_class_function(snapshot: SnapshotAssertion) -> None: - function_parameter_data = get_function_parameter_data("nested_class_function", "NestedClass", "plaintext") +def test_function_parameters_function_module_params(snapshot: SnapshotAssertion) -> None: + function_parameter_data = get_function_parameter_data(function_name="params") + assert function_parameter_data == snapshot + + +def test_function_parameters_function_module_illegal_params(snapshot: SnapshotAssertion) -> None: + function_parameter_data = get_function_parameter_data(function_name="illegal_params") + assert function_parameter_data == snapshot + + +def test_function_parameters_function_module_special_params(snapshot: SnapshotAssertion) -> None: + function_parameter_data = get_function_parameter_data(function_name="special_params") + assert function_parameter_data == snapshot + + +def test_function_parameters_function_module_param_position(snapshot: SnapshotAssertion) -> None: + function_parameter_data = get_function_parameter_data(function_name="param_position") + assert function_parameter_data == snapshot + + +def test_function_parameters_function_module_opt_pos_only(snapshot: SnapshotAssertion) -> None: + function_parameter_data = get_function_parameter_data(function_name="opt_pos_only") + assert function_parameter_data == snapshot + + +def test_function_parameters_function_module_req_name_only(snapshot: SnapshotAssertion) -> None: + function_parameter_data = get_function_parameter_data(function_name="req_name_only") + assert function_parameter_data == snapshot + + +def test_function_parameters_function_module_arg(snapshot: SnapshotAssertion) -> None: + function_parameter_data = get_function_parameter_data(function_name="arg") + assert function_parameter_data == snapshot + + +def test_function_parameters_function_module_args_type(snapshot: SnapshotAssertion) -> None: + function_parameter_data = get_function_parameter_data(function_name="args_type") + assert function_parameter_data == snapshot + + +def test_function_parameters_function_module_callable_type(snapshot: SnapshotAssertion) -> None: + function_parameter_data = get_function_parameter_data(function_name="callable_type") assert function_parameter_data == snapshot def test_function_parameters_epydoc_docstring_func(snapshot: SnapshotAssertion) -> None: - function_parameter_data = get_function_parameter_data("epydoc_docstring_func", "EpydocDocstringClass", "epydoc") + function_parameter_data = get_function_parameter_data( + module_name="docstring_module", + function_name="epydoc_docstring_func", + parent_class_name="EpydocDocstringClass", + docstring_style="epydoc") assert function_parameter_data == snapshot def test_function_parameters_EpydocDocstringClass___init__(snapshot: SnapshotAssertion) -> None: # noqa: N802 - function_parameter_data = get_function_parameter_data("__init__", "EpydocDocstringClass", "epydoc") + function_parameter_data = get_function_parameter_data( + module_name="docstring_module", + function_name="__init__", + parent_class_name="EpydocDocstringClass", + docstring_style="epydoc" + ) assert function_parameter_data == snapshot def test_function_parameters_rest_docstring_func(snapshot: SnapshotAssertion) -> None: - function_parameter_data = get_function_parameter_data("rest_docstring_func", "RestDocstringClass", "rest") + function_parameter_data = get_function_parameter_data( + module_name="docstring_module", + function_name="rest_docstring_func", + parent_class_name="RestDocstringClass", + docstring_style="rest" + ) assert function_parameter_data == snapshot def test_function_parameters_RestDocstringClass___init__(snapshot: SnapshotAssertion) -> None: # noqa: N802 - function_parameter_data = get_function_parameter_data("__init__", "RestDocstringClass", "rest") + function_parameter_data = get_function_parameter_data( + module_name="docstring_module", + function_name="__init__", + parent_class_name="RestDocstringClass", + docstring_style="rest" + ) assert function_parameter_data == snapshot def test_function_parameters_numpy_docstring_func(snapshot: SnapshotAssertion) -> None: - function_parameter_data = get_function_parameter_data("numpy_docstring_func", "NumpyDocstringClass", "numpydoc") + function_parameter_data = get_function_parameter_data( + module_name="docstring_module", + function_name="numpy_docstring_func", + parent_class_name="NumpyDocstringClass", + docstring_style="numpydoc" + ) assert function_parameter_data == snapshot def test_function_parameters_NumpyDocstringClass___init__(snapshot: SnapshotAssertion) -> None: # noqa: N802 - function_parameter_data = get_function_parameter_data("__init__", "NumpyDocstringClass", "numpydoc") + function_parameter_data = get_function_parameter_data( + module_name="docstring_module", + function_name="__init__", + parent_class_name="NumpyDocstringClass", + docstring_style="numpydoc" + ) assert function_parameter_data == snapshot def test_function_parameters_google_docstring_func(snapshot: SnapshotAssertion) -> None: - function_parameter_data = get_function_parameter_data("google_docstring_func", "GoogleDocstringClass", "google") + function_parameter_data = get_function_parameter_data( + module_name="docstring_module", + function_name="google_docstring_func", + parent_class_name="GoogleDocstringClass", + docstring_style="google" + ) assert function_parameter_data == snapshot def test_function_parameters_GoogleDocstringClass___init__(snapshot: SnapshotAssertion) -> None: # noqa: N802 - function_parameter_data = get_function_parameter_data("__init__", "GoogleDocstringClass", "google") + function_parameter_data = get_function_parameter_data( + module_name="docstring_module", + function_name="__init__", + parent_class_name="GoogleDocstringClass", + docstring_style="google" + ) assert function_parameter_data == snapshot # ############################## Function Results ############################## # -def get_function_result_data(function_name: str, parent_class_name: str, docstring_style: str) -> list: - function_data: dict = _get_specific_function_data(function_name, parent_class_name) +def get_function_result_data( + module_name: str, + function_name: str, + parent_class_name: str, + docstring_style: str = "plaintext" +) -> list: + function_data: dict = _get_specific_function_data(module_name, function_name, parent_class_name, docstring_style) function_result_ids: list[str] = function_data["results"] api_data = get_api_data(docstring_style) - all_results: list[dict] = api_data["results"] # Sort out the results we need and return - return [result for result in all_results if result["id"] in function_result_ids] + return [ + result + for result in api_data["results"] + if result["id"] in function_result_ids + ] -def test_function_results_global_func(snapshot: SnapshotAssertion) -> None: - function_result_data = get_function_result_data("global_func", "", "plaintext") +def test_function_results_instance_method(snapshot: SnapshotAssertion) -> None: + function_result_data = get_function_result_data("function_module", "instance_method", "FunctionModuleClassB") assert function_result_data == snapshot -def test_function_results_multiple_results(snapshot: SnapshotAssertion) -> None: - function_result_data = get_function_result_data("multiple_results", "SomeClass", "plaintext") +def test_function_results_static_method_params(snapshot: SnapshotAssertion) -> None: + function_result_data = get_function_result_data("function_module", "static_method_params", "FunctionModuleClassB") assert function_result_data == snapshot -def test_function_results_infer_function(snapshot: SnapshotAssertion) -> None: - function_result_data = get_function_result_data("infer_function", "InferMyTypes", "plaintext") +def test_function_results_class_method_params(snapshot: SnapshotAssertion) -> None: + function_result_data = get_function_result_data("function_module", "class_method_params", "FunctionModuleClassB") assert function_result_data == snapshot -def test_function_results_static_function(snapshot: SnapshotAssertion) -> None: - function_result_data = get_function_result_data("static_function", "SomeClass", "plaintext") +def test_function_results_nested_class_function(snapshot: SnapshotAssertion) -> None: + function_result_data = get_function_result_data("function_module", "nested_class_function", "FunctionModuleClassC") assert function_result_data == snapshot -def test_function_results_test_position(snapshot: SnapshotAssertion) -> None: - function_result_data = get_function_result_data("test_position", "SomeClass", "plaintext") +def test_function_results_callable_type(snapshot: SnapshotAssertion) -> None: + function_result_data = get_function_result_data("function_module", "callable_type", "") assert function_result_data == snapshot -def test_function_results_nested_class_function(snapshot: SnapshotAssertion) -> None: - function_result_data = get_function_result_data("nested_class_function", "NestedClass", "plaintext") +def test_function_results_multiple_results(snapshot: SnapshotAssertion) -> None: + function_result_data = get_function_result_data("function_module", "multiple_results", "") + assert function_result_data == snapshot + + +def test_function_results_infer_function(snapshot: SnapshotAssertion) -> None: + function_result_data = get_function_result_data("infer_types_module", "infer_function", "InferMyTypes") assert function_result_data == snapshot def test_function_results_epydoc_docstring_func(snapshot: SnapshotAssertion) -> None: - function_result_data = get_function_result_data("epydoc_docstring_func", "EpydocDocstringClass", "epydoc") + function_result_data = get_function_result_data( + "docstring_module", + "epydoc_docstring_func", + "EpydocDocstringClass", + "epydoc" + ) assert function_result_data == snapshot def test_function_results_rest_docstring_func(snapshot: SnapshotAssertion) -> None: - function_result_data = get_function_result_data("rest_docstring_func", "RestDocstringClass", "rest") + function_result_data = get_function_result_data( + "docstring_module", + "rest_docstring_func", + "RestDocstringClass", + "rest" + ) assert function_result_data == snapshot def test_function_results_numpy_docstring_func(snapshot: SnapshotAssertion) -> None: - function_result_data = get_function_result_data("numpy_docstring_func", "NumpyDocstringClass", "numpydoc") + function_result_data = get_function_result_data( + "docstring_module", + "numpy_docstring_func", + "NumpyDocstringClass", + "numpydoc" + ) assert function_result_data == snapshot def test_function_results_google_docstring_func(snapshot: SnapshotAssertion) -> None: - function_result_data = get_function_result_data("google_docstring_func", "GoogleDocstringClass", "google") + function_result_data = get_function_result_data( + "docstring_module", + "google_docstring_func", + "GoogleDocstringClass", + "google" + ) assert function_result_data == snapshot diff --git a/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr b/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr index aefae482..5faab763 100644 --- a/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr +++ b/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr @@ -1,17 +1,17 @@ # serializer version: 1 # name: test_class_attribute_creation ''' - package test_stub_generation.attribute_module + package test_package.attribute_module - class A() + class AttributesClassA() - class B() { + class AttributesClassB() { @PythonName("type_hint_public") static attr typeHintPublic: Int @PythonName("no_type_hint_public") static attr noTypeHintPublic: Int @PythonName("object_attr") - static attr objectAttr: A + static attr objectAttr: AttributesClassA // TODO Safe-DS does not support tuple types. @PythonName("tuple_attr_1") static attr tupleAttr1: Tuple @@ -24,19 +24,19 @@ @PythonName("list_attr_1") static attr listAttr1: List @PythonName("list_attr_2") - static attr listAttr2: List> + static attr listAttr2: List> // TODO List type has to many type arguments. @PythonName("list_attr_3") - static attr listAttr3: List + static attr listAttr3: List // TODO List type has to many type arguments. @PythonName("list_attr_4") - static attr listAttr4: List> + static attr listAttr4: List> @PythonName("dict_attr_1") static attr dictAttr1: Map @PythonName("dict_attr_2") static attr dictAttr2: Map @PythonName("dict_attr_3") - static attr dictAttr3: Map, A?> + static attr dictAttr3: Map, AttributesClassA?> @PythonName("bool_attr") static attr boolAttr: Boolean @PythonName("none_attr") @@ -67,20 +67,20 @@ # --- # name: test_class_creation ''' - package test_stub_generation.class_module + package test_package.class_module - class A() + class ClassModuleEmptyClassA() - class B( + class ClassModuleClassB( a: Int, - b: A? - ) sub A { + b: ClassModuleEmptyClassA? + ) sub ClassModuleEmptyClassA { // TODO Result type information missing. fun f() } // TODO Safe-DS does not support multiple inheritance. - class C() sub A, B { + class ClassModuleClassC() sub ClassModuleEmptyClassA, ClassModuleClassB { @PythonName("attr_1") static attr attr1: Int @PythonName("attr_2") @@ -90,9 +90,16 @@ fun f1() } - class D() { - class E() { - class F() + class ClassModuleClassD() { + class ClassModuleNestedClassE() { + @PythonName("nested_attr_1") + static attr nestedAttr1: Nothing? + + class _ClassModulePrivateDoubleNestedClassF() + + // TODO Result type information missing. + @PythonName("class_e_func") + fun classEFunc() } } @@ -100,7 +107,11 @@ # --- # name: test_enum_creation ''' - package test_stub_generation.enum_module + package test_package.enum_module + + from another_path.another_module import AnotherClass as _AcImportAlias + + enum _ReexportedEmptyEnum enum EnumTest { ONE @@ -128,7 +139,7 @@ # --- # name: test_function_creation ''' - package test_stub_generation.function_module + package test_package.function_module from typing import Callable @@ -141,7 +152,7 @@ i: Int, `union`: union, lst: List, - obj: A + obj: FunctionModuleClassA ) // TODO List type has to many type arguments. @@ -219,39 +230,60 @@ fun oneResult() -> result1: Int @PythonName("multiple_results") - fun multipleResults() -> (result1: String, result2: Int, result3: Boolean, result4: A) + fun multipleResults() -> (result1: String, result2: Int, result3: Boolean, result4: FunctionModuleClassA) @PythonName("callable_type") fun callableType( param: (a: String) -> (b: Int, c: String) ) -> result1: (a: Int, b: Int) -> c: Int - class A() + class FunctionModuleClassA() // TODO Some parameter have no type information. - class B( + class FunctionModuleClassB( @PythonName("init_param") initParam ) { + class FunctionModuleClassC() { + class FunctionModuleClassD() + + @PythonName("nested_class_function") + fun nestedClassFunction( + param1: Int + ) -> result1: Boolean + } + @PythonName("instance_method") fun instanceMethod( - a: A - ) -> result1: A + a: FunctionModuleClassA + ) -> result1: FunctionModuleClassA // TODO Result type information missing. @PythonName("static_method") static fun staticMethod() + // TODO Result type information missing. + @PythonName("static_method_params") + static fun staticMethodParams( + @PythonName("param_1") param1: Int + ) + // TODO Result type information missing. // TODO Safe-DS does not support class methods. @PythonName("class_method") static fun classMethod() + + // TODO Safe-DS does not support class methods. + @PythonName("class_method_params") + static fun classMethodParams( + @PythonName("param_1") param1: Int + ) -> result1: Boolean } ''' # --- # name: test_import_creation ''' - package test_stub_generation.import_module + package test_package.import_module import mypy as `static` @@ -261,7 +293,7 @@ # --- # name: test_type_inference ''' - package test_stub_generation.infer_types_module + package test_package.infer_types_module class InferMyTypes( @PythonName("init_param") initParam: Int = 1 @@ -276,14 +308,14 @@ static fun inferFunction( @PythonName("infer_param") inferParam: Int = 1, @PythonName("infer_param_2") inferParam2: Int = Something - ) -> (result1: InferMyTypes, result2: Nothing?, result3: SomeClass, result4: Boolean, result5: Float, result6: Int, result7: String) + ) -> (result1: InferMyTypes, result2: ModuleClass, result3: Nothing?, result4: Boolean, result5: Float, result6: Int, result7: String) } ''' # --- # name: test_variance_creation ''' - package test_stub_generation.variance_module + package test_package.variance_module from typing import Generic from typing import TypeVar diff --git a/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py b/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py index 7740fdb4..fccad5b6 100644 --- a/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py +++ b/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py @@ -15,7 +15,7 @@ # Setup - Run API to create stub files _lib_dir = Path(__file__).parent.parent.parent -_test_package_name = "test_stub_generation" +_test_package_name = "test_package" _test_package_dir = Path(_lib_dir / "data" / _test_package_name) _out_dir = Path(_lib_dir / "data" / "out") _out_dir_stubs = Path(_out_dir / _test_package_name) @@ -33,9 +33,9 @@ def _assert_file_creation_recursive(python_path: Path, stub_path: Path) -> None: stub_files: list[Path] = list(stub_path.iterdir()) # Remove __init__ files and private files without public reexported content. - # We reexport public content from _module_3 and _module_6, not from _module_2 and _module_4. + # We reexport public content from _module_3 and _module_6, not from empty_module, _module_2 and _module_4. for i, item in enumerate(python_files): - if item.is_file() and item.stem in {"__init__", "_module_2", "_module_4"}: + if item.is_file() and item.stem in {"__init__", "_module_2", "_module_4", "empty_module"}: python_files.pop(i) assert len(python_files) == len(stub_files) diff --git a/tests/safeds_stubgen/test_main.py b/tests/safeds_stubgen/test_main.py index 79a6615d..15495174 100644 --- a/tests/safeds_stubgen/test_main.py +++ b/tests/safeds_stubgen/test_main.py @@ -7,7 +7,7 @@ from syrupy import SnapshotAssertion _lib_dir = Path(__file__).parent.parent.parent -_test_package_name = "test_package" +_test_package_name = "test_main" _main_dir = Path(_lib_dir / "src" / "main.py") _test_package_dir = Path(_lib_dir / "tests" / "data" / _test_package_name) _out_dir = Path(_lib_dir / "tests" / "data" / "out") From fb2256b2cecb62f1c381343f03a838305c979562 Mon Sep 17 00:00:00 2001 From: Arsam Date: Tue, 21 Nov 2023 20:06:40 +0100 Subject: [PATCH 049/109] [WIP] Added handling for @property and @abstractmethod decorators --- src/safeds_stubgen/api_analyzer/_api.py | 6 +- .../api_analyzer/_ast_visitor.py | 2 + .../api_analyzer/_ast_walker.py | 3 +- .../stubs_generator/_generate_stubs.py | 84 ++- tests/data/test_package/abstract_module.py | 24 + tests/data/test_package/function_module.py | 13 + .../__snapshots__/test_main.ambr | 20 + .../__snapshots__/test__get_api.ambr | 499 ++++++++++++++++++ .../api_analyzer/test__get_api.py | 158 +++++- .../__snapshots__/test_generate_stubs.ambr | 41 ++ .../stubs_generator/test_generate_stubs.py | 5 + 11 files changed, 816 insertions(+), 39 deletions(-) create mode 100644 tests/data/test_package/abstract_module.py diff --git a/src/safeds_stubgen/api_analyzer/_api.py b/src/safeds_stubgen/api_analyzer/_api.py index 2934c9e4..212da1fe 100644 --- a/src/safeds_stubgen/api_analyzer/_api.py +++ b/src/safeds_stubgen/api_analyzer/_api.py @@ -233,7 +233,9 @@ class Function: docstring: FunctionDocstring is_public: bool is_static: bool - is_class_method: bool = False + is_class_method: bool + is_abstract_method: bool + is_property: bool results: list[Result] = field(default_factory=list) reexported_by: list[Module] = field(default_factory=list) parameters: list[Parameter] = field(default_factory=list) @@ -246,6 +248,8 @@ def to_dict(self) -> dict[str, Any]: "is_public": self.is_public, "is_static": self.is_static, "is_class_method": self.is_class_method, + "is_abstract_method": self.is_abstract_method, + "is_property": self.is_property, "results": [result.id for result in self.results], "reexported_by": [module.id for module in self.reexported_by], "parameters": [parameter.id for parameter in self.parameters], diff --git a/src/safeds_stubgen/api_analyzer/_ast_visitor.py b/src/safeds_stubgen/api_analyzer/_ast_visitor.py index a85a13d1..cd36e7be 100644 --- a/src/safeds_stubgen/api_analyzer/_ast_visitor.py +++ b/src/safeds_stubgen/api_analyzer/_ast_visitor.py @@ -227,6 +227,8 @@ def enter_funcdef(self, node: mp_nodes.FuncDef) -> None: is_public=is_public, is_static=is_static, is_class_method=node.is_class, + is_abstract_method=node.abstract_status != 0, + is_property=node.is_property, results=results, reexported_by=reexported_by, parameters=arguments, diff --git a/src/safeds_stubgen/api_analyzer/_ast_walker.py b/src/safeds_stubgen/api_analyzer/_ast_walker.py index 6ff59713..42c1803e 100644 --- a/src/safeds_stubgen/api_analyzer/_ast_walker.py +++ b/src/safeds_stubgen/api_analyzer/_ast_walker.py @@ -30,7 +30,8 @@ def walk(self, tree: MypyFile) -> None: self.__walk(tree, set()) def __walk(self, node: MypyFile | ClassDef | Decorator | FuncDef | AssignmentStmt, visited_nodes: set) -> None: - # It's possible to get decorator data but for now we'll ignore them and just get the func + # We ignore decorators and just take theire inner functions, since we can get decorator information from the + # function node too if isinstance(node, Decorator): node = node.func diff --git a/src/safeds_stubgen/stubs_generator/_generate_stubs.py b/src/safeds_stubgen/stubs_generator/_generate_stubs.py index 44c8c939..f2253d9c 100644 --- a/src/safeds_stubgen/stubs_generator/_generate_stubs.py +++ b/src/safeds_stubgen/stubs_generator/_generate_stubs.py @@ -14,6 +14,7 @@ ParameterAssignment, QualifiedImport, Result, + UnionType, VarianceType, WildcardImport, ) @@ -114,10 +115,23 @@ def create_module_string(self, module: Module) -> str: if wildcard_imports: module_text += f"\n{wildcard_imports}\n" - # Create global functions + # Create global functions and properties + module_properties = [] + module_functions = [] for function in module.global_functions: if function.is_public: - module_text += f"\n{self._create_function_string(function, is_method=False)}\n" + if function.is_property: + module_properties.append( + f"\n{self._create_property_function_string(function)}\n" + ) + else: + module_functions.append( + f"\n{self._create_function_string(function, is_method=False)}\n" + ) + + # We want the properties first, then the functions + for item in module_properties + module_functions: + module_text += item # Create classes, class attr. & class methods for class_ in module.classes: @@ -135,12 +149,19 @@ def _create_class_string(self, class_: Class, class_indentation: str = "") -> st class_text = "" # Constructor parameter - constructor = class_.constructor - parameter_info = "" - if constructor: - parameter_info = self._create_parameter_string( - constructor.parameters, class_indentation, is_instance_method=True - ) + is_abstract_class = False # Todo Frage: See PR #33 + if is_abstract_class: + # Abstract classes have no constructor + constructor_info = "" + else: + constructor = class_.constructor + parameter_info = "" + if constructor: + parameter_info = self._create_parameter_string( + constructor.parameters, class_indentation, is_instance_method=True + ) + + constructor_info = f"({parameter_info})" # Superclasses superclasses = class_.superclasses @@ -196,7 +217,7 @@ def _create_class_string(self, class_: Class, class_indentation: str = "") -> st # Class signature line class_signature = ( f"{class_indentation}{self._create_todo_msg(class_indentation)}class " - f"{class_.name}{variance_info}({parameter_info}){superclass_info}{constraints_info}" + f"{class_.name}{variance_info}{constructor_info}{superclass_info}{constraints_info}" ) # Attributes @@ -245,12 +266,23 @@ def _create_class_string(self, class_: Class, class_indentation: str = "") -> st # Methods class_methods: list[str] = [] + class_property_methods: list[str] = [] for method in class_.methods: if not method.is_public: continue - class_methods.append( - self._create_function_string(method, inner_indentations, is_method=True), - ) + elif method.is_property: + class_property_methods.append( + self._create_property_function_string(method, inner_indentations), + ) + else: + class_methods.append( + self._create_function_string(method, inner_indentations, is_method=True), + ) + + if class_property_methods: + properties = "\n".join(class_property_methods) + class_text += f"\n{properties}\n" + if class_methods: methods = "\n\n".join(class_methods) class_text += f"\n{methods}\n" @@ -291,6 +323,9 @@ def _create_function_string(self, function: Function, indentations: str = "", is if camel_case_name != name: function_name_annotation = f"{indentations}{self._create_name_annotation(name)}\n" + # Escape keywords + camel_case_name = self._replace_if_safeds_keyword(camel_case_name) + result_string = self._create_result_string(function.results) # Create string and return @@ -301,6 +336,31 @@ def _create_function_string(self, function: Function, indentations: str = "", is f"{result_string}" ) + def _create_property_function_string(self, function: Function, indentations: str = "") -> str: + """Create a string for functions with @property decorator. + + Functions or methods with the @property decorator are handled the same way as class attributes. + """ + name = function.name + camel_case_name = _convert_snake_to_camel_case(name) + function_name_annotation = "" + if camel_case_name != name: + function_name_annotation = f"{self._create_name_annotation(name)} " + + # Escape keywords + camel_case_name = self._replace_if_safeds_keyword(camel_case_name) + + # Create type information + types = UnionType(types=[result.type for result in function.results]).to_dict() + property_type = self._create_type_string(types) + type_string = f": {property_type}" if property_type else "" + + return ( + f"{self._create_todo_msg(indentations)}" + f"{indentations}{function_name_annotation}" + f"attr {camel_case_name}{type_string}" + ) + def _create_result_string(self, function_results: list[Result]) -> str: results: list[str] = [] for result in function_results: diff --git a/tests/data/test_package/abstract_module.py b/tests/data/test_package/abstract_module.py new file mode 100644 index 00000000..67f77afe --- /dev/null +++ b/tests/data/test_package/abstract_module.py @@ -0,0 +1,24 @@ +from abc import ABC, abstractmethod + + +class AbstractModuleClass(ABC): + def __init__(self, param): + ... + + @abstractmethod + def abstract_method(self): ... + + @abstractmethod + def abstract_method_params(self, param_1: int, param_2=False) -> list[str, int]: ... + + @staticmethod + @abstractmethod + def abstract_static_method(): ... + + @staticmethod + @abstractmethod + def abstract_static_method_params(param: float) -> bool: ... + + @property + @abstractmethod + def abstract_property_method(self) -> tuple[float, int]: ... diff --git a/tests/data/test_package/function_module.py b/tests/data/test_package/function_module.py index 02a1cbbc..f2581b70 100644 --- a/tests/data/test_package/function_module.py +++ b/tests/data/test_package/function_module.py @@ -87,3 +87,16 @@ def multiple_results() -> tuple[str, int, bool, FunctionModuleClassA]: ... def callable_type(param: Callable[[str], tuple[int, str]]) -> Callable[[int, int], int]: ... + + +@property +def property_function(): ... + + +@property +def property_function_params() -> str: ... + + +@property +def property_function_infer(): + return "some string" diff --git a/tests/safeds_stubgen/__snapshots__/test_main.ambr b/tests/safeds_stubgen/__snapshots__/test_main.ambr index 8e8060b3..cfbb205a 100644 --- a/tests/safeds_stubgen/__snapshots__/test_main.ambr +++ b/tests/safeds_stubgen/__snapshots__/test_main.ambr @@ -145,7 +145,9 @@ ''', }), 'id': 'test_main/main_test_module/ModuleClass/__init__', + 'is_abstract_method': False, 'is_class_method': False, + 'is_property': False, 'is_public': True, 'is_static': False, 'name': '__init__', @@ -222,7 +224,9 @@ 'full_docstring': '', }), 'id': 'test_main/main_test_module/_PrivateClass/__init__', + 'is_abstract_method': False, 'is_class_method': False, + 'is_property': False, 'is_public': False, 'is_static': False, 'name': '__init__', @@ -311,7 +315,9 @@ 'full_docstring': '', }), 'id': 'test_main/main_test_module/ModuleClass/NestedClass/nested_class_function', + 'is_abstract_method': False, 'is_class_method': False, + 'is_property': False, 'is_public': True, 'is_static': False, 'name': 'nested_class_function', @@ -339,7 +345,9 @@ ''', }), 'id': 'test_main/main_test_module/ModuleClass/__init__', + 'is_abstract_method': False, 'is_class_method': False, + 'is_property': False, 'is_public': True, 'is_static': False, 'name': '__init__', @@ -366,7 +374,9 @@ ''', }), 'id': 'test_main/main_test_module/ModuleClass/_some_function', + 'is_abstract_method': False, 'is_class_method': False, + 'is_property': False, 'is_public': False, 'is_static': False, 'name': '_some_function', @@ -387,7 +397,9 @@ 'full_docstring': '', }), 'id': 'test_main/main_test_module/_PrivateClass/NestedPrivateClass/static_nested_private_class_function', + 'is_abstract_method': False, 'is_class_method': False, + 'is_property': False, 'is_public': False, 'is_static': True, 'name': 'static_nested_private_class_function', @@ -404,7 +416,9 @@ 'full_docstring': '', }), 'id': 'test_main/main_test_module/_PrivateClass/__init__', + 'is_abstract_method': False, 'is_class_method': False, + 'is_property': False, 'is_public': False, 'is_static': False, 'name': '__init__', @@ -422,7 +436,9 @@ 'full_docstring': '', }), 'id': 'test_main/main_test_module/_PrivateClass/public_func_in_private_class', + 'is_abstract_method': False, 'is_class_method': False, + 'is_property': False, 'is_public': False, 'is_static': False, 'name': 'public_func_in_private_class', @@ -440,7 +456,9 @@ 'full_docstring': '', }), 'id': 'test_main/main_test_module/_private_global_func', + 'is_abstract_method': False, 'is_class_method': False, + 'is_property': False, 'is_public': False, 'is_static': False, 'name': '_private_global_func', @@ -466,7 +484,9 @@ ''', }), 'id': 'test_main/main_test_module/global_func', + 'is_abstract_method': False, 'is_class_method': False, + 'is_property': False, 'is_public': True, 'is_static': False, 'name': 'global_func', diff --git a/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr b/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr index 398c7615..ba0fe7b1 100644 --- a/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr +++ b/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr @@ -727,6 +727,115 @@ }), ]) # --- +# name: test_class_methods_AbstractModuleClass + list([ + dict({ + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_package/abstract_module/AbstractModuleClass/abstract_method', + 'is_abstract_method': True, + 'is_class_method': False, + 'is_property': False, + 'is_public': True, + 'is_static': False, + 'name': 'abstract_method', + 'parameters': list([ + 'test_package/abstract_module/AbstractModuleClass/abstract_method/self', + ]), + 'reexported_by': list([ + ]), + 'results': list([ + ]), + }), + dict({ + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_package/abstract_module/AbstractModuleClass/abstract_method_params', + 'is_abstract_method': True, + 'is_class_method': False, + 'is_property': False, + 'is_public': True, + 'is_static': False, + 'name': 'abstract_method_params', + 'parameters': list([ + 'test_package/abstract_module/AbstractModuleClass/abstract_method_params/self', + 'test_package/abstract_module/AbstractModuleClass/abstract_method_params/param_1', + 'test_package/abstract_module/AbstractModuleClass/abstract_method_params/param_2', + ]), + 'reexported_by': list([ + ]), + 'results': list([ + 'test_package/abstract_module/AbstractModuleClass/abstract_method_params/result_1', + ]), + }), + dict({ + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_package/abstract_module/AbstractModuleClass/abstract_property_method', + 'is_abstract_method': True, + 'is_class_method': False, + 'is_property': True, + 'is_public': True, + 'is_static': False, + 'name': 'abstract_property_method', + 'parameters': list([ + 'test_package/abstract_module/AbstractModuleClass/abstract_property_method/self', + ]), + 'reexported_by': list([ + ]), + 'results': list([ + 'test_package/abstract_module/AbstractModuleClass/abstract_property_method/result_1', + 'test_package/abstract_module/AbstractModuleClass/abstract_property_method/result_2', + ]), + }), + dict({ + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_package/abstract_module/AbstractModuleClass/abstract_static_method', + 'is_abstract_method': True, + 'is_class_method': False, + 'is_property': False, + 'is_public': True, + 'is_static': True, + 'name': 'abstract_static_method', + 'parameters': list([ + ]), + 'reexported_by': list([ + ]), + 'results': list([ + ]), + }), + dict({ + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_package/abstract_module/AbstractModuleClass/abstract_static_method_params', + 'is_abstract_method': True, + 'is_class_method': False, + 'is_property': False, + 'is_public': True, + 'is_static': True, + 'name': 'abstract_static_method_params', + 'parameters': list([ + 'test_package/abstract_module/AbstractModuleClass/abstract_static_method_params/param', + ]), + 'reexported_by': list([ + ]), + 'results': list([ + 'test_package/abstract_module/AbstractModuleClass/abstract_static_method_params/result_1', + ]), + }), + ]) +# --- # name: test_class_methods_ClassModuleClassB list([ dict({ @@ -735,7 +844,9 @@ 'full_docstring': '', }), 'id': 'test_package/class_module/ClassModuleClassB/f', + 'is_abstract_method': False, 'is_class_method': False, + 'is_property': False, 'is_public': True, 'is_static': False, 'name': 'f', @@ -757,7 +868,9 @@ 'full_docstring': '', }), 'id': 'test_package/class_module/ClassModuleClassC/f1', + 'is_abstract_method': False, 'is_class_method': False, + 'is_property': False, 'is_public': True, 'is_static': False, 'name': 'f1', @@ -783,7 +896,9 @@ 'full_docstring': '', }), 'id': 'test_package/class_module/ClassModuleClassD/ClassModuleNestedClassE/class_e_func', + 'is_abstract_method': False, 'is_class_method': False, + 'is_property': False, 'is_public': True, 'is_static': False, 'name': 'class_e_func', @@ -814,7 +929,9 @@ ''', }), 'id': 'test_package/docstring_module/EpydocDocstringClass/epydoc_docstring_func', + 'is_abstract_method': False, 'is_class_method': False, + 'is_property': False, 'is_public': True, 'is_static': False, 'name': 'epydoc_docstring_func', @@ -857,7 +974,9 @@ ''', }), 'id': 'test_package/docstring_module/GoogleDocstringClass/google_docstring_func', + 'is_abstract_method': False, 'is_class_method': False, + 'is_property': False, 'is_public': True, 'is_static': False, 'name': 'google_docstring_func', @@ -882,7 +1001,9 @@ 'full_docstring': '', }), 'id': 'test_package/infer_types_module/InferMyTypes/infer_function', + 'is_abstract_method': False, 'is_class_method': False, + 'is_property': False, 'is_public': True, 'is_static': True, 'name': 'infer_function', @@ -932,7 +1053,9 @@ ''', }), 'id': 'test_package/docstring_module/NumpyDocstringClass/numpy_docstring_func', + 'is_abstract_method': False, 'is_class_method': False, + 'is_property': False, 'is_public': True, 'is_static': False, 'name': 'numpy_docstring_func', @@ -957,7 +1080,9 @@ 'full_docstring': '', }), 'id': 'test_package/_reexport_module_1/ReexportClass/_private_class_method_of_reexported_class', + 'is_abstract_method': False, 'is_class_method': False, + 'is_property': False, 'is_public': False, 'is_static': True, 'name': '_private_class_method_of_reexported_class', @@ -993,7 +1118,9 @@ ''', }), 'id': 'test_package/docstring_module/RestDocstringClass/rest_docstring_func', + 'is_abstract_method': False, 'is_class_method': False, + 'is_property': False, 'is_public': True, 'is_static': False, 'name': 'rest_docstring_func', @@ -1018,7 +1145,9 @@ 'full_docstring': '', }), 'id': 'test_package/class_module/ClassModuleClassD/ClassModuleNestedClassE/_ClassModulePrivateDoubleNestedClassF/_class_f_func', + 'is_abstract_method': False, 'is_class_method': False, + 'is_property': False, 'is_public': False, 'is_static': False, 'name': '_class_f_func', @@ -1040,7 +1169,9 @@ 'full_docstring': '', }), 'id': 'test_package/function_module/FunctionModuleClassB/class_method', + 'is_abstract_method': False, 'is_class_method': True, + 'is_property': False, 'is_public': True, 'is_static': False, 'name': 'class_method', @@ -1058,7 +1189,9 @@ 'full_docstring': '', }), 'id': 'test_package/function_module/FunctionModuleClassB/class_method_params', + 'is_abstract_method': False, 'is_class_method': True, + 'is_property': False, 'is_public': True, 'is_static': False, 'name': 'class_method_params', @@ -1078,7 +1211,9 @@ 'full_docstring': '', }), 'id': 'test_package/function_module/FunctionModuleClassB/instance_method', + 'is_abstract_method': False, 'is_class_method': False, + 'is_property': False, 'is_public': True, 'is_static': False, 'name': 'instance_method', @@ -1098,7 +1233,9 @@ 'full_docstring': '', }), 'id': 'test_package/function_module/FunctionModuleClassB/static_method', + 'is_abstract_method': False, 'is_class_method': False, + 'is_property': False, 'is_public': True, 'is_static': True, 'name': 'static_method', @@ -1115,7 +1252,9 @@ 'full_docstring': '', }), 'id': 'test_package/function_module/FunctionModuleClassB/static_method_params', + 'is_abstract_method': False, 'is_class_method': False, + 'is_property': False, 'is_public': True, 'is_static': True, 'name': 'static_method_params', @@ -1137,7 +1276,9 @@ 'full_docstring': '', }), 'id': 'test_package/function_module/FunctionModuleClassB/FunctionModuleClassC/nested_class_function', + 'is_abstract_method': False, 'is_class_method': False, + 'is_property': False, 'is_public': True, 'is_static': False, 'name': 'nested_class_function', @@ -1153,6 +1294,56 @@ }), ]) # --- +# name: test_classes_AbstractModuleClass + dict({ + 'attributes': list([ + ]), + 'classes': list([ + ]), + 'constructor': dict({ + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_package/abstract_module/AbstractModuleClass/__init__', + 'is_abstract_method': False, + 'is_class_method': False, + 'is_property': False, + 'is_public': True, + 'is_static': False, + 'name': '__init__', + 'parameters': list([ + 'test_package/abstract_module/AbstractModuleClass/__init__/self', + 'test_package/abstract_module/AbstractModuleClass/__init__/param', + ]), + 'reexported_by': list([ + ]), + 'results': list([ + ]), + }), + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_package/abstract_module/AbstractModuleClass', + 'is_public': True, + 'methods': list([ + 'test_package/abstract_module/AbstractModuleClass/abstract_method', + 'test_package/abstract_module/AbstractModuleClass/abstract_method_params', + 'test_package/abstract_module/AbstractModuleClass/abstract_static_method', + 'test_package/abstract_module/AbstractModuleClass/abstract_static_method_params', + 'test_package/abstract_module/AbstractModuleClass/abstract_property_method', + ]), + 'name': 'AbstractModuleClass', + 'reexported_by': list([ + ]), + 'superclasses': list([ + 'abc.ABC', + ]), + 'variances': list([ + ]), + }) +# --- # name: test_classes_AnotherReexportClass dict({ 'attributes': list([ @@ -1189,7 +1380,9 @@ 'full_docstring': '', }), 'id': 'test_package/class_module/ClassModuleClassB/__init__', + 'is_abstract_method': False, 'is_class_method': False, + 'is_property': False, 'is_public': True, 'is_static': False, 'name': '__init__', @@ -1341,7 +1534,9 @@ 'full_docstring': '', }), 'id': 'test_package/docstring_module/EpydocDocstringClass/__init__', + 'is_abstract_method': False, 'is_class_method': False, + 'is_property': False, 'is_public': True, 'is_static': False, 'name': '__init__', @@ -1417,7 +1612,9 @@ 'full_docstring': '', }), 'id': 'test_package/docstring_module/GoogleDocstringClass/__init__', + 'is_abstract_method': False, 'is_class_method': False, + 'is_property': False, 'is_public': True, 'is_static': False, 'name': '__init__', @@ -1476,7 +1673,9 @@ 'full_docstring': '', }), 'id': 'test_package/infer_types_module/InferMyTypes/__init__', + 'is_abstract_method': False, 'is_class_method': False, + 'is_property': False, 'is_public': True, 'is_static': False, 'name': '__init__', @@ -1520,7 +1719,9 @@ 'full_docstring': '', }), 'id': 'test_package/docstring_module/NumpyDocstringClass/__init__', + 'is_abstract_method': False, 'is_class_method': False, + 'is_property': False, 'is_public': True, 'is_static': False, 'name': '__init__', @@ -1608,7 +1809,9 @@ 'full_docstring': '', }), 'id': 'test_package/docstring_module/RestDocstringClass/__init__', + 'is_abstract_method': False, 'is_class_method': False, + 'is_property': False, 'is_public': True, 'is_static': False, 'name': '__init__', @@ -2097,6 +2300,97 @@ }), ]) # --- +# name: test_function_parameters_abstract_module_abstract_method_params + list([ + dict({ + 'assigned_by': 'POSITION_OR_NAME', + 'default_value': None, + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_package/abstract_module/AbstractModuleClass/abstract_method_params/param_1', + 'is_optional': False, + 'is_type_inferred': False, + 'name': 'param_1', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'int', + }), + }), + dict({ + 'assigned_by': 'POSITION_OR_NAME', + 'default_value': False, + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_package/abstract_module/AbstractModuleClass/abstract_method_params/param_2', + 'is_optional': True, + 'is_type_inferred': True, + 'name': 'param_2', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'bool', + }), + }), + dict({ + 'assigned_by': 'IMPLICIT', + 'default_value': None, + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_package/abstract_module/AbstractModuleClass/abstract_method_params/self', + 'is_optional': False, + 'is_type_inferred': False, + 'name': 'self', + 'type': None, + }), + ]) +# --- +# name: test_function_parameters_abstract_module_abstract_property_method + list([ + dict({ + 'assigned_by': 'IMPLICIT', + 'default_value': None, + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_package/abstract_module/AbstractModuleClass/abstract_property_method/self', + 'is_optional': False, + 'is_type_inferred': False, + 'name': 'self', + 'type': None, + }), + ]) +# --- +# name: test_function_parameters_abstract_module_abstract_static_method_params + list([ + dict({ + 'assigned_by': 'POSITION_OR_NAME', + 'default_value': None, + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_package/abstract_module/AbstractModuleClass/abstract_static_method_params/param', + 'is_optional': False, + 'is_type_inferred': False, + 'name': 'param', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'float', + }), + }), + ]) +# --- # name: test_function_parameters_epydoc_docstring_func list([ dict({ @@ -3190,6 +3484,79 @@ }), ]) # --- +# name: test_function_results_abstract_method_params + list([ + dict({ + 'docstring': dict({ + 'description': '', + 'type': '', + }), + 'id': 'test_package/abstract_module/AbstractModuleClass/abstract_method_params/result_1', + 'is_type_inferred': False, + 'name': 'result_1', + 'type': dict({ + 'kind': 'ListType', + 'types': list([ + dict({ + 'kind': 'NamedType', + 'name': 'int', + }), + dict({ + 'kind': 'NamedType', + 'name': 'str', + }), + ]), + }), + }), + ]) +# --- +# name: test_function_results_abstract_property_method + list([ + dict({ + 'docstring': dict({ + 'description': '', + 'type': '', + }), + 'id': 'test_package/abstract_module/AbstractModuleClass/abstract_property_method/result_1', + 'is_type_inferred': False, + 'name': 'result_1', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'float', + }), + }), + dict({ + 'docstring': dict({ + 'description': '', + 'type': '', + }), + 'id': 'test_package/abstract_module/AbstractModuleClass/abstract_property_method/result_2', + 'is_type_inferred': False, + 'name': 'result_2', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'int', + }), + }), + ]) +# --- +# name: test_function_results_abstract_static_method_params + list([ + dict({ + 'docstring': dict({ + 'description': '', + 'type': '', + }), + 'id': 'test_package/abstract_module/AbstractModuleClass/abstract_static_method_params/result_1', + 'is_type_inferred': False, + 'name': 'result_1', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'bool', + }), + }), + ]) +# --- # name: test_function_results_callable_type list([ dict({ @@ -3254,6 +3621,44 @@ }), ]) # --- +# name: test_function_results_function_module_property_function + list([ + ]) +# --- +# name: test_function_results_function_module_property_function_infer + list([ + dict({ + 'docstring': dict({ + 'description': '', + 'type': '', + }), + 'id': 'test_package/function_module/property_function_infer/result_1', + 'is_type_inferred': True, + 'name': 'result_1', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'str', + }), + }), + ]) +# --- +# name: test_function_results_function_module_property_function_params + list([ + dict({ + 'docstring': dict({ + 'description': '', + 'type': '', + }), + 'id': 'test_package/function_module/property_function_params/result_1', + 'is_type_inferred': False, + 'name': 'result_1', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'str', + }), + }), + ]) +# --- # name: test_function_results_google_docstring_func list([ dict({ @@ -3505,7 +3910,9 @@ 'full_docstring': '', }), 'id': 'test_package/_reexport_module_1/reexported_function', + 'is_abstract_method': False, 'is_class_method': False, + 'is_property': False, 'is_public': False, 'is_static': False, 'name': 'reexported_function', @@ -3526,7 +3933,9 @@ 'full_docstring': '', }), 'id': 'test_package/_reexport_module_2/reexported_function_2', + 'is_abstract_method': False, 'is_class_method': False, + 'is_property': False, 'is_public': True, 'is_static': False, 'name': 'reexported_function_2', @@ -3548,7 +3957,9 @@ 'full_docstring': '', }), 'id': 'test_package/_reexport_module_3/reexported_function_3', + 'is_abstract_method': False, 'is_class_method': False, + 'is_property': False, 'is_public': False, 'is_static': False, 'name': 'reexported_function_3', @@ -3570,7 +3981,9 @@ 'full_docstring': '', }), 'id': 'test_package/_reexport_module_4/_reexported_function_4', + 'is_abstract_method': False, 'is_class_method': False, + 'is_property': False, 'is_public': False, 'is_static': False, 'name': '_reexported_function_4', @@ -3588,7 +4001,9 @@ 'full_docstring': '', }), 'id': 'test_package/_reexport_module_4/_unreexported_function', + 'is_abstract_method': False, 'is_class_method': False, + 'is_property': False, 'is_public': False, 'is_static': False, 'name': '_unreexported_function', @@ -3609,7 +4024,9 @@ 'full_docstring': '', }), 'id': 'test_package/function_module/_private', + 'is_abstract_method': False, 'is_class_method': False, + 'is_property': False, 'is_public': False, 'is_static': False, 'name': '_private', @@ -3627,7 +4044,9 @@ 'full_docstring': '', }), 'id': 'test_package/function_module/arg', + 'is_abstract_method': False, 'is_class_method': False, + 'is_property': False, 'is_public': True, 'is_static': False, 'name': 'arg', @@ -3646,7 +4065,9 @@ 'full_docstring': '', }), 'id': 'test_package/function_module/args_type', + 'is_abstract_method': False, 'is_class_method': False, + 'is_property': False, 'is_public': True, 'is_static': False, 'name': 'args_type', @@ -3665,7 +4086,9 @@ 'full_docstring': '', }), 'id': 'test_package/function_module/callable_type', + 'is_abstract_method': False, 'is_class_method': False, + 'is_property': False, 'is_public': True, 'is_static': False, 'name': 'callable_type', @@ -3684,7 +4107,9 @@ 'full_docstring': '', }), 'id': 'test_package/function_module/illegal_params', + 'is_abstract_method': False, 'is_class_method': False, + 'is_property': False, 'is_public': True, 'is_static': False, 'name': 'illegal_params', @@ -3705,7 +4130,9 @@ 'full_docstring': '', }), 'id': 'test_package/function_module/multiple_results', + 'is_abstract_method': False, 'is_class_method': False, + 'is_property': False, 'is_public': True, 'is_static': False, 'name': 'multiple_results', @@ -3726,7 +4153,9 @@ 'full_docstring': '', }), 'id': 'test_package/function_module/one_result', + 'is_abstract_method': False, 'is_class_method': False, + 'is_property': False, 'is_public': True, 'is_static': False, 'name': 'one_result', @@ -3744,7 +4173,9 @@ 'full_docstring': '', }), 'id': 'test_package/function_module/opt_pos_only', + 'is_abstract_method': False, 'is_class_method': False, + 'is_property': False, 'is_public': True, 'is_static': False, 'name': 'opt_pos_only', @@ -3763,7 +4194,9 @@ 'full_docstring': '', }), 'id': 'test_package/function_module/param_position', + 'is_abstract_method': False, 'is_class_method': False, + 'is_property': False, 'is_public': True, 'is_static': False, 'name': 'param_position', @@ -3786,7 +4219,9 @@ 'full_docstring': '', }), 'id': 'test_package/function_module/params', + 'is_abstract_method': False, 'is_class_method': False, + 'is_property': False, 'is_public': True, 'is_static': False, 'name': 'params', @@ -3801,13 +4236,73 @@ 'results': list([ ]), }), + dict({ + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_package/function_module/property_function', + 'is_abstract_method': False, + 'is_class_method': False, + 'is_property': True, + 'is_public': True, + 'is_static': False, + 'name': 'property_function', + 'parameters': list([ + ]), + 'reexported_by': list([ + ]), + 'results': list([ + ]), + }), + dict({ + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_package/function_module/property_function_infer', + 'is_abstract_method': False, + 'is_class_method': False, + 'is_property': True, + 'is_public': True, + 'is_static': False, + 'name': 'property_function_infer', + 'parameters': list([ + ]), + 'reexported_by': list([ + ]), + 'results': list([ + ]), + }), + dict({ + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_package/function_module/property_function_params', + 'is_abstract_method': False, + 'is_class_method': False, + 'is_property': True, + 'is_public': True, + 'is_static': False, + 'name': 'property_function_params', + 'parameters': list([ + ]), + 'reexported_by': list([ + ]), + 'results': list([ + 'test_package/function_module/property_function_params/result_1', + ]), + }), dict({ 'docstring': dict({ 'description': '', 'full_docstring': '', }), 'id': 'test_package/function_module/public_no_params_no_result', + 'is_abstract_method': False, 'is_class_method': False, + 'is_property': False, 'is_public': True, 'is_static': False, 'name': 'public_no_params_no_result', @@ -3824,7 +4319,9 @@ 'full_docstring': '', }), 'id': 'test_package/function_module/req_name_only', + 'is_abstract_method': False, 'is_class_method': False, + 'is_property': False, 'is_public': True, 'is_static': False, 'name': 'req_name_only', @@ -3843,7 +4340,9 @@ 'full_docstring': '', }), 'id': 'test_package/function_module/special_params', + 'is_abstract_method': False, 'is_class_method': False, + 'is_property': False, 'is_public': True, 'is_static': False, 'name': 'special_params', diff --git a/tests/safeds_stubgen/api_analyzer/test__get_api.py b/tests/safeds_stubgen/api_analyzer/test__get_api.py index 6326ee17..b923237a 100644 --- a/tests/safeds_stubgen/api_analyzer/test__get_api.py +++ b/tests/safeds_stubgen/api_analyzer/test__get_api.py @@ -252,6 +252,11 @@ def test_classes_FourthReexportClass(snapshot: SnapshotAssertion) -> None: # no assert class_data == snapshot +def test_classes_AbstractModuleClass(snapshot: SnapshotAssertion) -> None: # noqa: N802 + class_data = _get_specific_class_data("abstract_module", "AbstractModuleClass") + assert class_data == snapshot + + # ############################## Class Attributes ############################## # def get_class_attribute_data(module_name: str, class_name: str, docstring_style: str) -> list: class_data: dict = _get_specific_class_data(module_name, class_name, docstring_style) @@ -443,6 +448,11 @@ def test_class_methods_ReexportClass(snapshot: SnapshotAssertion) -> None: # no assert class_methods_data == snapshot +def test_class_methods_AbstractModuleClass(snapshot: SnapshotAssertion) -> None: # noqa: N802 + class_methods_data = get_class_methods_data("abstract_module", "AbstractModuleClass") + assert class_methods_data == snapshot + + def test_class_methods_EpydocDocstringClass(snapshot: SnapshotAssertion) -> None: # noqa: N802 class_methods_data = get_class_methods_data("docstring_module", "EpydocDocstringClass", "epydoc") assert class_methods_data == snapshot @@ -578,6 +588,33 @@ def test_function_parameters_function_module_callable_type(snapshot: SnapshotAss assert function_parameter_data == snapshot +def test_function_parameters_abstract_module_abstract_method_params(snapshot: SnapshotAssertion) -> None: + function_parameter_data = get_function_parameter_data( + module_name="abstract_module", + function_name="abstract_method_params", + parent_class_name="AbstractModuleClass", + ) + assert function_parameter_data == snapshot + + +def test_function_parameters_abstract_module_abstract_static_method_params(snapshot: SnapshotAssertion) -> None: + function_parameter_data = get_function_parameter_data( + module_name="abstract_module", + function_name="abstract_static_method_params", + parent_class_name="AbstractModuleClass", + ) + assert function_parameter_data == snapshot + + +def test_function_parameters_abstract_module_abstract_property_method(snapshot: SnapshotAssertion) -> None: + function_parameter_data = get_function_parameter_data( + module_name="abstract_module", + function_name="abstract_property_method", + parent_class_name="AbstractModuleClass", + ) + assert function_parameter_data == snapshot + + def test_function_parameters_epydoc_docstring_func(snapshot: SnapshotAssertion) -> None: function_parameter_data = get_function_parameter_data( module_name="docstring_module", @@ -659,9 +696,9 @@ def test_function_parameters_GoogleDocstringClass___init__(snapshot: SnapshotAss # ############################## Function Results ############################## # def get_function_result_data( - module_name: str, function_name: str, - parent_class_name: str, + module_name: str = "function_module", + parent_class_name: str = "", docstring_style: str = "plaintext" ) -> list: function_data: dict = _get_specific_function_data(module_name, function_name, parent_class_name, docstring_style) @@ -678,75 +715,146 @@ def get_function_result_data( def test_function_results_instance_method(snapshot: SnapshotAssertion) -> None: - function_result_data = get_function_result_data("function_module", "instance_method", "FunctionModuleClassB") + function_result_data = get_function_result_data( + function_name="instance_method", + parent_class_name="FunctionModuleClassB" + ) assert function_result_data == snapshot def test_function_results_static_method_params(snapshot: SnapshotAssertion) -> None: - function_result_data = get_function_result_data("function_module", "static_method_params", "FunctionModuleClassB") + function_result_data = get_function_result_data( + function_name="static_method_params", + parent_class_name="FunctionModuleClassB" + ) assert function_result_data == snapshot def test_function_results_class_method_params(snapshot: SnapshotAssertion) -> None: - function_result_data = get_function_result_data("function_module", "class_method_params", "FunctionModuleClassB") + function_result_data = get_function_result_data( + function_name="class_method_params", + parent_class_name="FunctionModuleClassB" + ) assert function_result_data == snapshot def test_function_results_nested_class_function(snapshot: SnapshotAssertion) -> None: - function_result_data = get_function_result_data("function_module", "nested_class_function", "FunctionModuleClassC") + function_result_data = get_function_result_data( + function_name="nested_class_function", + parent_class_name="FunctionModuleClassC" + ) assert function_result_data == snapshot def test_function_results_callable_type(snapshot: SnapshotAssertion) -> None: - function_result_data = get_function_result_data("function_module", "callable_type", "") + function_result_data = get_function_result_data( + function_name="callable_type", + ) assert function_result_data == snapshot def test_function_results_multiple_results(snapshot: SnapshotAssertion) -> None: - function_result_data = get_function_result_data("function_module", "multiple_results", "") + function_result_data = get_function_result_data( + function_name="multiple_results", + ) assert function_result_data == snapshot def test_function_results_infer_function(snapshot: SnapshotAssertion) -> None: - function_result_data = get_function_result_data("infer_types_module", "infer_function", "InferMyTypes") + function_result_data = get_function_result_data( + module_name="infer_types_module", + function_name="infer_function", + parent_class_name="InferMyTypes" + ) + assert function_result_data == snapshot + + +def test_function_results_abstract_method_params(snapshot: SnapshotAssertion) -> None: + function_result_data = get_function_result_data( + module_name="abstract_module", + function_name="abstract_method_params", + parent_class_name="AbstractModuleClass" + ) + assert function_result_data == snapshot + + +def test_function_results_abstract_static_method_params(snapshot: SnapshotAssertion) -> None: + function_result_data = get_function_result_data( + module_name="abstract_module", + function_name="abstract_static_method_params", + parent_class_name="AbstractModuleClass" + ) + assert function_result_data == snapshot + + +def test_function_results_abstract_property_method(snapshot: SnapshotAssertion) -> None: + function_result_data = get_function_result_data( + module_name="abstract_module", + function_name="abstract_property_method", + parent_class_name="AbstractModuleClass" + ) + assert function_result_data == snapshot + + +def test_function_results_function_module_property_function(snapshot: SnapshotAssertion) -> None: + function_result_data = get_function_result_data( + module_name="function_module", + function_name="property_function", + ) + assert function_result_data == snapshot + + +def test_function_results_function_module_property_function_params(snapshot: SnapshotAssertion) -> None: + function_result_data = get_function_result_data( + module_name="function_module", + function_name="property_function_params", + ) + assert function_result_data == snapshot + + +def test_function_results_function_module_property_function_infer(snapshot: SnapshotAssertion) -> None: + function_result_data = get_function_result_data( + module_name="function_module", + function_name="property_function_infer", + ) assert function_result_data == snapshot def test_function_results_epydoc_docstring_func(snapshot: SnapshotAssertion) -> None: function_result_data = get_function_result_data( - "docstring_module", - "epydoc_docstring_func", - "EpydocDocstringClass", - "epydoc" + module_name="docstring_module", + function_name="epydoc_docstring_func", + parent_class_name="EpydocDocstringClass", + docstring_style="epydoc" ) assert function_result_data == snapshot def test_function_results_rest_docstring_func(snapshot: SnapshotAssertion) -> None: function_result_data = get_function_result_data( - "docstring_module", - "rest_docstring_func", - "RestDocstringClass", - "rest" + module_name="docstring_module", + function_name="rest_docstring_func", + parent_class_name="RestDocstringClass", + docstring_style="rest" ) assert function_result_data == snapshot def test_function_results_numpy_docstring_func(snapshot: SnapshotAssertion) -> None: function_result_data = get_function_result_data( - "docstring_module", - "numpy_docstring_func", - "NumpyDocstringClass", - "numpydoc" + module_name="docstring_module", + function_name="numpy_docstring_func", + parent_class_name="NumpyDocstringClass", + docstring_style="numpydoc" ) assert function_result_data == snapshot def test_function_results_google_docstring_func(snapshot: SnapshotAssertion) -> None: function_result_data = get_function_result_data( - "docstring_module", - "google_docstring_func", - "GoogleDocstringClass", - "google" + module_name="docstring_module", + function_name="google_docstring_func", + parent_class_name="GoogleDocstringClass", + docstring_style="google" ) assert function_result_data == snapshot diff --git a/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr b/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr index 5faab763..5bf7bb7d 100644 --- a/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr +++ b/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr @@ -1,4 +1,39 @@ # serializer version: 1 +# name: test_abstract_creation + ''' + package test_package.abstract_module + + from abc import ABC + from abc import abstractmethod + + // TODO Some parameter have no type information. + class AbstractModuleClass( + param + ) sub ABC { + @PythonName("abstract_property_method") attr abstractPropertyMethod: union + + // TODO Result type information missing. + @PythonName("abstract_method") + fun abstractMethod() + + @PythonName("abstract_method_params") + fun abstractMethodParams( + @PythonName("param_1") param1: Int, + @PythonName("param_2") param2: Boolean = False + ) -> result1: List + + // TODO Result type information missing. + @PythonName("abstract_static_method") + static fun abstractStaticMethod() + + @PythonName("abstract_static_method_params") + static fun abstractStaticMethodParams( + param: Float + ) -> result1: Boolean + } + + ''' +# --- # name: test_class_attribute_creation ''' package test_package.attribute_module @@ -143,6 +178,12 @@ from typing import Callable + @PythonName("property_function") attr propertyFunction + + @PythonName("property_function_params") attr propertyFunctionParams: String + + @PythonName("property_function_infer") attr propertyFunctionInfer + // TODO Result type information missing. @PythonName("public_no_params_no_result") fun publicNoParamsNoResult() diff --git a/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py b/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py index fccad5b6..975725b4 100644 --- a/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py +++ b/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py @@ -99,6 +99,11 @@ def test_variance_creation(snapshot: SnapshotAssertion) -> None: assert_stubs_snapshot("variance_module", snapshot) +# Todo Check snapshot +def test_abstract_creation(snapshot: SnapshotAssertion) -> None: + assert_stubs_snapshot("abstract_module", snapshot) + + # Todo def test_docstring_creation() -> None: ... From d0dac2b22ef24c640937dec988632d2d100ae675 Mon Sep 17 00:00:00 2001 From: Arsam Date: Wed, 22 Nov 2023 20:27:54 +0100 Subject: [PATCH 050/109] [WIP] Stubs generator: ABC classes won't have a constructor --- src/safeds_stubgen/api_analyzer/_api.py | 3 +- .../api_analyzer/_ast_visitor.py | 3 +- .../stubs_generator/_generate_stubs.py | 3 +- .../__snapshots__/test_main.ambr | 10 ---- .../__snapshots__/test__get_api.ambr | 49 ------------------- .../__snapshots__/test_generate_stubs.ambr | 5 +- 6 files changed, 5 insertions(+), 68 deletions(-) diff --git a/src/safeds_stubgen/api_analyzer/_api.py b/src/safeds_stubgen/api_analyzer/_api.py index 212da1fe..d7ec7b4a 100644 --- a/src/safeds_stubgen/api_analyzer/_api.py +++ b/src/safeds_stubgen/api_analyzer/_api.py @@ -168,6 +168,7 @@ class Class: superclasses: list[str] is_public: bool docstring: ClassDocstring + is_abstract: bool = False constructor: Function | None = None constructor_fulldocstring: str = "" reexported_by: list[Module] = field(default_factory=list) @@ -234,7 +235,6 @@ class Function: is_public: bool is_static: bool is_class_method: bool - is_abstract_method: bool is_property: bool results: list[Result] = field(default_factory=list) reexported_by: list[Module] = field(default_factory=list) @@ -248,7 +248,6 @@ def to_dict(self) -> dict[str, Any]: "is_public": self.is_public, "is_static": self.is_static, "is_class_method": self.is_class_method, - "is_abstract_method": self.is_abstract_method, "is_property": self.is_property, "results": [result.id for result in self.results], "reexported_by": [module.id for module in self.reexported_by], diff --git a/src/safeds_stubgen/api_analyzer/_ast_visitor.py b/src/safeds_stubgen/api_analyzer/_ast_visitor.py index cd36e7be..7ae3e990 100644 --- a/src/safeds_stubgen/api_analyzer/_ast_visitor.py +++ b/src/safeds_stubgen/api_analyzer/_ast_visitor.py @@ -161,6 +161,7 @@ def enter_classdef(self, node: mp_nodes.ClassDef) -> None: # superclasses # Todo Aliasing: Werden noch nicht aufgelöst superclasses = [superclass.fullname for superclass in node.base_type_exprs if hasattr(superclass, "fullname")] + is_abstract_class = "abc.ABC" in superclasses # Get reexported data reexported_by = self._get_reexported_by(name) @@ -179,6 +180,7 @@ def enter_classdef(self, node: mp_nodes.ClassDef) -> None: name=name, superclasses=superclasses, is_public=self._is_public(node.name, name), + is_abstract=is_abstract_class, docstring=docstring, reexported_by=reexported_by, constructor_fulldocstring=constructor_fulldocstring, @@ -227,7 +229,6 @@ def enter_funcdef(self, node: mp_nodes.FuncDef) -> None: is_public=is_public, is_static=is_static, is_class_method=node.is_class, - is_abstract_method=node.abstract_status != 0, is_property=node.is_property, results=results, reexported_by=reexported_by, diff --git a/src/safeds_stubgen/stubs_generator/_generate_stubs.py b/src/safeds_stubgen/stubs_generator/_generate_stubs.py index f2253d9c..d18a433e 100644 --- a/src/safeds_stubgen/stubs_generator/_generate_stubs.py +++ b/src/safeds_stubgen/stubs_generator/_generate_stubs.py @@ -149,8 +149,7 @@ def _create_class_string(self, class_: Class, class_indentation: str = "") -> st class_text = "" # Constructor parameter - is_abstract_class = False # Todo Frage: See PR #33 - if is_abstract_class: + if class_.is_abstract: # Abstract classes have no constructor constructor_info = "" else: diff --git a/tests/safeds_stubgen/__snapshots__/test_main.ambr b/tests/safeds_stubgen/__snapshots__/test_main.ambr index cfbb205a..6b5a8515 100644 --- a/tests/safeds_stubgen/__snapshots__/test_main.ambr +++ b/tests/safeds_stubgen/__snapshots__/test_main.ambr @@ -145,7 +145,6 @@ ''', }), 'id': 'test_main/main_test_module/ModuleClass/__init__', - 'is_abstract_method': False, 'is_class_method': False, 'is_property': False, 'is_public': True, @@ -224,7 +223,6 @@ 'full_docstring': '', }), 'id': 'test_main/main_test_module/_PrivateClass/__init__', - 'is_abstract_method': False, 'is_class_method': False, 'is_property': False, 'is_public': False, @@ -315,7 +313,6 @@ 'full_docstring': '', }), 'id': 'test_main/main_test_module/ModuleClass/NestedClass/nested_class_function', - 'is_abstract_method': False, 'is_class_method': False, 'is_property': False, 'is_public': True, @@ -345,7 +342,6 @@ ''', }), 'id': 'test_main/main_test_module/ModuleClass/__init__', - 'is_abstract_method': False, 'is_class_method': False, 'is_property': False, 'is_public': True, @@ -374,7 +370,6 @@ ''', }), 'id': 'test_main/main_test_module/ModuleClass/_some_function', - 'is_abstract_method': False, 'is_class_method': False, 'is_property': False, 'is_public': False, @@ -397,7 +392,6 @@ 'full_docstring': '', }), 'id': 'test_main/main_test_module/_PrivateClass/NestedPrivateClass/static_nested_private_class_function', - 'is_abstract_method': False, 'is_class_method': False, 'is_property': False, 'is_public': False, @@ -416,7 +410,6 @@ 'full_docstring': '', }), 'id': 'test_main/main_test_module/_PrivateClass/__init__', - 'is_abstract_method': False, 'is_class_method': False, 'is_property': False, 'is_public': False, @@ -436,7 +429,6 @@ 'full_docstring': '', }), 'id': 'test_main/main_test_module/_PrivateClass/public_func_in_private_class', - 'is_abstract_method': False, 'is_class_method': False, 'is_property': False, 'is_public': False, @@ -456,7 +448,6 @@ 'full_docstring': '', }), 'id': 'test_main/main_test_module/_private_global_func', - 'is_abstract_method': False, 'is_class_method': False, 'is_property': False, 'is_public': False, @@ -484,7 +475,6 @@ ''', }), 'id': 'test_main/main_test_module/global_func', - 'is_abstract_method': False, 'is_class_method': False, 'is_property': False, 'is_public': True, diff --git a/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr b/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr index ba0fe7b1..ebceffcb 100644 --- a/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr +++ b/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr @@ -735,7 +735,6 @@ 'full_docstring': '', }), 'id': 'test_package/abstract_module/AbstractModuleClass/abstract_method', - 'is_abstract_method': True, 'is_class_method': False, 'is_property': False, 'is_public': True, @@ -755,7 +754,6 @@ 'full_docstring': '', }), 'id': 'test_package/abstract_module/AbstractModuleClass/abstract_method_params', - 'is_abstract_method': True, 'is_class_method': False, 'is_property': False, 'is_public': True, @@ -778,7 +776,6 @@ 'full_docstring': '', }), 'id': 'test_package/abstract_module/AbstractModuleClass/abstract_property_method', - 'is_abstract_method': True, 'is_class_method': False, 'is_property': True, 'is_public': True, @@ -800,7 +797,6 @@ 'full_docstring': '', }), 'id': 'test_package/abstract_module/AbstractModuleClass/abstract_static_method', - 'is_abstract_method': True, 'is_class_method': False, 'is_property': False, 'is_public': True, @@ -819,7 +815,6 @@ 'full_docstring': '', }), 'id': 'test_package/abstract_module/AbstractModuleClass/abstract_static_method_params', - 'is_abstract_method': True, 'is_class_method': False, 'is_property': False, 'is_public': True, @@ -844,7 +839,6 @@ 'full_docstring': '', }), 'id': 'test_package/class_module/ClassModuleClassB/f', - 'is_abstract_method': False, 'is_class_method': False, 'is_property': False, 'is_public': True, @@ -868,7 +862,6 @@ 'full_docstring': '', }), 'id': 'test_package/class_module/ClassModuleClassC/f1', - 'is_abstract_method': False, 'is_class_method': False, 'is_property': False, 'is_public': True, @@ -896,7 +889,6 @@ 'full_docstring': '', }), 'id': 'test_package/class_module/ClassModuleClassD/ClassModuleNestedClassE/class_e_func', - 'is_abstract_method': False, 'is_class_method': False, 'is_property': False, 'is_public': True, @@ -929,7 +921,6 @@ ''', }), 'id': 'test_package/docstring_module/EpydocDocstringClass/epydoc_docstring_func', - 'is_abstract_method': False, 'is_class_method': False, 'is_property': False, 'is_public': True, @@ -974,7 +965,6 @@ ''', }), 'id': 'test_package/docstring_module/GoogleDocstringClass/google_docstring_func', - 'is_abstract_method': False, 'is_class_method': False, 'is_property': False, 'is_public': True, @@ -1001,7 +991,6 @@ 'full_docstring': '', }), 'id': 'test_package/infer_types_module/InferMyTypes/infer_function', - 'is_abstract_method': False, 'is_class_method': False, 'is_property': False, 'is_public': True, @@ -1053,7 +1042,6 @@ ''', }), 'id': 'test_package/docstring_module/NumpyDocstringClass/numpy_docstring_func', - 'is_abstract_method': False, 'is_class_method': False, 'is_property': False, 'is_public': True, @@ -1080,7 +1068,6 @@ 'full_docstring': '', }), 'id': 'test_package/_reexport_module_1/ReexportClass/_private_class_method_of_reexported_class', - 'is_abstract_method': False, 'is_class_method': False, 'is_property': False, 'is_public': False, @@ -1118,7 +1105,6 @@ ''', }), 'id': 'test_package/docstring_module/RestDocstringClass/rest_docstring_func', - 'is_abstract_method': False, 'is_class_method': False, 'is_property': False, 'is_public': True, @@ -1145,7 +1131,6 @@ 'full_docstring': '', }), 'id': 'test_package/class_module/ClassModuleClassD/ClassModuleNestedClassE/_ClassModulePrivateDoubleNestedClassF/_class_f_func', - 'is_abstract_method': False, 'is_class_method': False, 'is_property': False, 'is_public': False, @@ -1169,7 +1154,6 @@ 'full_docstring': '', }), 'id': 'test_package/function_module/FunctionModuleClassB/class_method', - 'is_abstract_method': False, 'is_class_method': True, 'is_property': False, 'is_public': True, @@ -1189,7 +1173,6 @@ 'full_docstring': '', }), 'id': 'test_package/function_module/FunctionModuleClassB/class_method_params', - 'is_abstract_method': False, 'is_class_method': True, 'is_property': False, 'is_public': True, @@ -1211,7 +1194,6 @@ 'full_docstring': '', }), 'id': 'test_package/function_module/FunctionModuleClassB/instance_method', - 'is_abstract_method': False, 'is_class_method': False, 'is_property': False, 'is_public': True, @@ -1233,7 +1215,6 @@ 'full_docstring': '', }), 'id': 'test_package/function_module/FunctionModuleClassB/static_method', - 'is_abstract_method': False, 'is_class_method': False, 'is_property': False, 'is_public': True, @@ -1252,7 +1233,6 @@ 'full_docstring': '', }), 'id': 'test_package/function_module/FunctionModuleClassB/static_method_params', - 'is_abstract_method': False, 'is_class_method': False, 'is_property': False, 'is_public': True, @@ -1276,7 +1256,6 @@ 'full_docstring': '', }), 'id': 'test_package/function_module/FunctionModuleClassB/FunctionModuleClassC/nested_class_function', - 'is_abstract_method': False, 'is_class_method': False, 'is_property': False, 'is_public': True, @@ -1306,7 +1285,6 @@ 'full_docstring': '', }), 'id': 'test_package/abstract_module/AbstractModuleClass/__init__', - 'is_abstract_method': False, 'is_class_method': False, 'is_property': False, 'is_public': True, @@ -1380,7 +1358,6 @@ 'full_docstring': '', }), 'id': 'test_package/class_module/ClassModuleClassB/__init__', - 'is_abstract_method': False, 'is_class_method': False, 'is_property': False, 'is_public': True, @@ -1534,7 +1511,6 @@ 'full_docstring': '', }), 'id': 'test_package/docstring_module/EpydocDocstringClass/__init__', - 'is_abstract_method': False, 'is_class_method': False, 'is_property': False, 'is_public': True, @@ -1612,7 +1588,6 @@ 'full_docstring': '', }), 'id': 'test_package/docstring_module/GoogleDocstringClass/__init__', - 'is_abstract_method': False, 'is_class_method': False, 'is_property': False, 'is_public': True, @@ -1673,7 +1648,6 @@ 'full_docstring': '', }), 'id': 'test_package/infer_types_module/InferMyTypes/__init__', - 'is_abstract_method': False, 'is_class_method': False, 'is_property': False, 'is_public': True, @@ -1719,7 +1693,6 @@ 'full_docstring': '', }), 'id': 'test_package/docstring_module/NumpyDocstringClass/__init__', - 'is_abstract_method': False, 'is_class_method': False, 'is_property': False, 'is_public': True, @@ -1809,7 +1782,6 @@ 'full_docstring': '', }), 'id': 'test_package/docstring_module/RestDocstringClass/__init__', - 'is_abstract_method': False, 'is_class_method': False, 'is_property': False, 'is_public': True, @@ -3910,7 +3882,6 @@ 'full_docstring': '', }), 'id': 'test_package/_reexport_module_1/reexported_function', - 'is_abstract_method': False, 'is_class_method': False, 'is_property': False, 'is_public': False, @@ -3933,7 +3904,6 @@ 'full_docstring': '', }), 'id': 'test_package/_reexport_module_2/reexported_function_2', - 'is_abstract_method': False, 'is_class_method': False, 'is_property': False, 'is_public': True, @@ -3957,7 +3927,6 @@ 'full_docstring': '', }), 'id': 'test_package/_reexport_module_3/reexported_function_3', - 'is_abstract_method': False, 'is_class_method': False, 'is_property': False, 'is_public': False, @@ -3981,7 +3950,6 @@ 'full_docstring': '', }), 'id': 'test_package/_reexport_module_4/_reexported_function_4', - 'is_abstract_method': False, 'is_class_method': False, 'is_property': False, 'is_public': False, @@ -4001,7 +3969,6 @@ 'full_docstring': '', }), 'id': 'test_package/_reexport_module_4/_unreexported_function', - 'is_abstract_method': False, 'is_class_method': False, 'is_property': False, 'is_public': False, @@ -4024,7 +3991,6 @@ 'full_docstring': '', }), 'id': 'test_package/function_module/_private', - 'is_abstract_method': False, 'is_class_method': False, 'is_property': False, 'is_public': False, @@ -4044,7 +4010,6 @@ 'full_docstring': '', }), 'id': 'test_package/function_module/arg', - 'is_abstract_method': False, 'is_class_method': False, 'is_property': False, 'is_public': True, @@ -4065,7 +4030,6 @@ 'full_docstring': '', }), 'id': 'test_package/function_module/args_type', - 'is_abstract_method': False, 'is_class_method': False, 'is_property': False, 'is_public': True, @@ -4086,7 +4050,6 @@ 'full_docstring': '', }), 'id': 'test_package/function_module/callable_type', - 'is_abstract_method': False, 'is_class_method': False, 'is_property': False, 'is_public': True, @@ -4107,7 +4070,6 @@ 'full_docstring': '', }), 'id': 'test_package/function_module/illegal_params', - 'is_abstract_method': False, 'is_class_method': False, 'is_property': False, 'is_public': True, @@ -4130,7 +4092,6 @@ 'full_docstring': '', }), 'id': 'test_package/function_module/multiple_results', - 'is_abstract_method': False, 'is_class_method': False, 'is_property': False, 'is_public': True, @@ -4153,7 +4114,6 @@ 'full_docstring': '', }), 'id': 'test_package/function_module/one_result', - 'is_abstract_method': False, 'is_class_method': False, 'is_property': False, 'is_public': True, @@ -4173,7 +4133,6 @@ 'full_docstring': '', }), 'id': 'test_package/function_module/opt_pos_only', - 'is_abstract_method': False, 'is_class_method': False, 'is_property': False, 'is_public': True, @@ -4194,7 +4153,6 @@ 'full_docstring': '', }), 'id': 'test_package/function_module/param_position', - 'is_abstract_method': False, 'is_class_method': False, 'is_property': False, 'is_public': True, @@ -4219,7 +4177,6 @@ 'full_docstring': '', }), 'id': 'test_package/function_module/params', - 'is_abstract_method': False, 'is_class_method': False, 'is_property': False, 'is_public': True, @@ -4242,7 +4199,6 @@ 'full_docstring': '', }), 'id': 'test_package/function_module/property_function', - 'is_abstract_method': False, 'is_class_method': False, 'is_property': True, 'is_public': True, @@ -4261,7 +4217,6 @@ 'full_docstring': '', }), 'id': 'test_package/function_module/property_function_infer', - 'is_abstract_method': False, 'is_class_method': False, 'is_property': True, 'is_public': True, @@ -4280,7 +4235,6 @@ 'full_docstring': '', }), 'id': 'test_package/function_module/property_function_params', - 'is_abstract_method': False, 'is_class_method': False, 'is_property': True, 'is_public': True, @@ -4300,7 +4254,6 @@ 'full_docstring': '', }), 'id': 'test_package/function_module/public_no_params_no_result', - 'is_abstract_method': False, 'is_class_method': False, 'is_property': False, 'is_public': True, @@ -4319,7 +4272,6 @@ 'full_docstring': '', }), 'id': 'test_package/function_module/req_name_only', - 'is_abstract_method': False, 'is_class_method': False, 'is_property': False, 'is_public': True, @@ -4340,7 +4292,6 @@ 'full_docstring': '', }), 'id': 'test_package/function_module/special_params', - 'is_abstract_method': False, 'is_class_method': False, 'is_property': False, 'is_public': True, diff --git a/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr b/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr index 5bf7bb7d..facebd4e 100644 --- a/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr +++ b/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr @@ -6,10 +6,7 @@ from abc import ABC from abc import abstractmethod - // TODO Some parameter have no type information. - class AbstractModuleClass( - param - ) sub ABC { + class AbstractModuleClass sub ABC { @PythonName("abstract_property_method") attr abstractPropertyMethod: union // TODO Result type information missing. From 7085ee0c859ae83039dd17550489b67f48db3af5 Mon Sep 17 00:00:00 2001 From: Arsam Date: Fri, 24 Nov 2023 13:47:23 +0100 Subject: [PATCH 051/109] Fixed bugs and adjusted test snapshots --- .../api_analyzer/_ast_visitor.py | 50 +++++++++++-------- tests/data/test_package/abstract_module.py | 3 +- .../__snapshots__/test__get_api.ambr | 5 +- .../__snapshots__/test_generate_stubs.ambr | 4 +- 4 files changed, 33 insertions(+), 29 deletions(-) diff --git a/src/safeds_stubgen/api_analyzer/_ast_visitor.py b/src/safeds_stubgen/api_analyzer/_ast_visitor.py index 7ae3e990..064dea2b 100644 --- a/src/safeds_stubgen/api_analyzer/_ast_visitor.py +++ b/src/safeds_stubgen/api_analyzer/_ast_visitor.py @@ -382,6 +382,16 @@ def _get_types_from_return_stmts(return_stmts: list[mp_nodes.ReturnStmt]) -> lis return_types.sort(key=lambda x: x.name) return return_types + def _infer_type_from_return_stmts(self, func_node: mp_nodes.FuncDef) -> sds_types.AbstractType | None: + func_defn = get_funcdef_definitions(func_node) + return_stmts = find_return_stmts_recursive(func_defn) + if return_stmts: + return_stmt_types = self._get_types_from_return_stmts(return_stmts) + if len(return_stmt_types) >= 2: + return sds_types.TupleType(types=return_stmt_types) + return return_stmt_types[0] + return None + def _create_result(self, node: mp_nodes.FuncDef, function_id: str) -> list[Result]: # __init__ functions aren't supposed to have returns, so we can ignore them if node.name == "__init__": @@ -389,32 +399,28 @@ def _create_result(self, node: mp_nodes.FuncDef, function_id: str) -> list[Resul ret_type = None is_type_inferred = False - if getattr(node, "type", None): + if hasattr(node, "type"): node_type = node.type if node_type is not None and hasattr(node_type, "ret_type"): node_ret_type = node_type.ret_type - else: # pragma: no cover - raise AttributeError("Result has no return type information.") - - if not isinstance(node_ret_type, mp_types.NoneType): - # In Mypy AnyTypes can occur because of different reasons (see TypeOfAny Class) - if (isinstance(node_ret_type, mp_types.AnyType) and - node_ret_type.type_of_any == mp_types.TypeOfAny.unannotated): - # In this case, the "Any" type was given, because there was no annotation, therefore we have to - # either infer the type or set no type at all. To infer the type, we iterate through all return - # statements - func_defn = get_funcdef_definitions(node) - return_stmts = find_return_stmts_recursive(func_defn) - if return_stmts: - is_type_inferred = True - return_stmt_types = self._get_types_from_return_stmts(return_stmts) - if len(return_stmt_types) >= 2: - ret_type = sds_types.TupleType(types=return_stmt_types) - else: - ret_type = return_stmt_types[0] - else: - ret_type = mypy_type_to_abstract_type(node_ret_type) + if not isinstance(node_ret_type, mp_types.NoneType): + # In Mypy AnyType can be set as type because of different reasons (see TypeOfAny + # class-documentation) + if (isinstance(node_ret_type, mp_types.AnyType) and + node_ret_type.type_of_any == mp_types.TypeOfAny.unannotated): + # In this case, the "Any" type was given, because there was no annotation, therefore we have to + # either infer the type or set no type at all. To infer the type, we iterate through all return + # statements + ret_type = self._infer_type_from_return_stmts(node) + is_type_inferred = ret_type is not None + + else: + ret_type = mypy_type_to_abstract_type(node_ret_type) + else: + # Infer type + ret_type = self._infer_type_from_return_stmts(node) + is_type_inferred = ret_type is not None if ret_type is None: return [] diff --git a/tests/data/test_package/abstract_module.py b/tests/data/test_package/abstract_module.py index 67f77afe..92fa3af0 100644 --- a/tests/data/test_package/abstract_module.py +++ b/tests/data/test_package/abstract_module.py @@ -8,8 +8,9 @@ def __init__(self, param): @abstractmethod def abstract_method(self): ... + # Todo Frage: Bei list[str, int], also mehrere elemente, bekommen wir list[Any] @abstractmethod - def abstract_method_params(self, param_1: int, param_2=False) -> list[str, int]: ... + def abstract_method_params(self, param_1: int, param_2=False) -> list[str]: ... @staticmethod @abstractmethod diff --git a/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr b/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr index ebceffcb..bfee344a 100644 --- a/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr +++ b/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr @@ -3469,10 +3469,6 @@ 'type': dict({ 'kind': 'ListType', 'types': list([ - dict({ - 'kind': 'NamedType', - 'name': 'int', - }), dict({ 'kind': 'NamedType', 'name': 'str', @@ -4227,6 +4223,7 @@ 'reexported_by': list([ ]), 'results': list([ + 'test_package/function_module/property_function_infer/result_1', ]), }), dict({ diff --git a/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr b/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr index facebd4e..852752e1 100644 --- a/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr +++ b/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr @@ -17,7 +17,7 @@ fun abstractMethodParams( @PythonName("param_1") param1: Int, @PythonName("param_2") param2: Boolean = False - ) -> result1: List + ) -> result1: List // TODO Result type information missing. @PythonName("abstract_static_method") @@ -179,7 +179,7 @@ @PythonName("property_function_params") attr propertyFunctionParams: String - @PythonName("property_function_infer") attr propertyFunctionInfer + @PythonName("property_function_infer") attr propertyFunctionInfer: String // TODO Result type information missing. @PythonName("public_no_params_no_result") From b7a7730d531cbf1abb788c166ae54d728d878bbd Mon Sep 17 00:00:00 2001 From: Arsam Date: Fri, 24 Nov 2023 14:46:19 +0100 Subject: [PATCH 052/109] Stubs generator: Added @PythonModule annotation for package information, class names will also be converted to camelCase and be checked for keywords, abstract classes won't have inheritance information, add @Pure annotation for functions, fixed bugs and adjusted tests --- .../stubs_generator/_generate_stubs.py | 38 +++++- tests/data/test_package/function_module.py | 18 ++- .../__snapshots__/test__get_api.ambr | 123 +++++++++--------- .../api_analyzer/test__get_api.py | 8 ++ .../__snapshots__/test_generate_stubs.ambr | 74 ++++++++--- 5 files changed, 166 insertions(+), 95 deletions(-) diff --git a/src/safeds_stubgen/stubs_generator/_generate_stubs.py b/src/safeds_stubgen/stubs_generator/_generate_stubs.py index d18a433e..4f4bd5d4 100644 --- a/src/safeds_stubgen/stubs_generator/_generate_stubs.py +++ b/src/safeds_stubgen/stubs_generator/_generate_stubs.py @@ -52,9 +52,11 @@ def generate_stubs(api: API, out_path: Path) -> None: module_text = generator.create_module_string(module) # Each text block we create ends with "\n", therefore, is there is only the package information - # the file would look like this: "package path.to.package\n". With the split we can check if the module - # has enough information, if not, we won't create it in the first place. - if len(module_text.split("\n")) <= 2: + # the file would look like this: "package path.to.myPackage\n" or this: + # '@PythonModule("path.to.my_package")\npackage path.to.myPackage\n'. With the split we check if the module + # has enough information, if not, we won't create it. + splitted_text = module_text.split("\n") + if len(splitted_text) <= 2 or (len(splitted_text) == 3 and splitted_text[1].startswith("package ")): continue # Create module dir @@ -104,7 +106,11 @@ def __init__(self) -> None: def create_module_string(self, module: Module) -> str: # Create package info package_info = module.id.replace("/", ".") - module_text = f"package {package_info}\n" + package_info_camel_case = _convert_snake_to_camel_case(package_info) + module_name_info = "" + if package_info != package_info_camel_case: + module_name_info = f'@PythonModule("{package_info}")\n' + module_text = f"{module_name_info}package {package_info_camel_case}\n" # Create imports qualified_imports = self._create_qualified_imports_string(module.qualified_imports) @@ -165,7 +171,7 @@ def _create_class_string(self, class_: Class, class_indentation: str = "") -> st # Superclasses superclasses = class_.superclasses superclass_info = "" - if superclasses: + if superclasses and not class_.is_abstract: superclass_names = [ self._split_import_id(superclass)[1] for superclass in superclasses @@ -213,10 +219,18 @@ def _create_class_string(self, class_: Class, class_indentation: str = "") -> st constraints_info_inner = f",\n{inner_indentations}".join(constraints) constraints_info = f" where {{\n{inner_indentations}{constraints_info_inner}\n}}" + # Class name - Convert to camelCase and check for keywords + class_name = class_.name + python_name_info = "" + class_name_camel_case = _convert_snake_to_camel_case(class_name) + if class_name_camel_case != class_name: + python_name_info = f"{class_indentation}{self._create_name_annotation(class_name)}\n" + class_name_camel_case = self._replace_if_safeds_keyword(class_name_camel_case) + # Class signature line class_signature = ( - f"{class_indentation}{self._create_todo_msg(class_indentation)}class " - f"{class_.name}{variance_info}{constructor_info}{superclass_info}{constraints_info}" + f"{python_name_info}{class_indentation}{self._create_todo_msg(class_indentation)}class " + f"{class_name_camel_case}{variance_info}{constructor_info}{superclass_info}{constraints_info}" ) # Attributes @@ -330,6 +344,7 @@ def _create_function_string(self, function: Function, indentations: str = "", is # Create string and return return ( f"{self._create_todo_msg(indentations)}" + f"{indentations}@Pure\n" f"{function_name_annotation}" f"{indentations}{static}fun {camel_case_name}({func_params})" f"{result_string}" @@ -410,6 +425,9 @@ def _create_parameter_string( default_value = f"{param_default_value}" else: default_value = f'"{param_default_value}"' + elif isinstance(param_default_value, bool): + # Bool values have to be written in lower case + default_value = "true" if param_default_value else "false" else: default_value = param_default_value param_value = f" = {default_value}" @@ -422,6 +440,12 @@ def _create_parameter_string( # Parameter type param_type = self._create_type_string(parameter_type_data) type_string = f": {param_type}" if param_type else "" + elif assigned_by == ParameterAssignment.POSITIONAL_VARARG: + # Todo Frage: Wenn *args und **kwargs keinen Typ haben und auf Any gesetzt werden trotzdem + # "// TODO ..." erstellen? + type_string = ": List" + elif assigned_by == ParameterAssignment.NAMED_VARARG: + type_string = ": Map" else: self._current_todo_msgs.add("param without type") diff --git a/tests/data/test_package/function_module.py b/tests/data/test_package/function_module.py index f2581b70..f3a41609 100644 --- a/tests/data/test_package/function_module.py +++ b/tests/data/test_package/function_module.py @@ -73,7 +73,6 @@ def opt_pos_only(required, optional=1, /): ... def req_name_only(*, required, optional=1): ... -# Todo Frage: Welche type hints sollten hier erstellt werden? Aktuell werden gar keine erstellt def arg(*args, **kwargs): ... @@ -89,14 +88,13 @@ def multiple_results() -> tuple[str, int, bool, FunctionModuleClassA]: ... def callable_type(param: Callable[[str], tuple[int, str]]) -> Callable[[int, int], int]: ... -@property -def property_function(): ... +class FunctionModulePropertiesClass: + @property + def property_function(self): ... + @property + def property_function_params(self) -> str: ... -@property -def property_function_params() -> str: ... - - -@property -def property_function_infer(): - return "some string" + @property + def property_function_infer(self): + return "some string" diff --git a/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr b/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr index bfee344a..423c72bf 100644 --- a/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr +++ b/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr @@ -939,6 +939,69 @@ }), ]) # --- +# name: test_class_methods_FunctionModulePropertiesClass + list([ + dict({ + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_package/function_module/FunctionModulePropertiesClass/property_function', + 'is_class_method': False, + 'is_property': True, + 'is_public': True, + 'is_static': False, + 'name': 'property_function', + 'parameters': list([ + 'test_package/function_module/FunctionModulePropertiesClass/property_function/self', + ]), + 'reexported_by': list([ + ]), + 'results': list([ + ]), + }), + dict({ + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_package/function_module/FunctionModulePropertiesClass/property_function_infer', + 'is_class_method': False, + 'is_property': True, + 'is_public': True, + 'is_static': False, + 'name': 'property_function_infer', + 'parameters': list([ + 'test_package/function_module/FunctionModulePropertiesClass/property_function_infer/self', + ]), + 'reexported_by': list([ + ]), + 'results': list([ + 'test_package/function_module/FunctionModulePropertiesClass/property_function_infer/result_1', + ]), + }), + dict({ + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_package/function_module/FunctionModulePropertiesClass/property_function_params', + 'is_class_method': False, + 'is_property': True, + 'is_public': True, + 'is_static': False, + 'name': 'property_function_params', + 'parameters': list([ + 'test_package/function_module/FunctionModulePropertiesClass/property_function_params/self', + ]), + 'reexported_by': list([ + ]), + 'results': list([ + 'test_package/function_module/FunctionModulePropertiesClass/property_function_params/result_1', + ]), + }), + ]) +# --- # name: test_class_methods_GoogleDocstringClass list([ dict({ @@ -3600,7 +3663,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/property_function_infer/result_1', + 'id': 'test_package/function_module/FunctionModulePropertiesClass/property_function_infer/result_1', 'is_type_inferred': True, 'name': 'result_1', 'type': dict({ @@ -3617,7 +3680,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/property_function_params/result_1', + 'id': 'test_package/function_module/FunctionModulePropertiesClass/property_function_params/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ @@ -4189,62 +4252,6 @@ 'results': list([ ]), }), - dict({ - 'docstring': dict({ - 'description': '', - 'full_docstring': '', - }), - 'id': 'test_package/function_module/property_function', - 'is_class_method': False, - 'is_property': True, - 'is_public': True, - 'is_static': False, - 'name': 'property_function', - 'parameters': list([ - ]), - 'reexported_by': list([ - ]), - 'results': list([ - ]), - }), - dict({ - 'docstring': dict({ - 'description': '', - 'full_docstring': '', - }), - 'id': 'test_package/function_module/property_function_infer', - 'is_class_method': False, - 'is_property': True, - 'is_public': True, - 'is_static': False, - 'name': 'property_function_infer', - 'parameters': list([ - ]), - 'reexported_by': list([ - ]), - 'results': list([ - 'test_package/function_module/property_function_infer/result_1', - ]), - }), - dict({ - 'docstring': dict({ - 'description': '', - 'full_docstring': '', - }), - 'id': 'test_package/function_module/property_function_params', - 'is_class_method': False, - 'is_property': True, - 'is_public': True, - 'is_static': False, - 'name': 'property_function_params', - 'parameters': list([ - ]), - 'reexported_by': list([ - ]), - 'results': list([ - 'test_package/function_module/property_function_params/result_1', - ]), - }), dict({ 'docstring': dict({ 'description': '', diff --git a/tests/safeds_stubgen/api_analyzer/test__get_api.py b/tests/safeds_stubgen/api_analyzer/test__get_api.py index b923237a..7bde682b 100644 --- a/tests/safeds_stubgen/api_analyzer/test__get_api.py +++ b/tests/safeds_stubgen/api_analyzer/test__get_api.py @@ -433,6 +433,11 @@ def test_class_methods_InferMyTypes(snapshot: SnapshotAssertion) -> None: # noq assert class_methods_data == snapshot +def test_class_methods_FunctionModulePropertiesClass(snapshot: SnapshotAssertion) -> None: # noqa: N802 + class_methods_data = get_class_methods_data("function_module", "FunctionModulePropertiesClass") + assert class_methods_data == snapshot + + def test_class_methods_ClassModuleNestedClassE(snapshot: SnapshotAssertion) -> None: # noqa: N802 class_methods_data = get_class_methods_data("class_module", "ClassModuleNestedClassE") assert class_methods_data == snapshot @@ -800,6 +805,7 @@ def test_function_results_function_module_property_function(snapshot: SnapshotAs function_result_data = get_function_result_data( module_name="function_module", function_name="property_function", + parent_class_name="FunctionModulePropertiesClass", ) assert function_result_data == snapshot @@ -808,6 +814,7 @@ def test_function_results_function_module_property_function_params(snapshot: Sna function_result_data = get_function_result_data( module_name="function_module", function_name="property_function_params", + parent_class_name="FunctionModulePropertiesClass", ) assert function_result_data == snapshot @@ -816,6 +823,7 @@ def test_function_results_function_module_property_function_infer(snapshot: Snap function_result_data = get_function_result_data( module_name="function_module", function_name="property_function_infer", + parent_class_name="FunctionModulePropertiesClass", ) assert function_result_data == snapshot diff --git a/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr b/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr index 852752e1..8148efbb 100644 --- a/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr +++ b/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr @@ -1,28 +1,33 @@ # serializer version: 1 # name: test_abstract_creation ''' - package test_package.abstract_module + @PythonModule("test_package.abstract_module") + package testPackage.abstractModule from abc import ABC from abc import abstractmethod - class AbstractModuleClass sub ABC { + class AbstractModuleClass { @PythonName("abstract_property_method") attr abstractPropertyMethod: union // TODO Result type information missing. + @Pure @PythonName("abstract_method") fun abstractMethod() + @Pure @PythonName("abstract_method_params") fun abstractMethodParams( @PythonName("param_1") param1: Int, - @PythonName("param_2") param2: Boolean = False + @PythonName("param_2") param2: Boolean = false ) -> result1: List // TODO Result type information missing. + @Pure @PythonName("abstract_static_method") static fun abstractStaticMethod() + @Pure @PythonName("abstract_static_method_params") static fun abstractStaticMethodParams( param: Float @@ -33,7 +38,8 @@ # --- # name: test_class_attribute_creation ''' - package test_package.attribute_module + @PythonModule("test_package.attribute_module") + package testPackage.attributeModule class AttributesClassA() @@ -99,7 +105,8 @@ # --- # name: test_class_creation ''' - package test_package.class_module + @PythonModule("test_package.class_module") + package testPackage.classModule class ClassModuleEmptyClassA() @@ -108,6 +115,7 @@ b: ClassModuleEmptyClassA? ) sub ClassModuleEmptyClassA { // TODO Result type information missing. + @Pure fun f() } @@ -119,6 +127,7 @@ static attr attr2: Int // TODO Result type information missing. + @Pure fun f1() } @@ -127,9 +136,11 @@ @PythonName("nested_attr_1") static attr nestedAttr1: Nothing? - class _ClassModulePrivateDoubleNestedClassF() + @PythonName("_ClassModulePrivateDoubleNestedClassF") + class ClassModulePrivateDoubleNestedClassF() // TODO Result type information missing. + @Pure @PythonName("class_e_func") fun classEFunc() } @@ -139,7 +150,8 @@ # --- # name: test_enum_creation ''' - package test_package.enum_module + @PythonModule("test_package.enum_module") + package testPackage.enumModule from another_path.another_module import AnotherClass as _AcImportAlias @@ -171,21 +183,18 @@ # --- # name: test_function_creation ''' - package test_package.function_module + @PythonModule("test_package.function_module") + package testPackage.functionModule from typing import Callable - @PythonName("property_function") attr propertyFunction - - @PythonName("property_function_params") attr propertyFunctionParams: String - - @PythonName("property_function_infer") attr propertyFunctionInfer: String - // TODO Result type information missing. + @Pure @PythonName("public_no_params_no_result") fun publicNoParamsNoResult() // TODO Result type information missing. + @Pure fun params( i: Int, `union`: union, @@ -196,6 +205,7 @@ // TODO List type has to many type arguments. // TODO Result type information missing. // TODO Safe-DS does not support tuple types. + @Pure @PythonName("illegal_params") fun illegalParams( lst: List, @@ -205,6 +215,7 @@ ) // TODO Result type information missing. + @Pure @PythonName("special_params") fun specialParams( @PythonName("none_union") noneUnion: Nothing?, @@ -220,6 +231,7 @@ // TODO Result type information missing. // TODO Safe-DS does not support required but name only parameter assignments. // TODO Some parameter have no type information. + @Pure @PythonName("param_position") fun paramPosition( self, @@ -233,6 +245,7 @@ // TODO Result type information missing. // TODO Safe-DS does not support optional but position only parameter assignments. // TODO Some parameter have no type information. + @Pure @PythonName("opt_pos_only") fun optPosOnly( required, @@ -242,6 +255,7 @@ // TODO Result type information missing. // TODO Safe-DS does not support required but name only parameter assignments. // TODO Some parameter have no type information. + @Pure @PythonName("req_name_only") fun reqNameOnly( required, @@ -250,26 +264,30 @@ // TODO Result type information missing. // TODO Safe-DS does not support variadic parameters. - // TODO Some parameter have no type information. + @Pure fun arg( - args, - kwargs + args: List, + kwargs: Map ) // TODO Result type information missing. // TODO Safe-DS does not support variadic parameters. + @Pure @PythonName("args_type") fun argsType( args: List, kwargs: Map ) + @Pure @PythonName("one_result") fun oneResult() -> result1: Int + @Pure @PythonName("multiple_results") fun multipleResults() -> (result1: String, result2: Int, result3: Boolean, result4: FunctionModuleClassA) + @Pure @PythonName("callable_type") fun callableType( param: (a: String) -> (b: Int, c: String) @@ -284,22 +302,26 @@ class FunctionModuleClassC() { class FunctionModuleClassD() + @Pure @PythonName("nested_class_function") fun nestedClassFunction( param1: Int ) -> result1: Boolean } + @Pure @PythonName("instance_method") fun instanceMethod( a: FunctionModuleClassA ) -> result1: FunctionModuleClassA // TODO Result type information missing. + @Pure @PythonName("static_method") static fun staticMethod() // TODO Result type information missing. + @Pure @PythonName("static_method_params") static fun staticMethodParams( @PythonName("param_1") param1: Int @@ -307,21 +329,30 @@ // TODO Result type information missing. // TODO Safe-DS does not support class methods. + @Pure @PythonName("class_method") static fun classMethod() // TODO Safe-DS does not support class methods. + @Pure @PythonName("class_method_params") static fun classMethodParams( @PythonName("param_1") param1: Int ) -> result1: Boolean } + class FunctionModulePropertiesClass() { + @PythonName("property_function") attr propertyFunction + @PythonName("property_function_params") attr propertyFunctionParams: String + @PythonName("property_function_infer") attr propertyFunctionInfer: String + } + ''' # --- # name: test_import_creation ''' - package test_package.import_module + @PythonModule("test_package.import_module") + package testPackage.importModule import mypy as `static` @@ -331,7 +362,8 @@ # --- # name: test_type_inference ''' - package test_package.infer_types_module + @PythonModule("test_package.infer_types_module") + package testPackage.inferTypesModule class InferMyTypes( @PythonName("init_param") initParam: Int = 1 @@ -342,6 +374,7 @@ @PythonName("init_infer") attr initInfer + @Pure @PythonName("infer_function") static fun inferFunction( @PythonName("infer_param") inferParam: Int = 1, @@ -353,7 +386,8 @@ # --- # name: test_variance_creation ''' - package test_package.variance_module + @PythonModule("test_package.variance_module") + package testPackage.varianceModule from typing import Generic from typing import TypeVar From 6466dfb9538d0fbedf6998467d235500cb94a184 Mon Sep 17 00:00:00 2001 From: Arsam Date: Mon, 27 Nov 2023 21:19:55 +0100 Subject: [PATCH 053/109] AST Visitor: Parameter can have callables as type, fixed representation for multiple result types, added better type inference for results & added qname field for NamedTypes --- .../api_analyzer/_ast_visitor.py | 238 +++++++++++------- src/safeds_stubgen/api_analyzer/_types.py | 7 +- .../stubs_generator/_generate_stubs.py | 2 +- tests/data/test_package/attribute_module.py | 9 + tests/data/test_package/function_module.py | 20 +- tests/data/test_package/infer_types_module.py | 4 +- 6 files changed, 185 insertions(+), 95 deletions(-) diff --git a/src/safeds_stubgen/api_analyzer/_ast_visitor.py b/src/safeds_stubgen/api_analyzer/_ast_visitor.py index 064dea2b..159c509f 100644 --- a/src/safeds_stubgen/api_analyzer/_ast_visitor.py +++ b/src/safeds_stubgen/api_analyzer/_ast_visitor.py @@ -358,35 +358,41 @@ def leave_assignmentstmt(self, _: mp_nodes.AssignmentStmt) -> None: # #### Result utilities - @staticmethod - def _get_types_from_return_stmts(return_stmts: list[mp_nodes.ReturnStmt]) -> list[sds_types.AbstractType]: - types = set() - for return_stmt in return_stmts: - expr = return_stmt.expr - if isinstance(expr, mp_nodes.NameExpr): - if expr.name in {"False", "True"}: - types.add(sds_types.NamedType(name="bool")) - else: - types.add(sds_types.NamedType(name=expr.name)) - elif isinstance(expr, mp_nodes.IntExpr): - types.add(sds_types.NamedType(name="int")) - elif isinstance(expr, mp_nodes.FloatExpr): - types.add(sds_types.NamedType(name="float")) - elif isinstance(expr, mp_nodes.StrExpr): - types.add(sds_types.NamedType(name="str")) - else: # pragma: no cover - raise TypeError("Unexpected expression type for return type.") - - # We have to sort the list for the snapshot tests - return_types = list(types) - return_types.sort(key=lambda x: x.name) - return return_types + def _mypy_expression_to_sds_type(self, expr: mp_nodes.Expression) -> sds_types.NamedType | sds_types.TupleType: + if isinstance(expr, mp_nodes.NameExpr): + if expr.name in {"False", "True"}: + return sds_types.NamedType(name="bool") + else: + return sds_types.NamedType(name=expr.name) + elif isinstance(expr, mp_nodes.IntExpr): + return sds_types.NamedType(name="int") + elif isinstance(expr, mp_nodes.FloatExpr): + return sds_types.NamedType(name="float") + elif isinstance(expr, mp_nodes.StrExpr): + return sds_types.NamedType(name="str") + elif isinstance(expr, mp_nodes.TupleExpr): + return sds_types.TupleType(types=[ + self._mypy_expression_to_sds_type(item) + for item in expr.items + ]) + else: # pragma: no cover + raise TypeError("Unexpected expression type for return type.") - def _infer_type_from_return_stmts(self, func_node: mp_nodes.FuncDef) -> sds_types.AbstractType | None: + def _infer_type_from_return_stmts( + self, func_node: mp_nodes.FuncDef + ) -> sds_types.NamedType | sds_types.TupleType | None: func_defn = get_funcdef_definitions(func_node) return_stmts = find_return_stmts_recursive(func_defn) if return_stmts: - return_stmt_types = self._get_types_from_return_stmts(return_stmts) + types = { + self._mypy_expression_to_sds_type(return_stmt.expr) + for return_stmt in return_stmts + } + + # We have to sort the list for the snapshot tests + return_stmt_types = list(types) + return_stmt_types.sort(key=lambda x: x.__hash__()) + if len(return_stmt_types) >= 2: return sds_types.TupleType(types=return_stmt_types) return return_stmt_types[0] @@ -425,24 +431,58 @@ def _create_result(self, node: mp_nodes.FuncDef, function_id: str) -> list[Resul if ret_type is None: return [] - results = [] - docstring = self.docstring_parser.get_result_documentation(node) - - # Results that are tuples will be split into multiple results - ret_types = ret_type.types if isinstance(ret_type, sds_types.TupleType) else [ret_type] - for i, type_ in enumerate(ret_types): - name = f"result_{i + 1}" - results.append( - Result( - id=f"{function_id}/{name}", - type=type_, - is_type_inferred=is_type_inferred, - name=name, - docstring=docstring, - ), - ) + # We create a two-dimensional array for results, b/c tuples are counted as multiple results, but normal returns + # have to be grouped as one Union. + # For example, if a function has the following returns: "return 42" and "return True, 1.2" we would have to + # group the integer and boolean as result_1: Union[int, bool] and the float number as + # result_2: Union[float, None]. + result_array: list[list] = [] + if is_type_inferred and isinstance(ret_type, sds_types.TupleType): + type_: sds_types.NamedType | sds_types.TupleType + for type_ in ret_type.types: + if isinstance(type_, sds_types.NamedType): + if result_array: + result_array[0].append(type_) + else: + result_array.append([type_]) + else: + for i, type__ in enumerate(type_.types): + if len(result_array) > i: + result_array[i].append(type__) + else: + result_array.append([type__]) + + results = [] + docstring = self.docstring_parser.get_result_documentation(node) + for i, result_list in enumerate(result_array): + result_count = len(result_list) + if result_count == 0: + break + elif result_count == 1: + result_type = result_list[0] + else: + result_type = sds_types.UnionType(result_list) + + name = f"result_{i + 1}" + results.append( + Result( + id=f"{function_id}/{name}", + type=result_type, + is_type_inferred=is_type_inferred, + name=name, + docstring=docstring, + ) + ) + + return results - return results + return [Result( + id=f"{function_id}/result_1", + type=ret_type, + is_type_inferred=is_type_inferred, + name="result_1", + docstring=self.docstring_parser.get_result_documentation(node), + )] # #### Attribute utilities @@ -589,6 +629,60 @@ def _create_attribute( # #### Parameter utilities + def _get_default_parameter_value_and_type( + self, initializer: mp_nodes.Expression, infer_arg_type: bool = False + ) -> tuple[None | str | float | int | bool | NoneType, None | sds_types.NamedType]: + # Get default value information + default_value = None + arg_type = None + + if hasattr(initializer, "value"): + value = initializer.value + elif isinstance(initializer, mp_nodes.NameExpr): + if initializer.name == "None": + value = None + elif initializer.name == "True": + value = True + elif initializer.name == "False": + value = False + else: + # Check if callee path is in our package and create type information + if self._check_if_qname_in_package(initializer.fullname): + default_value = initializer.name + if infer_arg_type: + arg_type = sds_types.NamedType(initializer.name, initializer.fullname) + + return default_value, arg_type + + elif isinstance(initializer, mp_nodes.CallExpr): + # Check if callee path is in our package and create type information + # Todo Frage: Wie stellen wir Call Expressions wie SomeClass() als type dar? Mit oder ohne "()" + if self._check_if_qname_in_package(initializer.callee.fullname): + default_value = f"{initializer.callee.name}()" + if infer_arg_type: + arg_type = sds_types.NamedType(initializer.callee.name, initializer.callee.fullname) + + return default_value, arg_type + + else: # pragma: no cover + raise ValueError("No value found for parameter") + + if type(value) in {str, bool, int, float, NoneType}: + default_value = value + + # Infer the type, if no type hint was found + if infer_arg_type: + value_type_name = { + str: "str", + bool: "bool", + int: "int", + float: "float", + NoneType: "None", + }[type(value)] + arg_type = sds_types.NamedType(name=value_type_name) + + return default_value, arg_type + def _parse_parameter_data(self, node: mp_nodes.FuncDef, function_id: str) -> list[Parameter]: arguments: list[Parameter] = [] @@ -616,50 +710,20 @@ def _parse_parameter_data(self, node: mp_nodes.FuncDef, function_id: str) -> lis elif type_annotation is not None: arg_type = mypy_type_to_abstract_type(mypy_type) - # Get default value information - default_value = None - is_optional = False + # Get default value and infer type information initializer = argument.initializer + default_value = None if initializer is not None: - if not hasattr(initializer, "value"): - if isinstance(initializer, mp_nodes.CallExpr): - # Special case when the default is a call expression, we set the value to tuple, so that it will - # be ignored later on when creating the default_value - value = tuple - elif hasattr(initializer, "name"): - if initializer.name == "None": - value = None - elif initializer.name == "True": - value = True - elif initializer.name == "False": - value = False - else: - # Todo Frage: We don't support other classes as type hints for parameters - # (Wenn z.B. ein Parameter eine Klasse als default value hat) - # Thus we set the value to tuple, so that it will be ignored later on when creating the - # default_value - value = tuple - else: # pragma: no cover - raise ValueError("No value found for parameter") - else: - value = initializer.value - - if type(value) in {str, bool, int, float, NoneType}: - default_value = value - is_optional = True - - # Infer the type, if no type hint was found - if arg_type is None: - value_type_name = { - str: "str", - bool: "bool", - int: "int", - float: "float", - NoneType: "None", - }[type(value)] - arg_type = sds_types.NamedType(name=value_type_name) - is_type_inferred = True + infer_arg_type = arg_type is None + default_value, inferred_arg_type = self._get_default_parameter_value_and_type( + initializer=initializer, + infer_arg_type=infer_arg_type + ) + if infer_arg_type: + arg_type = inferred_arg_type + is_type_inferred = True + # Create parameter docstring parent = self.__declaration_stack[-1] docstring = self.docstring_parser.get_parameter_documentation( function_node=node, @@ -668,11 +732,12 @@ def _parse_parameter_data(self, node: mp_nodes.FuncDef, function_id: str) -> lis parent_class=parent if isinstance(parent, Class) else None, ) + # Create parameter object arguments.append( Parameter( id=f"{function_id}/{arg_name}", name=arg_name, - is_optional=is_optional, + is_optional=default_value is not None, default_value=default_value, assigned_by=arg_kind, docstring=docstring, @@ -727,6 +792,11 @@ def _add_reexports(self, module: Module) -> None: # #### Misc. utilities + # Todo This check is currently too weak, we should try to get the path to the package from the api object, not + # just the package name + def _check_if_qname_in_package(self, qname: str) -> bool: + return self.api.package in qname + def _create_module_id(self, qname: str) -> str: """Create an ID for the module object. diff --git a/src/safeds_stubgen/api_analyzer/_types.py b/src/safeds_stubgen/api_analyzer/_types.py index 714edce0..8a3f8041 100644 --- a/src/safeds_stubgen/api_analyzer/_types.py +++ b/src/safeds_stubgen/api_analyzer/_types.py @@ -45,17 +45,18 @@ def to_dict(self) -> dict[str, Any]: @dataclass(frozen=True) class NamedType(AbstractType): name: str + qname: str = "" @classmethod def from_dict(cls, d: dict[str, Any]) -> NamedType: return NamedType(d["name"]) @classmethod - def from_string(cls, string: str) -> NamedType: - return NamedType(string) + def from_string(cls, name: str, qname: str = "") -> NamedType: + return NamedType(name, qname) def to_dict(self) -> dict[str, str]: - return {"kind": self.__class__.__name__, "name": self.name} + return {"kind": self.__class__.__name__, "name": self.name, "qname": self.qname} @dataclass(frozen=True) diff --git a/src/safeds_stubgen/stubs_generator/_generate_stubs.py b/src/safeds_stubgen/stubs_generator/_generate_stubs.py index 4f4bd5d4..2d95f83b 100644 --- a/src/safeds_stubgen/stubs_generator/_generate_stubs.py +++ b/src/safeds_stubgen/stubs_generator/_generate_stubs.py @@ -442,7 +442,7 @@ def _create_parameter_string( type_string = f": {param_type}" if param_type else "" elif assigned_by == ParameterAssignment.POSITIONAL_VARARG: # Todo Frage: Wenn *args und **kwargs keinen Typ haben und auf Any gesetzt werden trotzdem - # "// TODO ..." erstellen? + # "param without type" msg erstellen? type_string = ": List" elif assigned_by == ParameterAssignment.NAMED_VARARG: type_string = ": Map" diff --git a/tests/data/test_package/attribute_module.py b/tests/data/test_package/attribute_module.py index 885e1d56..b1d6bdc9 100644 --- a/tests/data/test_package/attribute_module.py +++ b/tests/data/test_package/attribute_module.py @@ -1,3 +1,6 @@ +from typing import Optional, Final, Literal + + class AttributesClassA: ... @@ -10,6 +13,7 @@ class AttributesClassB: _no_type_hint_private = 1 object_attr: AttributesClassA + callexpr_attr: AttributesClassA() tuple_attr_1: tuple tuple_attr_2: tuple[str | int] @@ -29,6 +33,11 @@ class AttributesClassB: flaot_attr: float int_or_bool_attr: int | bool str_attr_with_none_value: str = None + set_: set + + optional: Optional[int] + final: Final[str] = "Value" + literal: Literal["Some String"] multi_attr_1, _multi_attr_2_private = (123456, "I am a String") multi_attr_3 = _multi_attr_4_private = ["I am some", "kind of list"] diff --git a/tests/data/test_package/function_module.py b/tests/data/test_package/function_module.py index f3a41609..1371ca8d 100644 --- a/tests/data/test_package/function_module.py +++ b/tests/data/test_package/function_module.py @@ -1,4 +1,4 @@ -from typing import Callable +from typing import Callable, Optional, Literal class FunctionModuleClassA: @@ -37,10 +37,20 @@ def public_no_params_no_result(): ... def params( - i: int, - union: int | bool, - lst: list[int], + integer: int, + boolean: bool, + float_: 1.2, + none: None, + string: str, obj: FunctionModuleClassA, + callexpr: FunctionModuleClassA(), + union: int | bool, + list_: list[int], + dictionary: dict[str, int | float], + set_: set[str], + optional: Optional[int], + tuple_: tuple[int, str, bool], + literal: Literal["Some String"] ): ... @@ -64,7 +74,7 @@ def special_params( ): ... -def param_position(self, a, /, b: bool, c=1, *, d=FunctionModuleClassA(), e: int = 1): ... +def param_position(self, a, /, b: bool, c=FunctionModuleClassA, *, d=FunctionModuleClassA(), e: int = 1): ... def opt_pos_only(required, optional=1, /): ... diff --git a/tests/data/test_package/infer_types_module.py b/tests/data/test_package/infer_types_module.py index b5e67caf..3a6b0c1e 100644 --- a/tests/data/test_package/infer_types_module.py +++ b/tests/data/test_package/infer_types_module.py @@ -7,7 +7,7 @@ def __init__(self, init_param=1): @staticmethod def infer_function(infer_param=1, infer_param_2: int = "Something"): if infer_param_2: - return False + return False, 12 elif infer_param: if infer_param: return 12 @@ -23,7 +23,7 @@ def infer_function(infer_param=1, infer_param_2: int = "Something"): while infer_param_2: if infer_param_2: - return 1.23 + return 1.23, 1.22, 1.21 else: infer_param_2 = 0 From 4aea41ee5264370babe5d82d868e383689a5e031 Mon Sep 17 00:00:00 2001 From: Arsam Date: Mon, 27 Nov 2023 22:17:56 +0100 Subject: [PATCH 054/109] Added handling for final type attributes and UpperCamelCase stub names for classes. Adjusted test snapshots and added tests --- .../api_analyzer/_ast_visitor.py | 2 +- .../api_analyzer/_mypy_helpers.py | 18 +- .../stubs_generator/_generate_stubs.py | 17 +- tests/data/test_package/attribute_module.py | 2 + .../__snapshots__/test_main.ambr | 19 + .../__snapshots__/test__get_api.ambr | 672 ++++++++++++++++-- .../safeds_stubgen/api_analyzer/test_types.py | 78 +- .../__snapshots__/test_generate_stubs.ambr | 45 +- 8 files changed, 738 insertions(+), 115 deletions(-) diff --git a/src/safeds_stubgen/api_analyzer/_ast_visitor.py b/src/safeds_stubgen/api_analyzer/_ast_visitor.py index 159c509f..172f1700 100644 --- a/src/safeds_stubgen/api_analyzer/_ast_visitor.py +++ b/src/safeds_stubgen/api_analyzer/_ast_visitor.py @@ -605,7 +605,7 @@ def _create_attribute( type_ = None if attribute_type is not None: - type_ = mypy_type_to_abstract_type(attribute_type) + type_ = mypy_type_to_abstract_type(attribute_type, unanalyzed_type) # Get docstring parent = self.__declaration_stack[-1] diff --git a/src/safeds_stubgen/api_analyzer/_mypy_helpers.py b/src/safeds_stubgen/api_analyzer/_mypy_helpers.py index da16b14b..3e9b4186 100644 --- a/src/safeds_stubgen/api_analyzer/_mypy_helpers.py +++ b/src/safeds_stubgen/api_analyzer/_mypy_helpers.py @@ -31,9 +31,23 @@ def get_mypyfile_definitions(node: MypyFile) -> list: return node.defs -def mypy_type_to_abstract_type(mypy_type: Instance | ProperType | MypyType) -> AbstractType: +def mypy_type_to_abstract_type( + mypy_type: Instance | ProperType | MypyType, + unanalyzed_type: mp_types.Type | None = None +) -> AbstractType: + + # Final type + if unanalyzed_type is not None and hasattr(unanalyzed_type, "name") and unanalyzed_type.name == "Final": + types = [ + mypy_type_to_abstract_type(arg) + for arg in unanalyzed_type.args + ] + if len(types) == 1: + return sds_types.FinalType(type_=types[0]) + return sds_types.FinalType(type_=sds_types.UnionType(types=types)) + # Iterable mypy types - if isinstance(mypy_type, mp_types.TupleType): + elif isinstance(mypy_type, mp_types.TupleType): return sds_types.TupleType(types=[ mypy_type_to_abstract_type(item) for item in mypy_type.items diff --git a/src/safeds_stubgen/stubs_generator/_generate_stubs.py b/src/safeds_stubgen/stubs_generator/_generate_stubs.py index 2d95f83b..9f8c92c5 100644 --- a/src/safeds_stubgen/stubs_generator/_generate_stubs.py +++ b/src/safeds_stubgen/stubs_generator/_generate_stubs.py @@ -71,7 +71,7 @@ def generate_stubs(api: API, out_path: Path) -> None: f.write(module_text) -def _convert_snake_to_camel_case(name: str) -> str: +def _convert_snake_to_camel_case(name: str, is_class_name: bool = False) -> str: if name == "_": return name @@ -86,6 +86,16 @@ def _convert_snake_to_camel_case(name: str) -> str: # Remove underscores and join in camelCase name_parts = cleaned_name.split("_") + + # UpperCamelCase for class names + if is_class_name: + return "".join( + part[0].upper() + part[1:] + for part in name_parts + if part + ) + + # Normal camelCase for everything else return name_parts[0] + "".join( part[0].upper() + part[1:] for part in name_parts[1:] @@ -222,7 +232,7 @@ def _create_class_string(self, class_: Class, class_indentation: str = "") -> st # Class name - Convert to camelCase and check for keywords class_name = class_.name python_name_info = "" - class_name_camel_case = _convert_snake_to_camel_case(class_name) + class_name_camel_case = _convert_snake_to_camel_case(class_name, is_class_name=True) if class_name_camel_case != class_name: python_name_info = f"{class_indentation}{self._create_name_annotation(class_name)}\n" class_name_camel_case = self._replace_if_safeds_keyword(class_name_camel_case) @@ -569,7 +579,8 @@ def _create_type_string(self, type_data: dict | None) -> str: case _: return name elif kind == "FinalType": - return self._create_type_string(type_data) + # Todo Frage: How are final types to be depicted? + return self._create_type_string(type_data["type"]) elif kind == "CallableType": name_generator = self._callable_type_name_generator() diff --git a/tests/data/test_package/attribute_module.py b/tests/data/test_package/attribute_module.py index b1d6bdc9..fbd616f9 100644 --- a/tests/data/test_package/attribute_module.py +++ b/tests/data/test_package/attribute_module.py @@ -37,6 +37,8 @@ class AttributesClassB: optional: Optional[int] final: Final[str] = "Value" + finals: Final[str, int] = "Value" + final_union: Final[str | int] = "Value" literal: Literal["Some String"] multi_attr_1, _multi_attr_2_private = (123456, "I am a String") diff --git a/tests/safeds_stubgen/__snapshots__/test_main.ambr b/tests/safeds_stubgen/__snapshots__/test_main.ambr index 6b5a8515..15e71567 100644 --- a/tests/safeds_stubgen/__snapshots__/test_main.ambr +++ b/tests/safeds_stubgen/__snapshots__/test_main.ambr @@ -16,6 +16,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'float', + 'qname': '', }), }), dict({ @@ -32,6 +33,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'int', + 'qname': '', }), }), dict({ @@ -48,6 +50,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'bool', + 'qname': '', }), }), dict({ @@ -64,6 +67,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'int', + 'qname': '', }), }), dict({ @@ -80,6 +84,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'int', + 'qname': '', }), }), dict({ @@ -96,6 +101,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'int', + 'qname': '', }), }), ]), @@ -569,6 +575,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'int', + 'qname': '', }), }), dict({ @@ -628,6 +635,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'AnotherClass', + 'qname': '', }), }), dict({ @@ -645,6 +653,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'bool', + 'qname': '', }), }), dict({ @@ -704,6 +713,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'str', + 'qname': '', }), }), dict({ @@ -724,10 +734,12 @@ dict({ 'kind': 'NamedType', 'name': 'AnotherClass', + 'qname': '', }), dict({ 'kind': 'NamedType', 'name': 'None', + 'qname': '', }), ]), }), @@ -751,10 +763,12 @@ dict({ 'kind': 'NamedType', 'name': 'bool', + 'qname': '', }), dict({ 'kind': 'NamedType', 'name': 'None', + 'qname': '', }), ]), }), @@ -772,6 +786,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'AnotherClass', + 'qname': '', }), }), dict({ @@ -788,14 +803,17 @@ dict({ 'kind': 'NamedType', 'name': 'AnotherClass', + 'qname': '', }), dict({ 'kind': 'NamedType', 'name': 'AnotherClass', + 'qname': '', }), dict({ 'kind': 'NamedType', 'name': 'AnotherClass', + 'qname': '', }), ]), }), @@ -811,6 +829,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'AnotherClass', + 'qname': '', }), }), ]), diff --git a/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr b/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr index 423c72bf..f4d2d85e 100644 --- a/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr +++ b/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr @@ -15,6 +15,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'str', + 'qname': '', }), }), dict({ @@ -34,6 +35,7 @@ dict({ 'kind': 'NamedType', 'name': 'str', + 'qname': '', }), ]), }), @@ -52,6 +54,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'int', + 'qname': '', }), }), dict({ @@ -68,6 +71,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'int', + 'qname': '', }), }), dict({ @@ -84,6 +88,24 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'bool', + 'qname': '', + }), + }), + dict({ + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_package/attribute_module/AttributesClassB/callexpr_attr', + 'is_public': True, + 'is_static': True, + 'is_type_inferred': False, + 'name': 'callexpr_attr', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'Any', + 'qname': '', }), }), dict({ @@ -101,11 +123,13 @@ 'key_type': dict({ 'kind': 'NamedType', 'name': 'Any', + 'qname': '', }), 'kind': 'DictType', 'value_type': dict({ 'kind': 'NamedType', 'name': 'Any', + 'qname': '', }), }), }), @@ -124,11 +148,13 @@ 'key_type': dict({ 'kind': 'NamedType', 'name': 'str', + 'qname': '', }), 'kind': 'DictType', 'value_type': dict({ 'kind': 'NamedType', 'name': 'int', + 'qname': '', }), }), }), @@ -150,10 +176,12 @@ dict({ 'kind': 'NamedType', 'name': 'str', + 'qname': '', }), dict({ 'kind': 'NamedType', 'name': 'int', + 'qname': '', }), ]), }), @@ -164,10 +192,92 @@ dict({ 'kind': 'NamedType', 'name': 'None', + 'qname': '', }), dict({ 'kind': 'NamedType', 'name': 'AttributesClassA', + 'qname': '', + }), + ]), + }), + }), + }), + dict({ + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_package/attribute_module/AttributesClassB/final', + 'is_public': True, + 'is_static': True, + 'is_type_inferred': False, + 'name': 'final', + 'type': dict({ + 'kind': 'FinalType', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'str', + 'qname': '', + }), + }), + }), + dict({ + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_package/attribute_module/AttributesClassB/final_union', + 'is_public': True, + 'is_static': True, + 'is_type_inferred': False, + 'name': 'final_union', + 'type': dict({ + 'kind': 'FinalType', + 'type': dict({ + 'kind': 'UnionType', + 'types': list([ + dict({ + 'kind': 'NamedType', + 'name': 'str', + 'qname': '', + }), + dict({ + 'kind': 'NamedType', + 'name': 'int', + 'qname': '', + }), + ]), + }), + }), + }), + dict({ + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_package/attribute_module/AttributesClassB/finals', + 'is_public': True, + 'is_static': True, + 'is_type_inferred': False, + 'name': 'finals', + 'type': dict({ + 'kind': 'FinalType', + 'type': dict({ + 'kind': 'UnionType', + 'types': list([ + dict({ + 'kind': 'NamedType', + 'name': 'str', + 'qname': '', + }), + dict({ + 'kind': 'NamedType', + 'name': 'int', + 'qname': '', }), ]), }), @@ -187,6 +297,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'float', + 'qname': '', }), }), dict({ @@ -203,6 +314,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'bool', + 'qname': '', }), }), dict({ @@ -222,10 +334,12 @@ dict({ 'kind': 'NamedType', 'name': 'int', + 'qname': '', }), dict({ 'kind': 'NamedType', 'name': 'bool', + 'qname': '', }), ]), }), @@ -267,10 +381,12 @@ dict({ 'kind': 'NamedType', 'name': 'str', + 'qname': '', }), dict({ 'kind': 'NamedType', 'name': 'AttributesClassA', + 'qname': '', }), ]), }), @@ -294,10 +410,12 @@ dict({ 'kind': 'NamedType', 'name': 'str', + 'qname': '', }), dict({ 'kind': 'NamedType', 'name': 'AttributesClassA', + 'qname': '', }), ]), }), @@ -319,6 +437,7 @@ dict({ 'kind': 'NamedType', 'name': 'str', + 'qname': '', }), dict({ 'kind': 'UnionType', @@ -326,16 +445,34 @@ dict({ 'kind': 'NamedType', 'name': 'AttributesClassA', + 'qname': '', }), dict({ 'kind': 'NamedType', 'name': 'int', + 'qname': '', }), ]), }), ]), }), }), + dict({ + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_package/attribute_module/AttributesClassB/literal', + 'is_public': True, + 'is_static': True, + 'is_type_inferred': False, + 'name': 'literal', + 'type': dict({ + 'kind': 'LiteralType', + 'literal': 'Some String', + }), + }), dict({ 'docstring': dict({ 'default_value': '', @@ -350,6 +487,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'int', + 'qname': '', }), }), dict({ @@ -369,6 +507,7 @@ dict({ 'kind': 'NamedType', 'name': 'str', + 'qname': '', }), ]), }), @@ -387,6 +526,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'str', + 'qname': '', }), }), dict({ @@ -403,6 +543,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'str', + 'qname': '', }), }), dict({ @@ -419,6 +560,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'str', + 'qname': '', }), }), dict({ @@ -435,6 +577,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'str', + 'qname': '', }), }), dict({ @@ -451,6 +594,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'int', + 'qname': '', }), }), dict({ @@ -467,6 +611,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'None', + 'qname': '', }), }), dict({ @@ -483,6 +628,56 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'AttributesClassA', + 'qname': '', + }), + }), + dict({ + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_package/attribute_module/AttributesClassB/optional', + 'is_public': True, + 'is_static': True, + 'is_type_inferred': False, + 'name': 'optional', + 'type': dict({ + 'kind': 'UnionType', + 'types': list([ + dict({ + 'kind': 'NamedType', + 'name': 'int', + 'qname': '', + }), + dict({ + 'kind': 'NamedType', + 'name': 'None', + 'qname': '', + }), + ]), + }), + }), + dict({ + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_package/attribute_module/AttributesClassB/set_', + 'is_public': True, + 'is_static': True, + 'is_type_inferred': False, + 'name': 'set_', + 'type': dict({ + 'kind': 'SetType', + 'types': list([ + dict({ + 'kind': 'NamedType', + 'name': 'Any', + 'qname': '', + }), + ]), }), }), dict({ @@ -499,6 +694,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'str', + 'qname': '', }), }), dict({ @@ -518,6 +714,7 @@ dict({ 'kind': 'NamedType', 'name': 'Any', + 'qname': '', }), ]), }), @@ -542,10 +739,12 @@ dict({ 'kind': 'NamedType', 'name': 'str', + 'qname': '', }), dict({ 'kind': 'NamedType', 'name': 'int', + 'qname': '', }), ]), }), @@ -569,10 +768,12 @@ dict({ 'kind': 'NamedType', 'name': 'str', + 'qname': '', }), dict({ 'kind': 'NamedType', 'name': 'int', + 'qname': '', }), ]), }), @@ -591,6 +792,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'int', + 'qname': '', }), }), ]) @@ -611,6 +813,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'None', + 'qname': '', }), }), dict({ @@ -627,6 +830,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'None', + 'qname': '', }), }), ]) @@ -647,6 +851,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'str', + 'qname': '', }), }), ]) @@ -667,6 +872,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'str', + 'qname': '', }), }), ]) @@ -687,6 +893,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'str', + 'qname': '', }), }), ]) @@ -707,6 +914,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'float', + 'qname': '', }), }), dict({ @@ -723,6 +931,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'bool', + 'qname': '', }), }), ]) @@ -1069,10 +1278,6 @@ 'test_package/infer_types_module/InferMyTypes/infer_function/result_1', 'test_package/infer_types_module/InferMyTypes/infer_function/result_2', 'test_package/infer_types_module/InferMyTypes/infer_function/result_3', - 'test_package/infer_types_module/InferMyTypes/infer_function/result_4', - 'test_package/infer_types_module/InferMyTypes/infer_function/result_5', - 'test_package/infer_types_module/InferMyTypes/infer_function/result_6', - 'test_package/infer_types_module/InferMyTypes/infer_function/result_7', ]), }), ]) @@ -1910,6 +2115,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'str', + 'qname': '', }), 'variance_type': 'COVARIANT', }), @@ -1918,6 +2124,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'A', + 'qname': '', }), 'variance_type': 'CONTRAVARIANT', }), @@ -1929,6 +2136,7 @@ dict({ 'kind': 'NamedType', 'name': 'int', + 'qname': '', }), dict({ 'kind': 'UnionType', @@ -1979,6 +2187,7 @@ dict({ 'kind': 'NamedType', 'name': 'int', + 'qname': '', }), dict({ 'kind': 'UnionType', @@ -2212,6 +2421,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'str', + 'qname': '', }), }), dict({ @@ -2247,6 +2457,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'str', + 'qname': '', }), }), dict({ @@ -2282,6 +2493,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'str', + 'qname': '', }), }), dict({ @@ -2317,6 +2529,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'str', + 'qname': '', }), }), dict({ @@ -2352,6 +2565,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'int', + 'qname': '', }), }), dict({ @@ -2369,6 +2583,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'bool', + 'qname': '', }), }), dict({ @@ -2422,6 +2637,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'float', + 'qname': '', }), }), ]) @@ -2457,6 +2673,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'int', + 'qname': '', }), }), dict({ @@ -2474,6 +2691,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'int', + 'qname': '', }), }), ]) @@ -2559,6 +2777,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'int', + 'qname': '', }), }), ]) @@ -2580,6 +2799,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'int', + 'qname': '', }), }), ]) @@ -2601,6 +2821,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'int', + 'qname': '', }), }), dict({ @@ -2689,6 +2910,7 @@ dict({ 'kind': 'NamedType', 'name': 'int', + 'qname': '', }), ]), }), @@ -2709,11 +2931,13 @@ 'key_type': dict({ 'kind': 'NamedType', 'name': 'str', + 'qname': '', }), 'kind': 'DictType', 'value_type': dict({ 'kind': 'NamedType', 'name': 'int', + 'qname': '', }), }), }), @@ -2739,6 +2963,7 @@ dict({ 'kind': 'NamedType', 'name': 'str', + 'qname': '', }), ]), 'return_type': dict({ @@ -2747,10 +2972,12 @@ dict({ 'kind': 'NamedType', 'name': 'int', + 'qname': '', }), dict({ 'kind': 'NamedType', 'name': 'str', + 'qname': '', }), ]), }), @@ -2775,6 +3002,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'int', + 'qname': '', }), }), dict({ @@ -2795,10 +3023,12 @@ dict({ 'kind': 'NamedType', 'name': 'int', + 'qname': '', }), dict({ 'kind': 'NamedType', 'name': 'str', + 'qname': '', }), ]), }), @@ -2821,14 +3051,17 @@ dict({ 'kind': 'NamedType', 'name': 'int', + 'qname': '', }), dict({ 'kind': 'NamedType', 'name': 'str', + 'qname': '', }), dict({ 'kind': 'NamedType', 'name': 'int', + 'qname': '', }), ]), }), @@ -2851,18 +3084,22 @@ dict({ 'kind': 'NamedType', 'name': 'int', + 'qname': '', }), dict({ 'kind': 'NamedType', 'name': 'str', + 'qname': '', }), dict({ 'kind': 'NamedType', 'name': 'bool', + 'qname': '', }), dict({ 'kind': 'NamedType', 'name': 'int', + 'qname': '', }), ]), }), @@ -2886,6 +3123,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'int', + 'qname': '', }), }), dict({ @@ -2935,11 +3173,12 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'bool', + 'qname': '', }), }), dict({ 'assigned_by': 'POSITION_OR_NAME', - 'default_value': 1, + 'default_value': 'FunctionModuleClassA', 'docstring': dict({ 'default_value': '', 'description': '', @@ -2951,22 +3190,27 @@ 'name': 'c', 'type': dict({ 'kind': 'NamedType', - 'name': 'int', + 'name': 'FunctionModuleClassA', + 'qname': 'tests.data.test_package.function_module.FunctionModuleClassA', }), }), dict({ 'assigned_by': 'NAME_ONLY', - 'default_value': None, + 'default_value': 'FunctionModuleClassA()', 'docstring': dict({ 'default_value': '', 'description': '', 'type': '', }), 'id': 'test_package/function_module/param_position/d', - 'is_optional': False, - 'is_type_inferred': False, + 'is_optional': True, + 'is_type_inferred': True, 'name': 'd', - 'type': None, + 'type': dict({ + 'kind': 'NamedType', + 'name': 'FunctionModuleClassA', + 'qname': 'tests.data.test_package.function_module.FunctionModuleClassA', + }), }), dict({ 'assigned_by': 'NAME_ONLY', @@ -2983,6 +3227,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'int', + 'qname': '', }), }), dict({ @@ -3011,13 +3256,100 @@ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/params/i', + 'id': 'test_package/function_module/params/boolean', + 'is_optional': False, + 'is_type_inferred': False, + 'name': 'boolean', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'bool', + 'qname': '', + }), + }), + dict({ + 'assigned_by': 'POSITION_OR_NAME', + 'default_value': None, + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_package/function_module/params/callexpr', + 'is_optional': False, + 'is_type_inferred': False, + 'name': 'callexpr', + 'type': None, + }), + dict({ + 'assigned_by': 'POSITION_OR_NAME', + 'default_value': None, + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_package/function_module/params/dictionary', + 'is_optional': False, + 'is_type_inferred': False, + 'name': 'dictionary', + 'type': dict({ + 'key_type': dict({ + 'kind': 'NamedType', + 'name': 'str', + 'qname': '', + }), + 'kind': 'DictType', + 'value_type': dict({ + 'kind': 'UnionType', + 'types': list([ + dict({ + 'kind': 'NamedType', + 'name': 'int', + 'qname': '', + }), + dict({ + 'kind': 'NamedType', + 'name': 'float', + 'qname': '', + }), + ]), + }), + }), + }), + dict({ + 'assigned_by': 'POSITION_OR_NAME', + 'default_value': None, + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_package/function_module/params/float_', + 'is_optional': False, + 'is_type_inferred': False, + 'name': 'float_', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'float', + 'qname': '', + }), + }), + dict({ + 'assigned_by': 'POSITION_OR_NAME', + 'default_value': None, + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_package/function_module/params/integer', 'is_optional': False, 'is_type_inferred': False, - 'name': 'i', + 'name': 'integer', 'type': dict({ 'kind': 'NamedType', 'name': 'int', + 'qname': '', }), }), dict({ @@ -3028,20 +3360,56 @@ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/params/lst', + 'id': 'test_package/function_module/params/list_', 'is_optional': False, 'is_type_inferred': False, - 'name': 'lst', + 'name': 'list_', 'type': dict({ 'kind': 'ListType', 'types': list([ dict({ 'kind': 'NamedType', 'name': 'int', + 'qname': '', }), ]), }), }), + dict({ + 'assigned_by': 'POSITION_OR_NAME', + 'default_value': None, + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_package/function_module/params/literal', + 'is_optional': False, + 'is_type_inferred': False, + 'name': 'literal', + 'type': dict({ + 'kind': 'LiteralType', + 'literal': 'Some String', + }), + }), + dict({ + 'assigned_by': 'POSITION_OR_NAME', + 'default_value': None, + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_package/function_module/params/none', + 'is_optional': False, + 'is_type_inferred': False, + 'name': 'none', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'None', + 'qname': '', + }), + }), dict({ 'assigned_by': 'POSITION_OR_NAME', 'default_value': None, @@ -3057,6 +3425,109 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'FunctionModuleClassA', + 'qname': '', + }), + }), + dict({ + 'assigned_by': 'POSITION_OR_NAME', + 'default_value': None, + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_package/function_module/params/optional', + 'is_optional': False, + 'is_type_inferred': False, + 'name': 'optional', + 'type': dict({ + 'kind': 'UnionType', + 'types': list([ + dict({ + 'kind': 'NamedType', + 'name': 'int', + 'qname': '', + }), + dict({ + 'kind': 'NamedType', + 'name': 'None', + 'qname': '', + }), + ]), + }), + }), + dict({ + 'assigned_by': 'POSITION_OR_NAME', + 'default_value': None, + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_package/function_module/params/set_', + 'is_optional': False, + 'is_type_inferred': False, + 'name': 'set_', + 'type': dict({ + 'kind': 'SetType', + 'types': list([ + dict({ + 'kind': 'NamedType', + 'name': 'str', + 'qname': '', + }), + ]), + }), + }), + dict({ + 'assigned_by': 'POSITION_OR_NAME', + 'default_value': None, + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_package/function_module/params/string', + 'is_optional': False, + 'is_type_inferred': False, + 'name': 'string', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'str', + 'qname': '', + }), + }), + dict({ + 'assigned_by': 'POSITION_OR_NAME', + 'default_value': None, + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_package/function_module/params/tuple_', + 'is_optional': False, + 'is_type_inferred': False, + 'name': 'tuple_', + 'type': dict({ + 'kind': 'TupleType', + 'types': list([ + dict({ + 'kind': 'NamedType', + 'name': 'int', + 'qname': '', + }), + dict({ + 'kind': 'NamedType', + 'name': 'str', + 'qname': '', + }), + dict({ + 'kind': 'NamedType', + 'name': 'bool', + 'qname': '', + }), + ]), }), }), dict({ @@ -3077,10 +3548,12 @@ dict({ 'kind': 'NamedType', 'name': 'int', + 'qname': '', }), dict({ 'kind': 'NamedType', 'name': 'bool', + 'qname': '', }), ]), }), @@ -3108,6 +3581,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'int', + 'qname': '', }), }), dict({ @@ -3146,10 +3620,12 @@ dict({ 'kind': 'NamedType', 'name': 'bool', + 'qname': '', }), dict({ 'kind': 'NamedType', 'name': 'None', + 'qname': '', }), ]), }), @@ -3169,6 +3645,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'None', + 'qname': '', }), }), dict({ @@ -3189,14 +3666,17 @@ dict({ 'kind': 'NamedType', 'name': 'None', + 'qname': '', }), dict({ 'kind': 'NamedType', 'name': 'bool', + 'qname': '', }), dict({ 'kind': 'NamedType', 'name': 'int', + 'qname': '', }), ]), }), @@ -3219,14 +3699,17 @@ dict({ 'kind': 'NamedType', 'name': 'None', + 'qname': '', }), dict({ 'kind': 'NamedType', 'name': 'bool', + 'qname': '', }), dict({ 'kind': 'NamedType', 'name': 'None', + 'qname': '', }), ]), }), @@ -3249,10 +3732,12 @@ dict({ 'kind': 'NamedType', 'name': 'None', + 'qname': '', }), dict({ 'kind': 'NamedType', 'name': 'bool', + 'qname': '', }), ]), }), @@ -3275,6 +3760,7 @@ dict({ 'kind': 'NamedType', 'name': 'None', + 'qname': '', }), dict({ 'kind': 'ListType', @@ -3285,10 +3771,12 @@ dict({ 'kind': 'NamedType', 'name': 'None', + 'qname': '', }), dict({ 'kind': 'NamedType', 'name': 'None', + 'qname': '', }), ]), }), @@ -3297,6 +3785,7 @@ dict({ 'kind': 'NamedType', 'name': 'None', + 'qname': '', }), ]), }), @@ -3319,18 +3808,22 @@ dict({ 'kind': 'NamedType', 'name': 'None', + 'qname': '', }), dict({ 'kind': 'NamedType', 'name': 'None', + 'qname': '', }), dict({ 'kind': 'NamedType', 'name': 'bool', + 'qname': '', }), dict({ 'kind': 'NamedType', 'name': 'None', + 'qname': '', }), ]), }), @@ -3353,10 +3846,12 @@ dict({ 'kind': 'NamedType', 'name': 'None', + 'qname': '', }), dict({ 'kind': 'NamedType', 'name': 'None', + 'qname': '', }), ]), }), @@ -3394,6 +3889,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'int', + 'qname': '', }), }), dict({ @@ -3411,6 +3907,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'int', + 'qname': '', }), }), ]) @@ -3446,6 +3943,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'int', + 'qname': '', }), }), dict({ @@ -3463,6 +3961,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'int', + 'qname': '', }), }), ]) @@ -3498,6 +3997,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'int', + 'qname': '', }), }), dict({ @@ -3515,6 +4015,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'int', + 'qname': '', }), }), ]) @@ -3535,6 +4036,7 @@ dict({ 'kind': 'NamedType', 'name': 'str', + 'qname': '', }), ]), }), @@ -3584,6 +4086,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'bool', + 'qname': '', }), }), ]) @@ -3604,15 +4107,18 @@ dict({ 'kind': 'NamedType', 'name': 'int', + 'qname': '', }), dict({ 'kind': 'NamedType', 'name': 'int', + 'qname': '', }), ]), 'return_type': dict({ 'kind': 'NamedType', 'name': 'int', + 'qname': '', }), }), }), @@ -3631,6 +4137,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'bool', + 'qname': '', }), }), ]) @@ -3648,6 +4155,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'bool', + 'qname': '', }), }), ]) @@ -3669,6 +4177,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'str', + 'qname': '', }), }), ]) @@ -3686,6 +4195,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'str', + 'qname': '', }), }), ]) @@ -3706,6 +4216,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'bool', + 'qname': '', }), }), ]) @@ -3721,8 +4232,49 @@ 'is_type_inferred': True, 'name': 'result_1', 'type': dict({ - 'kind': 'NamedType', - 'name': 'InferMyTypes', + 'kind': 'UnionType', + 'types': list([ + dict({ + 'kind': 'NamedType', + 'name': 'float', + 'qname': '', + }), + dict({ + 'kind': 'NamedType', + 'name': 'ModuleClass', + 'qname': '', + }), + dict({ + 'kind': 'NamedType', + 'name': 'int', + 'qname': '', + }), + dict({ + 'kind': 'NamedType', + 'name': 'bool', + 'qname': '', + }), + dict({ + 'kind': 'NamedType', + 'name': 'None', + 'qname': '', + }), + dict({ + 'kind': 'NamedType', + 'name': 'bool', + 'qname': '', + }), + dict({ + 'kind': 'NamedType', + 'name': 'InferMyTypes', + 'qname': '', + }), + dict({ + 'kind': 'NamedType', + 'name': 'str', + 'qname': '', + }), + ]), }), }), dict({ @@ -3734,8 +4286,19 @@ 'is_type_inferred': True, 'name': 'result_2', 'type': dict({ - 'kind': 'NamedType', - 'name': 'ModuleClass', + 'kind': 'UnionType', + 'types': list([ + dict({ + 'kind': 'NamedType', + 'name': 'float', + 'qname': '', + }), + dict({ + 'kind': 'NamedType', + 'name': 'int', + 'qname': '', + }), + ]), }), }), dict({ @@ -3746,61 +4309,10 @@ 'id': 'test_package/infer_types_module/InferMyTypes/infer_function/result_3', 'is_type_inferred': True, 'name': 'result_3', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'None', - }), - }), - dict({ - 'docstring': dict({ - 'description': '', - 'type': '', - }), - 'id': 'test_package/infer_types_module/InferMyTypes/infer_function/result_4', - 'is_type_inferred': True, - 'name': 'result_4', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'bool', - }), - }), - dict({ - 'docstring': dict({ - 'description': '', - 'type': '', - }), - 'id': 'test_package/infer_types_module/InferMyTypes/infer_function/result_5', - 'is_type_inferred': True, - 'name': 'result_5', 'type': dict({ 'kind': 'NamedType', 'name': 'float', - }), - }), - dict({ - 'docstring': dict({ - 'description': '', - 'type': '', - }), - 'id': 'test_package/infer_types_module/InferMyTypes/infer_function/result_6', - 'is_type_inferred': True, - 'name': 'result_6', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'int', - }), - }), - dict({ - 'docstring': dict({ - 'description': '', - 'type': '', - }), - 'id': 'test_package/infer_types_module/InferMyTypes/infer_function/result_7', - 'is_type_inferred': True, - 'name': 'result_7', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'str', + 'qname': '', }), }), ]) @@ -3818,6 +4330,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'FunctionModuleClassA', + 'qname': '', }), }), ]) @@ -3891,6 +4404,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'bool', + 'qname': '', }), }), ]) @@ -3908,6 +4422,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'bool', + 'qname': '', }), }), ]) @@ -3925,6 +4440,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'bool', + 'qname': '', }), }), ]) @@ -4242,10 +4758,20 @@ 'is_static': False, 'name': 'params', 'parameters': list([ - 'test_package/function_module/params/i', - 'test_package/function_module/params/union', - 'test_package/function_module/params/lst', + 'test_package/function_module/params/integer', + 'test_package/function_module/params/boolean', + 'test_package/function_module/params/float_', + 'test_package/function_module/params/none', + 'test_package/function_module/params/string', 'test_package/function_module/params/obj', + 'test_package/function_module/params/callexpr', + 'test_package/function_module/params/union', + 'test_package/function_module/params/list_', + 'test_package/function_module/params/dictionary', + 'test_package/function_module/params/set_', + 'test_package/function_module/params/optional', + 'test_package/function_module/params/tuple_', + 'test_package/function_module/params/literal', ]), 'reexported_by': list([ ]), diff --git a/tests/safeds_stubgen/api_analyzer/test_types.py b/tests/safeds_stubgen/api_analyzer/test_types.py index 53ddc329..ca773e02 100644 --- a/tests/safeds_stubgen/api_analyzer/test_types.py +++ b/tests/safeds_stubgen/api_analyzer/test_types.py @@ -68,7 +68,7 @@ def test_correct_hash() -> None: def test_named_type() -> None: name = "str" named_type = NamedType(name) - named_type_dict = {"kind": "NamedType", "name": name} + named_type_dict = {"kind": "NamedType", "name": name, "qname": ""} assert AbstractType.from_dict(named_type_dict) == named_type @@ -114,7 +114,10 @@ def test_union_type() -> None: union_type = UnionType([NamedType("str"), NamedType("int")]) union_type_dict = { "kind": "UnionType", - "types": [{"kind": "NamedType", "name": "str"}, {"kind": "NamedType", "name": "int"}], + "types": [ + {"kind": "NamedType", "name": "str", "qname": ""}, + {"kind": "NamedType", "name": "int", "qname": ""} + ], } assert AbstractType.from_dict(union_type_dict) == union_type @@ -134,9 +137,13 @@ def test_callable_type() -> None: ) callable_type_dict = { "kind": "CallableType", - "parameter_types": [{"kind": "NamedType", "name": "str"}, {"kind": "NamedType", "name": "int"}], + "parameter_types": [ + {"kind": "NamedType", "name": "str", "qname": ""}, + {"kind": "NamedType", "name": "int", "qname": ""} + ], "return_type": {"kind": "TupleType", "types": [ - {"kind": "NamedType", "name": "bool"}, {"kind": "NamedType", "name": "None"} + {"kind": "NamedType", "name": "bool", "qname": ""}, + {"kind": "NamedType", "name": "None", "qname": ""} ]}, } @@ -154,7 +161,10 @@ def test_list_type() -> None: list_type = ListType([NamedType("str"), NamedType("int")]) list_type_dict = { "kind": "ListType", - "types": [{"kind": "NamedType", "name": "str"}, {"kind": "NamedType", "name": "int"}], + "types": [ + {"kind": "NamedType", "name": "str", "qname": ""}, + {"kind": "NamedType", "name": "int", "qname": ""} + ], } assert AbstractType.from_dict(list_type_dict) == list_type @@ -176,11 +186,17 @@ def test_dict_type() -> None: "kind": "DictType", "key_type": { "kind": "UnionType", - "types": [{"kind": "NamedType", "name": "str"}, {"kind": "NamedType", "name": "int"}], + "types": [ + {"kind": "NamedType", "name": "str", "qname": ""}, + {"kind": "NamedType", "name": "int", "qname": ""} + ], }, "value_type": { "kind": "UnionType", - "types": [{"kind": "NamedType", "name": "str"}, {"kind": "NamedType", "name": "int"}], + "types": [ + {"kind": "NamedType", "name": "str", "qname": ""}, + {"kind": "NamedType", "name": "int", "qname": ""} + ], }, } @@ -198,7 +214,10 @@ def test_set_type() -> None: set_type = SetType([NamedType("str"), NamedType("int")]) set_type_dict = { "kind": "SetType", - "types": [{"kind": "NamedType", "name": "str"}, {"kind": "NamedType", "name": "int"}], + "types": [ + {"kind": "NamedType", "name": "str", "qname": ""}, + {"kind": "NamedType", "name": "int", "qname": ""} + ], } assert AbstractType.from_dict(set_type_dict) == set_type @@ -215,7 +234,7 @@ def test_optional_type() -> None: type_ = OptionalType(NamedType("some_type")) type_dict = { "kind": "OptionalType", - "type": {"kind": "NamedType", "name": "some_type"}, + "type": {"kind": "NamedType", "name": "some_type", "qname": ""}, } assert AbstractType.from_dict(type_dict) == type_ @@ -249,7 +268,7 @@ def test_final_type() -> None: type_ = FinalType(NamedType("some_type")) type_dict = { "kind": "FinalType", - "type": {"kind": "NamedType", "name": "some_type"}, + "type": {"kind": "NamedType", "name": "some_type", "qname": ""}, } assert AbstractType.from_dict(type_dict) == type_ @@ -266,7 +285,10 @@ def test_tuple_type() -> None: set_type = TupleType([NamedType("str"), NamedType("int")]) set_type_dict = { "kind": "TupleType", - "types": [{"kind": "NamedType", "name": "str"}, {"kind": "NamedType", "name": "int"}], + "types": [ + {"kind": "NamedType", "name": "str", "qname": ""}, + {"kind": "NamedType", "name": "int", "qname": ""} + ], } assert AbstractType.from_dict(set_type_dict) == set_type @@ -419,7 +441,7 @@ def test_enum_from_string(docstring_type: str, expected: set[str] | None) -> Non # [ # ( # "", -# {"kind": "NamedType", "name": "None"} +# {"kind": "NamedType", "name": "None", "qname": ""} # ), # ( # "int, or None, 'manual', {'auto', 'sqrt', 'log2'}, default='auto'", @@ -427,9 +449,9 @@ def test_enum_from_string(docstring_type: str, expected: set[str] | None) -> Non # "kind": "UnionType", # "types": [ # {"kind": "EnumType", "values": {"auto", "log2", "sqrt"}}, -# {"kind": "NamedType", "name": "int"}, -# {"kind": "NamedType", "name": "None"}, -# {"kind": "NamedType", "name": "'manual'"}, +# {"kind": "NamedType", "name": "int", "qname": ""}, +# {"kind": "NamedType", "name": "None", "qname": ""}, +# {"kind": "NamedType", "name": "'manual'", "qname": ""}, # ], # }, # ), @@ -438,20 +460,20 @@ def test_enum_from_string(docstring_type: str, expected: set[str] | None) -> Non # { # "kind": "UnionType", # "types": [ -# {"kind": "NamedType", "name": "tuple of slice"}, -# {"kind": "NamedType", "name": "AUTO"}, -# {"kind": "NamedType", "name": "array of shape (12,2)"}, +# {"kind": "NamedType", "name": "tuple of slice", "qname": ""}, +# {"kind": "NamedType", "name": "AUTO", "qname": ""}, +# {"kind": "NamedType", "name": "array of shape (12,2)", "qname": ""}, # ], # }, # ), -# ("object", {"kind": "NamedType", "name": "object"}), +# ("object", {"kind": "NamedType", "name": "object", "qname": ""}), # ( # "ndarray, shape (n_samples,), default=None", # { # "kind": "UnionType", # "types": [ -# {"kind": "NamedType", "name": "ndarray"}, -# {"kind": "NamedType", "name": "shape (n_samples,)"}, +# {"kind": "NamedType", "name": "ndarray", "qname": ""}, +# {"kind": "NamedType", "name": "shape (n_samples,)", "qname": ""}, # ], # }, # ), @@ -460,8 +482,8 @@ def test_enum_from_string(docstring_type: str, expected: set[str] | None) -> Non # { # "kind": "UnionType", # "types": [ -# {"kind": "NamedType", "name": "estor adventus"}, -# {"kind": "NamedType", "name": "None"}, +# {"kind": "NamedType", "name": "estor adventus", "qname": ""}, +# {"kind": "NamedType", "name": "None", "qname": ""}, # ], # }, # ), @@ -470,11 +492,11 @@ def test_enum_from_string(docstring_type: str, expected: set[str] | None) -> Non # { # "kind": "UnionType", # "types": [ -# {"kind": "NamedType", "name": "int"}, -# {"kind": "NamedType", "name": "array-like"}, +# {"kind": "NamedType", "name": "int", "qname": ""}, +# {"kind": "NamedType", "name": "array-like", "qname": ""}, # { # "kind": "NamedType", -# "name": "shape (n_samples, n_classes) or (n_samples, 1) when binary.", +# "name": "shape (n_samples, n_classes) or (n_samples, 1) when binary.", "qname": "" # }, # ], # }, @@ -546,8 +568,8 @@ def test_enum_from_string(docstring_type: str, expected: set[str] | None) -> Non # "min_inclusive": True, # }, # {"kind": "EnumType", "values": ["today", "yesterday"]}, -# {"kind": "NamedType", "name": "int"}, -# {"kind": "NamedType", "name": "'Auto'"}, +# {"kind": "NamedType", "name": "int", "qname": ""}, +# {"kind": "NamedType", "name": "'Auto'", "qname": ""}, # ], # }, # ), diff --git a/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr b/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr index 8148efbb..4ef3f4d9 100644 --- a/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr +++ b/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr @@ -8,7 +8,8 @@ from abc import abstractmethod class AbstractModuleClass { - @PythonName("abstract_property_method") attr abstractPropertyMethod: union + // TODO Safe-DS does not support tuple types. + @PythonName("abstract_property_method") attr abstractPropertyMethod: Tuple // TODO Result type information missing. @Pure @@ -41,6 +42,10 @@ @PythonModule("test_package.attribute_module") package testPackage.attributeModule + from typing import Optional + from typing import Final + from typing import Literal + class AttributesClassA() class AttributesClassB() { @@ -50,6 +55,8 @@ static attr noTypeHintPublic: Int @PythonName("object_attr") static attr objectAttr: AttributesClassA + @PythonName("callexpr_attr") + static attr callexprAttr: Any // TODO Safe-DS does not support tuple types. @PythonName("tuple_attr_1") static attr tupleAttr1: Tuple @@ -85,6 +92,14 @@ static attr intOrBoolAttr: union @PythonName("str_attr_with_none_value") static attr strAttrWithNoneValue: String + @PythonName("set_") + static attr set: Set + static attr optional: Int? + static attr final: String + static attr finals: union + @PythonName("final_union") + static attr finalUnion: union + static attr `literal`: literal @PythonName("multi_attr_1") static attr multiAttr1: Int @PythonName("multi_attr_3") @@ -187,6 +202,8 @@ package testPackage.functionModule from typing import Callable + from typing import Optional + from typing import Literal // TODO Result type information missing. @Pure @@ -194,12 +211,24 @@ fun publicNoParamsNoResult() // TODO Result type information missing. + // TODO Safe-DS does not support tuple types. + // TODO Some parameter have no type information. @Pure fun params( - i: Int, + integer: Int, + boolean: Boolean, + @PythonName("float_") float: Float, + none: Nothing?, + string: String, + obj: FunctionModuleClassA, + callexpr, `union`: union, - lst: List, - obj: FunctionModuleClassA + @PythonName("list_") list: List, + dictionary: Map>, + @PythonName("set_") set: Set, + optional: Int?, + @PythonName("tuple_") tuple: Tuple, + `literal`: literal ) // TODO List type has to many type arguments. @@ -229,7 +258,6 @@ ) // TODO Result type information missing. - // TODO Safe-DS does not support required but name only parameter assignments. // TODO Some parameter have no type information. @Pure @PythonName("param_position") @@ -237,8 +265,8 @@ self, a, b: Boolean, - c: Int = 1, - d, + c: FunctionModuleClassA = FunctionModuleClassA, + d: FunctionModuleClassA = FunctionModuleClassA(), e: Int = 1 ) @@ -283,6 +311,7 @@ @PythonName("one_result") fun oneResult() -> result1: Int + // TODO Safe-DS does not support tuple types. @Pure @PythonName("multiple_results") fun multipleResults() -> (result1: String, result2: Int, result3: Boolean, result4: FunctionModuleClassA) @@ -379,7 +408,7 @@ static fun inferFunction( @PythonName("infer_param") inferParam: Int = 1, @PythonName("infer_param_2") inferParam2: Int = Something - ) -> (result1: InferMyTypes, result2: ModuleClass, result3: Nothing?, result4: Boolean, result5: Float, result6: Int, result7: String) + ) -> (result1: union, result2: union, result3: Float) } ''' From 4bff2cb7ea8d8d3564a58b8f25c4895d4e99137c Mon Sep 17 00:00:00 2001 From: Arsam Date: Mon, 27 Nov 2023 23:11:55 +0100 Subject: [PATCH 055/109] Fixed bugs and tests, added qnames for some NamedTypes --- .../api_analyzer/_ast_visitor.py | 14 +++++- .../api_analyzer/_mypy_helpers.py | 4 +- tests/data/test_main/main_test_module.py | 1 + tests/data/test_package/function_module.py | 2 +- tests/data/test_package/infer_types_module.py | 13 +++++- .../__snapshots__/test_main.ambr | 16 +++---- .../__snapshots__/test__get_api.ambr | 46 +++++++++++++------ .../__snapshots__/test_generate_stubs.ambr | 22 ++++++--- 8 files changed, 83 insertions(+), 35 deletions(-) diff --git a/src/safeds_stubgen/api_analyzer/_ast_visitor.py b/src/safeds_stubgen/api_analyzer/_ast_visitor.py index 172f1700..3c046655 100644 --- a/src/safeds_stubgen/api_analyzer/_ast_visitor.py +++ b/src/safeds_stubgen/api_analyzer/_ast_visitor.py @@ -363,7 +363,7 @@ def _mypy_expression_to_sds_type(self, expr: mp_nodes.Expression) -> sds_types.N if expr.name in {"False", "True"}: return sds_types.NamedType(name="bool") else: - return sds_types.NamedType(name=expr.name) + return sds_types.NamedType(name=expr.name, qname=expr.fullname) elif isinstance(expr, mp_nodes.IntExpr): return sds_types.NamedType(name="int") elif isinstance(expr, mp_nodes.FloatExpr): @@ -476,6 +476,18 @@ def _create_result(self, node: mp_nodes.FuncDef, function_id: str) -> list[Resul return results + elif isinstance(ret_type, sds_types.TupleType): + return [ + Result( + id=f"{function_id}/result_{i + 1}", + type=type_, + is_type_inferred=is_type_inferred, + name=f"result_{i + 1}", + docstring=self.docstring_parser.get_result_documentation(node), + ) + for i, type_ in enumerate(ret_type.types) + ] + return [Result( id=f"{function_id}/result_1", type=ret_type, diff --git a/src/safeds_stubgen/api_analyzer/_mypy_helpers.py b/src/safeds_stubgen/api_analyzer/_mypy_helpers.py index 3e9b4186..54a5b61e 100644 --- a/src/safeds_stubgen/api_analyzer/_mypy_helpers.py +++ b/src/safeds_stubgen/api_analyzer/_mypy_helpers.py @@ -79,7 +79,7 @@ def mypy_type_to_abstract_type( mypy_type_to_abstract_type(arg) for arg in mypy_type.args ]) - # Todo Aliasing: Import auflösen + # Todo Aliasing: Import auflösen, wir können wir keinen fullname (qname) bekommen return sds_types.NamedType(name=mypy_type.name) elif isinstance(mypy_type, mp_types.TypeType): # The first parameter of cls methods @@ -119,7 +119,7 @@ def mypy_type_to_abstract_type( return sds_types.DictType(key_type=key_type, value_type=value_type) else: - return sds_types.NamedType(name=type_name) + return sds_types.NamedType(name=type_name, qname=mypy_type.type.fullname) raise ValueError("Unexpected type.") diff --git a/tests/data/test_main/main_test_module.py b/tests/data/test_main/main_test_module.py index 23c7a231..214e6864 100644 --- a/tests/data/test_main/main_test_module.py +++ b/tests/data/test_main/main_test_module.py @@ -15,6 +15,7 @@ ac_alias = AnotherClass +# Todo Frage: Ist bei den Stubs param_2 optional? Wird None als default value unterstützt? # noinspection PyUnusedLocal def global_func(param_1: str = "first param", param_2: ac_alias | None = None) -> ac_alias: """Docstring 1. diff --git a/tests/data/test_package/function_module.py b/tests/data/test_package/function_module.py index 1371ca8d..976e69da 100644 --- a/tests/data/test_package/function_module.py +++ b/tests/data/test_package/function_module.py @@ -39,7 +39,7 @@ def public_no_params_no_result(): ... def params( integer: int, boolean: bool, - float_: 1.2, + float_: float, none: None, string: str, obj: FunctionModuleClassA, diff --git a/tests/data/test_package/infer_types_module.py b/tests/data/test_package/infer_types_module.py index 3a6b0c1e..b3567425 100644 --- a/tests/data/test_package/infer_types_module.py +++ b/tests/data/test_package/infer_types_module.py @@ -1,5 +1,14 @@ +class InferMe: + ... + + class InferMyTypes: - infer_attr = 1 + infer_int = 1 + infer_float = 1.2 + infer_bool = False + infer_str = "String" + infer_none = None + infer_obj = InferMe # Todo Frage: Ist "static attr inferObj: () -> a: InferMe" richtig? def __init__(self, init_param=1): self.init_infer = 3 @@ -33,6 +42,6 @@ def infer_function(infer_param=1, infer_param_2: int = "Something"): for _ in (1, 2): if infer_param_2: - return ModuleClass + return InferMe return int diff --git a/tests/safeds_stubgen/__snapshots__/test_main.ambr b/tests/safeds_stubgen/__snapshots__/test_main.ambr index 15e71567..fce8144d 100644 --- a/tests/safeds_stubgen/__snapshots__/test_main.ambr +++ b/tests/safeds_stubgen/__snapshots__/test_main.ambr @@ -635,7 +635,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'AnotherClass', - 'qname': '', + 'qname': 'tests.data.test_main.another_path.another_module.AnotherClass', }), }), dict({ @@ -725,7 +725,7 @@ 'type': '', }), 'id': 'test_main/main_test_module/global_func/param_2', - 'is_optional': True, + 'is_optional': False, 'is_type_inferred': False, 'name': 'param_2', 'type': dict({ @@ -734,7 +734,7 @@ dict({ 'kind': 'NamedType', 'name': 'AnotherClass', - 'qname': '', + 'qname': 'tests.data.test_main.another_path.another_module.AnotherClass', }), dict({ 'kind': 'NamedType', @@ -786,7 +786,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'AnotherClass', - 'qname': '', + 'qname': 'tests.data.test_main.another_path.another_module.AnotherClass', }), }), dict({ @@ -803,17 +803,17 @@ dict({ 'kind': 'NamedType', 'name': 'AnotherClass', - 'qname': '', + 'qname': 'tests.data.test_main.another_path.another_module.AnotherClass', }), dict({ 'kind': 'NamedType', 'name': 'AnotherClass', - 'qname': '', + 'qname': 'tests.data.test_main.another_path.another_module.AnotherClass', }), dict({ 'kind': 'NamedType', 'name': 'AnotherClass', - 'qname': '', + 'qname': 'tests.data.test_main.another_path.another_module.AnotherClass', }), ]), }), @@ -829,7 +829,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'AnotherClass', - 'qname': '', + 'qname': 'tests.data.test_main.another_path.another_module.AnotherClass', }), }), ]), diff --git a/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr b/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr index f4d2d85e..f016936a 100644 --- a/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr +++ b/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr @@ -197,7 +197,7 @@ dict({ 'kind': 'NamedType', 'name': 'AttributesClassA', - 'qname': '', + 'qname': 'tests.data.test_package.attribute_module.AttributesClassA', }), ]), }), @@ -628,7 +628,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'AttributesClassA', - 'qname': '', + 'qname': 'tests.data.test_package.attribute_module.AttributesClassA', }), }), dict({ @@ -1905,7 +1905,12 @@ # name: test_classes_InferMyTypes dict({ 'attributes': list([ - 'test_package/infer_types_module/InferMyTypes/infer_attr', + 'test_package/infer_types_module/InferMyTypes/infer_int', + 'test_package/infer_types_module/InferMyTypes/infer_float', + 'test_package/infer_types_module/InferMyTypes/infer_bool', + 'test_package/infer_types_module/InferMyTypes/infer_str', + 'test_package/infer_types_module/InferMyTypes/infer_none', + 'test_package/infer_types_module/InferMyTypes/infer_obj', 'test_package/infer_types_module/InferMyTypes/init_infer', ]), 'classes': list([ @@ -2124,7 +2129,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'A', - 'qname': '', + 'qname': 'tests.data.test_package.variance_module.A', }), 'variance_type': 'CONTRAVARIANT', }), @@ -3425,7 +3430,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'FunctionModuleClassA', - 'qname': '', + 'qname': 'tests.data.test_package.function_module.FunctionModuleClassA', }), }), dict({ @@ -4056,6 +4061,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'float', + 'qname': '', }), }), dict({ @@ -4069,6 +4075,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'int', + 'qname': '', }), }), ]) @@ -4236,27 +4243,32 @@ 'types': list([ dict({ 'kind': 'NamedType', - 'name': 'float', + 'name': 'int', 'qname': '', }), dict({ 'kind': 'NamedType', - 'name': 'ModuleClass', - 'qname': '', + 'name': 'InferMe', + 'qname': 'tests.data.test_package.infer_types_module.InferMe', }), dict({ 'kind': 'NamedType', - 'name': 'int', + 'name': 'None', + 'qname': 'builtins.None', + }), + dict({ + 'kind': 'NamedType', + 'name': 'float', 'qname': '', }), dict({ 'kind': 'NamedType', 'name': 'bool', - 'qname': '', + 'qname': 'builtins.bool', }), dict({ 'kind': 'NamedType', - 'name': 'None', + 'name': 'str', 'qname': '', }), dict({ @@ -4267,12 +4279,12 @@ dict({ 'kind': 'NamedType', 'name': 'InferMyTypes', - 'qname': '', + 'qname': 'tests.data.test_package.infer_types_module.InferMyTypes', }), dict({ 'kind': 'NamedType', - 'name': 'str', - 'qname': '', + 'name': 'int', + 'qname': 'builtins.int', }), ]), }), @@ -4330,7 +4342,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'FunctionModuleClassA', - 'qname': '', + 'qname': 'tests.data.test_package.function_module.FunctionModuleClassA', }), }), ]) @@ -4348,6 +4360,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'str', + 'qname': '', }), }), dict({ @@ -4361,6 +4374,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'int', + 'qname': '', }), }), dict({ @@ -4374,6 +4388,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'bool', + 'qname': '', }), }), dict({ @@ -4387,6 +4402,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'FunctionModuleClassA', + 'qname': 'tests.data.test_package.function_module.FunctionModuleClassA', }), }), ]) diff --git a/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr b/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr index 4ef3f4d9..21fd1a6c 100644 --- a/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr +++ b/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr @@ -8,8 +8,7 @@ from abc import abstractmethod class AbstractModuleClass { - // TODO Safe-DS does not support tuple types. - @PythonName("abstract_property_method") attr abstractPropertyMethod: Tuple + @PythonName("abstract_property_method") attr abstractPropertyMethod: union // TODO Result type information missing. @Pure @@ -311,7 +310,6 @@ @PythonName("one_result") fun oneResult() -> result1: Int - // TODO Safe-DS does not support tuple types. @Pure @PythonName("multiple_results") fun multipleResults() -> (result1: String, result2: Int, result3: Boolean, result4: FunctionModuleClassA) @@ -394,11 +392,23 @@ @PythonModule("test_package.infer_types_module") package testPackage.inferTypesModule + class InferMe() + class InferMyTypes( @PythonName("init_param") initParam: Int = 1 ) { - @PythonName("infer_attr") - static attr inferAttr: Int + @PythonName("infer_int") + static attr inferInt: Int + @PythonName("infer_float") + static attr inferFloat: Float + @PythonName("infer_bool") + static attr inferBool: Boolean + @PythonName("infer_str") + static attr inferStr: String + @PythonName("infer_none") + static attr inferNone: Nothing? + @PythonName("infer_obj") + static attr inferObj: () -> a: InferMe // TODO Attribute has no type information. @PythonName("init_infer") attr initInfer @@ -408,7 +418,7 @@ static fun inferFunction( @PythonName("infer_param") inferParam: Int = 1, @PythonName("infer_param_2") inferParam2: Int = Something - ) -> (result1: union, result2: union, result3: Float) + ) -> (result1: union, result2: union, result3: Float) } ''' From 8b44fe62d88bdbf95b3efcad9a2b3752682a187d Mon Sep 17 00:00:00 2001 From: Arsam Date: Mon, 27 Nov 2023 23:39:15 +0100 Subject: [PATCH 056/109] Fixed a bug where attributes with call expressions as type hint would get "Any" as type --- .../api_analyzer/_ast_visitor.py | 5 ++- .../__snapshots__/test__get_api.ambr | 36 +++++++++---------- .../__snapshots__/test_generate_stubs.ambr | 3 +- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/safeds_stubgen/api_analyzer/_ast_visitor.py b/src/safeds_stubgen/api_analyzer/_ast_visitor.py index 3c046655..6a15fac9 100644 --- a/src/safeds_stubgen/api_analyzer/_ast_visitor.py +++ b/src/safeds_stubgen/api_analyzer/_ast_visitor.py @@ -616,7 +616,10 @@ def _create_attribute( raise TypeError("Attribute has an unexpected type.") type_ = None - if attribute_type is not None: + # Ignore types that are special mypy any types + if (attribute_type is not None and + not (isinstance(attribute_type, mp_types.AnyType) and attribute_type.type_of_any in + {mp_types.TypeOfAny.unannotated, mp_types.TypeOfAny.from_error})): type_ = mypy_type_to_abstract_type(attribute_type, unanalyzed_type) # Get docstring diff --git a/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr b/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr index f016936a..a3fc4811 100644 --- a/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr +++ b/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr @@ -102,11 +102,7 @@ 'is_static': True, 'is_type_inferred': False, 'name': 'callexpr_attr', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'Any', - 'qname': '', - }), + 'type': None, }), dict({ 'docstring': dict({ @@ -4243,48 +4239,48 @@ 'types': list([ dict({ 'kind': 'NamedType', - 'name': 'int', + 'name': 'float', 'qname': '', }), dict({ 'kind': 'NamedType', - 'name': 'InferMe', - 'qname': 'tests.data.test_package.infer_types_module.InferMe', + 'name': 'InferMyTypes', + 'qname': 'tests.data.test_package.infer_types_module.InferMyTypes', }), dict({ 'kind': 'NamedType', - 'name': 'None', - 'qname': 'builtins.None', + 'name': 'bool', + 'qname': '', }), dict({ 'kind': 'NamedType', - 'name': 'float', + 'name': 'str', 'qname': '', }), dict({ 'kind': 'NamedType', - 'name': 'bool', - 'qname': 'builtins.bool', + 'name': 'InferMe', + 'qname': 'tests.data.test_package.infer_types_module.InferMe', }), dict({ 'kind': 'NamedType', - 'name': 'str', - 'qname': '', + 'name': 'bool', + 'qname': 'builtins.bool', }), dict({ 'kind': 'NamedType', - 'name': 'bool', - 'qname': '', + 'name': 'None', + 'qname': 'builtins.None', }), dict({ 'kind': 'NamedType', - 'name': 'InferMyTypes', - 'qname': 'tests.data.test_package.infer_types_module.InferMyTypes', + 'name': 'int', + 'qname': 'builtins.int', }), dict({ 'kind': 'NamedType', 'name': 'int', - 'qname': 'builtins.int', + 'qname': '', }), ]), }), diff --git a/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr b/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr index 21fd1a6c..78ccb232 100644 --- a/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr +++ b/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr @@ -54,8 +54,9 @@ static attr noTypeHintPublic: Int @PythonName("object_attr") static attr objectAttr: AttributesClassA + // TODO Attribute has no type information. @PythonName("callexpr_attr") - static attr callexprAttr: Any + static attr callexprAttr // TODO Safe-DS does not support tuple types. @PythonName("tuple_attr_1") static attr tupleAttr1: Tuple From efaab1fdb88148d1549e53cfaae787eaabb0b597 Mon Sep 17 00:00:00 2001 From: Arsam Date: Tue, 28 Nov 2023 00:11:45 +0100 Subject: [PATCH 057/109] fixed a test snapshot bug where return types would be unsorted and mixed up with every test run --- .../api_analyzer/_ast_visitor.py | 8 ++++- .../__snapshots__/test__get_api.ambr | 30 +++++++++---------- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/src/safeds_stubgen/api_analyzer/_ast_visitor.py b/src/safeds_stubgen/api_analyzer/_ast_visitor.py index 6a15fac9..b5454ffc 100644 --- a/src/safeds_stubgen/api_analyzer/_ast_visitor.py +++ b/src/safeds_stubgen/api_analyzer/_ast_visitor.py @@ -391,7 +391,13 @@ def _infer_type_from_return_stmts( # We have to sort the list for the snapshot tests return_stmt_types = list(types) - return_stmt_types.sort(key=lambda x: x.__hash__()) + return_stmt_types.sort( + key=lambda x: ( + x.name + if isinstance(x, sds_types.NamedType) + else str(len(x.types)) + ) + ) if len(return_stmt_types) >= 2: return sds_types.TupleType(types=return_stmt_types) diff --git a/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr b/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr index a3fc4811..7954d694 100644 --- a/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr +++ b/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr @@ -4237,16 +4237,6 @@ 'type': dict({ 'kind': 'UnionType', 'types': list([ - dict({ - 'kind': 'NamedType', - 'name': 'float', - 'qname': '', - }), - dict({ - 'kind': 'NamedType', - 'name': 'InferMyTypes', - 'qname': 'tests.data.test_package.infer_types_module.InferMyTypes', - }), dict({ 'kind': 'NamedType', 'name': 'bool', @@ -4254,7 +4244,7 @@ }), dict({ 'kind': 'NamedType', - 'name': 'str', + 'name': 'float', 'qname': '', }), dict({ @@ -4264,14 +4254,19 @@ }), dict({ 'kind': 'NamedType', - 'name': 'bool', - 'qname': 'builtins.bool', + 'name': 'InferMyTypes', + 'qname': 'tests.data.test_package.infer_types_module.InferMyTypes', }), dict({ 'kind': 'NamedType', 'name': 'None', 'qname': 'builtins.None', }), + dict({ + 'kind': 'NamedType', + 'name': 'bool', + 'qname': 'builtins.bool', + }), dict({ 'kind': 'NamedType', 'name': 'int', @@ -4282,6 +4277,11 @@ 'name': 'int', 'qname': '', }), + dict({ + 'kind': 'NamedType', + 'name': 'str', + 'qname': '', + }), ]), }), }), @@ -4298,12 +4298,12 @@ 'types': list([ dict({ 'kind': 'NamedType', - 'name': 'float', + 'name': 'int', 'qname': '', }), dict({ 'kind': 'NamedType', - 'name': 'int', + 'name': 'float', 'qname': '', }), ]), From f448d1ebc2e5fc6a81fab5dca5abe6eb6a1951b0 Mon Sep 17 00:00:00 2001 From: Arsam Date: Wed, 29 Nov 2023 12:24:48 +0100 Subject: [PATCH 058/109] Added more cases where NamedType get qname information and adjusted tests --- .../api_analyzer/_mypy_helpers.py | 9 +- src/safeds_stubgen/api_analyzer/_types.py | 6 + .../__snapshots__/test_main.ambr | 24 +- .../__snapshots__/test__get_api.ambr | 250 +++++++++--------- 4 files changed, 145 insertions(+), 144 deletions(-) diff --git a/src/safeds_stubgen/api_analyzer/_mypy_helpers.py b/src/safeds_stubgen/api_analyzer/_mypy_helpers.py index 54a5b61e..b5736c87 100644 --- a/src/safeds_stubgen/api_analyzer/_mypy_helpers.py +++ b/src/safeds_stubgen/api_analyzer/_mypy_helpers.py @@ -70,7 +70,7 @@ def mypy_type_to_abstract_type( elif isinstance(mypy_type, mp_types.AnyType): return sds_types.NamedType(name="Any") elif isinstance(mypy_type, mp_types.NoneType): - return sds_types.NamedType(name="None") + return sds_types.NamedType(name="None", qname="builtins.None") elif isinstance(mypy_type, mp_types.LiteralType): return sds_types.LiteralType(literal=mypy_type.value) elif isinstance(mypy_type, mp_types.UnboundType): @@ -81,17 +81,12 @@ def mypy_type_to_abstract_type( ]) # Todo Aliasing: Import auflösen, wir können wir keinen fullname (qname) bekommen return sds_types.NamedType(name=mypy_type.name) - elif isinstance(mypy_type, mp_types.TypeType): - # The first parameter of cls methods - type_item = mypy_type.item - if isinstance(type_item, Instance): - return sds_types.NamedType(name=type_item.type.name) # Builtins elif isinstance(mypy_type, Instance): type_name = mypy_type.type.name if type_name in {"int", "str", "bool", "float"}: - return sds_types.NamedType(name=type_name) + return sds_types.NamedType(name=type_name, qname=mypy_type.type.fullname) # Iterable builtins elif type_name in {"tuple", "list", "set"}: diff --git a/src/safeds_stubgen/api_analyzer/_types.py b/src/safeds_stubgen/api_analyzer/_types.py index 8a3f8041..8cf656fe 100644 --- a/src/safeds_stubgen/api_analyzer/_types.py +++ b/src/safeds_stubgen/api_analyzer/_types.py @@ -58,6 +58,12 @@ def from_string(cls, name: str, qname: str = "") -> NamedType: def to_dict(self) -> dict[str, str]: return {"kind": self.__class__.__name__, "name": self.name, "qname": self.qname} + def __eq__(self, other: NamedType) -> bool: + return self.name == other.name and self.qname == other.qname + + def __hash__(self) -> int: + return hash((self.name, self.qname)) + @dataclass(frozen=True) class EnumType(AbstractType): diff --git a/tests/safeds_stubgen/__snapshots__/test_main.ambr b/tests/safeds_stubgen/__snapshots__/test_main.ambr index fce8144d..2375edc6 100644 --- a/tests/safeds_stubgen/__snapshots__/test_main.ambr +++ b/tests/safeds_stubgen/__snapshots__/test_main.ambr @@ -16,7 +16,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'float', - 'qname': '', + 'qname': 'builtins.float', }), }), dict({ @@ -33,7 +33,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'int', - 'qname': '', + 'qname': 'builtins.int', }), }), dict({ @@ -50,7 +50,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'bool', - 'qname': '', + 'qname': 'builtins.bool', }), }), dict({ @@ -67,7 +67,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'int', - 'qname': '', + 'qname': 'builtins.int', }), }), dict({ @@ -84,7 +84,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'int', - 'qname': '', + 'qname': 'builtins.int', }), }), dict({ @@ -101,7 +101,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'int', - 'qname': '', + 'qname': 'builtins.int', }), }), ]), @@ -575,7 +575,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'int', - 'qname': '', + 'qname': 'builtins.int', }), }), dict({ @@ -653,7 +653,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'bool', - 'qname': '', + 'qname': 'builtins.bool', }), }), dict({ @@ -713,7 +713,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'str', - 'qname': '', + 'qname': 'builtins.str', }), }), dict({ @@ -739,7 +739,7 @@ dict({ 'kind': 'NamedType', 'name': 'None', - 'qname': '', + 'qname': 'builtins.None', }), ]), }), @@ -763,12 +763,12 @@ dict({ 'kind': 'NamedType', 'name': 'bool', - 'qname': '', + 'qname': 'builtins.bool', }), dict({ 'kind': 'NamedType', 'name': 'None', - 'qname': '', + 'qname': 'builtins.None', }), ]), }), diff --git a/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr b/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr index 7954d694..c2a49372 100644 --- a/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr +++ b/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr @@ -15,7 +15,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'str', - 'qname': '', + 'qname': 'builtins.str', }), }), dict({ @@ -35,7 +35,7 @@ dict({ 'kind': 'NamedType', 'name': 'str', - 'qname': '', + 'qname': 'builtins.str', }), ]), }), @@ -54,7 +54,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'int', - 'qname': '', + 'qname': 'builtins.int', }), }), dict({ @@ -71,7 +71,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'int', - 'qname': '', + 'qname': 'builtins.int', }), }), dict({ @@ -88,7 +88,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'bool', - 'qname': '', + 'qname': 'builtins.bool', }), }), dict({ @@ -144,13 +144,13 @@ 'key_type': dict({ 'kind': 'NamedType', 'name': 'str', - 'qname': '', + 'qname': 'builtins.str', }), 'kind': 'DictType', 'value_type': dict({ 'kind': 'NamedType', 'name': 'int', - 'qname': '', + 'qname': 'builtins.int', }), }), }), @@ -172,12 +172,12 @@ dict({ 'kind': 'NamedType', 'name': 'str', - 'qname': '', + 'qname': 'builtins.str', }), dict({ 'kind': 'NamedType', 'name': 'int', - 'qname': '', + 'qname': 'builtins.int', }), ]), }), @@ -188,7 +188,7 @@ dict({ 'kind': 'NamedType', 'name': 'None', - 'qname': '', + 'qname': 'builtins.None', }), dict({ 'kind': 'NamedType', @@ -293,7 +293,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'float', - 'qname': '', + 'qname': 'builtins.float', }), }), dict({ @@ -310,7 +310,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'bool', - 'qname': '', + 'qname': 'builtins.bool', }), }), dict({ @@ -330,12 +330,12 @@ dict({ 'kind': 'NamedType', 'name': 'int', - 'qname': '', + 'qname': 'builtins.int', }), dict({ 'kind': 'NamedType', 'name': 'bool', - 'qname': '', + 'qname': 'builtins.bool', }), ]), }), @@ -483,7 +483,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'int', - 'qname': '', + 'qname': 'builtins.int', }), }), dict({ @@ -503,7 +503,7 @@ dict({ 'kind': 'NamedType', 'name': 'str', - 'qname': '', + 'qname': 'builtins.str', }), ]), }), @@ -522,7 +522,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'str', - 'qname': '', + 'qname': 'builtins.str', }), }), dict({ @@ -539,7 +539,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'str', - 'qname': '', + 'qname': 'builtins.str', }), }), dict({ @@ -556,7 +556,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'str', - 'qname': '', + 'qname': 'builtins.str', }), }), dict({ @@ -573,7 +573,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'str', - 'qname': '', + 'qname': 'builtins.str', }), }), dict({ @@ -590,7 +590,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'int', - 'qname': '', + 'qname': 'builtins.int', }), }), dict({ @@ -607,7 +607,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'None', - 'qname': '', + 'qname': 'builtins.None', }), }), dict({ @@ -644,12 +644,12 @@ dict({ 'kind': 'NamedType', 'name': 'int', - 'qname': '', + 'qname': 'builtins.int', }), dict({ 'kind': 'NamedType', 'name': 'None', - 'qname': '', + 'qname': 'builtins.None', }), ]), }), @@ -690,7 +690,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'str', - 'qname': '', + 'qname': 'builtins.str', }), }), dict({ @@ -735,12 +735,12 @@ dict({ 'kind': 'NamedType', 'name': 'str', - 'qname': '', + 'qname': 'builtins.str', }), dict({ 'kind': 'NamedType', 'name': 'int', - 'qname': '', + 'qname': 'builtins.int', }), ]), }), @@ -764,12 +764,12 @@ dict({ 'kind': 'NamedType', 'name': 'str', - 'qname': '', + 'qname': 'builtins.str', }), dict({ 'kind': 'NamedType', 'name': 'int', - 'qname': '', + 'qname': 'builtins.int', }), ]), }), @@ -788,7 +788,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'int', - 'qname': '', + 'qname': 'builtins.int', }), }), ]) @@ -809,7 +809,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'None', - 'qname': '', + 'qname': 'builtins.None', }), }), dict({ @@ -826,7 +826,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'None', - 'qname': '', + 'qname': 'builtins.None', }), }), ]) @@ -847,7 +847,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'str', - 'qname': '', + 'qname': 'builtins.str', }), }), ]) @@ -868,7 +868,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'str', - 'qname': '', + 'qname': 'builtins.str', }), }), ]) @@ -889,7 +889,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'str', - 'qname': '', + 'qname': 'builtins.str', }), }), ]) @@ -910,7 +910,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'float', - 'qname': '', + 'qname': 'builtins.float', }), }), dict({ @@ -927,7 +927,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'bool', - 'qname': '', + 'qname': 'builtins.bool', }), }), ]) @@ -2116,7 +2116,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'str', - 'qname': '', + 'qname': 'builtins.str', }), 'variance_type': 'COVARIANT', }), @@ -2137,7 +2137,7 @@ dict({ 'kind': 'NamedType', 'name': 'int', - 'qname': '', + 'qname': 'builtins.int', }), dict({ 'kind': 'UnionType', @@ -2188,7 +2188,7 @@ dict({ 'kind': 'NamedType', 'name': 'int', - 'qname': '', + 'qname': 'builtins.int', }), dict({ 'kind': 'UnionType', @@ -2422,7 +2422,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'str', - 'qname': '', + 'qname': 'builtins.str', }), }), dict({ @@ -2458,7 +2458,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'str', - 'qname': '', + 'qname': 'builtins.str', }), }), dict({ @@ -2494,7 +2494,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'str', - 'qname': '', + 'qname': 'builtins.str', }), }), dict({ @@ -2530,7 +2530,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'str', - 'qname': '', + 'qname': 'builtins.str', }), }), dict({ @@ -2566,7 +2566,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'int', - 'qname': '', + 'qname': 'builtins.int', }), }), dict({ @@ -2638,7 +2638,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'float', - 'qname': '', + 'qname': 'builtins.float', }), }), ]) @@ -2674,7 +2674,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'int', - 'qname': '', + 'qname': 'builtins.int', }), }), dict({ @@ -2692,7 +2692,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'int', - 'qname': '', + 'qname': 'builtins.int', }), }), ]) @@ -2778,7 +2778,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'int', - 'qname': '', + 'qname': 'builtins.int', }), }), ]) @@ -2800,7 +2800,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'int', - 'qname': '', + 'qname': 'builtins.int', }), }), ]) @@ -2822,7 +2822,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'int', - 'qname': '', + 'qname': 'builtins.int', }), }), dict({ @@ -2911,7 +2911,7 @@ dict({ 'kind': 'NamedType', 'name': 'int', - 'qname': '', + 'qname': 'builtins.int', }), ]), }), @@ -2932,13 +2932,13 @@ 'key_type': dict({ 'kind': 'NamedType', 'name': 'str', - 'qname': '', + 'qname': 'builtins.str', }), 'kind': 'DictType', 'value_type': dict({ 'kind': 'NamedType', 'name': 'int', - 'qname': '', + 'qname': 'builtins.int', }), }), }), @@ -2964,7 +2964,7 @@ dict({ 'kind': 'NamedType', 'name': 'str', - 'qname': '', + 'qname': 'builtins.str', }), ]), 'return_type': dict({ @@ -2973,12 +2973,12 @@ dict({ 'kind': 'NamedType', 'name': 'int', - 'qname': '', + 'qname': 'builtins.int', }), dict({ 'kind': 'NamedType', 'name': 'str', - 'qname': '', + 'qname': 'builtins.str', }), ]), }), @@ -3003,7 +3003,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'int', - 'qname': '', + 'qname': 'builtins.int', }), }), dict({ @@ -3085,22 +3085,22 @@ dict({ 'kind': 'NamedType', 'name': 'int', - 'qname': '', + 'qname': 'builtins.int', }), dict({ 'kind': 'NamedType', 'name': 'str', - 'qname': '', + 'qname': 'builtins.str', }), dict({ 'kind': 'NamedType', 'name': 'bool', - 'qname': '', + 'qname': 'builtins.bool', }), dict({ 'kind': 'NamedType', 'name': 'int', - 'qname': '', + 'qname': 'builtins.int', }), ]), }), @@ -3174,7 +3174,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'bool', - 'qname': '', + 'qname': 'builtins.bool', }), }), dict({ @@ -3228,7 +3228,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'int', - 'qname': '', + 'qname': 'builtins.int', }), }), dict({ @@ -3264,7 +3264,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'bool', - 'qname': '', + 'qname': 'builtins.bool', }), }), dict({ @@ -3297,7 +3297,7 @@ 'key_type': dict({ 'kind': 'NamedType', 'name': 'str', - 'qname': '', + 'qname': 'builtins.str', }), 'kind': 'DictType', 'value_type': dict({ @@ -3306,12 +3306,12 @@ dict({ 'kind': 'NamedType', 'name': 'int', - 'qname': '', + 'qname': 'builtins.int', }), dict({ 'kind': 'NamedType', 'name': 'float', - 'qname': '', + 'qname': 'builtins.float', }), ]), }), @@ -3332,7 +3332,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'float', - 'qname': '', + 'qname': 'builtins.float', }), }), dict({ @@ -3350,7 +3350,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'int', - 'qname': '', + 'qname': 'builtins.int', }), }), dict({ @@ -3371,7 +3371,7 @@ dict({ 'kind': 'NamedType', 'name': 'int', - 'qname': '', + 'qname': 'builtins.int', }), ]), }), @@ -3408,7 +3408,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'None', - 'qname': '', + 'qname': 'builtins.None', }), }), dict({ @@ -3447,12 +3447,12 @@ dict({ 'kind': 'NamedType', 'name': 'int', - 'qname': '', + 'qname': 'builtins.int', }), dict({ 'kind': 'NamedType', 'name': 'None', - 'qname': '', + 'qname': 'builtins.None', }), ]), }), @@ -3475,7 +3475,7 @@ dict({ 'kind': 'NamedType', 'name': 'str', - 'qname': '', + 'qname': 'builtins.str', }), ]), }), @@ -3495,7 +3495,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'str', - 'qname': '', + 'qname': 'builtins.str', }), }), dict({ @@ -3516,17 +3516,17 @@ dict({ 'kind': 'NamedType', 'name': 'int', - 'qname': '', + 'qname': 'builtins.int', }), dict({ 'kind': 'NamedType', 'name': 'str', - 'qname': '', + 'qname': 'builtins.str', }), dict({ 'kind': 'NamedType', 'name': 'bool', - 'qname': '', + 'qname': 'builtins.bool', }), ]), }), @@ -3549,12 +3549,12 @@ dict({ 'kind': 'NamedType', 'name': 'int', - 'qname': '', + 'qname': 'builtins.int', }), dict({ 'kind': 'NamedType', 'name': 'bool', - 'qname': '', + 'qname': 'builtins.bool', }), ]), }), @@ -3621,12 +3621,12 @@ dict({ 'kind': 'NamedType', 'name': 'bool', - 'qname': '', + 'qname': 'builtins.bool', }), dict({ 'kind': 'NamedType', 'name': 'None', - 'qname': '', + 'qname': 'builtins.None', }), ]), }), @@ -3646,7 +3646,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'None', - 'qname': '', + 'qname': 'builtins.None', }), }), dict({ @@ -3667,17 +3667,17 @@ dict({ 'kind': 'NamedType', 'name': 'None', - 'qname': '', + 'qname': 'builtins.None', }), dict({ 'kind': 'NamedType', 'name': 'bool', - 'qname': '', + 'qname': 'builtins.bool', }), dict({ 'kind': 'NamedType', 'name': 'int', - 'qname': '', + 'qname': 'builtins.int', }), ]), }), @@ -3700,17 +3700,17 @@ dict({ 'kind': 'NamedType', 'name': 'None', - 'qname': '', + 'qname': 'builtins.None', }), dict({ 'kind': 'NamedType', 'name': 'bool', - 'qname': '', + 'qname': 'builtins.bool', }), dict({ 'kind': 'NamedType', 'name': 'None', - 'qname': '', + 'qname': 'builtins.None', }), ]), }), @@ -3733,12 +3733,12 @@ dict({ 'kind': 'NamedType', 'name': 'None', - 'qname': '', + 'qname': 'builtins.None', }), dict({ 'kind': 'NamedType', 'name': 'bool', - 'qname': '', + 'qname': 'builtins.bool', }), ]), }), @@ -3761,7 +3761,7 @@ dict({ 'kind': 'NamedType', 'name': 'None', - 'qname': '', + 'qname': 'builtins.None', }), dict({ 'kind': 'ListType', @@ -3772,12 +3772,12 @@ dict({ 'kind': 'NamedType', 'name': 'None', - 'qname': '', + 'qname': 'builtins.None', }), dict({ 'kind': 'NamedType', 'name': 'None', - 'qname': '', + 'qname': 'builtins.None', }), ]), }), @@ -3786,7 +3786,7 @@ dict({ 'kind': 'NamedType', 'name': 'None', - 'qname': '', + 'qname': 'builtins.None', }), ]), }), @@ -3809,22 +3809,22 @@ dict({ 'kind': 'NamedType', 'name': 'None', - 'qname': '', + 'qname': 'builtins.None', }), dict({ 'kind': 'NamedType', 'name': 'None', - 'qname': '', + 'qname': 'builtins.None', }), dict({ 'kind': 'NamedType', 'name': 'bool', - 'qname': '', + 'qname': 'builtins.bool', }), dict({ 'kind': 'NamedType', 'name': 'None', - 'qname': '', + 'qname': 'builtins.None', }), ]), }), @@ -3847,12 +3847,12 @@ dict({ 'kind': 'NamedType', 'name': 'None', - 'qname': '', + 'qname': 'builtins.None', }), dict({ 'kind': 'NamedType', 'name': 'None', - 'qname': '', + 'qname': 'builtins.None', }), ]), }), @@ -3890,7 +3890,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'int', - 'qname': '', + 'qname': 'builtins.int', }), }), dict({ @@ -3908,7 +3908,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'int', - 'qname': '', + 'qname': 'builtins.int', }), }), ]) @@ -3944,7 +3944,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'int', - 'qname': '', + 'qname': 'builtins.int', }), }), dict({ @@ -3962,7 +3962,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'int', - 'qname': '', + 'qname': 'builtins.int', }), }), ]) @@ -3998,7 +3998,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'int', - 'qname': '', + 'qname': 'builtins.int', }), }), dict({ @@ -4016,7 +4016,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'int', - 'qname': '', + 'qname': 'builtins.int', }), }), ]) @@ -4037,7 +4037,7 @@ dict({ 'kind': 'NamedType', 'name': 'str', - 'qname': '', + 'qname': 'builtins.str', }), ]), }), @@ -4057,7 +4057,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'float', - 'qname': '', + 'qname': 'builtins.float', }), }), dict({ @@ -4071,7 +4071,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'int', - 'qname': '', + 'qname': 'builtins.int', }), }), ]) @@ -4089,7 +4089,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'bool', - 'qname': '', + 'qname': 'builtins.bool', }), }), ]) @@ -4110,18 +4110,18 @@ dict({ 'kind': 'NamedType', 'name': 'int', - 'qname': '', + 'qname': 'builtins.int', }), dict({ 'kind': 'NamedType', 'name': 'int', - 'qname': '', + 'qname': 'builtins.int', }), ]), 'return_type': dict({ 'kind': 'NamedType', 'name': 'int', - 'qname': '', + 'qname': 'builtins.int', }), }), }), @@ -4140,7 +4140,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'bool', - 'qname': '', + 'qname': 'builtins.bool', }), }), ]) @@ -4158,7 +4158,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'bool', - 'qname': '', + 'qname': 'builtins.bool', }), }), ]) @@ -4198,7 +4198,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'str', - 'qname': '', + 'qname': 'builtins.str', }), }), ]) @@ -4219,7 +4219,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'bool', - 'qname': '', + 'qname': 'builtins.bool', }), }), ]) @@ -4356,7 +4356,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'str', - 'qname': '', + 'qname': 'builtins.str', }), }), dict({ @@ -4370,7 +4370,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'int', - 'qname': '', + 'qname': 'builtins.int', }), }), dict({ @@ -4384,7 +4384,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'bool', - 'qname': '', + 'qname': 'builtins.bool', }), }), dict({ @@ -4416,7 +4416,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'bool', - 'qname': '', + 'qname': 'builtins.bool', }), }), ]) @@ -4434,7 +4434,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'bool', - 'qname': '', + 'qname': 'builtins.bool', }), }), ]) @@ -4452,7 +4452,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'bool', - 'qname': '', + 'qname': 'builtins.bool', }), }), ]) From 75df41e658689fc93ebd2e5fabc43594802c33b0 Mon Sep 17 00:00:00 2001 From: Arsam Date: Wed, 29 Nov 2023 12:48:51 +0100 Subject: [PATCH 059/109] Added more cases where NamedType get qname information and added more test cases --- .../api_analyzer/_ast_visitor.py | 14 ++--- src/safeds_stubgen/api_analyzer/_types.py | 6 +- tests/data/test_package/function_module.py | 57 +++++++++++++++++-- .../__snapshots__/test__get_api.ambr | 40 ++++++++----- .../__snapshots__/test_generate_stubs.ambr | 4 +- 5 files changed, 91 insertions(+), 30 deletions(-) diff --git a/src/safeds_stubgen/api_analyzer/_ast_visitor.py b/src/safeds_stubgen/api_analyzer/_ast_visitor.py index b5454ffc..af680814 100644 --- a/src/safeds_stubgen/api_analyzer/_ast_visitor.py +++ b/src/safeds_stubgen/api_analyzer/_ast_visitor.py @@ -361,15 +361,15 @@ def leave_assignmentstmt(self, _: mp_nodes.AssignmentStmt) -> None: def _mypy_expression_to_sds_type(self, expr: mp_nodes.Expression) -> sds_types.NamedType | sds_types.TupleType: if isinstance(expr, mp_nodes.NameExpr): if expr.name in {"False", "True"}: - return sds_types.NamedType(name="bool") + return sds_types.NamedType(name="bool", qname="builtins.bool") else: return sds_types.NamedType(name=expr.name, qname=expr.fullname) elif isinstance(expr, mp_nodes.IntExpr): - return sds_types.NamedType(name="int") + return sds_types.NamedType(name="int", qname="builtins.int") elif isinstance(expr, mp_nodes.FloatExpr): - return sds_types.NamedType(name="float") + return sds_types.NamedType(name="float", qname="builtins.float") elif isinstance(expr, mp_nodes.StrExpr): - return sds_types.NamedType(name="str") + return sds_types.NamedType(name="str", qname="builtins.str") elif isinstance(expr, mp_nodes.TupleExpr): return sds_types.TupleType(types=[ self._mypy_expression_to_sds_type(item) @@ -671,7 +671,7 @@ def _get_default_parameter_value_and_type( if self._check_if_qname_in_package(initializer.fullname): default_value = initializer.name if infer_arg_type: - arg_type = sds_types.NamedType(initializer.name, initializer.fullname) + arg_type = sds_types.NamedType(name=initializer.name, qname=initializer.fullname) return default_value, arg_type @@ -681,7 +681,7 @@ def _get_default_parameter_value_and_type( if self._check_if_qname_in_package(initializer.callee.fullname): default_value = f"{initializer.callee.name}()" if infer_arg_type: - arg_type = sds_types.NamedType(initializer.callee.name, initializer.callee.fullname) + arg_type = sds_types.NamedType(name=initializer.callee.name, qname=initializer.callee.fullname) return default_value, arg_type @@ -700,7 +700,7 @@ def _get_default_parameter_value_and_type( float: "float", NoneType: "None", }[type(value)] - arg_type = sds_types.NamedType(name=value_type_name) + arg_type = sds_types.NamedType(name=value_type_name, qname=f"builtins.{value_type_name}") return default_value, arg_type diff --git a/src/safeds_stubgen/api_analyzer/_types.py b/src/safeds_stubgen/api_analyzer/_types.py index 8cf656fe..80774d2a 100644 --- a/src/safeds_stubgen/api_analyzer/_types.py +++ b/src/safeds_stubgen/api_analyzer/_types.py @@ -49,7 +49,7 @@ class NamedType(AbstractType): @classmethod def from_dict(cls, d: dict[str, Any]) -> NamedType: - return NamedType(d["name"]) + return NamedType(d["name"], d["qname"]) @classmethod def from_string(cls, name: str, qname: str = "") -> NamedType: @@ -459,7 +459,7 @@ def __hash__(self) -> int: # # Todo Return mypy\types -> Type class # def create_type(type_string: str, description: str) -> AbstractType: # if not type_string: -# return NamedType("None") +# return NamedType("None", "builtins.None") # # type_string = type_string.replace(" ", "") # @@ -518,7 +518,7 @@ def __hash__(self) -> int: # type_ = _create_enum_boundry_type(type_string, description) # if type_ is not None: # return type_ -# return NamedType(type_string) +# return NamedType(name=type_string, qname=) # # # # todo übernehmen in create_type -> Tests schlagen nun fehl diff --git a/tests/data/test_package/function_module.py b/tests/data/test_package/function_module.py index 976e69da..fac34c0b 100644 --- a/tests/data/test_package/function_module.py +++ b/tests/data/test_package/function_module.py @@ -1,4 +1,4 @@ -from typing import Callable, Optional, Literal +from typing import Callable, Optional, Literal, Any class FunctionModuleClassA: @@ -50,7 +50,8 @@ def params( set_: set[str], optional: Optional[int], tuple_: tuple[int, str, bool], - literal: Literal["Some String"] + literal: Literal["Some String"], + any_: Any ): ... @@ -89,10 +90,58 @@ def arg(*args, **kwargs): ... def args_type(*args: int, **kwargs: int): ... -def one_result() -> int: ... +def int_result() -> int: ... -def multiple_results() -> tuple[str, int, bool, FunctionModuleClassA]: ... +def str_result() -> str: ... + + +def bool_result() -> str: ... + + +def float_result() -> float: ... + + +def none_result() -> None: ... + + +def obj_result() -> FunctionModuleClassA: ... + + +def callexr_result() -> FunctionModuleClassA(): ... + + +def tuple_results() -> tuple[str, FunctionModuleClassA]: ... + + +def union_results() -> int | str: ... + + +def list_results() -> list[int]: ... + + +def illegal_list_results() -> list[int, str]: ... + + +def dictionary_results() -> dict[str, FunctionModuleClassA]: ... + + +def illegal_dictionary_results() -> dict[int, str, FunctionModuleClassA]: ... + + +def union_dictionary_results() -> dict[int | str, bool | float]: ... + + +def set_results() -> set[str]: ... + + +def optional_results() -> Optional[int]: ... + + +def literal_results() -> Literal["Some String"]: ... + + +def any_results() -> Any: ... def callable_type(param: Callable[[str], tuple[int, str]]) -> Callable[[int, int], int]: ... diff --git a/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr b/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr index c2a49372..e9e6c38a 100644 --- a/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr +++ b/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr @@ -2584,7 +2584,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'bool', - 'qname': '', + 'qname': 'builtins.bool', }), }), dict({ @@ -3124,7 +3124,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'int', - 'qname': '', + 'qname': 'builtins.int', }), }), dict({ @@ -3249,6 +3249,20 @@ # --- # name: test_function_parameters_function_module_params list([ + dict({ + 'assigned_by': 'POSITION_OR_NAME', + 'default_value': None, + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_package/function_module/params/any_', + 'is_optional': False, + 'is_type_inferred': False, + 'name': 'any_', + 'type': None, + }), dict({ 'assigned_by': 'POSITION_OR_NAME', 'default_value': None, @@ -3582,7 +3596,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'int', - 'qname': '', + 'qname': 'builtins.int', }), }), dict({ @@ -4180,7 +4194,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'str', - 'qname': '', + 'qname': 'builtins.str', }), }), ]) @@ -4240,12 +4254,12 @@ dict({ 'kind': 'NamedType', 'name': 'bool', - 'qname': '', + 'qname': 'builtins.bool', }), dict({ 'kind': 'NamedType', 'name': 'float', - 'qname': '', + 'qname': 'builtins.float', }), dict({ 'kind': 'NamedType', @@ -4272,15 +4286,10 @@ 'name': 'int', 'qname': 'builtins.int', }), - dict({ - 'kind': 'NamedType', - 'name': 'int', - 'qname': '', - }), dict({ 'kind': 'NamedType', 'name': 'str', - 'qname': '', + 'qname': 'builtins.str', }), ]), }), @@ -4299,12 +4308,12 @@ dict({ 'kind': 'NamedType', 'name': 'int', - 'qname': '', + 'qname': 'builtins.int', }), dict({ 'kind': 'NamedType', 'name': 'float', - 'qname': '', + 'qname': 'builtins.float', }), ]), }), @@ -4320,7 +4329,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'float', - 'qname': '', + 'qname': 'builtins.float', }), }), ]) @@ -4784,6 +4793,7 @@ 'test_package/function_module/params/optional', 'test_package/function_module/params/tuple_', 'test_package/function_module/params/literal', + 'test_package/function_module/params/any_', ]), 'reexported_by': list([ ]), diff --git a/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr b/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr index 78ccb232..87b7d5db 100644 --- a/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr +++ b/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr @@ -204,6 +204,7 @@ from typing import Callable from typing import Optional from typing import Literal + from typing import Any // TODO Result type information missing. @Pure @@ -228,7 +229,8 @@ @PythonName("set_") set: Set, optional: Int?, @PythonName("tuple_") tuple: Tuple, - `literal`: literal + `literal`: literal, + @PythonName("any_") any ) // TODO List type has to many type arguments. From 684d40ae26749e091ab73ca8cf32834c02c593a9 Mon Sep 17 00:00:00 2001 From: Arsam Date: Wed, 29 Nov 2023 12:55:11 +0100 Subject: [PATCH 060/109] Adjusted test snapshots --- .../__snapshots__/test__get_api.ambr | 379 ++++++++++++++---- .../__snapshots__/test_generate_stubs.ambr | 75 +++- 2 files changed, 381 insertions(+), 73 deletions(-) diff --git a/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr b/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr index e9e6c38a..eb941440 100644 --- a/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr +++ b/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr @@ -4352,66 +4352,6 @@ }), ]) # --- -# name: test_function_results_multiple_results - list([ - dict({ - 'docstring': dict({ - 'description': '', - 'type': '', - }), - 'id': 'test_package/function_module/multiple_results/result_1', - 'is_type_inferred': False, - 'name': 'result_1', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'str', - 'qname': 'builtins.str', - }), - }), - dict({ - 'docstring': dict({ - 'description': '', - 'type': '', - }), - 'id': 'test_package/function_module/multiple_results/result_2', - 'is_type_inferred': False, - 'name': 'result_2', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'int', - 'qname': 'builtins.int', - }), - }), - dict({ - 'docstring': dict({ - 'description': '', - 'type': '', - }), - 'id': 'test_package/function_module/multiple_results/result_3', - 'is_type_inferred': False, - 'name': 'result_3', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'bool', - 'qname': 'builtins.bool', - }), - }), - dict({ - 'docstring': dict({ - 'description': '', - 'type': '', - }), - 'id': 'test_package/function_module/multiple_results/result_4', - 'is_type_inferred': False, - 'name': 'result_4', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'FunctionModuleClassA', - 'qname': 'tests.data.test_package.function_module.FunctionModuleClassA', - }), - }), - ]) -# --- # name: test_function_results_nested_class_function list([ dict({ @@ -4600,6 +4540,25 @@ 'results': list([ ]), }), + dict({ + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_package/function_module/any_results', + 'is_class_method': False, + 'is_property': False, + 'is_public': True, + 'is_static': False, + 'name': 'any_results', + 'parameters': list([ + ]), + 'reexported_by': list([ + ]), + 'results': list([ + 'test_package/function_module/any_results/result_1', + ]), + }), dict({ 'docstring': dict({ 'description': '', @@ -4640,6 +4599,25 @@ 'results': list([ ]), }), + dict({ + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_package/function_module/bool_result', + 'is_class_method': False, + 'is_property': False, + 'is_public': True, + 'is_static': False, + 'name': 'bool_result', + 'parameters': list([ + ]), + 'reexported_by': list([ + ]), + 'results': list([ + 'test_package/function_module/bool_result/result_1', + ]), + }), dict({ 'docstring': dict({ 'description': '', @@ -4660,6 +4638,101 @@ 'test_package/function_module/callable_type/result_1', ]), }), + dict({ + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_package/function_module/callexr_result', + 'is_class_method': False, + 'is_property': False, + 'is_public': True, + 'is_static': False, + 'name': 'callexr_result', + 'parameters': list([ + ]), + 'reexported_by': list([ + ]), + 'results': list([ + 'test_package/function_module/callexr_result/result_1', + ]), + }), + dict({ + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_package/function_module/dictionary_results', + 'is_class_method': False, + 'is_property': False, + 'is_public': True, + 'is_static': False, + 'name': 'dictionary_results', + 'parameters': list([ + ]), + 'reexported_by': list([ + ]), + 'results': list([ + 'test_package/function_module/dictionary_results/result_1', + ]), + }), + dict({ + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_package/function_module/float_result', + 'is_class_method': False, + 'is_property': False, + 'is_public': True, + 'is_static': False, + 'name': 'float_result', + 'parameters': list([ + ]), + 'reexported_by': list([ + ]), + 'results': list([ + 'test_package/function_module/float_result/result_1', + ]), + }), + dict({ + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_package/function_module/illegal_dictionary_results', + 'is_class_method': False, + 'is_property': False, + 'is_public': True, + 'is_static': False, + 'name': 'illegal_dictionary_results', + 'parameters': list([ + ]), + 'reexported_by': list([ + ]), + 'results': list([ + 'test_package/function_module/illegal_dictionary_results/result_1', + ]), + }), + dict({ + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_package/function_module/illegal_list_results', + 'is_class_method': False, + 'is_property': False, + 'is_public': True, + 'is_static': False, + 'name': 'illegal_list_results', + 'parameters': list([ + ]), + 'reexported_by': list([ + ]), + 'results': list([ + 'test_package/function_module/illegal_list_results/result_1', + ]), + }), dict({ 'docstring': dict({ 'description': '', @@ -4687,21 +4760,74 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/function_module/multiple_results', + 'id': 'test_package/function_module/int_result', + 'is_class_method': False, + 'is_property': False, + 'is_public': True, + 'is_static': False, + 'name': 'int_result', + 'parameters': list([ + ]), + 'reexported_by': list([ + ]), + 'results': list([ + 'test_package/function_module/int_result/result_1', + ]), + }), + dict({ + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_package/function_module/list_results', + 'is_class_method': False, + 'is_property': False, + 'is_public': True, + 'is_static': False, + 'name': 'list_results', + 'parameters': list([ + ]), + 'reexported_by': list([ + ]), + 'results': list([ + 'test_package/function_module/list_results/result_1', + ]), + }), + dict({ + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_package/function_module/literal_results', + 'is_class_method': False, + 'is_property': False, + 'is_public': True, + 'is_static': False, + 'name': 'literal_results', + 'parameters': list([ + ]), + 'reexported_by': list([ + ]), + 'results': list([ + 'test_package/function_module/literal_results/result_1', + ]), + }), + dict({ + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_package/function_module/none_result', 'is_class_method': False, 'is_property': False, 'is_public': True, 'is_static': False, - 'name': 'multiple_results', + 'name': 'none_result', 'parameters': list([ ]), 'reexported_by': list([ ]), 'results': list([ - 'test_package/function_module/multiple_results/result_1', - 'test_package/function_module/multiple_results/result_2', - 'test_package/function_module/multiple_results/result_3', - 'test_package/function_module/multiple_results/result_4', ]), }), dict({ @@ -4709,18 +4835,18 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/function_module/one_result', + 'id': 'test_package/function_module/obj_result', 'is_class_method': False, 'is_property': False, 'is_public': True, 'is_static': False, - 'name': 'one_result', + 'name': 'obj_result', 'parameters': list([ ]), 'reexported_by': list([ ]), 'results': list([ - 'test_package/function_module/one_result/result_1', + 'test_package/function_module/obj_result/result_1', ]), }), dict({ @@ -4743,6 +4869,25 @@ 'results': list([ ]), }), + dict({ + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_package/function_module/optional_results', + 'is_class_method': False, + 'is_property': False, + 'is_public': True, + 'is_static': False, + 'name': 'optional_results', + 'parameters': list([ + ]), + 'reexported_by': list([ + ]), + 'results': list([ + 'test_package/function_module/optional_results/result_1', + ]), + }), dict({ 'docstring': dict({ 'description': '', @@ -4838,6 +4983,25 @@ 'results': list([ ]), }), + dict({ + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_package/function_module/set_results', + 'is_class_method': False, + 'is_property': False, + 'is_public': True, + 'is_static': False, + 'name': 'set_results', + 'parameters': list([ + ]), + 'reexported_by': list([ + ]), + 'results': list([ + 'test_package/function_module/set_results/result_1', + ]), + }), dict({ 'docstring': dict({ 'description': '', @@ -4864,6 +5028,83 @@ 'results': list([ ]), }), + dict({ + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_package/function_module/str_result', + 'is_class_method': False, + 'is_property': False, + 'is_public': True, + 'is_static': False, + 'name': 'str_result', + 'parameters': list([ + ]), + 'reexported_by': list([ + ]), + 'results': list([ + 'test_package/function_module/str_result/result_1', + ]), + }), + dict({ + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_package/function_module/tuple_results', + 'is_class_method': False, + 'is_property': False, + 'is_public': True, + 'is_static': False, + 'name': 'tuple_results', + 'parameters': list([ + ]), + 'reexported_by': list([ + ]), + 'results': list([ + 'test_package/function_module/tuple_results/result_1', + 'test_package/function_module/tuple_results/result_2', + ]), + }), + dict({ + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_package/function_module/union_dictionary_results', + 'is_class_method': False, + 'is_property': False, + 'is_public': True, + 'is_static': False, + 'name': 'union_dictionary_results', + 'parameters': list([ + ]), + 'reexported_by': list([ + ]), + 'results': list([ + 'test_package/function_module/union_dictionary_results/result_1', + ]), + }), + dict({ + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_package/function_module/union_results', + 'is_class_method': False, + 'is_property': False, + 'is_public': True, + 'is_static': False, + 'name': 'union_results', + 'parameters': list([ + ]), + 'reexported_by': list([ + ]), + 'results': list([ + 'test_package/function_module/union_results/result_1', + ]), + }), ]) # --- # name: test_imports___init___qualified_imports diff --git a/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr b/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr index 87b7d5db..ca03da72 100644 --- a/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr +++ b/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr @@ -310,12 +310,79 @@ ) @Pure - @PythonName("one_result") - fun oneResult() -> result1: Int + @PythonName("int_result") + fun intResult() -> result1: Int @Pure - @PythonName("multiple_results") - fun multipleResults() -> (result1: String, result2: Int, result3: Boolean, result4: FunctionModuleClassA) + @PythonName("str_result") + fun strResult() -> result1: String + + @Pure + @PythonName("bool_result") + fun boolResult() -> result1: Boolean + + @Pure + @PythonName("float_result") + fun floatResult() -> result1: Float + + // TODO Result type information missing. + @Pure + @PythonName("none_result") + fun noneResult() + + @Pure + @PythonName("obj_result") + fun objResult() -> result1: FunctionModuleClassA + + // TODO Result type information missing. + @Pure + @PythonName("callexr_result") + fun callexrResult() + + @Pure + @PythonName("tuple_results") + fun tupleResults() -> (result1: String, result2: FunctionModuleClassA) + + @Pure + @PythonName("union_results") + fun unionResults() -> result1: union + + @Pure + @PythonName("list_results") + fun listResults() -> result1: List + + // TODO List type has to many type arguments. + @Pure + @PythonName("illegal_list_results") + fun illegalListResults() -> result1: List + + @Pure + @PythonName("dictionary_results") + fun dictionaryResults() -> result1: Map + + @Pure + @PythonName("illegal_dictionary_results") + fun illegalDictionaryResults() -> result1: Map + + @Pure + @PythonName("union_dictionary_results") + fun unionDictionaryResults() -> result1: Map, union> + + @Pure + @PythonName("set_results") + fun setResults() -> result1: Set + + @Pure + @PythonName("optional_results") + fun optionalResults() -> result1: Int? + + @Pure + @PythonName("literal_results") + fun literalResults() -> result1: literal<"Some String"> + + @Pure + @PythonName("any_results") + fun anyResults() -> result1: Any @Pure @PythonName("callable_type") From d6b8bf7837a0fb1d6e3025a3fddc22bc3aefaf9d Mon Sep 17 00:00:00 2001 From: Arsam Date: Wed, 29 Nov 2023 14:15:00 +0100 Subject: [PATCH 061/109] API-Analyzer: Better handling for Any types and illegal list and set types; Stubs-Generator: fixed string literal types --- .../api_analyzer/_ast_visitor.py | 37 +++++++------- .../api_analyzer/_mypy_helpers.py | 50 ++++++++++++++----- .../stubs_generator/_generate_stubs.py | 5 +- tests/data/test_package/function_module.py | 5 +- .../__snapshots__/test__get_api.ambr | 26 +++++++++- .../__snapshots__/test_generate_stubs.ambr | 11 ++-- 6 files changed, 95 insertions(+), 39 deletions(-) diff --git a/src/safeds_stubgen/api_analyzer/_ast_visitor.py b/src/safeds_stubgen/api_analyzer/_ast_visitor.py index af680814..d33e5c08 100644 --- a/src/safeds_stubgen/api_analyzer/_ast_visitor.py +++ b/src/safeds_stubgen/api_analyzer/_ast_visitor.py @@ -29,6 +29,7 @@ get_classdef_definitions, get_funcdef_definitions, get_mypyfile_definitions, + has_correct_type_of_any, mypy_type_to_abstract_type, mypy_variance_parser, ) @@ -155,7 +156,7 @@ def enter_classdef(self, node: mp_nodes.ClassDef) -> None: variances.append(Variance( name=generic_type.name, type=variance_values, - variance_type=variance_type + variance_type=variance_type, )) # superclasses @@ -184,7 +185,7 @@ def enter_classdef(self, node: mp_nodes.ClassDef) -> None: docstring=docstring, reexported_by=reexported_by, constructor_fulldocstring=constructor_fulldocstring, - variances=variances + variances=variances, ) self.__declaration_stack.append(class_) @@ -379,8 +380,9 @@ def _mypy_expression_to_sds_type(self, expr: mp_nodes.Expression) -> sds_types.N raise TypeError("Unexpected expression type for return type.") def _infer_type_from_return_stmts( - self, func_node: mp_nodes.FuncDef + self, func_node: mp_nodes.FuncDef, ) -> sds_types.NamedType | sds_types.TupleType | None: + # To infer the type, we iterate through all return statements we find in the function func_defn = get_funcdef_definitions(func_node) return_stmts = find_return_stmts_recursive(func_defn) if return_stmts: @@ -396,7 +398,7 @@ def _infer_type_from_return_stmts( x.name if isinstance(x, sds_types.NamedType) else str(len(x.types)) - ) + ), ) if len(return_stmt_types) >= 2: @@ -417,18 +419,14 @@ def _create_result(self, node: mp_nodes.FuncDef, function_id: str) -> list[Resul node_ret_type = node_type.ret_type if not isinstance(node_ret_type, mp_types.NoneType): - # In Mypy AnyType can be set as type because of different reasons (see TypeOfAny - # class-documentation) if (isinstance(node_ret_type, mp_types.AnyType) and - node_ret_type.type_of_any == mp_types.TypeOfAny.unannotated): - # In this case, the "Any" type was given, because there was no annotation, therefore we have to - # either infer the type or set no type at all. To infer the type, we iterate through all return - # statements + not has_correct_type_of_any(node_ret_type.type_of_any)): + # In this case, the "Any" type was given because it was not explicitly annotated. + # Therefor we have to either infer the type or set no type at all. ret_type = self._infer_type_from_return_stmts(node) is_type_inferred = ret_type is not None - else: - ret_type = mypy_type_to_abstract_type(node_ret_type) + ret_type = mypy_type_to_abstract_type(node_ret_type, node.unanalyzed_type.ret_type) else: # Infer type ret_type = self._infer_type_from_return_stmts(node) @@ -477,7 +475,7 @@ def _create_result(self, node: mp_nodes.FuncDef, function_id: str) -> list[Resul is_type_inferred=is_type_inferred, name=name, docstring=docstring, - ) + ), ) return results @@ -591,7 +589,7 @@ def _create_attribute( # MemberExpr are constructor (__init__) attributes if isinstance(attribute, mp_nodes.MemberExpr): attribute_type = node.type - if isinstance(attribute_type, mp_types.AnyType) and mp_types.TypeOfAny.unannotated: + if isinstance(attribute_type, mp_types.AnyType) and not has_correct_type_of_any(attribute_type.type_of_any): attribute_type = None # Sometimes the is_inferred value is True even thoght has_explicit_value is False, thus we HAVE to check @@ -623,9 +621,8 @@ def _create_attribute( type_ = None # Ignore types that are special mypy any types - if (attribute_type is not None and - not (isinstance(attribute_type, mp_types.AnyType) and attribute_type.type_of_any in - {mp_types.TypeOfAny.unannotated, mp_types.TypeOfAny.from_error})): + if (attribute_type is not None and not (isinstance(attribute_type, mp_types.AnyType) and + not has_correct_type_of_any(attribute_type.type_of_any))): type_ = mypy_type_to_abstract_type(attribute_type, unanalyzed_type) # Get docstring @@ -651,7 +648,7 @@ def _create_attribute( # #### Parameter utilities def _get_default_parameter_value_and_type( - self, initializer: mp_nodes.Expression, infer_arg_type: bool = False + self, initializer: mp_nodes.Expression, infer_arg_type: bool = False, ) -> tuple[None | str | float | int | bool | NoneType, None | sds_types.NamedType]: # Get default value information default_value = None @@ -718,7 +715,7 @@ def _parse_parameter_data(self, node: mp_nodes.FuncDef, function_id: str) -> lis type_annotation = argument.type_annotation arg_type = None - if isinstance(mypy_type, mp_types.AnyType) and mp_types.TypeOfAny.unannotated: + if isinstance(mypy_type, mp_types.AnyType) and not has_correct_type_of_any(mypy_type.type_of_any): # We try to infer the type through the default value later, if possible pass elif (isinstance(type_annotation, mp_types.UnboundType) and @@ -738,7 +735,7 @@ def _parse_parameter_data(self, node: mp_nodes.FuncDef, function_id: str) -> lis infer_arg_type = arg_type is None default_value, inferred_arg_type = self._get_default_parameter_value_and_type( initializer=initializer, - infer_arg_type=infer_arg_type + infer_arg_type=infer_arg_type, ) if infer_arg_type: arg_type = inferred_arg_type diff --git a/src/safeds_stubgen/api_analyzer/_mypy_helpers.py b/src/safeds_stubgen/api_analyzer/_mypy_helpers.py index b5736c87..14d26cae 100644 --- a/src/safeds_stubgen/api_analyzer/_mypy_helpers.py +++ b/src/safeds_stubgen/api_analyzer/_mypy_helpers.py @@ -33,21 +33,38 @@ def get_mypyfile_definitions(node: MypyFile) -> list: def mypy_type_to_abstract_type( mypy_type: Instance | ProperType | MypyType, - unanalyzed_type: mp_types.Type | None = None + unanalyzed_type: mp_types.Type | None = None, ) -> AbstractType: - # Final type - if unanalyzed_type is not None and hasattr(unanalyzed_type, "name") and unanalyzed_type.name == "Final": - types = [ - mypy_type_to_abstract_type(arg) - for arg in unanalyzed_type.args - ] - if len(types) == 1: - return sds_types.FinalType(type_=types[0]) - return sds_types.FinalType(type_=sds_types.UnionType(types=types)) + # Special cases where we need the unanalyzed_type to get the type information we need + if unanalyzed_type is not None and hasattr(unanalyzed_type, "name"): + unanalyzed_type_name = unanalyzed_type.name + if unanalyzed_type_name == "Final": + # Final type + types = [ + mypy_type_to_abstract_type(arg) + for arg in unanalyzed_type.args + ] + if len(types) == 1: + return sds_types.FinalType(type_=types[0]) + return sds_types.FinalType(type_=sds_types.UnionType(types=types)) + elif (unanalyzed_type_name in {"list", "set"} and + len(mypy_type.args) == 1 and + isinstance(mypy_type.args[0], mp_types.AnyType) and + not has_correct_type_of_any(mypy_type.args[0].type_of_any)): + # This case happens if we have a list or set with multiple arguments like "list[str, int]" which is + # not allowed. In this case mypy interprets the type as "list[Any]", but we want the real types + # of the list arguments, which we cant get through the "unanalyzed_type" attribute + return { + "list": sds_types.ListType, + "set": sds_types.SetType + }[unanalyzed_type_name](types=[ + mypy_type_to_abstract_type(arg) + for arg in unanalyzed_type.args + ]) # Iterable mypy types - elif isinstance(mypy_type, mp_types.TupleType): + if isinstance(mypy_type, mp_types.TupleType): return sds_types.TupleType(types=[ mypy_type_to_abstract_type(item) for item in mypy_type.items @@ -65,7 +82,7 @@ def mypy_type_to_abstract_type( mypy_type_to_abstract_type(arg_type) for arg_type in mypy_type.arg_types ], - return_type=mypy_type_to_abstract_type(mypy_type.ret_type) + return_type=mypy_type_to_abstract_type(mypy_type.ret_type), ) elif isinstance(mypy_type, mp_types.AnyType): return sds_types.NamedType(name="Any") @@ -164,3 +181,12 @@ def mypy_variance_parser(mypy_variance_type: Literal[0, 1, 2]) -> VarianceType: return VarianceType.CONTRAVARIANT case _: # pragma: no cover raise ValueError("Mypy variance parser received an illegal parameter value.") + + +def has_correct_type_of_any(type_of_any: int) -> bool: + # In Mypy AnyType can be set as type because of different reasons (see TypeOfAny class-documentation) + return type_of_any in { + mp_types.TypeOfAny.explicit, + mp_types.TypeOfAny.from_omitted_generics, + mp_types.TypeOfAny.from_another_any, + } diff --git a/src/safeds_stubgen/stubs_generator/_generate_stubs.py b/src/safeds_stubgen/stubs_generator/_generate_stubs.py index 9f8c92c5..b55c0b6c 100644 --- a/src/safeds_stubgen/stubs_generator/_generate_stubs.py +++ b/src/safeds_stubgen/stubs_generator/_generate_stubs.py @@ -660,7 +660,10 @@ def _create_type_string(self, type_data: dict | None) -> str: return f"Map<{key_data}>" return "Map" elif kind == "LiteralType": - return f"literal<{type_data['literal']}>" + literal_type = type_data["literal"] + if isinstance(literal_type, str): + literal_type = f'"{literal_type}"' + return f"literal<{literal_type}>" raise ValueError(f"Unexpected type: {kind}") diff --git a/tests/data/test_package/function_module.py b/tests/data/test_package/function_module.py index fac34c0b..fe19c120 100644 --- a/tests/data/test_package/function_module.py +++ b/tests/data/test_package/function_module.py @@ -96,7 +96,7 @@ def int_result() -> int: ... def str_result() -> str: ... -def bool_result() -> str: ... +def bool_result() -> bool: ... def float_result() -> float: ... @@ -135,6 +135,9 @@ def union_dictionary_results() -> dict[int | str, bool | float]: ... def set_results() -> set[str]: ... +def illgeal_set_results() -> set[str, bool]: ... + + def optional_results() -> Optional[int]: ... diff --git a/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr b/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr index eb941440..4561515e 100644 --- a/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr +++ b/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr @@ -3261,7 +3261,11 @@ 'is_optional': False, 'is_type_inferred': False, 'name': 'any_', - 'type': None, + 'type': dict({ + 'kind': 'NamedType', + 'name': 'Any', + 'qname': '', + }), }), dict({ 'assigned_by': 'POSITION_OR_NAME', @@ -4654,7 +4658,6 @@ 'reexported_by': list([ ]), 'results': list([ - 'test_package/function_module/callexr_result/result_1', ]), }), dict({ @@ -4755,6 +4758,25 @@ 'results': list([ ]), }), + dict({ + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_package/function_module/illgeal_set_results', + 'is_class_method': False, + 'is_property': False, + 'is_public': True, + 'is_static': False, + 'name': 'illgeal_set_results', + 'parameters': list([ + ]), + 'reexported_by': list([ + ]), + 'results': list([ + 'test_package/function_module/illgeal_set_results/result_1', + ]), + }), dict({ 'docstring': dict({ 'description': '', diff --git a/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr b/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr index ca03da72..9424720f 100644 --- a/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr +++ b/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr @@ -99,7 +99,7 @@ static attr finals: union @PythonName("final_union") static attr finalUnion: union - static attr `literal`: literal + static attr `literal`: literal<"Some String"> @PythonName("multi_attr_1") static attr multiAttr1: Int @PythonName("multi_attr_3") @@ -229,8 +229,8 @@ @PythonName("set_") set: Set, optional: Int?, @PythonName("tuple_") tuple: Tuple, - `literal`: literal, - @PythonName("any_") any + `literal`: literal<"Some String">, + @PythonName("any_") any: Any ) // TODO List type has to many type arguments. @@ -372,6 +372,11 @@ @PythonName("set_results") fun setResults() -> result1: Set + // TODO Set type has to many type arguments. + @Pure + @PythonName("illgeal_set_results") + fun illgealSetResults() -> result1: Set + @Pure @PythonName("optional_results") fun optionalResults() -> result1: Int? From e171213c2e04625fe8b7f37c3bfb471b99401cf5 Mon Sep 17 00:00:00 2001 From: Arsam Date: Wed, 29 Nov 2023 14:33:51 +0100 Subject: [PATCH 062/109] Added more test cases --- tests/data/test_package/function_module.py | 2 +- .../__snapshots__/test__get_api.ambr | 475 ++++++++++++++++-- .../api_analyzer/test__get_api.py | 57 ++- .../__snapshots__/test_generate_stubs.ambr | 4 +- 4 files changed, 490 insertions(+), 48 deletions(-) diff --git a/tests/data/test_package/function_module.py b/tests/data/test_package/function_module.py index fe19c120..41106244 100644 --- a/tests/data/test_package/function_module.py +++ b/tests/data/test_package/function_module.py @@ -135,7 +135,7 @@ def union_dictionary_results() -> dict[int | str, bool | float]: ... def set_results() -> set[str]: ... -def illgeal_set_results() -> set[str, bool]: ... +def illegal_set_results() -> set[str, bool]: ... def optional_results() -> Optional[int]: ... diff --git a/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr b/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr index 4561515e..8595bb26 100644 --- a/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr +++ b/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr @@ -4112,39 +4112,6 @@ }), ]) # --- -# name: test_function_results_callable_type - list([ - dict({ - 'docstring': dict({ - 'description': '', - 'type': '', - }), - 'id': 'test_package/function_module/callable_type/result_1', - 'is_type_inferred': False, - 'name': 'result_1', - 'type': dict({ - 'kind': 'CallableType', - 'parameter_types': list([ - dict({ - 'kind': 'NamedType', - 'name': 'int', - 'qname': 'builtins.int', - }), - dict({ - 'kind': 'NamedType', - 'name': 'int', - 'qname': 'builtins.int', - }), - ]), - 'return_type': dict({ - 'kind': 'NamedType', - 'name': 'int', - 'qname': 'builtins.int', - }), - }), - }), - ]) -# --- # name: test_function_results_class_method_params list([ dict({ @@ -4356,6 +4323,442 @@ }), ]) # --- +# name: test_function_results_int_result[any_results] + list([ + dict({ + 'docstring': dict({ + 'description': '', + 'type': '', + }), + 'id': 'test_package/function_module/any_results/result_1', + 'is_type_inferred': False, + 'name': 'result_1', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'Any', + 'qname': '', + }), + }), + ]) +# --- +# name: test_function_results_int_result[callable_type] + list([ + dict({ + 'docstring': dict({ + 'description': '', + 'type': '', + }), + 'id': 'test_package/function_module/callable_type/result_1', + 'is_type_inferred': False, + 'name': 'result_1', + 'type': dict({ + 'kind': 'CallableType', + 'parameter_types': list([ + dict({ + 'kind': 'NamedType', + 'name': 'int', + 'qname': 'builtins.int', + }), + dict({ + 'kind': 'NamedType', + 'name': 'int', + 'qname': 'builtins.int', + }), + ]), + 'return_type': dict({ + 'kind': 'NamedType', + 'name': 'int', + 'qname': 'builtins.int', + }), + }), + }), + ]) +# --- +# name: test_function_results_int_result[callexr_result] + list([ + ]) +# --- +# name: test_function_results_int_result[dictionary_results] + list([ + dict({ + 'docstring': dict({ + 'description': '', + 'type': '', + }), + 'id': 'test_package/function_module/dictionary_results/result_1', + 'is_type_inferred': False, + 'name': 'result_1', + 'type': dict({ + 'key_type': dict({ + 'kind': 'NamedType', + 'name': 'str', + 'qname': 'builtins.str', + }), + 'kind': 'DictType', + 'value_type': dict({ + 'kind': 'NamedType', + 'name': 'FunctionModuleClassA', + 'qname': 'tests.data.test_package.function_module.FunctionModuleClassA', + }), + }), + }), + ]) +# --- +# name: test_function_results_int_result[float_result] + list([ + dict({ + 'docstring': dict({ + 'description': '', + 'type': '', + }), + 'id': 'test_package/function_module/float_result/result_1', + 'is_type_inferred': False, + 'name': 'result_1', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'float', + 'qname': 'builtins.float', + }), + }), + ]) +# --- +# name: test_function_results_int_result[illegal_dictionary_results] + list([ + dict({ + 'docstring': dict({ + 'description': '', + 'type': '', + }), + 'id': 'test_package/function_module/illegal_dictionary_results/result_1', + 'is_type_inferred': False, + 'name': 'result_1', + 'type': dict({ + 'key_type': dict({ + 'kind': 'NamedType', + 'name': 'Any', + 'qname': '', + }), + 'kind': 'DictType', + 'value_type': dict({ + 'kind': 'NamedType', + 'name': 'Any', + 'qname': '', + }), + }), + }), + ]) +# --- +# name: test_function_results_int_result[illegal_list_results] + list([ + dict({ + 'docstring': dict({ + 'description': '', + 'type': '', + }), + 'id': 'test_package/function_module/illegal_list_results/result_1', + 'is_type_inferred': False, + 'name': 'result_1', + 'type': dict({ + 'kind': 'ListType', + 'types': list([ + dict({ + 'kind': 'NamedType', + 'name': 'int', + 'qname': '', + }), + dict({ + 'kind': 'NamedType', + 'name': 'str', + 'qname': '', + }), + ]), + }), + }), + ]) +# --- +# name: test_function_results_int_result[illegal_set_results] + list([ + dict({ + 'docstring': dict({ + 'description': '', + 'type': '', + }), + 'id': 'test_package/function_module/illegal_set_results/result_1', + 'is_type_inferred': False, + 'name': 'result_1', + 'type': dict({ + 'kind': 'SetType', + 'types': list([ + dict({ + 'kind': 'NamedType', + 'name': 'str', + 'qname': '', + }), + dict({ + 'kind': 'NamedType', + 'name': 'bool', + 'qname': '', + }), + ]), + }), + }), + ]) +# --- +# name: test_function_results_int_result[int_result] + list([ + dict({ + 'docstring': dict({ + 'description': '', + 'type': '', + }), + 'id': 'test_package/function_module/int_result/result_1', + 'is_type_inferred': False, + 'name': 'result_1', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'int', + 'qname': 'builtins.int', + }), + }), + ]) +# --- +# name: test_function_results_int_result[list_results] + list([ + dict({ + 'docstring': dict({ + 'description': '', + 'type': '', + }), + 'id': 'test_package/function_module/list_results/result_1', + 'is_type_inferred': False, + 'name': 'result_1', + 'type': dict({ + 'kind': 'ListType', + 'types': list([ + dict({ + 'kind': 'NamedType', + 'name': 'int', + 'qname': 'builtins.int', + }), + ]), + }), + }), + ]) +# --- +# name: test_function_results_int_result[literal_results] + list([ + dict({ + 'docstring': dict({ + 'description': '', + 'type': '', + }), + 'id': 'test_package/function_module/literal_results/result_1', + 'is_type_inferred': False, + 'name': 'result_1', + 'type': dict({ + 'kind': 'LiteralType', + 'literal': 'Some String', + }), + }), + ]) +# --- +# name: test_function_results_int_result[none_result] + list([ + ]) +# --- +# name: test_function_results_int_result[obj_result] + list([ + dict({ + 'docstring': dict({ + 'description': '', + 'type': '', + }), + 'id': 'test_package/function_module/obj_result/result_1', + 'is_type_inferred': False, + 'name': 'result_1', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'FunctionModuleClassA', + 'qname': 'tests.data.test_package.function_module.FunctionModuleClassA', + }), + }), + ]) +# --- +# name: test_function_results_int_result[optional_results] + list([ + dict({ + 'docstring': dict({ + 'description': '', + 'type': '', + }), + 'id': 'test_package/function_module/optional_results/result_1', + 'is_type_inferred': False, + 'name': 'result_1', + 'type': dict({ + 'kind': 'UnionType', + 'types': list([ + dict({ + 'kind': 'NamedType', + 'name': 'int', + 'qname': 'builtins.int', + }), + dict({ + 'kind': 'NamedType', + 'name': 'None', + 'qname': 'builtins.None', + }), + ]), + }), + }), + ]) +# --- +# name: test_function_results_int_result[set_results] + list([ + dict({ + 'docstring': dict({ + 'description': '', + 'type': '', + }), + 'id': 'test_package/function_module/set_results/result_1', + 'is_type_inferred': False, + 'name': 'result_1', + 'type': dict({ + 'kind': 'SetType', + 'types': list([ + dict({ + 'kind': 'NamedType', + 'name': 'str', + 'qname': 'builtins.str', + }), + ]), + }), + }), + ]) +# --- +# name: test_function_results_int_result[str_result] + list([ + dict({ + 'docstring': dict({ + 'description': '', + 'type': '', + }), + 'id': 'test_package/function_module/str_result/result_1', + 'is_type_inferred': False, + 'name': 'result_1', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'str', + 'qname': 'builtins.str', + }), + }), + ]) +# --- +# name: test_function_results_int_result[tuple_results] + list([ + dict({ + 'docstring': dict({ + 'description': '', + 'type': '', + }), + 'id': 'test_package/function_module/tuple_results/result_1', + 'is_type_inferred': False, + 'name': 'result_1', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'str', + 'qname': 'builtins.str', + }), + }), + dict({ + 'docstring': dict({ + 'description': '', + 'type': '', + }), + 'id': 'test_package/function_module/tuple_results/result_2', + 'is_type_inferred': False, + 'name': 'result_2', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'FunctionModuleClassA', + 'qname': 'tests.data.test_package.function_module.FunctionModuleClassA', + }), + }), + ]) +# --- +# name: test_function_results_int_result[union_dictionary_results] + list([ + dict({ + 'docstring': dict({ + 'description': '', + 'type': '', + }), + 'id': 'test_package/function_module/union_dictionary_results/result_1', + 'is_type_inferred': False, + 'name': 'result_1', + 'type': dict({ + 'key_type': dict({ + 'kind': 'UnionType', + 'types': list([ + dict({ + 'kind': 'NamedType', + 'name': 'int', + 'qname': 'builtins.int', + }), + dict({ + 'kind': 'NamedType', + 'name': 'str', + 'qname': 'builtins.str', + }), + ]), + }), + 'kind': 'DictType', + 'value_type': dict({ + 'kind': 'UnionType', + 'types': list([ + dict({ + 'kind': 'NamedType', + 'name': 'bool', + 'qname': 'builtins.bool', + }), + dict({ + 'kind': 'NamedType', + 'name': 'float', + 'qname': 'builtins.float', + }), + ]), + }), + }), + }), + ]) +# --- +# name: test_function_results_int_result[union_results] + list([ + dict({ + 'docstring': dict({ + 'description': '', + 'type': '', + }), + 'id': 'test_package/function_module/union_results/result_1', + 'is_type_inferred': False, + 'name': 'result_1', + 'type': dict({ + 'kind': 'UnionType', + 'types': list([ + dict({ + 'kind': 'NamedType', + 'name': 'int', + 'qname': 'builtins.int', + }), + dict({ + 'kind': 'NamedType', + 'name': 'str', + 'qname': 'builtins.str', + }), + ]), + }), + }), + ]) +# --- # name: test_function_results_nested_class_function list([ dict({ @@ -4763,18 +5166,18 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/function_module/illgeal_set_results', + 'id': 'test_package/function_module/illegal_set_results', 'is_class_method': False, 'is_property': False, 'is_public': True, 'is_static': False, - 'name': 'illgeal_set_results', + 'name': 'illegal_set_results', 'parameters': list([ ]), 'reexported_by': list([ ]), 'results': list([ - 'test_package/function_module/illgeal_set_results/result_1', + 'test_package/function_module/illegal_set_results/result_1', ]), }), dict({ diff --git a/tests/safeds_stubgen/api_analyzer/test__get_api.py b/tests/safeds_stubgen/api_analyzer/test__get_api.py index 7bde682b..cff2caec 100644 --- a/tests/safeds_stubgen/api_analyzer/test__get_api.py +++ b/tests/safeds_stubgen/api_analyzer/test__get_api.py @@ -3,6 +3,7 @@ from pathlib import Path from typing import TYPE_CHECKING +import pytest from safeds_stubgen.api_analyzer import get_api from safeds_stubgen.docstring_parsing import DocstringStyle @@ -751,16 +752,54 @@ def test_function_results_nested_class_function(snapshot: SnapshotAssertion) -> assert function_result_data == snapshot -def test_function_results_callable_type(snapshot: SnapshotAssertion) -> None: +@pytest.mark.parametrize( + argnames="func_name", + argvalues=[ + "int_result", + "str_result", + "float_result", + "none_result", + "obj_result", + "callexr_result", + "tuple_results", + "union_results", + "list_results", + "illegal_list_results", + "dictionary_results", + "illegal_dictionary_results", + "union_dictionary_results", + "set_results", + "illegal_set_results", + "optional_results", + "literal_results", + "any_results", + "callable_type", + ], + ids=[ + "int_result", + "str_result", + "float_result", + "none_result", + "obj_result", + "callexr_result", + "tuple_results", + "union_results", + "list_results", + "illegal_list_results", + "dictionary_results", + "illegal_dictionary_results", + "union_dictionary_results", + "set_results", + "illegal_set_results", + "optional_results", + "literal_results", + "any_results", + "callable_type", + ], +) +def test_function_results_int_result(func_name: str, snapshot: SnapshotAssertion) -> None: function_result_data = get_function_result_data( - function_name="callable_type", - ) - assert function_result_data == snapshot - - -def test_function_results_multiple_results(snapshot: SnapshotAssertion) -> None: - function_result_data = get_function_result_data( - function_name="multiple_results", + function_name=func_name, ) assert function_result_data == snapshot diff --git a/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr b/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr index 9424720f..7dd379cd 100644 --- a/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr +++ b/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr @@ -374,8 +374,8 @@ // TODO Set type has to many type arguments. @Pure - @PythonName("illgeal_set_results") - fun illgealSetResults() -> result1: Set + @PythonName("illegal_set_results") + fun illegalSetResults() -> result1: Set @Pure @PythonName("optional_results") From 006f98baa6499abcb2a608f576f7d4737c13d6b9 Mon Sep 17 00:00:00 2001 From: Arsam Date: Wed, 29 Nov 2023 16:54:20 +0100 Subject: [PATCH 063/109] Refactoring tests --- src/safeds_stubgen/api_analyzer/_types.py | 1 + .../__snapshots__/test__get_api.ambr | 1666 ++++++++--------- .../api_analyzer/test__get_api.py | 1057 ++++------- 3 files changed, 1186 insertions(+), 1538 deletions(-) diff --git a/src/safeds_stubgen/api_analyzer/_types.py b/src/safeds_stubgen/api_analyzer/_types.py index 80774d2a..739c2701 100644 --- a/src/safeds_stubgen/api_analyzer/_types.py +++ b/src/safeds_stubgen/api_analyzer/_types.py @@ -339,6 +339,7 @@ def __hash__(self) -> int: return hash(frozenset(self.types)) +# Todo Frage: Wird aktuell nicht benutzt, weil Mypy "Optional[int]" als "Union[int, None]" interpretiert. Remove? @dataclass(frozen=True) class OptionalType(AbstractType): type: AbstractType diff --git a/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr b/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr index 8595bb26..d580f8d5 100644 --- a/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr +++ b/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr @@ -1,5 +1,5 @@ # serializer version: 1 -# name: test_class_attributes_AttributesClassB +# name: test_class_attributes[AttributesClassB] list([ dict({ 'docstring': dict({ @@ -793,7 +793,7 @@ }), ]) # --- -# name: test_class_attributes_ClassModuleNestedClassE +# name: test_class_attributes[ClassModuleNestedClassE] list([ dict({ 'docstring': dict({ @@ -831,7 +831,7 @@ }), ]) # --- -# name: test_class_attributes_GoogleDocstringClass +# name: test_class_attributes[GoogleDocstringClass] list([ dict({ 'docstring': dict({ @@ -852,7 +852,7 @@ }), ]) # --- -# name: test_class_attributes_NumpyDocstringClass +# name: test_class_attributes[NumpyDocstringClass] list([ dict({ 'docstring': dict({ @@ -873,7 +873,7 @@ }), ]) # --- -# name: test_class_attributes_RestDocstringClass +# name: test_class_attributes[RestDocstringClass] list([ dict({ 'docstring': dict({ @@ -894,7 +894,7 @@ }), ]) # --- -# name: test_class_attributes__ClassModulePrivateClassG +# name: test_class_attributes[_ClassModulePrivateClassG] list([ dict({ 'docstring': dict({ @@ -932,7 +932,7 @@ }), ]) # --- -# name: test_class_methods_AbstractModuleClass +# name: test_class_methods[AbstractModuleClass] list([ dict({ 'docstring': dict({ @@ -1036,7 +1036,7 @@ }), ]) # --- -# name: test_class_methods_ClassModuleClassB +# name: test_class_methods[ClassModuleClassB] list([ dict({ 'docstring': dict({ @@ -1059,7 +1059,7 @@ }), ]) # --- -# name: test_class_methods_ClassModuleClassC +# name: test_class_methods[ClassModuleClassC] list([ dict({ 'docstring': dict({ @@ -1082,11 +1082,11 @@ }), ]) # --- -# name: test_class_methods_ClassModuleEmptyClassA +# name: test_class_methods[ClassModuleEmptyClassA] list([ ]) # --- -# name: test_class_methods_ClassModuleNestedClassE +# name: test_class_methods[ClassModuleNestedClassE] list([ dict({ 'docstring': dict({ @@ -1109,7 +1109,7 @@ }), ]) # --- -# name: test_class_methods_EpydocDocstringClass +# name: test_class_methods[EpydocDocstringClass] list([ dict({ 'docstring': dict({ @@ -1144,7 +1144,134 @@ }), ]) # --- -# name: test_class_methods_FunctionModulePropertiesClass +# name: test_class_methods[FunctionModuleClassB] + list([ + dict({ + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_package/function_module/FunctionModuleClassB/class_method', + 'is_class_method': True, + 'is_property': False, + 'is_public': True, + 'is_static': False, + 'name': 'class_method', + 'parameters': list([ + 'test_package/function_module/FunctionModuleClassB/class_method/cls', + ]), + 'reexported_by': list([ + ]), + 'results': list([ + ]), + }), + dict({ + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_package/function_module/FunctionModuleClassB/class_method_params', + 'is_class_method': True, + 'is_property': False, + 'is_public': True, + 'is_static': False, + 'name': 'class_method_params', + 'parameters': list([ + 'test_package/function_module/FunctionModuleClassB/class_method_params/cls', + 'test_package/function_module/FunctionModuleClassB/class_method_params/param_1', + ]), + 'reexported_by': list([ + ]), + 'results': list([ + 'test_package/function_module/FunctionModuleClassB/class_method_params/result_1', + ]), + }), + dict({ + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_package/function_module/FunctionModuleClassB/instance_method', + 'is_class_method': False, + 'is_property': False, + 'is_public': True, + 'is_static': False, + 'name': 'instance_method', + 'parameters': list([ + 'test_package/function_module/FunctionModuleClassB/instance_method/self', + 'test_package/function_module/FunctionModuleClassB/instance_method/a', + ]), + 'reexported_by': list([ + ]), + 'results': list([ + 'test_package/function_module/FunctionModuleClassB/instance_method/result_1', + ]), + }), + dict({ + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_package/function_module/FunctionModuleClassB/static_method', + 'is_class_method': False, + 'is_property': False, + 'is_public': True, + 'is_static': True, + 'name': 'static_method', + 'parameters': list([ + ]), + 'reexported_by': list([ + ]), + 'results': list([ + ]), + }), + dict({ + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_package/function_module/FunctionModuleClassB/static_method_params', + 'is_class_method': False, + 'is_property': False, + 'is_public': True, + 'is_static': True, + 'name': 'static_method_params', + 'parameters': list([ + 'test_package/function_module/FunctionModuleClassB/static_method_params/param_1', + ]), + 'reexported_by': list([ + ]), + 'results': list([ + ]), + }), + ]) +# --- +# name: test_class_methods[FunctionModuleClassC] + list([ + dict({ + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_package/function_module/FunctionModuleClassB/FunctionModuleClassC/nested_class_function', + 'is_class_method': False, + 'is_property': False, + 'is_public': True, + 'is_static': False, + 'name': 'nested_class_function', + 'parameters': list([ + 'test_package/function_module/FunctionModuleClassB/FunctionModuleClassC/nested_class_function/self', + 'test_package/function_module/FunctionModuleClassB/FunctionModuleClassC/nested_class_function/param1', + ]), + 'reexported_by': list([ + ]), + 'results': list([ + 'test_package/function_module/FunctionModuleClassB/FunctionModuleClassC/nested_class_function/result_1', + ]), + }), + ]) +# --- +# name: test_class_methods[FunctionModulePropertiesClass] list([ dict({ 'docstring': dict({ @@ -1207,7 +1334,7 @@ }), ]) # --- -# name: test_class_methods_GoogleDocstringClass +# name: test_class_methods[GoogleDocstringClass] list([ dict({ 'docstring': dict({ @@ -1251,7 +1378,7 @@ }), ]) # --- -# name: test_class_methods_InferMyTypes +# name: test_class_methods[InferMyTypes] list([ dict({ 'docstring': dict({ @@ -1278,7 +1405,7 @@ }), ]) # --- -# name: test_class_methods_NumpyDocstringClass +# name: test_class_methods[NumpyDocstringClass] list([ dict({ 'docstring': dict({ @@ -1324,7 +1451,7 @@ }), ]) # --- -# name: test_class_methods_ReexportClass +# name: test_class_methods[ReexportClass] list([ dict({ 'docstring': dict({ @@ -1347,7 +1474,7 @@ }), ]) # --- -# name: test_class_methods_RestDocstringClass +# name: test_class_methods[RestDocstringClass] list([ dict({ 'docstring': dict({ @@ -1387,7 +1514,7 @@ }), ]) # --- -# name: test_class_methods__ClassModulePrivateDoubleNestedClassF +# name: test_class_methods[_ClassModulePrivateDoubleNestedClassF] list([ dict({ 'docstring': dict({ @@ -1410,134 +1537,7 @@ }), ]) # --- -# name: test_class_methods_function_module_FunctionModuleClassB - list([ - dict({ - 'docstring': dict({ - 'description': '', - 'full_docstring': '', - }), - 'id': 'test_package/function_module/FunctionModuleClassB/class_method', - 'is_class_method': True, - 'is_property': False, - 'is_public': True, - 'is_static': False, - 'name': 'class_method', - 'parameters': list([ - 'test_package/function_module/FunctionModuleClassB/class_method/cls', - ]), - 'reexported_by': list([ - ]), - 'results': list([ - ]), - }), - dict({ - 'docstring': dict({ - 'description': '', - 'full_docstring': '', - }), - 'id': 'test_package/function_module/FunctionModuleClassB/class_method_params', - 'is_class_method': True, - 'is_property': False, - 'is_public': True, - 'is_static': False, - 'name': 'class_method_params', - 'parameters': list([ - 'test_package/function_module/FunctionModuleClassB/class_method_params/cls', - 'test_package/function_module/FunctionModuleClassB/class_method_params/param_1', - ]), - 'reexported_by': list([ - ]), - 'results': list([ - 'test_package/function_module/FunctionModuleClassB/class_method_params/result_1', - ]), - }), - dict({ - 'docstring': dict({ - 'description': '', - 'full_docstring': '', - }), - 'id': 'test_package/function_module/FunctionModuleClassB/instance_method', - 'is_class_method': False, - 'is_property': False, - 'is_public': True, - 'is_static': False, - 'name': 'instance_method', - 'parameters': list([ - 'test_package/function_module/FunctionModuleClassB/instance_method/self', - 'test_package/function_module/FunctionModuleClassB/instance_method/a', - ]), - 'reexported_by': list([ - ]), - 'results': list([ - 'test_package/function_module/FunctionModuleClassB/instance_method/result_1', - ]), - }), - dict({ - 'docstring': dict({ - 'description': '', - 'full_docstring': '', - }), - 'id': 'test_package/function_module/FunctionModuleClassB/static_method', - 'is_class_method': False, - 'is_property': False, - 'is_public': True, - 'is_static': True, - 'name': 'static_method', - 'parameters': list([ - ]), - 'reexported_by': list([ - ]), - 'results': list([ - ]), - }), - dict({ - 'docstring': dict({ - 'description': '', - 'full_docstring': '', - }), - 'id': 'test_package/function_module/FunctionModuleClassB/static_method_params', - 'is_class_method': False, - 'is_property': False, - 'is_public': True, - 'is_static': True, - 'name': 'static_method_params', - 'parameters': list([ - 'test_package/function_module/FunctionModuleClassB/static_method_params/param_1', - ]), - 'reexported_by': list([ - ]), - 'results': list([ - ]), - }), - ]) -# --- -# name: test_class_methods_function_module_FunctionModuleClassC - list([ - dict({ - 'docstring': dict({ - 'description': '', - 'full_docstring': '', - }), - 'id': 'test_package/function_module/FunctionModuleClassB/FunctionModuleClassC/nested_class_function', - 'is_class_method': False, - 'is_property': False, - 'is_public': True, - 'is_static': False, - 'name': 'nested_class_function', - 'parameters': list([ - 'test_package/function_module/FunctionModuleClassB/FunctionModuleClassC/nested_class_function/self', - 'test_package/function_module/FunctionModuleClassB/FunctionModuleClassC/nested_class_function/param1', - ]), - 'reexported_by': list([ - ]), - 'results': list([ - 'test_package/function_module/FunctionModuleClassB/FunctionModuleClassC/nested_class_function/result_1', - ]), - }), - ]) -# --- -# name: test_classes_AbstractModuleClass +# name: test_classes[AbstractModuleClass] dict({ 'attributes': list([ ]), @@ -1586,7 +1586,7 @@ ]), }) # --- -# name: test_classes_AnotherReexportClass +# name: test_classes[AnotherReexportClass] dict({ 'attributes': list([ ]), @@ -1610,7 +1610,7 @@ ]), }) # --- -# name: test_classes_ClassModuleClassB +# name: test_classes[ClassModuleClassB] dict({ 'attributes': list([ ]), @@ -1656,7 +1656,7 @@ ]), }) # --- -# name: test_classes_ClassModuleClassC +# name: test_classes[ClassModuleClassC] dict({ 'attributes': list([ 'test_package/class_module/ClassModuleClassC/attr_1', @@ -1685,7 +1685,7 @@ ]), }) # --- -# name: test_classes_ClassModuleClassD +# name: test_classes[ClassModuleClassD] dict({ 'attributes': list([ ]), @@ -1710,7 +1710,7 @@ ]), }) # --- -# name: test_classes_ClassModuleEmptyClassA +# name: test_classes[ClassModuleEmptyClassA] dict({ 'attributes': list([ ]), @@ -1734,7 +1734,7 @@ ]), }) # --- -# name: test_classes_ClassModuleNestedClassE +# name: test_classes[ClassModuleNestedClassE] dict({ 'attributes': list([ 'test_package/class_module/ClassModuleClassD/ClassModuleNestedClassE/nested_attr_1', @@ -1762,7 +1762,7 @@ ]), }) # --- -# name: test_classes_EpydocDocstringClass +# name: test_classes[EpydocDocstringClass] dict({ 'attributes': list([ 'test_package/docstring_module/EpydocDocstringClass/attr_1', @@ -1814,7 +1814,7 @@ ]), }) # --- -# name: test_classes_FourthReexportClass +# name: test_classes[FourthReexportClass] dict({ 'attributes': list([ ]), @@ -1839,7 +1839,7 @@ ]), }) # --- -# name: test_classes_GoogleDocstringClass +# name: test_classes[GoogleDocstringClass] dict({ 'attributes': list([ 'test_package/docstring_module/GoogleDocstringClass/attr_1', @@ -1898,7 +1898,7 @@ ]), }) # --- -# name: test_classes_InferMyTypes +# name: test_classes[InferMyTypes] dict({ 'attributes': list([ 'test_package/infer_types_module/InferMyTypes/infer_int', @@ -1949,7 +1949,7 @@ ]), }) # --- -# name: test_classes_NumpyDocstringClass +# name: test_classes[NumpyDocstringClass] dict({ 'attributes': list([ 'test_package/docstring_module/NumpyDocstringClass/attr_1', @@ -2012,7 +2012,7 @@ ]), }) # --- -# name: test_classes_ReexportClass +# name: test_classes[ReexportClass] dict({ 'attributes': list([ ]), @@ -2038,7 +2038,7 @@ ]), }) # --- -# name: test_classes_RestDocstringClass +# name: test_classes[RestDocstringClass] dict({ 'attributes': list([ 'test_package/docstring_module/RestDocstringClass/attr_1', @@ -2090,7 +2090,7 @@ ]), }) # --- -# name: test_classes_VarianceClassAll +# name: test_classes[VarianceClassAll] dict({ 'attributes': list([ ]), @@ -2159,7 +2159,7 @@ ]), }) # --- -# name: test_classes_VarianceClassOnlyInvariance +# name: test_classes[VarianceClassOnlyInvariance] dict({ 'attributes': list([ ]), @@ -2210,7 +2210,7 @@ ]), }) # --- -# name: test_classes__ClassModulePrivateClassG +# name: test_classes[_ClassModulePrivateClassG] dict({ 'attributes': list([ 'test_package/class_module/_ClassModulePrivateClassG/_attr_1', @@ -2236,7 +2236,7 @@ ]), }) # --- -# name: test_classes__ClassModulePrivateDoubleNestedClassF +# name: test_classes[_ClassModulePrivateDoubleNestedClassF] dict({ 'attributes': list([ ]), @@ -2261,7 +2261,7 @@ ]), }) # --- -# name: test_classes__ThirdReexportClass +# name: test_classes[_ThirdReexportClass] dict({ 'attributes': list([ ]), @@ -2286,14 +2286,22 @@ ]), }) # --- -# name: test_enum_instances_EnumTest +# name: test_enum_instances[EnumTest3] list([ dict({ - 'id': 'test_package/enum_module/EnumTest/EIGHT', - 'name': 'EIGHT', + 'id': 'test_package/enum_module/EnumTest3/ELEVEN', + 'name': 'ELEVEN', }), - dict({ - 'id': 'test_package/enum_module/EnumTest/FIVE', + ]) +# --- +# name: test_enum_instances[EnumTest] + list([ + dict({ + 'id': 'test_package/enum_module/EnumTest/EIGHT', + 'name': 'EIGHT', + }), + dict({ + 'id': 'test_package/enum_module/EnumTest/FIVE', 'name': 'FIVE', }), dict({ @@ -2326,19 +2334,37 @@ }), ]) # --- -# name: test_enum_instances_EnumTest3 +# name: test_enum_instances[_ReexportedEmptyEnum] list([ - dict({ - 'id': 'test_package/enum_module/EnumTest3/ELEVEN', - 'name': 'ELEVEN', - }), ]) # --- -# name: test_enum_instances__ReexportedEmptyEnum - list([ - ]) +# name: test_enums[EnumTest2] + dict({ + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_package/enum_module/EnumTest2', + 'instances': list([ + 'test_package/enum_module/EnumTest2/TEN', + ]), + 'name': 'EnumTest2', + }) +# --- +# name: test_enums[EnumTest3] + dict({ + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_package/enum_module/EnumTest3', + 'instances': list([ + 'test_package/enum_module/EnumTest3/ELEVEN', + ]), + 'name': 'EnumTest3', + }) # --- -# name: test_enums_EnumTest +# name: test_enums[EnumTest] dict({ 'docstring': dict({ 'description': ''' @@ -2367,33 +2393,7 @@ 'name': 'EnumTest', }) # --- -# name: test_enums_EnumTest2 - dict({ - 'docstring': dict({ - 'description': '', - 'full_docstring': '', - }), - 'id': 'test_package/enum_module/EnumTest2', - 'instances': list([ - 'test_package/enum_module/EnumTest2/TEN', - ]), - 'name': 'EnumTest2', - }) -# --- -# name: test_enums_EnumTest3 - dict({ - 'docstring': dict({ - 'description': '', - 'full_docstring': '', - }), - 'id': 'test_package/enum_module/EnumTest3', - 'instances': list([ - 'test_package/enum_module/EnumTest3/ELEVEN', - ]), - 'name': 'EnumTest3', - }) -# --- -# name: test_enums__ReexportedEmptyEnum +# name: test_enums[_ReexportedEmptyEnum] dict({ 'docstring': dict({ 'description': "Nothing's here.", @@ -2405,98 +2405,22 @@ 'name': '_ReexportedEmptyEnum', }) # --- -# name: test_function_parameters_EpydocDocstringClass___init__ +# name: test_function_parameters[FunctionModuleClassB.__init__] list([ dict({ 'assigned_by': 'POSITION_OR_NAME', 'default_value': None, - 'docstring': dict({ - 'default_value': '', - 'description': 'Parameter of the calculator. (Epydoc)', - 'type': 'str', - }), - 'id': 'test_package/docstring_module/EpydocDocstringClass/__init__/param_1', - 'is_optional': False, - 'is_type_inferred': False, - 'name': 'param_1', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'str', - 'qname': 'builtins.str', - }), - }), - dict({ - 'assigned_by': 'IMPLICIT', - 'default_value': None, 'docstring': dict({ 'default_value': '', 'description': '', 'type': '', }), - 'id': 'test_package/docstring_module/EpydocDocstringClass/__init__/self', - 'is_optional': False, - 'is_type_inferred': False, - 'name': 'self', - 'type': None, - }), - ]) -# --- -# name: test_function_parameters_GoogleDocstringClass___init__ - list([ - dict({ - 'assigned_by': 'POSITION_OR_NAME', - 'default_value': None, - 'docstring': dict({ - 'default_value': '', - 'description': 'Parameter of the calculator. (Google Style)', - 'type': 'str', - }), - 'id': 'test_package/docstring_module/GoogleDocstringClass/__init__/param_1', - 'is_optional': False, - 'is_type_inferred': False, - 'name': 'param_1', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'str', - 'qname': 'builtins.str', - }), - }), - dict({ - 'assigned_by': 'IMPLICIT', - 'default_value': None, - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_package/docstring_module/GoogleDocstringClass/__init__/self', + 'id': 'test_package/function_module/FunctionModuleClassB/__init__/init_param', 'is_optional': False, 'is_type_inferred': False, - 'name': 'self', + 'name': 'init_param', 'type': None, }), - ]) -# --- -# name: test_function_parameters_NumpyDocstringClass___init__ - list([ - dict({ - 'assigned_by': 'POSITION_OR_NAME', - 'default_value': None, - 'docstring': dict({ - 'default_value': '', - 'description': 'Parameter of the calculator. (Numpy)', - 'type': 'str', - }), - 'id': 'test_package/docstring_module/NumpyDocstringClass/__init__/param_1', - 'is_optional': False, - 'is_type_inferred': False, - 'name': 'param_1', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'str', - 'qname': 'builtins.str', - }), - }), dict({ 'assigned_by': 'IMPLICIT', 'default_value': None, @@ -2505,7 +2429,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/docstring_module/NumpyDocstringClass/__init__/self', + 'id': 'test_package/function_module/FunctionModuleClassB/__init__/self', 'is_optional': False, 'is_type_inferred': False, 'name': 'self', @@ -2513,43 +2437,25 @@ }), ]) # --- -# name: test_function_parameters_RestDocstringClass___init__ +# name: test_function_parameters[_private] list([ dict({ 'assigned_by': 'POSITION_OR_NAME', 'default_value': None, - 'docstring': dict({ - 'default_value': '', - 'description': 'Parameter of the calculator. (ReST)', - 'type': 'str', - }), - 'id': 'test_package/docstring_module/RestDocstringClass/__init__/param_1', - 'is_optional': False, - 'is_type_inferred': False, - 'name': 'param_1', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'str', - 'qname': 'builtins.str', - }), - }), - dict({ - 'assigned_by': 'IMPLICIT', - 'default_value': None, 'docstring': dict({ 'default_value': '', 'description': '', 'type': '', }), - 'id': 'test_package/docstring_module/RestDocstringClass/__init__/self', + 'id': 'test_package/function_module/_private/a', 'is_optional': False, 'is_type_inferred': False, - 'name': 'self', + 'name': 'a', 'type': None, }), ]) # --- -# name: test_function_parameters_abstract_module_abstract_method_params +# name: test_function_parameters[abstract_method_params] list([ dict({ 'assigned_by': 'POSITION_OR_NAME', @@ -2603,7 +2509,7 @@ }), ]) # --- -# name: test_function_parameters_abstract_module_abstract_property_method +# name: test_function_parameters[abstract_property_method] list([ dict({ 'assigned_by': 'IMPLICIT', @@ -2621,7 +2527,7 @@ }), ]) # --- -# name: test_function_parameters_abstract_module_abstract_static_method_params +# name: test_function_parameters[abstract_static_method_params] list([ dict({ 'assigned_by': 'POSITION_OR_NAME', @@ -2643,93 +2549,134 @@ }), ]) # --- -# name: test_function_parameters_epydoc_docstring_func +# name: test_function_parameters[arg] list([ dict({ - 'assigned_by': 'IMPLICIT', + 'assigned_by': 'POSITIONAL_VARARG', 'default_value': None, 'docstring': dict({ 'default_value': '', 'description': '', 'type': '', }), - 'id': 'test_package/docstring_module/EpydocDocstringClass/epydoc_docstring_func/self', + 'id': 'test_package/function_module/arg/args', 'is_optional': False, 'is_type_inferred': False, - 'name': 'self', + 'name': 'args', 'type': None, }), dict({ - 'assigned_by': 'POSITION_OR_NAME', + 'assigned_by': 'NAMED_VARARG', 'default_value': None, 'docstring': dict({ 'default_value': '', - 'description': 'First integer value for the calculation. (Epydoc)', - 'type': 'int', + 'description': '', + 'type': '', }), - 'id': 'test_package/docstring_module/EpydocDocstringClass/epydoc_docstring_func/x', + 'id': 'test_package/function_module/arg/kwargs', 'is_optional': False, 'is_type_inferred': False, - 'name': 'x', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'int', - 'qname': 'builtins.int', - }), + 'name': 'kwargs', + 'type': None, }), + ]) +# --- +# name: test_function_parameters[args_type] + list([ dict({ - 'assigned_by': 'POSITION_OR_NAME', + 'assigned_by': 'POSITIONAL_VARARG', 'default_value': None, 'docstring': dict({ 'default_value': '', - 'description': 'Second integer value for the calculation. (Epydoc)', - 'type': 'int', + 'description': '', + 'type': '', }), - 'id': 'test_package/docstring_module/EpydocDocstringClass/epydoc_docstring_func/y', + 'id': 'test_package/function_module/args_type/args', 'is_optional': False, 'is_type_inferred': False, - 'name': 'y', + 'name': 'args', 'type': dict({ - 'kind': 'NamedType', - 'name': 'int', - 'qname': 'builtins.int', + 'kind': 'TupleType', + 'types': list([ + dict({ + 'kind': 'NamedType', + 'name': 'int', + 'qname': 'builtins.int', + }), + ]), }), }), - ]) -# --- -# name: test_function_parameters_function_module_FunctionModuleClassB___init__ - list([ dict({ - 'assigned_by': 'POSITION_OR_NAME', + 'assigned_by': 'NAMED_VARARG', 'default_value': None, 'docstring': dict({ 'default_value': '', 'description': '', 'type': '', }), - 'id': 'test_package/function_module/FunctionModuleClassB/__init__/init_param', + 'id': 'test_package/function_module/args_type/kwargs', 'is_optional': False, 'is_type_inferred': False, - 'name': 'init_param', - 'type': None, + 'name': 'kwargs', + 'type': dict({ + 'key_type': dict({ + 'kind': 'NamedType', + 'name': 'str', + 'qname': 'builtins.str', + }), + 'kind': 'DictType', + 'value_type': dict({ + 'kind': 'NamedType', + 'name': 'int', + 'qname': 'builtins.int', + }), + }), }), + ]) +# --- +# name: test_function_parameters[callable_type] + list([ dict({ - 'assigned_by': 'IMPLICIT', + 'assigned_by': 'POSITION_OR_NAME', 'default_value': None, 'docstring': dict({ 'default_value': '', 'description': '', 'type': '', }), - 'id': 'test_package/function_module/FunctionModuleClassB/__init__/self', + 'id': 'test_package/function_module/callable_type/param', 'is_optional': False, 'is_type_inferred': False, - 'name': 'self', - 'type': None, + 'name': 'param', + 'type': dict({ + 'kind': 'CallableType', + 'parameter_types': list([ + dict({ + 'kind': 'NamedType', + 'name': 'str', + 'qname': 'builtins.str', + }), + ]), + 'return_type': dict({ + 'kind': 'TupleType', + 'types': list([ + dict({ + 'kind': 'NamedType', + 'name': 'int', + 'qname': 'builtins.int', + }), + dict({ + 'kind': 'NamedType', + 'name': 'str', + 'qname': 'builtins.str', + }), + ]), + }), + }), }), ]) # --- -# name: test_function_parameters_function_module_FunctionModuleClassB_class_method +# name: test_function_parameters[class_method] list([ dict({ 'assigned_by': 'IMPLICIT', @@ -2747,7 +2694,7 @@ }), ]) # --- -# name: test_function_parameters_function_module_FunctionModuleClassB_class_method_params +# name: test_function_parameters[class_method_params] list([ dict({ 'assigned_by': 'IMPLICIT', @@ -2783,48 +2730,44 @@ }), ]) # --- -# name: test_function_parameters_function_module_FunctionModuleClassB_static_method_params +# name: test_function_parameters[epydoc.__init__] list([ dict({ 'assigned_by': 'POSITION_OR_NAME', 'default_value': None, 'docstring': dict({ 'default_value': '', - 'description': '', - 'type': '', + 'description': 'Parameter of the calculator. (Epydoc)', + 'type': 'str', }), - 'id': 'test_package/function_module/FunctionModuleClassB/static_method_params/param_1', + 'id': 'test_package/docstring_module/EpydocDocstringClass/__init__/param_1', 'is_optional': False, 'is_type_inferred': False, 'name': 'param_1', 'type': dict({ 'kind': 'NamedType', - 'name': 'int', - 'qname': 'builtins.int', + 'name': 'str', + 'qname': 'builtins.str', }), }), - ]) -# --- -# name: test_function_parameters_function_module_FunctionModuleClassC_nested_class_function - list([ dict({ - 'assigned_by': 'POSITION_OR_NAME', + 'assigned_by': 'IMPLICIT', 'default_value': None, 'docstring': dict({ 'default_value': '', 'description': '', 'type': '', }), - 'id': 'test_package/function_module/FunctionModuleClassB/FunctionModuleClassC/nested_class_function/param1', + 'id': 'test_package/docstring_module/EpydocDocstringClass/__init__/self', 'is_optional': False, 'is_type_inferred': False, - 'name': 'param1', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'int', - 'qname': 'builtins.int', - }), + 'name': 'self', + 'type': None, }), + ]) +# --- +# name: test_function_parameters[epydoc_docstring_func] + list([ dict({ 'assigned_by': 'IMPLICIT', 'default_value': None, @@ -2833,160 +2776,141 @@ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/FunctionModuleClassB/FunctionModuleClassC/nested_class_function/self', + 'id': 'test_package/docstring_module/EpydocDocstringClass/epydoc_docstring_func/self', 'is_optional': False, 'is_type_inferred': False, 'name': 'self', 'type': None, }), - ]) -# --- -# name: test_function_parameters_function_module__private - list([ dict({ 'assigned_by': 'POSITION_OR_NAME', 'default_value': None, 'docstring': dict({ 'default_value': '', - 'description': '', - 'type': '', + 'description': 'First integer value for the calculation. (Epydoc)', + 'type': 'int', }), - 'id': 'test_package/function_module/_private/a', + 'id': 'test_package/docstring_module/EpydocDocstringClass/epydoc_docstring_func/x', 'is_optional': False, 'is_type_inferred': False, - 'name': 'a', - 'type': None, + 'name': 'x', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'int', + 'qname': 'builtins.int', + }), + }), + dict({ + 'assigned_by': 'POSITION_OR_NAME', + 'default_value': None, + 'docstring': dict({ + 'default_value': '', + 'description': 'Second integer value for the calculation. (Epydoc)', + 'type': 'int', + }), + 'id': 'test_package/docstring_module/EpydocDocstringClass/epydoc_docstring_func/y', + 'is_optional': False, + 'is_type_inferred': False, + 'name': 'y', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'int', + 'qname': 'builtins.int', + }), }), ]) # --- -# name: test_function_parameters_function_module_arg +# name: test_function_parameters[google.__init__] list([ dict({ - 'assigned_by': 'POSITIONAL_VARARG', + 'assigned_by': 'POSITION_OR_NAME', 'default_value': None, 'docstring': dict({ 'default_value': '', - 'description': '', - 'type': '', + 'description': 'Parameter of the calculator. (Google Style)', + 'type': 'str', }), - 'id': 'test_package/function_module/arg/args', + 'id': 'test_package/docstring_module/GoogleDocstringClass/__init__/param_1', 'is_optional': False, 'is_type_inferred': False, - 'name': 'args', - 'type': None, + 'name': 'param_1', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'str', + 'qname': 'builtins.str', + }), }), dict({ - 'assigned_by': 'NAMED_VARARG', + 'assigned_by': 'IMPLICIT', 'default_value': None, 'docstring': dict({ 'default_value': '', 'description': '', 'type': '', }), - 'id': 'test_package/function_module/arg/kwargs', + 'id': 'test_package/docstring_module/GoogleDocstringClass/__init__/self', 'is_optional': False, 'is_type_inferred': False, - 'name': 'kwargs', + 'name': 'self', 'type': None, }), ]) # --- -# name: test_function_parameters_function_module_args_type +# name: test_function_parameters[google_docstring_func] list([ dict({ - 'assigned_by': 'POSITIONAL_VARARG', + 'assigned_by': 'IMPLICIT', 'default_value': None, 'docstring': dict({ 'default_value': '', 'description': '', 'type': '', }), - 'id': 'test_package/function_module/args_type/args', + 'id': 'test_package/docstring_module/GoogleDocstringClass/google_docstring_func/self', 'is_optional': False, 'is_type_inferred': False, - 'name': 'args', - 'type': dict({ - 'kind': 'TupleType', - 'types': list([ - dict({ - 'kind': 'NamedType', - 'name': 'int', - 'qname': 'builtins.int', - }), - ]), - }), + 'name': 'self', + 'type': None, }), dict({ - 'assigned_by': 'NAMED_VARARG', + 'assigned_by': 'POSITION_OR_NAME', 'default_value': None, 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_package/function_module/args_type/kwargs', - 'is_optional': False, - 'is_type_inferred': False, - 'name': 'kwargs', - 'type': dict({ - 'key_type': dict({ - 'kind': 'NamedType', - 'name': 'str', - 'qname': 'builtins.str', - }), - 'kind': 'DictType', - 'value_type': dict({ - 'kind': 'NamedType', - 'name': 'int', - 'qname': 'builtins.int', - }), + 'default_value': '', + 'description': 'First integer value for the calculation. (Google Style)', + 'type': 'int', + }), + 'id': 'test_package/docstring_module/GoogleDocstringClass/google_docstring_func/x', + 'is_optional': False, + 'is_type_inferred': False, + 'name': 'x', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'int', + 'qname': 'builtins.int', }), }), - ]) -# --- -# name: test_function_parameters_function_module_callable_type - list([ dict({ 'assigned_by': 'POSITION_OR_NAME', 'default_value': None, 'docstring': dict({ 'default_value': '', - 'description': '', - 'type': '', + 'description': 'Second integer value for the calculation. (Google Style)', + 'type': 'int', }), - 'id': 'test_package/function_module/callable_type/param', + 'id': 'test_package/docstring_module/GoogleDocstringClass/google_docstring_func/y', 'is_optional': False, 'is_type_inferred': False, - 'name': 'param', + 'name': 'y', 'type': dict({ - 'kind': 'CallableType', - 'parameter_types': list([ - dict({ - 'kind': 'NamedType', - 'name': 'str', - 'qname': 'builtins.str', - }), - ]), - 'return_type': dict({ - 'kind': 'TupleType', - 'types': list([ - dict({ - 'kind': 'NamedType', - 'name': 'int', - 'qname': 'builtins.int', - }), - dict({ - 'kind': 'NamedType', - 'name': 'str', - 'qname': 'builtins.str', - }), - ]), - }), + 'kind': 'NamedType', + 'name': 'int', + 'qname': 'builtins.int', }), }), ]) # --- -# name: test_function_parameters_function_module_illegal_params +# name: test_function_parameters[illegal_params] list([ dict({ 'assigned_by': 'POSITION_OR_NAME', @@ -3107,7 +3031,133 @@ }), ]) # --- -# name: test_function_parameters_function_module_opt_pos_only +# name: test_function_parameters[nested_class_function] + list([ + dict({ + 'assigned_by': 'POSITION_OR_NAME', + 'default_value': None, + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_package/function_module/FunctionModuleClassB/FunctionModuleClassC/nested_class_function/param1', + 'is_optional': False, + 'is_type_inferred': False, + 'name': 'param1', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'int', + 'qname': 'builtins.int', + }), + }), + dict({ + 'assigned_by': 'IMPLICIT', + 'default_value': None, + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_package/function_module/FunctionModuleClassB/FunctionModuleClassC/nested_class_function/self', + 'is_optional': False, + 'is_type_inferred': False, + 'name': 'self', + 'type': None, + }), + ]) +# --- +# name: test_function_parameters[numpy.__init__] + list([ + dict({ + 'assigned_by': 'POSITION_OR_NAME', + 'default_value': None, + 'docstring': dict({ + 'default_value': '', + 'description': 'Parameter of the calculator. (Numpy)', + 'type': 'str', + }), + 'id': 'test_package/docstring_module/NumpyDocstringClass/__init__/param_1', + 'is_optional': False, + 'is_type_inferred': False, + 'name': 'param_1', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'str', + 'qname': 'builtins.str', + }), + }), + dict({ + 'assigned_by': 'IMPLICIT', + 'default_value': None, + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_package/docstring_module/NumpyDocstringClass/__init__/self', + 'is_optional': False, + 'is_type_inferred': False, + 'name': 'self', + 'type': None, + }), + ]) +# --- +# name: test_function_parameters[numpy_docstring_func] + list([ + dict({ + 'assigned_by': 'IMPLICIT', + 'default_value': None, + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_package/docstring_module/NumpyDocstringClass/numpy_docstring_func/self', + 'is_optional': False, + 'is_type_inferred': False, + 'name': 'self', + 'type': None, + }), + dict({ + 'assigned_by': 'POSITION_OR_NAME', + 'default_value': None, + 'docstring': dict({ + 'default_value': '', + 'description': 'First integer value for the calculation. (Numpy)', + 'type': 'int', + }), + 'id': 'test_package/docstring_module/NumpyDocstringClass/numpy_docstring_func/x', + 'is_optional': False, + 'is_type_inferred': False, + 'name': 'x', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'int', + 'qname': 'builtins.int', + }), + }), + dict({ + 'assigned_by': 'POSITION_OR_NAME', + 'default_value': None, + 'docstring': dict({ + 'default_value': '', + 'description': 'Second integer value for the calculation. (Numpy)', + 'type': 'int', + }), + 'id': 'test_package/docstring_module/NumpyDocstringClass/numpy_docstring_func/y', + 'is_optional': False, + 'is_type_inferred': False, + 'name': 'y', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'int', + 'qname': 'builtins.int', + }), + }), + ]) +# --- +# name: test_function_parameters[opt_pos_only] list([ dict({ 'assigned_by': 'POSITION_ONLY', @@ -3143,7 +3193,7 @@ }), ]) # --- -# name: test_function_parameters_function_module_param_position +# name: test_function_parameters[param_position] list([ dict({ 'assigned_by': 'POSITION_ONLY', @@ -3247,7 +3297,7 @@ }), ]) # --- -# name: test_function_parameters_function_module_params +# name: test_function_parameters[params] list([ dict({ 'assigned_by': 'POSITION_OR_NAME', @@ -3579,11 +3629,11 @@ }), ]) # --- -# name: test_function_parameters_function_module_public_no_params_no_result +# name: test_function_parameters[public_no_params_no_result] list([ ]) # --- -# name: test_function_parameters_function_module_req_name_only +# name: test_function_parameters[req_name_only] list([ dict({ 'assigned_by': 'NAME_ONLY', @@ -3611,15 +3661,105 @@ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/req_name_only/required', + 'id': 'test_package/function_module/req_name_only/required', + 'is_optional': False, + 'is_type_inferred': False, + 'name': 'required', + 'type': None, + }), + ]) +# --- +# name: test_function_parameters[rest.__init__] + list([ + dict({ + 'assigned_by': 'POSITION_OR_NAME', + 'default_value': None, + 'docstring': dict({ + 'default_value': '', + 'description': 'Parameter of the calculator. (ReST)', + 'type': 'str', + }), + 'id': 'test_package/docstring_module/RestDocstringClass/__init__/param_1', + 'is_optional': False, + 'is_type_inferred': False, + 'name': 'param_1', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'str', + 'qname': 'builtins.str', + }), + }), + dict({ + 'assigned_by': 'IMPLICIT', + 'default_value': None, + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_package/docstring_module/RestDocstringClass/__init__/self', + 'is_optional': False, + 'is_type_inferred': False, + 'name': 'self', + 'type': None, + }), + ]) +# --- +# name: test_function_parameters[rest_docstring_func] + list([ + dict({ + 'assigned_by': 'IMPLICIT', + 'default_value': None, + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_package/docstring_module/RestDocstringClass/rest_docstring_func/self', + 'is_optional': False, + 'is_type_inferred': False, + 'name': 'self', + 'type': None, + }), + dict({ + 'assigned_by': 'POSITION_OR_NAME', + 'default_value': None, + 'docstring': dict({ + 'default_value': '', + 'description': 'First integer value for the calculation. (ReST)', + 'type': 'int', + }), + 'id': 'test_package/docstring_module/RestDocstringClass/rest_docstring_func/x', + 'is_optional': False, + 'is_type_inferred': False, + 'name': 'x', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'int', + 'qname': 'builtins.int', + }), + }), + dict({ + 'assigned_by': 'POSITION_OR_NAME', + 'default_value': None, + 'docstring': dict({ + 'default_value': '', + 'description': 'Second integer value for the calculation. (ReST)', + 'type': 'int', + }), + 'id': 'test_package/docstring_module/RestDocstringClass/rest_docstring_func/y', 'is_optional': False, 'is_type_inferred': False, - 'name': 'required', - 'type': None, + 'name': 'y', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'int', + 'qname': 'builtins.int', + }), }), ]) # --- -# name: test_function_parameters_function_module_special_params +# name: test_function_parameters[special_params] list([ dict({ 'assigned_by': 'POSITION_OR_NAME', @@ -3877,106 +4017,75 @@ }), ]) # --- -# name: test_function_parameters_google_docstring_func +# name: test_function_parameters[static_method_params] list([ dict({ - 'assigned_by': 'IMPLICIT', + 'assigned_by': 'POSITION_OR_NAME', 'default_value': None, 'docstring': dict({ 'default_value': '', 'description': '', 'type': '', }), - 'id': 'test_package/docstring_module/GoogleDocstringClass/google_docstring_func/self', - 'is_optional': False, - 'is_type_inferred': False, - 'name': 'self', - 'type': None, - }), - dict({ - 'assigned_by': 'POSITION_OR_NAME', - 'default_value': None, - 'docstring': dict({ - 'default_value': '', - 'description': 'First integer value for the calculation. (Google Style)', - 'type': 'int', - }), - 'id': 'test_package/docstring_module/GoogleDocstringClass/google_docstring_func/x', + 'id': 'test_package/function_module/FunctionModuleClassB/static_method_params/param_1', 'is_optional': False, 'is_type_inferred': False, - 'name': 'x', + 'name': 'param_1', 'type': dict({ 'kind': 'NamedType', 'name': 'int', 'qname': 'builtins.int', }), }), + ]) +# --- +# name: test_function_results[abstract_method_params] + list([ dict({ - 'assigned_by': 'POSITION_OR_NAME', - 'default_value': None, 'docstring': dict({ - 'default_value': '', - 'description': 'Second integer value for the calculation. (Google Style)', - 'type': 'int', + 'description': '', + 'type': '', }), - 'id': 'test_package/docstring_module/GoogleDocstringClass/google_docstring_func/y', - 'is_optional': False, + 'id': 'test_package/abstract_module/AbstractModuleClass/abstract_method_params/result_1', 'is_type_inferred': False, - 'name': 'y', + 'name': 'result_1', 'type': dict({ - 'kind': 'NamedType', - 'name': 'int', - 'qname': 'builtins.int', + 'kind': 'ListType', + 'types': list([ + dict({ + 'kind': 'NamedType', + 'name': 'str', + 'qname': 'builtins.str', + }), + ]), }), }), ]) # --- -# name: test_function_parameters_numpy_docstring_func +# name: test_function_results[abstract_property_method] list([ dict({ - 'assigned_by': 'IMPLICIT', - 'default_value': None, 'docstring': dict({ - 'default_value': '', 'description': '', 'type': '', }), - 'id': 'test_package/docstring_module/NumpyDocstringClass/numpy_docstring_func/self', - 'is_optional': False, - 'is_type_inferred': False, - 'name': 'self', - 'type': None, - }), - dict({ - 'assigned_by': 'POSITION_OR_NAME', - 'default_value': None, - 'docstring': dict({ - 'default_value': '', - 'description': 'First integer value for the calculation. (Numpy)', - 'type': 'int', - }), - 'id': 'test_package/docstring_module/NumpyDocstringClass/numpy_docstring_func/x', - 'is_optional': False, + 'id': 'test_package/abstract_module/AbstractModuleClass/abstract_property_method/result_1', 'is_type_inferred': False, - 'name': 'x', + 'name': 'result_1', 'type': dict({ 'kind': 'NamedType', - 'name': 'int', - 'qname': 'builtins.int', + 'name': 'float', + 'qname': 'builtins.float', }), }), dict({ - 'assigned_by': 'POSITION_OR_NAME', - 'default_value': None, 'docstring': dict({ - 'default_value': '', - 'description': 'Second integer value for the calculation. (Numpy)', - 'type': 'int', + 'description': '', + 'type': '', }), - 'id': 'test_package/docstring_module/NumpyDocstringClass/numpy_docstring_func/y', - 'is_optional': False, + 'id': 'test_package/abstract_module/AbstractModuleClass/abstract_property_method/result_2', 'is_type_inferred': False, - 'name': 'y', + 'name': 'result_2', 'type': dict({ 'kind': 'NamedType', 'name': 'int', @@ -3985,123 +4094,131 @@ }), ]) # --- -# name: test_function_parameters_rest_docstring_func +# name: test_function_results[abstract_static_method_params] list([ dict({ - 'assigned_by': 'IMPLICIT', - 'default_value': None, 'docstring': dict({ - 'default_value': '', 'description': '', 'type': '', }), - 'id': 'test_package/docstring_module/RestDocstringClass/rest_docstring_func/self', - 'is_optional': False, - 'is_type_inferred': False, - 'name': 'self', - 'type': None, - }), - dict({ - 'assigned_by': 'POSITION_OR_NAME', - 'default_value': None, - 'docstring': dict({ - 'default_value': '', - 'description': 'First integer value for the calculation. (ReST)', - 'type': 'int', - }), - 'id': 'test_package/docstring_module/RestDocstringClass/rest_docstring_func/x', - 'is_optional': False, + 'id': 'test_package/abstract_module/AbstractModuleClass/abstract_static_method_params/result_1', 'is_type_inferred': False, - 'name': 'x', + 'name': 'result_1', 'type': dict({ 'kind': 'NamedType', - 'name': 'int', - 'qname': 'builtins.int', + 'name': 'bool', + 'qname': 'builtins.bool', }), }), + ]) +# --- +# name: test_function_results[any_results] + list([ dict({ - 'assigned_by': 'POSITION_OR_NAME', - 'default_value': None, 'docstring': dict({ - 'default_value': '', - 'description': 'Second integer value for the calculation. (ReST)', - 'type': 'int', + 'description': '', + 'type': '', }), - 'id': 'test_package/docstring_module/RestDocstringClass/rest_docstring_func/y', - 'is_optional': False, + 'id': 'test_package/function_module/any_results/result_1', 'is_type_inferred': False, - 'name': 'y', + 'name': 'result_1', 'type': dict({ 'kind': 'NamedType', - 'name': 'int', - 'qname': 'builtins.int', + 'name': 'Any', + 'qname': '', }), }), ]) # --- -# name: test_function_results_abstract_method_params +# name: test_function_results[callable_type] list([ dict({ 'docstring': dict({ 'description': '', 'type': '', }), - 'id': 'test_package/abstract_module/AbstractModuleClass/abstract_method_params/result_1', + 'id': 'test_package/function_module/callable_type/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ - 'kind': 'ListType', - 'types': list([ + 'kind': 'CallableType', + 'parameter_types': list([ dict({ 'kind': 'NamedType', - 'name': 'str', - 'qname': 'builtins.str', + 'name': 'int', + 'qname': 'builtins.int', + }), + dict({ + 'kind': 'NamedType', + 'name': 'int', + 'qname': 'builtins.int', }), ]), + 'return_type': dict({ + 'kind': 'NamedType', + 'name': 'int', + 'qname': 'builtins.int', + }), }), }), ]) # --- -# name: test_function_results_abstract_property_method +# name: test_function_results[callexr_result] + list([ + ]) +# --- +# name: test_function_results[class_method_params] list([ dict({ 'docstring': dict({ 'description': '', 'type': '', }), - 'id': 'test_package/abstract_module/AbstractModuleClass/abstract_property_method/result_1', + 'id': 'test_package/function_module/FunctionModuleClassB/class_method_params/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ 'kind': 'NamedType', - 'name': 'float', - 'qname': 'builtins.float', + 'name': 'bool', + 'qname': 'builtins.bool', }), }), + ]) +# --- +# name: test_function_results[dictionary_results] + list([ dict({ 'docstring': dict({ 'description': '', 'type': '', }), - 'id': 'test_package/abstract_module/AbstractModuleClass/abstract_property_method/result_2', + 'id': 'test_package/function_module/dictionary_results/result_1', 'is_type_inferred': False, - 'name': 'result_2', + 'name': 'result_1', 'type': dict({ - 'kind': 'NamedType', - 'name': 'int', - 'qname': 'builtins.int', + 'key_type': dict({ + 'kind': 'NamedType', + 'name': 'str', + 'qname': 'builtins.str', + }), + 'kind': 'DictType', + 'value_type': dict({ + 'kind': 'NamedType', + 'name': 'FunctionModuleClassA', + 'qname': 'tests.data.test_package.function_module.FunctionModuleClassA', + }), }), }), ]) # --- -# name: test_function_results_abstract_static_method_params +# name: test_function_results[epydoc_docstring_func] list([ dict({ 'docstring': dict({ - 'description': '', - 'type': '', + 'description': 'Checks if the sum of x and y is greater than 10. (Epydoc)', + 'type': 'bool', }), - 'id': 'test_package/abstract_module/AbstractModuleClass/abstract_static_method_params/result_1', + 'id': 'test_package/docstring_module/EpydocDocstringClass/epydoc_docstring_func/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ @@ -4112,32 +4229,35 @@ }), ]) # --- -# name: test_function_results_class_method_params +# name: test_function_results[float_result] list([ dict({ 'docstring': dict({ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/FunctionModuleClassB/class_method_params/result_1', + 'id': 'test_package/function_module/float_result/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ 'kind': 'NamedType', - 'name': 'bool', - 'qname': 'builtins.bool', + 'name': 'float', + 'qname': 'builtins.float', }), }), ]) # --- -# name: test_function_results_epydoc_docstring_func +# name: test_function_results[google_docstring_func] list([ dict({ 'docstring': dict({ - 'description': 'Checks if the sum of x and y is greater than 10. (Epydoc)', + 'description': ''' + Checks if the sum of x and y is greater than 10 and returns + a boolean value. (Google Style) + ''', 'type': 'bool', }), - 'id': 'test_package/docstring_module/EpydocDocstringClass/epydoc_docstring_func/result_1', + 'id': 'test_package/docstring_module/GoogleDocstringClass/google_docstring_func/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ @@ -4148,68 +4268,89 @@ }), ]) # --- -# name: test_function_results_function_module_property_function - list([ - ]) -# --- -# name: test_function_results_function_module_property_function_infer +# name: test_function_results[illegal_dictionary_results] list([ dict({ 'docstring': dict({ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/FunctionModulePropertiesClass/property_function_infer/result_1', - 'is_type_inferred': True, + 'id': 'test_package/function_module/illegal_dictionary_results/result_1', + 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ - 'kind': 'NamedType', - 'name': 'str', - 'qname': 'builtins.str', + 'key_type': dict({ + 'kind': 'NamedType', + 'name': 'Any', + 'qname': '', + }), + 'kind': 'DictType', + 'value_type': dict({ + 'kind': 'NamedType', + 'name': 'Any', + 'qname': '', + }), }), }), ]) # --- -# name: test_function_results_function_module_property_function_params +# name: test_function_results[illegal_list_results] list([ dict({ 'docstring': dict({ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/FunctionModulePropertiesClass/property_function_params/result_1', + 'id': 'test_package/function_module/illegal_list_results/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ - 'kind': 'NamedType', - 'name': 'str', - 'qname': 'builtins.str', + 'kind': 'ListType', + 'types': list([ + dict({ + 'kind': 'NamedType', + 'name': 'int', + 'qname': '', + }), + dict({ + 'kind': 'NamedType', + 'name': 'str', + 'qname': '', + }), + ]), }), }), ]) -# --- -# name: test_function_results_google_docstring_func - list([ - dict({ - 'docstring': dict({ - 'description': ''' - Checks if the sum of x and y is greater than 10 and returns - a boolean value. (Google Style) - ''', - 'type': 'bool', +# --- +# name: test_function_results[illegal_set_results] + list([ + dict({ + 'docstring': dict({ + 'description': '', + 'type': '', }), - 'id': 'test_package/docstring_module/GoogleDocstringClass/google_docstring_func/result_1', + 'id': 'test_package/function_module/illegal_set_results/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ - 'kind': 'NamedType', - 'name': 'bool', - 'qname': 'builtins.bool', + 'kind': 'SetType', + 'types': list([ + dict({ + 'kind': 'NamedType', + 'name': 'str', + 'qname': '', + }), + dict({ + 'kind': 'NamedType', + 'name': 'bool', + 'qname': '', + }), + ]), }), }), ]) # --- -# name: test_function_results_infer_function +# name: test_function_results[infer_function] list([ dict({ 'docstring': dict({ @@ -4305,7 +4446,7 @@ }), ]) # --- -# name: test_function_results_instance_method +# name: test_function_results[instance_method] list([ dict({ 'docstring': dict({ @@ -4323,296 +4464,209 @@ }), ]) # --- -# name: test_function_results_int_result[any_results] +# name: test_function_results[int_result] list([ dict({ 'docstring': dict({ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/any_results/result_1', + 'id': 'test_package/function_module/int_result/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ 'kind': 'NamedType', - 'name': 'Any', - 'qname': '', + 'name': 'int', + 'qname': 'builtins.int', }), }), ]) # --- -# name: test_function_results_int_result[callable_type] +# name: test_function_results[list_results] list([ dict({ 'docstring': dict({ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/callable_type/result_1', + 'id': 'test_package/function_module/list_results/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ - 'kind': 'CallableType', - 'parameter_types': list([ - dict({ - 'kind': 'NamedType', - 'name': 'int', - 'qname': 'builtins.int', - }), + 'kind': 'ListType', + 'types': list([ dict({ 'kind': 'NamedType', 'name': 'int', 'qname': 'builtins.int', }), ]), - 'return_type': dict({ - 'kind': 'NamedType', - 'name': 'int', - 'qname': 'builtins.int', - }), }), }), ]) # --- -# name: test_function_results_int_result[callexr_result] - list([ - ]) -# --- -# name: test_function_results_int_result[dictionary_results] +# name: test_function_results[literal_results] list([ dict({ 'docstring': dict({ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/dictionary_results/result_1', + 'id': 'test_package/function_module/literal_results/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ - 'key_type': dict({ - 'kind': 'NamedType', - 'name': 'str', - 'qname': 'builtins.str', - }), - 'kind': 'DictType', - 'value_type': dict({ - 'kind': 'NamedType', - 'name': 'FunctionModuleClassA', - 'qname': 'tests.data.test_package.function_module.FunctionModuleClassA', - }), + 'kind': 'LiteralType', + 'literal': 'Some String', }), }), ]) # --- -# name: test_function_results_int_result[float_result] +# name: test_function_results[nested_class_function] list([ dict({ 'docstring': dict({ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/float_result/result_1', + 'id': 'test_package/function_module/FunctionModuleClassB/FunctionModuleClassC/nested_class_function/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ 'kind': 'NamedType', - 'name': 'float', - 'qname': 'builtins.float', - }), - }), - ]) -# --- -# name: test_function_results_int_result[illegal_dictionary_results] - list([ - dict({ - 'docstring': dict({ - 'description': '', - 'type': '', - }), - 'id': 'test_package/function_module/illegal_dictionary_results/result_1', - 'is_type_inferred': False, - 'name': 'result_1', - 'type': dict({ - 'key_type': dict({ - 'kind': 'NamedType', - 'name': 'Any', - 'qname': '', - }), - 'kind': 'DictType', - 'value_type': dict({ - 'kind': 'NamedType', - 'name': 'Any', - 'qname': '', - }), + 'name': 'bool', + 'qname': 'builtins.bool', }), }), ]) # --- -# name: test_function_results_int_result[illegal_list_results] +# name: test_function_results[none_result] list([ - dict({ - 'docstring': dict({ - 'description': '', - 'type': '', - }), - 'id': 'test_package/function_module/illegal_list_results/result_1', - 'is_type_inferred': False, - 'name': 'result_1', - 'type': dict({ - 'kind': 'ListType', - 'types': list([ - dict({ - 'kind': 'NamedType', - 'name': 'int', - 'qname': '', - }), - dict({ - 'kind': 'NamedType', - 'name': 'str', - 'qname': '', - }), - ]), - }), - }), ]) # --- -# name: test_function_results_int_result[illegal_set_results] +# name: test_function_results[numpy_docstring_func] list([ dict({ 'docstring': dict({ - 'description': '', - 'type': '', + 'description': 'Checks if the sum of `x` and `y` is greater than 10. (Numpy)', + 'type': 'bool', }), - 'id': 'test_package/function_module/illegal_set_results/result_1', + 'id': 'test_package/docstring_module/NumpyDocstringClass/numpy_docstring_func/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ - 'kind': 'SetType', - 'types': list([ - dict({ - 'kind': 'NamedType', - 'name': 'str', - 'qname': '', - }), - dict({ - 'kind': 'NamedType', - 'name': 'bool', - 'qname': '', - }), - ]), + 'kind': 'NamedType', + 'name': 'bool', + 'qname': 'builtins.bool', }), }), ]) # --- -# name: test_function_results_int_result[int_result] +# name: test_function_results[obj_result] list([ dict({ 'docstring': dict({ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/int_result/result_1', + 'id': 'test_package/function_module/obj_result/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ 'kind': 'NamedType', - 'name': 'int', - 'qname': 'builtins.int', + 'name': 'FunctionModuleClassA', + 'qname': 'tests.data.test_package.function_module.FunctionModuleClassA', }), }), ]) # --- -# name: test_function_results_int_result[list_results] +# name: test_function_results[optional_results] list([ dict({ 'docstring': dict({ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/list_results/result_1', + 'id': 'test_package/function_module/optional_results/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ - 'kind': 'ListType', + 'kind': 'UnionType', 'types': list([ dict({ 'kind': 'NamedType', 'name': 'int', 'qname': 'builtins.int', }), + dict({ + 'kind': 'NamedType', + 'name': 'None', + 'qname': 'builtins.None', + }), ]), }), }), ]) # --- -# name: test_function_results_int_result[literal_results] +# name: test_function_results[property_function] + list([ + ]) +# --- +# name: test_function_results[property_function_infer] list([ dict({ 'docstring': dict({ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/literal_results/result_1', - 'is_type_inferred': False, + 'id': 'test_package/function_module/FunctionModulePropertiesClass/property_function_infer/result_1', + 'is_type_inferred': True, 'name': 'result_1', 'type': dict({ - 'kind': 'LiteralType', - 'literal': 'Some String', + 'kind': 'NamedType', + 'name': 'str', + 'qname': 'builtins.str', }), }), ]) # --- -# name: test_function_results_int_result[none_result] - list([ - ]) -# --- -# name: test_function_results_int_result[obj_result] +# name: test_function_results[property_function_params] list([ dict({ 'docstring': dict({ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/obj_result/result_1', + 'id': 'test_package/function_module/FunctionModulePropertiesClass/property_function_params/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ 'kind': 'NamedType', - 'name': 'FunctionModuleClassA', - 'qname': 'tests.data.test_package.function_module.FunctionModuleClassA', + 'name': 'str', + 'qname': 'builtins.str', }), }), ]) # --- -# name: test_function_results_int_result[optional_results] +# name: test_function_results[rest_docstring_func] list([ dict({ 'docstring': dict({ - 'description': '', - 'type': '', + 'description': 'Checks if the sum of x and y is greater than 10. (ReST)', + 'type': 'bool', }), - 'id': 'test_package/function_module/optional_results/result_1', + 'id': 'test_package/docstring_module/RestDocstringClass/rest_docstring_func/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ - 'kind': 'UnionType', - 'types': list([ - dict({ - 'kind': 'NamedType', - 'name': 'int', - 'qname': 'builtins.int', - }), - dict({ - 'kind': 'NamedType', - 'name': 'None', - 'qname': 'builtins.None', - }), - ]), + 'kind': 'NamedType', + 'name': 'bool', + 'qname': 'builtins.bool', }), }), ]) # --- -# name: test_function_results_int_result[set_results] +# name: test_function_results[set_results] list([ dict({ 'docstring': dict({ @@ -4635,7 +4689,11 @@ }), ]) # --- -# name: test_function_results_int_result[str_result] +# name: test_function_results[static_method_params] + list([ + ]) +# --- +# name: test_function_results[str_result] list([ dict({ 'docstring': dict({ @@ -4653,7 +4711,7 @@ }), ]) # --- -# name: test_function_results_int_result[tuple_results] +# name: test_function_results[tuple_results] list([ dict({ 'docstring': dict({ @@ -4685,7 +4743,7 @@ }), ]) # --- -# name: test_function_results_int_result[union_dictionary_results] +# name: test_function_results[union_dictionary_results] list([ dict({ 'docstring': dict({ @@ -4731,7 +4789,7 @@ }), ]) # --- -# name: test_function_results_int_result[union_results] +# name: test_function_results[union_results] list([ dict({ 'docstring': dict({ @@ -4759,65 +4817,7 @@ }), ]) # --- -# name: test_function_results_nested_class_function - list([ - dict({ - 'docstring': dict({ - 'description': '', - 'type': '', - }), - 'id': 'test_package/function_module/FunctionModuleClassB/FunctionModuleClassC/nested_class_function/result_1', - 'is_type_inferred': False, - 'name': 'result_1', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'bool', - 'qname': 'builtins.bool', - }), - }), - ]) -# --- -# name: test_function_results_numpy_docstring_func - list([ - dict({ - 'docstring': dict({ - 'description': 'Checks if the sum of `x` and `y` is greater than 10. (Numpy)', - 'type': 'bool', - }), - 'id': 'test_package/docstring_module/NumpyDocstringClass/numpy_docstring_func/result_1', - 'is_type_inferred': False, - 'name': 'result_1', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'bool', - 'qname': 'builtins.bool', - }), - }), - ]) -# --- -# name: test_function_results_rest_docstring_func - list([ - dict({ - 'docstring': dict({ - 'description': 'Checks if the sum of x and y is greater than 10. (ReST)', - 'type': 'bool', - }), - 'id': 'test_package/docstring_module/RestDocstringClass/rest_docstring_func/result_1', - 'is_type_inferred': False, - 'name': 'result_1', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'bool', - 'qname': 'builtins.bool', - }), - }), - ]) -# --- -# name: test_function_results_static_method_params - list([ - ]) -# --- -# name: test_global_functions__reexport_module_1 +# name: test_global_functions[_reexport_module_1] list([ dict({ 'docstring': dict({ @@ -4839,7 +4839,7 @@ }), ]) # --- -# name: test_global_functions__reexport_module_2 +# name: test_global_functions[_reexport_module_2] list([ dict({ 'docstring': dict({ @@ -4862,7 +4862,7 @@ }), ]) # --- -# name: test_global_functions__reexport_module_3 +# name: test_global_functions[_reexport_module_3] list([ dict({ 'docstring': dict({ @@ -4885,7 +4885,7 @@ }), ]) # --- -# name: test_global_functions__reexport_module_4 +# name: test_global_functions[_reexport_module_4] list([ dict({ 'docstring': dict({ @@ -4926,7 +4926,7 @@ }), ]) # --- -# name: test_global_functions_function_module +# name: test_global_functions[function_module] list([ dict({ 'docstring': dict({ @@ -5532,7 +5532,7 @@ }), ]) # --- -# name: test_imports___init___qualified_imports +# name: test_imports[__init__ (qualified_imports)] list([ dict({ 'alias': 'reex_1', @@ -5560,14 +5560,14 @@ }), ]) # --- -# name: test_imports___init___wildcard_imports +# name: test_imports[__init__ (wildcard_imports)] list([ dict({ 'module_name': '_reexport_module_3', }), ]) # --- -# name: test_imports_enum_module_qualified_imports +# name: test_imports[enum_module (qualified_imports)] list([ dict({ 'alias': None, @@ -5587,11 +5587,11 @@ }), ]) # --- -# name: test_imports_enum_module_wildcard_imports +# name: test_imports[enum_module (wildcard_imports)] list([ ]) # --- -# name: test_imports_module_qualified_imports +# name: test_imports[import_module (qualified_imports)] list([ dict({ 'alias': None, @@ -5607,14 +5607,14 @@ }), ]) # --- -# name: test_imports_module_wildcard_imports +# name: test_imports[import_module (wildcard_imports)] list([ dict({ 'module_name': 'math', }), ]) # --- -# name: test_modules___init__ +# name: test_modules[__init__] dict({ 'classes': list([ ]), @@ -5658,7 +5658,7 @@ ]), }) # --- -# name: test_modules_another_module +# name: test_modules[another_module] dict({ 'classes': list([ 'test_package/another_path/another_module/AnotherClass', @@ -5681,7 +5681,7 @@ ]), }) # --- -# name: test_modules_class_module +# name: test_modules[class_module] dict({ 'classes': list([ 'test_package/class_module/ClassModuleEmptyClassA', @@ -5703,7 +5703,7 @@ ]), }) # --- -# name: test_modules_docstring_module +# name: test_modules[docstring_module] dict({ 'classes': list([ 'test_package/docstring_module/EpydocDocstringClass', @@ -5729,7 +5729,7 @@ ]), }) # --- -# name: test_modules_enum_module +# name: test_modules[enum_module] dict({ 'classes': list([ ]), diff --git a/tests/safeds_stubgen/api_analyzer/test__get_api.py b/tests/safeds_stubgen/api_analyzer/test__get_api.py index cff2caec..455c96f8 100644 --- a/tests/safeds_stubgen/api_analyzer/test__get_api.py +++ b/tests/safeds_stubgen/api_analyzer/test__get_api.py @@ -100,263 +100,218 @@ def _get_specific_function_data( raise AssertionError -# ############################## Module ############################## # -def test_modules_class_module(snapshot: SnapshotAssertion) -> None: - module_data = _get_specific_module_data("class_module") - assert module_data == snapshot - - -def test_modules_another_module(snapshot: SnapshotAssertion) -> None: - module_data = _get_specific_module_data("another_module") - assert module_data == snapshot - - -def test_modules_enum_module(snapshot: SnapshotAssertion) -> None: - module_data = _get_specific_module_data("enum_module") - assert module_data == snapshot +_function_module_name = "function_module" +_enum_module_name = "enum_module" +_docstring_module_name = "docstring_module" +_class_module_name = "class_module" +_import_module_name = "import_module" +_abstract_module_name = "abstract_module" +_infer_types_module_name = "infer_types_module" -def test_modules___init__(snapshot: SnapshotAssertion) -> None: - module_data = _get_specific_module_data("__init__") - assert module_data == snapshot - - -def test_modules_docstring_module(snapshot: SnapshotAssertion) -> None: - module_data = _get_specific_module_data("docstring_module") +# ############################## Tests ############################## # +@pytest.mark.parametrize( + argnames="module_name", + argvalues=[ + _class_module_name, + "another_module", + _enum_module_name, + "__init__", + _docstring_module_name, + ], + ids=[ + _class_module_name, + "another_module", + _enum_module_name, + "__init__", + _docstring_module_name, + ], +) +def test_modules(module_name: str, snapshot: SnapshotAssertion) -> None: + module_data = _get_specific_module_data(module_name) assert module_data == snapshot -# ############################## Imports ############################## # Todo new tests after issue #38 -def get_import_data(module_name: str, import_type: str) -> list[dict]: +# Todo new tests after issue #38 +@pytest.mark.parametrize( + argnames=("module_name", "import_type"), + argvalues=[ + (_import_module_name, "qualified_imports"), + (_import_module_name, "wildcard_imports"), + (_enum_module_name, "qualified_imports"), + (_enum_module_name, "wildcard_imports"), + ("__init__", "qualified_imports"), + ("__init__", "wildcard_imports"), + ], + ids=[ + "import_module (qualified_imports)", + "import_module (wildcard_imports)", + "enum_module (qualified_imports)", + "enum_module (wildcard_imports)", + "__init__ (qualified_imports)", + "__init__ (wildcard_imports)", + ], +) +def test_imports(module_name: str, import_type: str, snapshot: SnapshotAssertion) -> None: module_data = _get_specific_module_data(module_name) - return module_data.get(import_type, []) - - -def test_imports_module_qualified_imports(snapshot: SnapshotAssertion) -> None: - import_data = get_import_data("import_module", "qualified_imports") + import_data = module_data.get(import_type, []) assert import_data == snapshot -def test_imports_module_wildcard_imports(snapshot: SnapshotAssertion) -> None: - import_data = get_import_data("import_module", "wildcard_imports") - assert import_data == snapshot - - -def test_imports_enum_module_qualified_imports(snapshot: SnapshotAssertion) -> None: - import_data = get_import_data("enum_module", "qualified_imports") - assert import_data == snapshot - - -def test_imports_enum_module_wildcard_imports(snapshot: SnapshotAssertion) -> None: - import_data = get_import_data("enum_module", "wildcard_imports") - assert import_data == snapshot - - -def test_imports___init___qualified_imports(snapshot: SnapshotAssertion) -> None: - import_data = get_import_data("__init__", "qualified_imports") - assert import_data == snapshot - - -def test_imports___init___wildcard_imports(snapshot: SnapshotAssertion) -> None: - import_data = get_import_data("__init__", "wildcard_imports") - assert import_data == snapshot - - -# ############################## Classes ############################## # -def test_classes_ClassModuleEmptyClassA(snapshot: SnapshotAssertion) -> None: # noqa: N802 - class_data = _get_specific_class_data("class_module", "ClassModuleEmptyClassA") - assert class_data == snapshot - - -def test_classes_ClassModuleClassB(snapshot: SnapshotAssertion) -> None: # noqa: N802 - class_data = _get_specific_class_data("class_module", "ClassModuleClassB") - assert class_data == snapshot - - -def test_classes_ClassModuleClassC(snapshot: SnapshotAssertion) -> None: # noqa: N802 - class_data = _get_specific_class_data("class_module", "ClassModuleClassC") - assert class_data == snapshot - - -def test_classes_ClassModuleClassD(snapshot: SnapshotAssertion) -> None: # noqa: N802 - class_data = _get_specific_class_data("class_module", "ClassModuleClassD") - assert class_data == snapshot - - -def test_classes_ClassModuleNestedClassE(snapshot: SnapshotAssertion) -> None: # noqa: N802 - class_data = _get_specific_class_data("class_module", "ClassModuleNestedClassE") - assert class_data == snapshot - - -def test_classes__ClassModulePrivateDoubleNestedClassF(snapshot: SnapshotAssertion) -> None: # noqa: N802 - class_data = _get_specific_class_data("class_module", "_ClassModulePrivateDoubleNestedClassF") - assert class_data == snapshot - - -def test_classes__ClassModulePrivateClassG(snapshot: SnapshotAssertion) -> None: # noqa: N802 - class_data = _get_specific_class_data("class_module", "_ClassModulePrivateClassG") - assert class_data == snapshot - - -def test_classes_VarianceClassAll(snapshot: SnapshotAssertion) -> None: # noqa: N802 - class_data = _get_specific_class_data("variance_module", "VarianceClassAll") - assert class_data == snapshot - - -def test_classes_VarianceClassOnlyInvariance(snapshot: SnapshotAssertion) -> None: # noqa: N802 - class_data = _get_specific_class_data("variance_module", "VarianceClassOnlyInvariance") - assert class_data == snapshot - - -def test_classes_InferMyTypes(snapshot: SnapshotAssertion) -> None: # noqa: N802 - class_data = _get_specific_class_data("infer_types_module", "InferMyTypes") - assert class_data == snapshot - - -def test_classes_EpydocDocstringClass(snapshot: SnapshotAssertion) -> None: # noqa: N802 - class_data = _get_specific_class_data("docstring_module", "EpydocDocstringClass", "epydoc") - assert class_data == snapshot - - -def test_classes_RestDocstringClass(snapshot: SnapshotAssertion) -> None: # noqa: N802 - class_data = _get_specific_class_data("docstring_module", "RestDocstringClass", "rest") - assert class_data == snapshot - - -def test_classes_NumpyDocstringClass(snapshot: SnapshotAssertion) -> None: # noqa: N802 - class_data = _get_specific_class_data("docstring_module", "NumpyDocstringClass", "numpydoc") - assert class_data == snapshot - - -def test_classes_GoogleDocstringClass(snapshot: SnapshotAssertion) -> None: # noqa: N802 - class_data = _get_specific_class_data("docstring_module", "GoogleDocstringClass", "google") - assert class_data == snapshot - - -def test_classes_ReexportClass(snapshot: SnapshotAssertion) -> None: # noqa: N802 - class_data = _get_specific_class_data("_reexport_module_1", "ReexportClass") - assert class_data == snapshot - - -def test_classes_AnotherReexportClass(snapshot: SnapshotAssertion) -> None: # noqa: N802 - class_data = _get_specific_class_data("_reexport_module_2", "AnotherReexportClass") - assert class_data == snapshot - - -def test_classes__ThirdReexportClass(snapshot: SnapshotAssertion) -> None: # noqa: N802 - class_data = _get_specific_class_data("_reexport_module_3", "_ThirdReexportClass") - assert class_data == snapshot - - -def test_classes_FourthReexportClass(snapshot: SnapshotAssertion) -> None: # noqa: N802 - class_data = _get_specific_class_data("_reexport_module_4", "FourthReexportClass") - assert class_data == snapshot - - -def test_classes_AbstractModuleClass(snapshot: SnapshotAssertion) -> None: # noqa: N802 - class_data = _get_specific_class_data("abstract_module", "AbstractModuleClass") +@pytest.mark.parametrize( + argnames=("module_name", "class_name", "docstring_style"), + argvalues=[ + (_class_module_name, "ClassModuleEmptyClassA", "plaintext"), + (_class_module_name, "ClassModuleClassB", "plaintext"), + (_class_module_name, "ClassModuleClassC", "plaintext"), + (_class_module_name, "ClassModuleClassD", "plaintext"), + (_class_module_name, "ClassModuleNestedClassE", "plaintext"), + (_class_module_name, "_ClassModulePrivateDoubleNestedClassF", "plaintext"), + (_class_module_name, "_ClassModulePrivateClassG", "plaintext"), + ("variance_module", "VarianceClassAll", "plaintext"), + ("variance_module", "VarianceClassOnlyInvariance", "plaintext"), + (_infer_types_module_name, "InferMyTypes", "plaintext"), + (_docstring_module_name, "EpydocDocstringClass", "epydoc"), + (_docstring_module_name, "RestDocstringClass", "rest"), + (_docstring_module_name, "NumpyDocstringClass", "numpydoc"), + (_docstring_module_name, "GoogleDocstringClass", "google"), + ("_reexport_module_1", "ReexportClass", "plaintext"), + ("_reexport_module_2", "AnotherReexportClass", "plaintext"), + ("_reexport_module_3", "_ThirdReexportClass", "plaintext"), + ("_reexport_module_4", "FourthReexportClass", "plaintext"), + (_abstract_module_name, "AbstractModuleClass", "plaintext"), + ], + ids=[ + "ClassModuleEmptyClassA", + "ClassModuleClassB", + "ClassModuleClassC", + "ClassModuleClassD", + "ClassModuleNestedClassE", + "_ClassModulePrivateDoubleNestedClassF", + "_ClassModulePrivateClassG", + "VarianceClassAll", + "VarianceClassOnlyInvariance", + "InferMyTypes", + "EpydocDocstringClass", + "RestDocstringClass", + "NumpyDocstringClass", + "GoogleDocstringClass", + "ReexportClass", + "AnotherReexportClass", + "_ThirdReexportClass", + "FourthReexportClass", + "AbstractModuleClass", + ], +) +def test_classes(module_name: str, class_name: str, docstring_style: str, snapshot: SnapshotAssertion) -> None: + class_data = _get_specific_class_data(module_name, class_name, docstring_style, is_enum=False) assert class_data == snapshot -# ############################## Class Attributes ############################## # -def get_class_attribute_data(module_name: str, class_name: str, docstring_style: str) -> list: +# Todo Epydoc Tests are deactivated right now, since attribute handling is not implemented yet for the docstring_parser +@pytest.mark.parametrize( + argnames=("module_name", "class_name", "docstring_style"), + argvalues=[ + ("attribute_module", "AttributesClassB", "plaintext"), + (_class_module_name, "ClassModuleNestedClassE", "plaintext"), + (_class_module_name, "_ClassModulePrivateClassG", "plaintext"), + # (_docstring_module_name, "EpydocDocstringClass", "epydoc"), + (_docstring_module_name, "RestDocstringClass", "rest"), + (_docstring_module_name, "NumpyDocstringClass", "numpydoc"), + (_docstring_module_name, "GoogleDocstringClass", "google"), + ], + ids=[ + "AttributesClassB", + "ClassModuleNestedClassE", + "_ClassModulePrivateClassG", + # "EpydocDocstringClass", + "RestDocstringClass", + "NumpyDocstringClass", + "GoogleDocstringClass", + ], +) +def test_class_attributes(module_name: str, class_name: str, docstring_style: str, snapshot: SnapshotAssertion) -> None: class_data: dict = _get_specific_class_data(module_name, class_name, docstring_style) class_attr_ids: list[str] = class_data["attributes"] - # Sort out the class attribute data we need and return api_data = get_api_data(docstring_style) - return [attr for attr in api_data["attributes"] if attr["id"] in class_attr_ids] - - -def test_class_attributes_AttributesClassB(snapshot: SnapshotAssertion) -> None: # noqa: N802 - class_data = get_class_attribute_data("attribute_module", "AttributesClassB", "plaintext") - assert class_data == snapshot - - -def test_class_attributes_ClassModuleNestedClassE(snapshot: SnapshotAssertion) -> None: # noqa: N802 - class_data = get_class_attribute_data("class_module", "ClassModuleNestedClassE", "plaintext") - assert class_data == snapshot - - -def test_class_attributes__ClassModulePrivateClassG(snapshot: SnapshotAssertion) -> None: # noqa: N802 - class_data = get_class_attribute_data("class_module", "_ClassModulePrivateClassG", "plaintext") - assert class_data == snapshot - - -# Todo Epydoc Tests are deactivated right now, since attribute handling is not implemented yet in the -# docstring_parser library -def xtest_class_attributes_EpydocDocstringClass(snapshot: SnapshotAssertion) -> None: # noqa: N802 - class_data = get_class_attribute_data("docstring_module", "EpydocDocstringClass", "epydoc") - assert class_data == snapshot - - -def test_class_attributes_RestDocstringClass(snapshot: SnapshotAssertion) -> None: # noqa: N802 - class_data = get_class_attribute_data("docstring_module", "RestDocstringClass", "rest") - assert class_data == snapshot - - -def test_class_attributes_NumpyDocstringClass(snapshot: SnapshotAssertion) -> None: # noqa: N802 - class_data = get_class_attribute_data("docstring_module", "NumpyDocstringClass", "numpydoc") - assert class_data == snapshot - - -def test_class_attributes_GoogleDocstringClass(snapshot: SnapshotAssertion) -> None: # noqa: N802 - class_data = get_class_attribute_data("docstring_module", "GoogleDocstringClass", "google") - assert class_data == snapshot - - -# ############################## Enums ############################## # -def test_enums_EnumTest(snapshot: SnapshotAssertion) -> None: # noqa: N802 - enum_data = _get_specific_class_data("enum_module", "EnumTest", is_enum=True) - assert enum_data == snapshot - - -def test_enums__ReexportedEmptyEnum(snapshot: SnapshotAssertion) -> None: # noqa: N802 - enum_data = _get_specific_class_data("enum_module", "_ReexportedEmptyEnum", is_enum=True) - assert enum_data == snapshot + # Sort out the class attribute data we need and return + class_attribute_data = [ + attr + for attr in api_data["attributes"] + if attr["id"] in class_attr_ids + ] -def test_enums_EnumTest2(snapshot: SnapshotAssertion) -> None: # noqa: N802 - enum_data = _get_specific_class_data("enum_module", "EnumTest2", is_enum=True) - assert enum_data == snapshot + assert class_attribute_data == snapshot -def test_enums_EnumTest3(snapshot: SnapshotAssertion) -> None: # noqa: N802 - enum_data = _get_specific_class_data("enum_module", "EnumTest3", is_enum=True) +@pytest.mark.parametrize( + argnames=("module_name", "class_name"), + argvalues=[ + (_enum_module_name, "EnumTest"), + (_enum_module_name, "_ReexportedEmptyEnum"), + (_enum_module_name, "EnumTest2"), + (_enum_module_name, "EnumTest3"), + ], + ids=[ + "EnumTest", + "_ReexportedEmptyEnum", + "EnumTest2", + "EnumTest3", + ], +) +def test_enums(module_name: str, class_name: str, snapshot: SnapshotAssertion) -> None: + enum_data = _get_specific_class_data(module_name, class_name, is_enum=True) assert enum_data == snapshot -# ############################## Enum Instances ############################## # -def get_enum_instance_data(enum_name: str, module_name: str = "enum_module") -> list: +@pytest.mark.parametrize( + argnames=("enum_name", "module_name"), + argvalues=[ + ("EnumTest", _enum_module_name), + ("_ReexportedEmptyEnum", _enum_module_name), + ("EnumTest3", _enum_module_name) + ], + ids=[ + "EnumTest", + "_ReexportedEmptyEnum", + "EnumTest3", + ], +) +def test_enum_instances(enum_name: str, module_name: str, snapshot: SnapshotAssertion) -> None: # Get enum data enum_data = _get_specific_class_data(module_name, enum_name, is_enum=True) enum_instance_ids = enum_data["instances"] # Sort out the enum instances we need and return - return [ + enum_instance_data = [ enum_instance for enum_instance in api_data_paintext["enum_instances"] if enum_instance["id"] in enum_instance_ids ] - -def test_enum_instances_EnumTest(snapshot: SnapshotAssertion) -> None: # noqa: N802 - enum_instance_data = get_enum_instance_data("EnumTest") assert enum_instance_data == snapshot -def test_enum_instances__ReexportedEmptyEnum(snapshot: SnapshotAssertion) -> None: # noqa: N802 - enum_instance_data = get_enum_instance_data("_ReexportedEmptyEnum") - assert enum_instance_data == snapshot - - -def test_enum_instances_EnumTest3(snapshot: SnapshotAssertion) -> None: # noqa: N802 - enum_instance_data = get_enum_instance_data("EnumTest3") - assert enum_instance_data == snapshot - - -# ############################## Global Functions ############################## # -def get_global_function_data(module_name: str) -> list: +@pytest.mark.parametrize( + argnames="module_name", + argvalues=[ + _function_module_name, + "_reexport_module_1", + "_reexport_module_2", + "_reexport_module_3", + "_reexport_module_4", + ], + ids=[ + _function_module_name, + "_reexport_module_1", + "_reexport_module_2", + "_reexport_module_3", + "_reexport_module_4", + ], +) +def test_global_functions(module_name: str, snapshot: SnapshotAssertion) -> None: # Get function data module_data = _get_specific_module_data(module_name) global_function_ids = module_data["functions"] @@ -364,36 +319,53 @@ def get_global_function_data(module_name: str) -> list: all_functions: list[dict] = api_data_paintext["functions"] # Sort out the functions we need and return - return [function for function in all_functions if function["id"] in global_function_ids] - - -def test_global_functions_function_module(snapshot: SnapshotAssertion) -> None: - global_function_data = get_global_function_data("function_module") - assert global_function_data == snapshot - - -def test_global_functions__reexport_module_1(snapshot: SnapshotAssertion) -> None: - global_function_data = get_global_function_data("_reexport_module_1") - assert global_function_data == snapshot - - -def test_global_functions__reexport_module_2(snapshot: SnapshotAssertion) -> None: - global_function_data = get_global_function_data("_reexport_module_2") - assert global_function_data == snapshot - - -def test_global_functions__reexport_module_3(snapshot: SnapshotAssertion) -> None: - global_function_data = get_global_function_data("_reexport_module_3") - assert global_function_data == snapshot - + global_function_data = [ + function + for function in all_functions + if function["id"] in global_function_ids + ] -def test_global_functions__reexport_module_4(snapshot: SnapshotAssertion) -> None: - global_function_data = get_global_function_data("_reexport_module_4") assert global_function_data == snapshot -# ############################## Class Methods ############################## # -def get_class_methods_data(module_name: str, class_name: str, docstring_style: str = "plaintext") -> list: +@pytest.mark.parametrize( + argnames=("module_name", "class_name", "docstring_style"), + argvalues=[ + (_class_module_name, "ClassModuleEmptyClassA", "plaintext"), + (_class_module_name, "ClassModuleClassB", "plaintext"), + (_class_module_name, "ClassModuleClassC", "plaintext"), + (_class_module_name, "ClassModuleNestedClassE", "plaintext"), + (_class_module_name, "_ClassModulePrivateDoubleNestedClassF", "plaintext"), + (_function_module_name, "FunctionModuleClassB", "plaintext"), + (_function_module_name, "FunctionModuleClassC", "plaintext"), + (_function_module_name, "FunctionModulePropertiesClass", "plaintext"), + (_infer_types_module_name, "InferMyTypes", "plaintext"), + ("_reexport_module_1", "ReexportClass", "plaintext"), + (_abstract_module_name, "AbstractModuleClass", "plaintext"), + (_docstring_module_name, "EpydocDocstringClass", "epydoc"), + (_docstring_module_name, "RestDocstringClass", "rest"), + (_docstring_module_name, "NumpyDocstringClass", "numpydoc"), + (_docstring_module_name, "GoogleDocstringClass", "google"), + ], + ids=[ + "ClassModuleEmptyClassA", + "ClassModuleClassB", + "ClassModuleClassC", + "ClassModuleNestedClassE", + "_ClassModulePrivateDoubleNestedClassF", + "FunctionModuleClassB", + "FunctionModuleClassC", + "FunctionModulePropertiesClass", + "InferMyTypes", + "ReexportClass", + "AbstractModuleClass", + "EpydocDocstringClass", + "RestDocstringClass", + "NumpyDocstringClass", + "GoogleDocstringClass", + ], +) +def test_class_methods(module_name: str, class_name: str, docstring_style: str, snapshot: SnapshotAssertion) -> None: class_data: dict = _get_specific_class_data(module_name, class_name) class_method_ids: list[str] = class_data["methods"] @@ -401,379 +373,132 @@ def get_class_methods_data(module_name: str, class_name: str, docstring_style: s all_functions: list[dict] = api_data["functions"] # Sort out the functions we need and return - return [method for method in all_functions if method["id"] in class_method_ids] - - -def test_class_methods_ClassModuleEmptyClassA(snapshot: SnapshotAssertion) -> None: # noqa: N802 - class_methods_data = get_class_methods_data("class_module", "ClassModuleEmptyClassA") - assert class_methods_data == snapshot - - -def test_class_methods_ClassModuleClassB(snapshot: SnapshotAssertion) -> None: # noqa: N802 - class_methods_data = get_class_methods_data("class_module", "ClassModuleClassB") - assert class_methods_data == snapshot - - -def test_class_methods_ClassModuleClassC(snapshot: SnapshotAssertion) -> None: # noqa: N802 - class_methods_data = get_class_methods_data("class_module", "ClassModuleClassC") - assert class_methods_data == snapshot - - -def test_class_methods_function_module_FunctionModuleClassB(snapshot: SnapshotAssertion) -> None: # noqa: N802 - class_methods_data = get_class_methods_data("function_module", "FunctionModuleClassB") - assert class_methods_data == snapshot - - -def test_class_methods_function_module_FunctionModuleClassC(snapshot: SnapshotAssertion) -> None: # noqa: N802 - class_methods_data = get_class_methods_data("function_module", "FunctionModuleClassC") - assert class_methods_data == snapshot - - -def test_class_methods_InferMyTypes(snapshot: SnapshotAssertion) -> None: # noqa: N802 - class_methods_data = get_class_methods_data("infer_types_module", "InferMyTypes") - assert class_methods_data == snapshot - - -def test_class_methods_FunctionModulePropertiesClass(snapshot: SnapshotAssertion) -> None: # noqa: N802 - class_methods_data = get_class_methods_data("function_module", "FunctionModulePropertiesClass") - assert class_methods_data == snapshot - - -def test_class_methods_ClassModuleNestedClassE(snapshot: SnapshotAssertion) -> None: # noqa: N802 - class_methods_data = get_class_methods_data("class_module", "ClassModuleNestedClassE") - assert class_methods_data == snapshot - - -def test_class_methods__ClassModulePrivateDoubleNestedClassF(snapshot: SnapshotAssertion) -> None: # noqa: N802 - class_methods_data = get_class_methods_data("class_module", "_ClassModulePrivateDoubleNestedClassF") - assert class_methods_data == snapshot - - -def test_class_methods_ReexportClass(snapshot: SnapshotAssertion) -> None: # noqa: N802 - class_methods_data = get_class_methods_data("_reexport_module_1", "ReexportClass") - assert class_methods_data == snapshot - - -def test_class_methods_AbstractModuleClass(snapshot: SnapshotAssertion) -> None: # noqa: N802 - class_methods_data = get_class_methods_data("abstract_module", "AbstractModuleClass") - assert class_methods_data == snapshot - - -def test_class_methods_EpydocDocstringClass(snapshot: SnapshotAssertion) -> None: # noqa: N802 - class_methods_data = get_class_methods_data("docstring_module", "EpydocDocstringClass", "epydoc") - assert class_methods_data == snapshot - - -def test_class_methods_RestDocstringClass(snapshot: SnapshotAssertion) -> None: # noqa: N802 - class_methods_data = get_class_methods_data("docstring_module", "RestDocstringClass", "rest") - assert class_methods_data == snapshot - - -def test_class_methods_NumpyDocstringClass(snapshot: SnapshotAssertion) -> None: # noqa: N802 - class_methods_data = get_class_methods_data("docstring_module", "NumpyDocstringClass", "numpydoc") - assert class_methods_data == snapshot - + class_methods_data = [ + method + for method in all_functions + if method["id"] in class_method_ids + ] -def test_class_methods_GoogleDocstringClass(snapshot: SnapshotAssertion) -> None: # noqa: N802 - class_methods_data = get_class_methods_data("docstring_module", "GoogleDocstringClass", "google") assert class_methods_data == snapshot -# ############################## Function Parameters ############################## # -def get_function_parameter_data( - function_name: str, - module_name: str = "function_module", - parent_class_name: str = "", - docstring_style: str = "plaintext" -) -> list: +@pytest.mark.parametrize( + argnames=("function_name", "module_name", "parent_class_name", "docstring_style"), + argvalues=[ + ("__init__", _function_module_name, "FunctionModuleClassB", "plaintext"), + ("static_method_params", _function_module_name, "FunctionModuleClassB", "plaintext"), + ("class_method", _function_module_name, "FunctionModuleClassB", "plaintext"), + ("class_method_params", _function_module_name, "FunctionModuleClassB", "plaintext"), + ("nested_class_function", _function_module_name, "FunctionModuleClassC", "plaintext"), + ("_private", _function_module_name, "", "plaintext"), + ("public_no_params_no_result", _function_module_name, "", "plaintext"), + ("params", _function_module_name, "", "plaintext"), + ("illegal_params", _function_module_name, "", "plaintext"), + ("special_params", _function_module_name, "", "plaintext"), + ("param_position", _function_module_name, "", "plaintext"), + ("opt_pos_only", _function_module_name, "", "plaintext"), + ("req_name_only", _function_module_name, "", "plaintext"), + ("arg", _function_module_name, "", "plaintext"), + ("args_type", _function_module_name, "", "plaintext"), + ("callable_type", _function_module_name, "", "plaintext"), + ("abstract_method_params", _abstract_module_name, "AbstractModuleClass", "plaintext"), + ("abstract_static_method_params", _abstract_module_name, "AbstractModuleClass", "plaintext"), + ("abstract_property_method", _abstract_module_name, "AbstractModuleClass", "plaintext"), + ("epydoc_docstring_func", _docstring_module_name, "EpydocDocstringClass", "epydoc"), + ("__init__", _docstring_module_name, "EpydocDocstringClass", "epydoc"), + ("rest_docstring_func", _docstring_module_name, "RestDocstringClass", "rest"), + ("__init__", _docstring_module_name, "RestDocstringClass", "rest"), + ("numpy_docstring_func", _docstring_module_name, "NumpyDocstringClass", "numpydoc"), + ("__init__", _docstring_module_name, "NumpyDocstringClass", "numpydoc"), + ("google_docstring_func", _docstring_module_name, "GoogleDocstringClass", "google"), + ("__init__", _docstring_module_name, "GoogleDocstringClass", "google"), + ], + ids=[ + "FunctionModuleClassB.__init__", + "static_method_params", + "class_method", + "class_method_params", + "nested_class_function", + "_private", + "public_no_params_no_result", + "params", + "illegal_params", + "special_params", + "param_position", + "opt_pos_only", + "req_name_only", + "arg", + "args_type", + "callable_type", + "abstract_method_params", + "abstract_static_method_params", + "abstract_property_method", + "epydoc_docstring_func", + "epydoc.__init__", + "rest_docstring_func", + "rest.__init__", + "numpy_docstring_func", + "numpy.__init__", + "google_docstring_func", + "google.__init__", + ], +) +def test_function_parameters( + function_name: str, module_name: str, parent_class_name: str, docstring_style: str, snapshot: SnapshotAssertion +) -> None: function_data: dict = _get_specific_function_data(module_name, function_name, parent_class_name, docstring_style) function_parameter_ids: list[str] = function_data["parameters"] api_data = get_api_data(docstring_style) # Sort out the parameters we need and return - return [ + function_parameter_data = [ parameter for parameter in api_data["parameters"] if parameter["id"] in function_parameter_ids ] - -def test_function_parameters_function_module_FunctionModuleClassB___init__(snapshot: SnapshotAssertion) -> None: # noqa: N802 - function_parameter_data = get_function_parameter_data( - function_name="__init__", - parent_class_name="FunctionModuleClassB" - ) - assert function_parameter_data == snapshot - - -def test_function_parameters_function_module_FunctionModuleClassB_static_method_params(snapshot: SnapshotAssertion) -> None: # noqa: N802 - function_parameter_data = get_function_parameter_data( - function_name="static_method_params", - parent_class_name="FunctionModuleClassB" - ) - assert function_parameter_data == snapshot - - -def test_function_parameters_function_module_FunctionModuleClassB_class_method(snapshot: SnapshotAssertion) -> None: # noqa: N802 - function_parameter_data = get_function_parameter_data( - function_name="class_method", - parent_class_name="FunctionModuleClassB" - ) - assert function_parameter_data == snapshot - - -def test_function_parameters_function_module_FunctionModuleClassB_class_method_params(snapshot: SnapshotAssertion) -> None: # noqa: N802 - function_parameter_data = get_function_parameter_data( - function_name="class_method_params", - parent_class_name="FunctionModuleClassB" - ) - assert function_parameter_data == snapshot - - -def test_function_parameters_function_module_FunctionModuleClassC_nested_class_function(snapshot: SnapshotAssertion) -> None: # noqa: N802 - function_parameter_data = get_function_parameter_data( - function_name="nested_class_function", - parent_class_name="FunctionModuleClassC" - ) - assert function_parameter_data == snapshot - - -def test_function_parameters_function_module__private(snapshot: SnapshotAssertion) -> None: - function_parameter_data = get_function_parameter_data(function_name="_private") - assert function_parameter_data == snapshot - - -def test_function_parameters_function_module_public_no_params_no_result(snapshot: SnapshotAssertion) -> None: - function_parameter_data = get_function_parameter_data(function_name="public_no_params_no_result") - assert function_parameter_data == snapshot - - -def test_function_parameters_function_module_params(snapshot: SnapshotAssertion) -> None: - function_parameter_data = get_function_parameter_data(function_name="params") - assert function_parameter_data == snapshot - - -def test_function_parameters_function_module_illegal_params(snapshot: SnapshotAssertion) -> None: - function_parameter_data = get_function_parameter_data(function_name="illegal_params") - assert function_parameter_data == snapshot - - -def test_function_parameters_function_module_special_params(snapshot: SnapshotAssertion) -> None: - function_parameter_data = get_function_parameter_data(function_name="special_params") - assert function_parameter_data == snapshot - - -def test_function_parameters_function_module_param_position(snapshot: SnapshotAssertion) -> None: - function_parameter_data = get_function_parameter_data(function_name="param_position") - assert function_parameter_data == snapshot - - -def test_function_parameters_function_module_opt_pos_only(snapshot: SnapshotAssertion) -> None: - function_parameter_data = get_function_parameter_data(function_name="opt_pos_only") - assert function_parameter_data == snapshot - - -def test_function_parameters_function_module_req_name_only(snapshot: SnapshotAssertion) -> None: - function_parameter_data = get_function_parameter_data(function_name="req_name_only") - assert function_parameter_data == snapshot - - -def test_function_parameters_function_module_arg(snapshot: SnapshotAssertion) -> None: - function_parameter_data = get_function_parameter_data(function_name="arg") assert function_parameter_data == snapshot -def test_function_parameters_function_module_args_type(snapshot: SnapshotAssertion) -> None: - function_parameter_data = get_function_parameter_data(function_name="args_type") - assert function_parameter_data == snapshot - - -def test_function_parameters_function_module_callable_type(snapshot: SnapshotAssertion) -> None: - function_parameter_data = get_function_parameter_data(function_name="callable_type") - assert function_parameter_data == snapshot - - -def test_function_parameters_abstract_module_abstract_method_params(snapshot: SnapshotAssertion) -> None: - function_parameter_data = get_function_parameter_data( - module_name="abstract_module", - function_name="abstract_method_params", - parent_class_name="AbstractModuleClass", - ) - assert function_parameter_data == snapshot - - -def test_function_parameters_abstract_module_abstract_static_method_params(snapshot: SnapshotAssertion) -> None: - function_parameter_data = get_function_parameter_data( - module_name="abstract_module", - function_name="abstract_static_method_params", - parent_class_name="AbstractModuleClass", - ) - assert function_parameter_data == snapshot - - -def test_function_parameters_abstract_module_abstract_property_method(snapshot: SnapshotAssertion) -> None: - function_parameter_data = get_function_parameter_data( - module_name="abstract_module", - function_name="abstract_property_method", - parent_class_name="AbstractModuleClass", - ) - assert function_parameter_data == snapshot - - -def test_function_parameters_epydoc_docstring_func(snapshot: SnapshotAssertion) -> None: - function_parameter_data = get_function_parameter_data( - module_name="docstring_module", - function_name="epydoc_docstring_func", - parent_class_name="EpydocDocstringClass", - docstring_style="epydoc") - assert function_parameter_data == snapshot - - -def test_function_parameters_EpydocDocstringClass___init__(snapshot: SnapshotAssertion) -> None: # noqa: N802 - function_parameter_data = get_function_parameter_data( - module_name="docstring_module", - function_name="__init__", - parent_class_name="EpydocDocstringClass", - docstring_style="epydoc" - ) - assert function_parameter_data == snapshot - - -def test_function_parameters_rest_docstring_func(snapshot: SnapshotAssertion) -> None: - function_parameter_data = get_function_parameter_data( - module_name="docstring_module", - function_name="rest_docstring_func", - parent_class_name="RestDocstringClass", - docstring_style="rest" - ) - assert function_parameter_data == snapshot - - -def test_function_parameters_RestDocstringClass___init__(snapshot: SnapshotAssertion) -> None: # noqa: N802 - function_parameter_data = get_function_parameter_data( - module_name="docstring_module", - function_name="__init__", - parent_class_name="RestDocstringClass", - docstring_style="rest" - ) - assert function_parameter_data == snapshot - - -def test_function_parameters_numpy_docstring_func(snapshot: SnapshotAssertion) -> None: - function_parameter_data = get_function_parameter_data( - module_name="docstring_module", - function_name="numpy_docstring_func", - parent_class_name="NumpyDocstringClass", - docstring_style="numpydoc" - ) - assert function_parameter_data == snapshot - - -def test_function_parameters_NumpyDocstringClass___init__(snapshot: SnapshotAssertion) -> None: # noqa: N802 - function_parameter_data = get_function_parameter_data( - module_name="docstring_module", - function_name="__init__", - parent_class_name="NumpyDocstringClass", - docstring_style="numpydoc" - ) - assert function_parameter_data == snapshot - - -def test_function_parameters_google_docstring_func(snapshot: SnapshotAssertion) -> None: - function_parameter_data = get_function_parameter_data( - module_name="docstring_module", - function_name="google_docstring_func", - parent_class_name="GoogleDocstringClass", - docstring_style="google" - ) - assert function_parameter_data == snapshot - - -def test_function_parameters_GoogleDocstringClass___init__(snapshot: SnapshotAssertion) -> None: # noqa: N802 - function_parameter_data = get_function_parameter_data( - module_name="docstring_module", - function_name="__init__", - parent_class_name="GoogleDocstringClass", - docstring_style="google" - ) - assert function_parameter_data == snapshot - - -# ############################## Function Results ############################## # -def get_function_result_data( - function_name: str, - module_name: str = "function_module", - parent_class_name: str = "", - docstring_style: str = "plaintext" -) -> list: - function_data: dict = _get_specific_function_data(module_name, function_name, parent_class_name, docstring_style) - function_result_ids: list[str] = function_data["results"] - - api_data = get_api_data(docstring_style) - - # Sort out the results we need and return - return [ - result - for result in api_data["results"] - if result["id"] in function_result_ids - ] - - -def test_function_results_instance_method(snapshot: SnapshotAssertion) -> None: - function_result_data = get_function_result_data( - function_name="instance_method", - parent_class_name="FunctionModuleClassB" - ) - assert function_result_data == snapshot - - -def test_function_results_static_method_params(snapshot: SnapshotAssertion) -> None: - function_result_data = get_function_result_data( - function_name="static_method_params", - parent_class_name="FunctionModuleClassB" - ) - assert function_result_data == snapshot - - -def test_function_results_class_method_params(snapshot: SnapshotAssertion) -> None: - function_result_data = get_function_result_data( - function_name="class_method_params", - parent_class_name="FunctionModuleClassB" - ) - assert function_result_data == snapshot - - -def test_function_results_nested_class_function(snapshot: SnapshotAssertion) -> None: - function_result_data = get_function_result_data( - function_name="nested_class_function", - parent_class_name="FunctionModuleClassC" - ) - assert function_result_data == snapshot - - @pytest.mark.parametrize( - argnames="func_name", + argnames=("function_name", "module_name", "parent_class_name", "docstring_style"), argvalues=[ - "int_result", - "str_result", - "float_result", - "none_result", - "obj_result", - "callexr_result", - "tuple_results", - "union_results", - "list_results", - "illegal_list_results", - "dictionary_results", - "illegal_dictionary_results", - "union_dictionary_results", - "set_results", - "illegal_set_results", - "optional_results", - "literal_results", - "any_results", - "callable_type", + ("int_result", _function_module_name, "", "plaintext"), + ("str_result", _function_module_name, "", "plaintext"), + ("float_result", _function_module_name, "", "plaintext"), + ("none_result", _function_module_name, "", "plaintext"), + ("obj_result", _function_module_name, "", "plaintext"), + ("callexr_result", _function_module_name, "", "plaintext"), + ("tuple_results", _function_module_name, "", "plaintext"), + ("union_results", _function_module_name, "", "plaintext"), + ("list_results", _function_module_name, "", "plaintext"), + ("illegal_list_results", _function_module_name, "", "plaintext"), + ("dictionary_results", _function_module_name, "", "plaintext"), + ("illegal_dictionary_results", _function_module_name, "", "plaintext"), + ("union_dictionary_results", _function_module_name, "", "plaintext"), + ("set_results", _function_module_name, "", "plaintext"), + ("illegal_set_results", _function_module_name, "", "plaintext"), + ("optional_results", _function_module_name, "", "plaintext"), + ("literal_results", _function_module_name, "", "plaintext"), + ("any_results", _function_module_name, "", "plaintext"), + ("callable_type", _function_module_name, "", "plaintext"), + ("instance_method", _function_module_name, "FunctionModuleClassB", "plaintext"), + ("static_method_params", _function_module_name, "FunctionModuleClassB", "plaintext"), + ("class_method_params", _function_module_name, "FunctionModuleClassB", "plaintext"), + ("nested_class_function", _function_module_name, "FunctionModuleClassC", "plaintext"), + ("property_function", _function_module_name, "FunctionModulePropertiesClass", "plaintext"), + ("property_function_params", _function_module_name, "FunctionModulePropertiesClass", "plaintext"), + ("property_function_infer", _function_module_name, "FunctionModulePropertiesClass", "plaintext"), + ("infer_function", _infer_types_module_name, "InferMyTypes", "plaintext"), + ("abstract_method_params", _abstract_module_name, "AbstractModuleClass", "plaintext"), + ("abstract_static_method_params", _abstract_module_name, "AbstractModuleClass", "plaintext"), + ("abstract_property_method", _abstract_module_name, "AbstractModuleClass", "plaintext"), + ("epydoc_docstring_func", _docstring_module_name, "EpydocDocstringClass", "epydoc"), + ("rest_docstring_func", _docstring_module_name, "RestDocstringClass", "rest"), + ("numpy_docstring_func", _docstring_module_name, "NumpyDocstringClass", "numpydoc"), + ("google_docstring_func", _docstring_module_name, "GoogleDocstringClass", "google"), + ], ids=[ "int_result", @@ -795,113 +520,35 @@ def test_function_results_nested_class_function(snapshot: SnapshotAssertion) -> "literal_results", "any_results", "callable_type", + "instance_method", + "static_method_params", + "class_method_params", + "nested_class_function", + "property_function", + "property_function_params", + "property_function_infer", + "infer_function", + "abstract_method_params", + "abstract_static_method_params", + "abstract_property_method", + "epydoc_docstring_func", + "rest_docstring_func", + "numpy_docstring_func", + "google_docstring_func", ], ) -def test_function_results_int_result(func_name: str, snapshot: SnapshotAssertion) -> None: - function_result_data = get_function_result_data( - function_name=func_name, - ) - assert function_result_data == snapshot - - -def test_function_results_infer_function(snapshot: SnapshotAssertion) -> None: - function_result_data = get_function_result_data( - module_name="infer_types_module", - function_name="infer_function", - parent_class_name="InferMyTypes" - ) - assert function_result_data == snapshot - - -def test_function_results_abstract_method_params(snapshot: SnapshotAssertion) -> None: - function_result_data = get_function_result_data( - module_name="abstract_module", - function_name="abstract_method_params", - parent_class_name="AbstractModuleClass" - ) - assert function_result_data == snapshot - - -def test_function_results_abstract_static_method_params(snapshot: SnapshotAssertion) -> None: - function_result_data = get_function_result_data( - module_name="abstract_module", - function_name="abstract_static_method_params", - parent_class_name="AbstractModuleClass" - ) - assert function_result_data == snapshot - - -def test_function_results_abstract_property_method(snapshot: SnapshotAssertion) -> None: - function_result_data = get_function_result_data( - module_name="abstract_module", - function_name="abstract_property_method", - parent_class_name="AbstractModuleClass" - ) - assert function_result_data == snapshot - - -def test_function_results_function_module_property_function(snapshot: SnapshotAssertion) -> None: - function_result_data = get_function_result_data( - module_name="function_module", - function_name="property_function", - parent_class_name="FunctionModulePropertiesClass", - ) - assert function_result_data == snapshot - - -def test_function_results_function_module_property_function_params(snapshot: SnapshotAssertion) -> None: - function_result_data = get_function_result_data( - module_name="function_module", - function_name="property_function_params", - parent_class_name="FunctionModulePropertiesClass", - ) - assert function_result_data == snapshot - - -def test_function_results_function_module_property_function_infer(snapshot: SnapshotAssertion) -> None: - function_result_data = get_function_result_data( - module_name="function_module", - function_name="property_function_infer", - parent_class_name="FunctionModulePropertiesClass", - ) - assert function_result_data == snapshot - - -def test_function_results_epydoc_docstring_func(snapshot: SnapshotAssertion) -> None: - function_result_data = get_function_result_data( - module_name="docstring_module", - function_name="epydoc_docstring_func", - parent_class_name="EpydocDocstringClass", - docstring_style="epydoc" - ) - assert function_result_data == snapshot - - -def test_function_results_rest_docstring_func(snapshot: SnapshotAssertion) -> None: - function_result_data = get_function_result_data( - module_name="docstring_module", - function_name="rest_docstring_func", - parent_class_name="RestDocstringClass", - docstring_style="rest" - ) - assert function_result_data == snapshot - - -def test_function_results_numpy_docstring_func(snapshot: SnapshotAssertion) -> None: - function_result_data = get_function_result_data( - module_name="docstring_module", - function_name="numpy_docstring_func", - parent_class_name="NumpyDocstringClass", - docstring_style="numpydoc" - ) - assert function_result_data == snapshot +def test_function_results( + function_name: str, module_name: str, parent_class_name: str, docstring_style: str, snapshot: SnapshotAssertion +) -> None: + function_data: dict = _get_specific_function_data(module_name, function_name, parent_class_name, docstring_style) + function_result_ids: list[str] = function_data["results"] + api_data = get_api_data(docstring_style) + # Sort out the results we need and return + function_result_data = [ + result + for result in api_data["results"] + if result["id"] in function_result_ids + ] -def test_function_results_google_docstring_func(snapshot: SnapshotAssertion) -> None: - function_result_data = get_function_result_data( - module_name="docstring_module", - function_name="google_docstring_func", - parent_class_name="GoogleDocstringClass", - docstring_style="google" - ) assert function_result_data == snapshot From 5bd771dce8f3d903694181ed6874ae53311b1031 Mon Sep 17 00:00:00 2001 From: Arsam Date: Wed, 29 Nov 2023 16:59:58 +0100 Subject: [PATCH 064/109] Added test case for snake_case to camelCase converter --- .../stubs_generator/test_generate_stubs.py | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py b/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py index 975725b4..b840bcce 100644 --- a/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py +++ b/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py @@ -109,49 +109,64 @@ def test_docstring_creation() -> None: ... @pytest.mark.parametrize( - ("name", "expected_result"), + ("name", "expected_result", "is_class_name"), [ ( "", "", + False ), ( "_", "_", + False ), ( "__get_function_name__", "getFunctionName", + False ), ( "__get_function_name", "getFunctionName", + False ), ( "get_function_name__", "getFunctionName", + False ), ( "__getFunction_name__", "getFunctionName", + False ), ( "__get__function___name__", "getFunctionName", + False ), ( "__get_funCtion_NamE__", "getFunCtionNamE", + False ), ( "getFunctionName", "getFunctionName", + False ), ( "a_a_A_aAAaA_1_1_2_aAa", "aAAAAAaA112AAa", + False + ), + ( + "some_class_name", + "SomeClassName", + True ), ], ) -def test_convert_snake_to_camel_case(name: str, expected_result: str) -> None: - assert _convert_snake_to_camel_case(name) == expected_result +def test_convert_snake_to_camel_case(name: str, expected_result: str, is_class_name: bool) -> None: + assert _convert_snake_to_camel_case(name, is_class_name) == expected_result From 852d48fc3258ca957b6277db3a4b2ff4f254c227 Mon Sep 17 00:00:00 2001 From: Arsam Date: Wed, 29 Nov 2023 17:29:25 +0100 Subject: [PATCH 065/109] Issue #39: The snake_case to camelCase converter can be toggled with the argument -ci. --- src/safeds_stubgen/api_analyzer/cli/_cli.py | 13 ++- .../stubs_generator/_generate_stubs.py | 94 ++++++++++--------- .../stubs_generator/test_generate_stubs.py | 56 ++++++++--- 3 files changed, 102 insertions(+), 61 deletions(-) diff --git a/src/safeds_stubgen/api_analyzer/cli/_cli.py b/src/safeds_stubgen/api_analyzer/cli/_cli.py index 9ba64610..72246b25 100644 --- a/src/safeds_stubgen/api_analyzer/cli/_cli.py +++ b/src/safeds_stubgen/api_analyzer/cli/_cli.py @@ -17,7 +17,7 @@ def cli() -> None: if args.verbose: logging.basicConfig(level=logging.INFO) - _run_api_command(args.package, args.src, args.out, args.docstyle, args.testrun) + _run_api_command(args.package, args.src, args.out, args.docstyle, args.testrun, args.convert_identifiers) def _get_args() -> argparse.Namespace: @@ -60,6 +60,14 @@ def _get_args() -> argparse.Namespace: required=False, action="store_true", ) + parser.add_argument( + "-ci", + "--convert_identifiers", + help="Set this flag if the identifiers should be converted to Safe-DS standard (UpperCamelCase for classes and " + "camelCase for everything else).", + required=False, + action="store_true", + ) return parser.parse_args() @@ -70,6 +78,7 @@ def _run_api_command( out_dir_path: Path, docstring_style: DocstringStyle, is_test_run: bool, + convert_identifiers: bool, ) -> None: """ List the API of a package. @@ -89,4 +98,4 @@ def _run_api_command( out_file_api = out_dir_path.joinpath(f"{package}__api.json") api.to_json_file(out_file_api) - generate_stubs(api, out_dir_path) + generate_stubs(api, out_dir_path, convert_identifiers) diff --git a/src/safeds_stubgen/stubs_generator/_generate_stubs.py b/src/safeds_stubgen/stubs_generator/_generate_stubs.py index b55c0b6c..1e0939f9 100644 --- a/src/safeds_stubgen/stubs_generator/_generate_stubs.py +++ b/src/safeds_stubgen/stubs_generator/_generate_stubs.py @@ -23,7 +23,7 @@ from collections.abc import Generator -def generate_stubs(api: API, out_path: Path) -> None: +def generate_stubs(api: API, out_path: Path, convert_identifiers: bool) -> None: """Generate Safe-DS stubs. Generates stub files from an API object and writes them to the out_path path. @@ -35,13 +35,16 @@ def generate_stubs(api: API, out_path: Path) -> None: out_path : Path The path in which the stub files should be created. If no such path exists this function creates the directory files. + convert_identifiers : bool + Set this True if the identifiers should be converted to Safe-DS standard (UpperCamelCase for classes and + camelCase for everything else). """ modules = api.modules.values() if not modules: return Path(out_path / api.package).mkdir(parents=True, exist_ok=True) - generator = StubsStringGenerator() + generator = StubsStringGenerator(convert_identifiers) for module in modules: module_name = module.name @@ -71,38 +74,6 @@ def generate_stubs(api: API, out_path: Path) -> None: f.write(module_text) -def _convert_snake_to_camel_case(name: str, is_class_name: bool = False) -> str: - if name == "_": - return name - - # Count underscores in front and behind the name - underscore_count_start = len(name) - len(name.lstrip("_")) - underscore_count_end = len(name) - len(name.rstrip("_")) - - if underscore_count_end == 0: - cleaned_name = name[underscore_count_start:] - else: - cleaned_name = name[underscore_count_start:-underscore_count_end] - - # Remove underscores and join in camelCase - name_parts = cleaned_name.split("_") - - # UpperCamelCase for class names - if is_class_name: - return "".join( - part[0].upper() + part[1:] - for part in name_parts - if part - ) - - # Normal camelCase for everything else - return name_parts[0] + "".join( - part[0].upper() + part[1:] - for part in name_parts[1:] - if part - ) - - class StubsStringGenerator: """Generate Safe-DS stub strings. @@ -110,13 +81,14 @@ class StubsStringGenerator: method. """ - def __init__(self) -> None: + def __init__(self, convert_identifiers: bool) -> None: self._current_todo_msgs: set[str] = set() + self.convert_identifiers = convert_identifiers def create_module_string(self, module: Module) -> str: # Create package info package_info = module.id.replace("/", ".") - package_info_camel_case = _convert_snake_to_camel_case(package_info) + package_info_camel_case = self._convert_snake_to_camel_case(package_info) module_name_info = "" if package_info != package_info_camel_case: module_name_info = f'@PythonModule("{package_info}")\n' @@ -212,7 +184,7 @@ def _create_class_string(self, class_: Class, class_indentation: str = "") -> st raise ValueError(f"Expected variance kind, got {variance.variance_type.name}.") # Convert name to camelCase and check for keywords - variance_name_camel_case = _convert_snake_to_camel_case(variance.name) + variance_name_camel_case = self._convert_snake_to_camel_case(variance.name) variance_name_camel_case = self._replace_if_safeds_keyword(variance_name_camel_case) variances.append(f"{variance_direction}{variance_name_camel_case}") @@ -232,7 +204,7 @@ def _create_class_string(self, class_: Class, class_indentation: str = "") -> st # Class name - Convert to camelCase and check for keywords class_name = class_.name python_name_info = "" - class_name_camel_case = _convert_snake_to_camel_case(class_name, is_class_name=True) + class_name_camel_case = self._convert_snake_to_camel_case(class_name, is_class_name=True) if class_name_camel_case != class_name: python_name_info = f"{class_indentation}{self._create_name_annotation(class_name)}\n" class_name_camel_case = self._replace_if_safeds_keyword(class_name_camel_case) @@ -259,7 +231,7 @@ def _create_class_string(self, class_: Class, class_indentation: str = "") -> st # Convert name to camelCase and add PythonName annotation attr_name = attribute.name - attr_name_camel_case = _convert_snake_to_camel_case(attr_name) + attr_name_camel_case = self._convert_snake_to_camel_case(attr_name) attr_name_annotation = "" if attr_name_camel_case != attr_name: attr_name_annotation = f"{self._create_name_annotation(attr_name)}\n{inner_indentations}" @@ -341,7 +313,7 @@ def _create_function_string(self, function: Function, indentations: str = "", is # Convert function name to camelCase name = function.name - camel_case_name = _convert_snake_to_camel_case(name) + camel_case_name = self._convert_snake_to_camel_case(name) function_name_annotation = "" if camel_case_name != name: function_name_annotation = f"{indentations}{self._create_name_annotation(name)}\n" @@ -366,7 +338,7 @@ def _create_property_function_string(self, function: Function, indentations: str Functions or methods with the @property decorator are handled the same way as class attributes. """ name = function.name - camel_case_name = _convert_snake_to_camel_case(name) + camel_case_name = self._convert_snake_to_camel_case(name) function_name_annotation = "" if camel_case_name != name: function_name_annotation = f"{self._create_name_annotation(name)} " @@ -391,7 +363,7 @@ def _create_result_string(self, function_results: list[Result]) -> str: result_type = result.type.to_dict() ret_type = self._create_type_string(result_type) type_string = f": {ret_type}" if ret_type else "" - result_name = _convert_snake_to_camel_case(result.name) + result_name = self._convert_snake_to_camel_case(result.name) result_name = self._replace_if_safeds_keyword(result_name) results.append( f"{result_name}" @@ -471,7 +443,7 @@ def _create_parameter_string( # Convert to camelCase if necessary name = parameter.name - camel_case_name = _convert_snake_to_camel_case(name) + camel_case_name = self._convert_snake_to_camel_case(name) name_annotation = "" if camel_case_name != name: # Memorize the changed name for the @PythonName() annotation @@ -540,7 +512,7 @@ def _create_enum_string(self, enum_data: Enum) -> str: name = enum_instance.name # Convert snake_case names to camelCase - camel_case_name = _convert_snake_to_camel_case(name) + camel_case_name = self._convert_snake_to_camel_case(name) annotation = "" if camel_case_name != name: annotation = f"\t{self._create_name_annotation(name)}\n" @@ -729,3 +701,37 @@ def _replace_if_safeds_keyword(keyword: str) -> str: }: return f"`{keyword}`" return keyword + + def _convert_snake_to_camel_case(self, name: str, is_class_name: bool = False) -> str: + if not self.convert_identifiers: + return name + + if name == "_": + return name + + # Count underscores in front and behind the name + underscore_count_start = len(name) - len(name.lstrip("_")) + underscore_count_end = len(name) - len(name.rstrip("_")) + + if underscore_count_end == 0: + cleaned_name = name[underscore_count_start:] + else: + cleaned_name = name[underscore_count_start:-underscore_count_end] + + # Remove underscores and join in camelCase + name_parts = cleaned_name.split("_") + + # UpperCamelCase for class names + if is_class_name: + return "".join( + part[0].upper() + part[1:] + for part in name_parts + if part + ) + + # Normal camelCase for everything else + return name_parts[0] + "".join( + part[0].upper() + part[1:] + for part in name_parts[1:] + if part + ) diff --git a/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py b/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py index b840bcce..e45996e1 100644 --- a/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py +++ b/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py @@ -8,7 +8,7 @@ from safeds_stubgen.stubs_generator import generate_stubs # noinspection PyProtectedMember -from safeds_stubgen.stubs_generator._generate_stubs import _convert_snake_to_camel_case +from safeds_stubgen.stubs_generator._generate_stubs import StubsStringGenerator if TYPE_CHECKING: from syrupy import SnapshotAssertion @@ -21,7 +21,7 @@ _out_dir_stubs = Path(_out_dir / _test_package_name) api = get_api(_test_package_name, _test_package_dir, is_test_run=True) -generate_stubs(api, _out_dir) +generate_stubs(api, _out_dir, convert_identifiers=True) # Utilites @@ -109,64 +109,90 @@ def test_docstring_creation() -> None: ... @pytest.mark.parametrize( - ("name", "expected_result", "is_class_name"), + ("name", "expected_result", "is_class_name", "convert_identifiers"), [ ( "", "", - False + False, + True ), ( "_", "_", - False + False, + True ), ( "__get_function_name__", "getFunctionName", - False + False, + True ), ( "__get_function_name", "getFunctionName", - False + False, + True ), ( "get_function_name__", "getFunctionName", - False + False, + True ), ( "__getFunction_name__", "getFunctionName", - False + False, + True ), ( "__get__function___name__", "getFunctionName", - False + False, + True ), ( "__get_funCtion_NamE__", "getFunCtionNamE", - False + False, + True ), ( "getFunctionName", "getFunctionName", - False + False, + True ), ( "a_a_A_aAAaA_1_1_2_aAa", "aAAAAAaA112AAa", - False + False, + True ), ( "some_class_name", "SomeClassName", + True, True ), + ( + "some_function_name", + "some_function_name", + False, + False + ), + ( + "some_class_name", + "some_class_name", + True, + False + ), ], ) -def test_convert_snake_to_camel_case(name: str, expected_result: str, is_class_name: bool) -> None: - assert _convert_snake_to_camel_case(name, is_class_name) == expected_result +def test_convert_snake_to_camel_case( + name: str, expected_result: str, is_class_name: bool, convert_identifiers: bool +) -> None: + stubs_string_generator = StubsStringGenerator(convert_identifiers=convert_identifiers) + assert stubs_string_generator._convert_snake_to_camel_case(name, is_class_name) == expected_result From 6b29c16cc5d1df0733e2da8587201cb2eabbf948 Mon Sep 17 00:00:00 2001 From: Arsam Date: Thu, 30 Nov 2023 15:14:41 +0100 Subject: [PATCH 066/109] Mostly refactoring, fixing some bugs and adding test cases --- .../api_analyzer/_ast_visitor.py | 247 +++++++++--------- .../api_analyzer/_mypy_helpers.py | 42 ++- .../stubs_generator/_generate_stubs.py | 12 +- tests/data/test_package/abstract_module.py | 3 +- tests/data/test_package/attribute_module.py | 14 +- tests/data/test_package/function_module.py | 5 +- tests/data/test_package/infer_types_module.py | 2 +- .../api_analyzer/test__get_api.py | 6 +- 8 files changed, 178 insertions(+), 153 deletions(-) diff --git a/src/safeds_stubgen/api_analyzer/_ast_visitor.py b/src/safeds_stubgen/api_analyzer/_ast_visitor.py index d33e5c08..a3fdd605 100644 --- a/src/safeds_stubgen/api_analyzer/_ast_visitor.py +++ b/src/safeds_stubgen/api_analyzer/_ast_visitor.py @@ -30,12 +30,13 @@ get_funcdef_definitions, get_mypyfile_definitions, has_correct_type_of_any, + mypy_expression_to_sds_type, mypy_type_to_abstract_type, mypy_variance_parser, ) if TYPE_CHECKING: - from safeds_stubgen.docstring_parsing import AbstractDocstringParser + from safeds_stubgen.docstring_parsing import AbstractDocstringParser, ResultDocstring class MyPyAstVisitor: @@ -217,7 +218,7 @@ def enter_funcdef(self, node: mp_nodes.FuncDef) -> None: arguments = self._parse_parameter_data(node, function_id) # Create results - results = self._create_result(node, function_id) + results = self._parse_results(node, function_id) # Get reexported data reexported_by = self._get_reexported_by(name) @@ -359,35 +360,63 @@ def leave_assignmentstmt(self, _: mp_nodes.AssignmentStmt) -> None: # #### Result utilities - def _mypy_expression_to_sds_type(self, expr: mp_nodes.Expression) -> sds_types.NamedType | sds_types.TupleType: - if isinstance(expr, mp_nodes.NameExpr): - if expr.name in {"False", "True"}: - return sds_types.NamedType(name="bool", qname="builtins.bool") + def _parse_results(self, node: mp_nodes.FuncDef, function_id: str) -> list[Result]: + # __init__ functions aren't supposed to have returns, so we can ignore them + if node.name == "__init__": + return [] + + # Get type + ret_type = None + is_type_inferred = False + if hasattr(node, "type"): + node_type = node.type + if node_type is not None and hasattr(node_type, "ret_type"): + node_ret_type = node_type.ret_type + + if not isinstance(node_ret_type, mp_types.NoneType): + if (isinstance(node_ret_type, mp_types.AnyType) and + not has_correct_type_of_any(node_ret_type.type_of_any)): + # In this case, the "Any" type was given because it was not explicitly annotated. + # Therefor we have to try to infer the type. + ret_type = self._infer_type_from_return_stmts(node) + is_type_inferred = ret_type is not None + else: + # Otherwise, we can parse the type normally + ret_type = mypy_type_to_abstract_type(node_ret_type, node.unanalyzed_type.ret_type) else: - return sds_types.NamedType(name=expr.name, qname=expr.fullname) - elif isinstance(expr, mp_nodes.IntExpr): - return sds_types.NamedType(name="int", qname="builtins.int") - elif isinstance(expr, mp_nodes.FloatExpr): - return sds_types.NamedType(name="float", qname="builtins.float") - elif isinstance(expr, mp_nodes.StrExpr): - return sds_types.NamedType(name="str", qname="builtins.str") - elif isinstance(expr, mp_nodes.TupleExpr): - return sds_types.TupleType(types=[ - self._mypy_expression_to_sds_type(item) - for item in expr.items - ]) - else: # pragma: no cover - raise TypeError("Unexpected expression type for return type.") + # Infer type + ret_type = self._infer_type_from_return_stmts(node) + is_type_inferred = ret_type is not None + + if ret_type is None: + return [] + + result_docstring = self.docstring_parser.get_result_documentation(node) + + if is_type_inferred and isinstance(ret_type, sds_types.TupleType): + return self._create_infered_results(ret_type, result_docstring, function_id) + + # If we got a TupleType, we can iterate it for the results, but if we got a NamedType, we have just one result + return_results = ret_type.types if isinstance(ret_type, sds_types.TupleType) else [ret_type] + return [ + Result( + id=f"{function_id}/result_{i + 1}", + type=type_, + is_type_inferred=is_type_inferred, + name=f"result_{i + 1}", + docstring=result_docstring, + ) + for i, type_ in enumerate(return_results) + ] - def _infer_type_from_return_stmts( - self, func_node: mp_nodes.FuncDef, - ) -> sds_types.NamedType | sds_types.TupleType | None: + @staticmethod + def _infer_type_from_return_stmts(func_node: mp_nodes.FuncDef) -> sds_types.NamedType | sds_types.TupleType | None: # To infer the type, we iterate through all return statements we find in the function func_defn = get_funcdef_definitions(func_node) return_stmts = find_return_stmts_recursive(func_defn) if return_stmts: types = { - self._mypy_expression_to_sds_type(return_stmt.expr) + mypy_expression_to_sds_type(return_stmt.expr) for return_stmt in return_stmts } @@ -406,105 +435,74 @@ def _infer_type_from_return_stmts( return return_stmt_types[0] return None - def _create_result(self, node: mp_nodes.FuncDef, function_id: str) -> list[Result]: - # __init__ functions aren't supposed to have returns, so we can ignore them - if node.name == "__init__": - return [] - - ret_type = None - is_type_inferred = False - if hasattr(node, "type"): - node_type = node.type - if node_type is not None and hasattr(node_type, "ret_type"): - node_ret_type = node_type.ret_type + @staticmethod + def _create_infered_results( + results: sds_types.TupleType, result_docstring: ResultDocstring, function_id: str, + ) -> list[Result]: + """Create Result objects with inferred results. - if not isinstance(node_ret_type, mp_types.NoneType): - if (isinstance(node_ret_type, mp_types.AnyType) and - not has_correct_type_of_any(node_ret_type.type_of_any)): - # In this case, the "Any" type was given because it was not explicitly annotated. - # Therefor we have to either infer the type or set no type at all. - ret_type = self._infer_type_from_return_stmts(node) - is_type_inferred = ret_type is not None - else: - ret_type = mypy_type_to_abstract_type(node_ret_type, node.unanalyzed_type.ret_type) - else: - # Infer type - ret_type = self._infer_type_from_return_stmts(node) - is_type_inferred = ret_type is not None + If we inferred the result types, we have to create a two-dimensional array for the results since tuples are + considered as multiple results, but other return types have to be grouped as one union. For example, if a + function has the following returns "return 42" and "return True, 1.2" we would have to group the integer and + boolean as "result_1: Union[int, bool]" and the float number as "result_2: Union[float, None]". - if ret_type is None: - return [] + Paramters + --------- + ret_type : sds_types.TupleType + An object representing a tuple with all inferred types. + result_docstring : ResultDocstring + The docstring of the function to which the results belong to. + function_id : str + The function ID. - # We create a two-dimensional array for results, b/c tuples are counted as multiple results, but normal returns - # have to be grouped as one Union. - # For example, if a function has the following returns: "return 42" and "return True, 1.2" we would have to - # group the integer and boolean as result_1: Union[int, bool] and the float number as - # result_2: Union[float, None]. + Returns + ------- + list[Result] + A list of Results objects representing the possible results of a funtion. + """ result_array: list[list] = [] - if is_type_inferred and isinstance(ret_type, sds_types.TupleType): - type_: sds_types.NamedType | sds_types.TupleType - for type_ in ret_type.types: - if isinstance(type_, sds_types.NamedType): - if result_array: - result_array[0].append(type_) - else: - result_array.append([type_]) - else: - for i, type__ in enumerate(type_.types): - if len(result_array) > i: - result_array[i].append(type__) - else: - result_array.append([type__]) - - results = [] - docstring = self.docstring_parser.get_result_documentation(node) - for i, result_list in enumerate(result_array): - result_count = len(result_list) - if result_count == 0: - break - elif result_count == 1: - result_type = result_list[0] + type_: sds_types.NamedType | sds_types.TupleType + for type_ in results.types: + if isinstance(type_, sds_types.NamedType): + if result_array: + result_array[0].append(type_) else: - result_type = sds_types.UnionType(result_list) - - name = f"result_{i + 1}" - results.append( - Result( - id=f"{function_id}/{name}", - type=result_type, - is_type_inferred=is_type_inferred, - name=name, - docstring=docstring, - ), - ) - - return results + result_array.append([type_]) + else: + for i, type__ in enumerate(type_.types): + if len(result_array) > i: + result_array[i].append(type__) + else: + result_array.append([type__]) + + inferred_results = [] + for i, result_list in enumerate(result_array): + result_count = len(result_list) + if result_count == 0: + break + elif result_count == 1: + result_type = result_list[0] + else: + result_type = sds_types.UnionType(result_list) - elif isinstance(ret_type, sds_types.TupleType): - return [ + name = f"result_{i + 1}" + inferred_results.append( Result( - id=f"{function_id}/result_{i + 1}", - type=type_, - is_type_inferred=is_type_inferred, - name=f"result_{i + 1}", - docstring=self.docstring_parser.get_result_documentation(node), - ) - for i, type_ in enumerate(ret_type.types) - ] + id=f"{function_id}/{name}", + type=result_type, + is_type_inferred=True, + name=name, + docstring=result_docstring, + ), + ) - return [Result( - id=f"{function_id}/result_1", - type=ret_type, - is_type_inferred=is_type_inferred, - name="result_1", - docstring=self.docstring_parser.get_result_documentation(node), - )] + return inferred_results # #### Attribute utilities def _parse_attributes( self, - lvalue: mp_nodes.Expression, + lvalue: mp_nodes.NameExpr | mp_nodes.MemberExpr | mp_nodes.TupleExpr, unanalyzed_type: mp_types.Type | None, is_static: bool = True, ) -> list[Attribute]: @@ -512,7 +510,7 @@ def _parse_attributes( attributes: list[Attribute] = [] if hasattr(lvalue, "name"): - if self.check_attribute_already_defined(lvalue, lvalue.name): + if self._is_attribute_already_defined(lvalue, lvalue.name): return attributes attributes.append( @@ -525,7 +523,7 @@ def _parse_attributes( if not hasattr(lvalue_, "name"): # pragma: no cover raise AttributeError("Expected value to have attribute 'name'.") - if self.check_attribute_already_defined(lvalue_, lvalue_.name): + if self._is_attribute_already_defined(lvalue_, lvalue_.name): continue attributes.append( @@ -534,7 +532,7 @@ def _parse_attributes( return attributes - def check_attribute_already_defined(self, lvalue: mp_nodes.Expression, value_name: str) -> bool: + def _is_attribute_already_defined(self, lvalue: mp_nodes.Expression, value_name: str) -> bool: assert isinstance(lvalue, mp_nodes.NameExpr | mp_nodes.MemberExpr | mp_nodes.TupleExpr) if hasattr(lvalue, "node"): node = lvalue.node @@ -554,7 +552,7 @@ def check_attribute_already_defined(self, lvalue: mp_nodes.Expression, value_nam if value_name == attribute.name: return True - raise ValueError(f"The attribute {value_name} has no value.") + raise ValueError(f"The attribute {value_name} has no value.") # pragma: no cover return False def _create_attribute( @@ -623,6 +621,7 @@ def _create_attribute( # Ignore types that are special mypy any types if (attribute_type is not None and not (isinstance(attribute_type, mp_types.AnyType) and not has_correct_type_of_any(attribute_type.type_of_any))): + # noinspection PyTypeChecker type_ = mypy_type_to_abstract_type(attribute_type, unanalyzed_type) # Get docstring @@ -673,13 +672,7 @@ def _get_default_parameter_value_and_type( return default_value, arg_type elif isinstance(initializer, mp_nodes.CallExpr): - # Check if callee path is in our package and create type information - # Todo Frage: Wie stellen wir Call Expressions wie SomeClass() als type dar? Mit oder ohne "()" - if self._check_if_qname_in_package(initializer.callee.fullname): - default_value = f"{initializer.callee.name}()" - if infer_arg_type: - arg_type = sds_types.NamedType(name=initializer.callee.name, qname=initializer.callee.fullname) - + # We do not support call expressions as types return default_value, arg_type else: # pragma: no cover @@ -709,17 +702,16 @@ def _parse_parameter_data(self, node: mp_nodes.FuncDef, function_id: str) -> lis mypy_type = argument.variable.type is_type_inferred = False arg_kind = get_argument_kind(argument) + type_annotation = argument.type_annotation + arg_type = None if mypy_type is None: # pragma: no cover raise ValueError("Argument has no type.") - - type_annotation = argument.type_annotation - arg_type = None - if isinstance(mypy_type, mp_types.AnyType) and not has_correct_type_of_any(mypy_type.type_of_any): + elif isinstance(mypy_type, mp_types.AnyType) and not has_correct_type_of_any(mypy_type.type_of_any): # We try to infer the type through the default value later, if possible pass elif (isinstance(type_annotation, mp_types.UnboundType) and - type_annotation.name == "list" and + type_annotation.name in {"list", "set"} and len(type_annotation.args) >= 2): # A special case where the argument is a list with multiple types. We have to handle this case like this # b/c something like list[int, str] is not allowed according to PEP and therefore not handled the normal @@ -811,7 +803,8 @@ def _add_reexports(self, module: Module) -> None: # #### Misc. utilities # Todo This check is currently too weak, we should try to get the path to the package from the api object, not - # just the package name + # just the package name. We will resolve this with or after issue #24 and #38, since more information are needed + # from the package. def _check_if_qname_in_package(self, qname: str) -> bool: return self.api.package in qname diff --git a/src/safeds_stubgen/api_analyzer/_mypy_helpers.py b/src/safeds_stubgen/api_analyzer/_mypy_helpers.py index 14d26cae..30a9f311 100644 --- a/src/safeds_stubgen/api_analyzer/_mypy_helpers.py +++ b/src/safeds_stubgen/api_analyzer/_mypy_helpers.py @@ -43,10 +43,12 @@ def mypy_type_to_abstract_type( # Final type types = [ mypy_type_to_abstract_type(arg) - for arg in unanalyzed_type.args + for arg in getattr(unanalyzed_type, "args", []) ] if len(types) == 1: return sds_types.FinalType(type_=types[0]) + elif len(types) == 0: # pragma: no cover + raise ValueError("Final type has no type arguments.") return sds_types.FinalType(type_=sds_types.UnionType(types=types)) elif (unanalyzed_type_name in {"list", "set"} and len(mypy_type.args) == 1 and @@ -55,13 +57,7 @@ def mypy_type_to_abstract_type( # This case happens if we have a list or set with multiple arguments like "list[str, int]" which is # not allowed. In this case mypy interprets the type as "list[Any]", but we want the real types # of the list arguments, which we cant get through the "unanalyzed_type" attribute - return { - "list": sds_types.ListType, - "set": sds_types.SetType - }[unanalyzed_type_name](types=[ - mypy_type_to_abstract_type(arg) - for arg in unanalyzed_type.args - ]) + return mypy_type_to_abstract_type(unanalyzed_type) # Iterable mypy types if isinstance(mypy_type, mp_types.TupleType): @@ -91,12 +87,15 @@ def mypy_type_to_abstract_type( elif isinstance(mypy_type, mp_types.LiteralType): return sds_types.LiteralType(literal=mypy_type.value) elif isinstance(mypy_type, mp_types.UnboundType): - if mypy_type.name == "list": - return sds_types.ListType(types=[ + if mypy_type.name in {"list", "set"}: + return { + "list": sds_types.ListType, + "set": sds_types.SetType, + }[mypy_type.name](types=[ mypy_type_to_abstract_type(arg) for arg in mypy_type.args ]) - # Todo Aliasing: Import auflösen, wir können wir keinen fullname (qname) bekommen + # Todo Aliasing: Import auflösen, wir können hier keinen fullname (qname) bekommen return sds_types.NamedType(name=mypy_type.name) # Builtins @@ -190,3 +189,24 @@ def has_correct_type_of_any(type_of_any: int) -> bool: mp_types.TypeOfAny.from_omitted_generics, mp_types.TypeOfAny.from_another_any, } + + +def mypy_expression_to_sds_type(expr: mp_nodes.Expression) -> sds_types.NamedType | sds_types.TupleType: + if isinstance(expr, mp_nodes.NameExpr): + if expr.name in {"False", "True"}: + return sds_types.NamedType(name="bool", qname="builtins.bool") + else: + return sds_types.NamedType(name=expr.name, qname=expr.fullname) + elif isinstance(expr, mp_nodes.IntExpr): + return sds_types.NamedType(name="int", qname="builtins.int") + elif isinstance(expr, mp_nodes.FloatExpr): + return sds_types.NamedType(name="float", qname="builtins.float") + elif isinstance(expr, mp_nodes.StrExpr): + return sds_types.NamedType(name="str", qname="builtins.str") + elif isinstance(expr, mp_nodes.TupleExpr): + return sds_types.TupleType(types=[ + mypy_expression_to_sds_type(item) + for item in expr.items + ]) + else: # pragma: no cover + raise TypeError("Unexpected expression type for return type.") diff --git a/src/safeds_stubgen/stubs_generator/_generate_stubs.py b/src/safeds_stubgen/stubs_generator/_generate_stubs.py index 1e0939f9..bb67c6d1 100644 --- a/src/safeds_stubgen/stubs_generator/_generate_stubs.py +++ b/src/safeds_stubgen/stubs_generator/_generate_stubs.py @@ -422,15 +422,14 @@ def _create_parameter_string( # Parameter type param_type = self._create_type_string(parameter_type_data) type_string = f": {param_type}" if param_type else "" - elif assigned_by == ParameterAssignment.POSITIONAL_VARARG: - # Todo Frage: Wenn *args und **kwargs keinen Typ haben und auf Any gesetzt werden trotzdem - # "param without type" msg erstellen? - type_string = ": List" - elif assigned_by == ParameterAssignment.NAMED_VARARG: - type_string = ": Map" else: self._current_todo_msgs.add("param without type") + if assigned_by == ParameterAssignment.POSITIONAL_VARARG: + type_string = ": List" + elif assigned_by == ParameterAssignment.NAMED_VARARG: + type_string = ": Map" + # Check if assigned_by is not illegal if assigned_by == ParameterAssignment.POSITION_ONLY and parameter.default_value is not None: self._current_todo_msgs.add("OPT_POS_ONLY") @@ -551,7 +550,6 @@ def _create_type_string(self, type_data: dict | None) -> str: case _: return name elif kind == "FinalType": - # Todo Frage: How are final types to be depicted? return self._create_type_string(type_data["type"]) elif kind == "CallableType": name_generator = self._callable_type_name_generator() diff --git a/tests/data/test_package/abstract_module.py b/tests/data/test_package/abstract_module.py index 92fa3af0..67f77afe 100644 --- a/tests/data/test_package/abstract_module.py +++ b/tests/data/test_package/abstract_module.py @@ -8,9 +8,8 @@ def __init__(self, param): @abstractmethod def abstract_method(self): ... - # Todo Frage: Bei list[str, int], also mehrere elemente, bekommen wir list[Any] @abstractmethod - def abstract_method_params(self, param_1: int, param_2=False) -> list[str]: ... + def abstract_method_params(self, param_1: int, param_2=False) -> list[str, int]: ... @staticmethod @abstractmethod diff --git a/tests/data/test_package/attribute_module.py b/tests/data/test_package/attribute_module.py index fbd616f9..7a271561 100644 --- a/tests/data/test_package/attribute_module.py +++ b/tests/data/test_package/attribute_module.py @@ -13,7 +13,13 @@ class AttributesClassB: _no_type_hint_private = 1 object_attr: AttributesClassA - callexpr_attr: AttributesClassA() + callexpr_attr_class: AttributesClassA() + + @staticmethod + def some_func() -> bool: + return True + + callexpr_attr_function: some_func() tuple_attr_1: tuple tuple_attr_2: tuple[str | int] @@ -24,6 +30,11 @@ class AttributesClassB: list_attr_3: list[str, AttributesClassA] list_attr_4: list[str, AttributesClassA | int] + set_attr_1: set + set_attr_2: set[str | AttributesClassA] + set_attr_3: set[str, AttributesClassA] + set_attr_4: set[str, AttributesClassA | int] + dict_attr_1: dict dict_attr_2: dict[str, int] dict_attr_3: dict[str | int, None | AttributesClassA] @@ -33,7 +44,6 @@ class AttributesClassB: flaot_attr: float int_or_bool_attr: int | bool str_attr_with_none_value: str = None - set_: set optional: Optional[int] final: Final[str] = "Value" diff --git a/tests/data/test_package/function_module.py b/tests/data/test_package/function_module.py index 41106244..d1cb1d72 100644 --- a/tests/data/test_package/function_module.py +++ b/tests/data/test_package/function_module.py @@ -108,7 +108,10 @@ def none_result() -> None: ... def obj_result() -> FunctionModuleClassA: ... -def callexr_result() -> FunctionModuleClassA(): ... +def callexr_result_class() -> FunctionModuleClassA(): ... + + +def callexr_result_function() -> float_result(): ... def tuple_results() -> tuple[str, FunctionModuleClassA]: ... diff --git a/tests/data/test_package/infer_types_module.py b/tests/data/test_package/infer_types_module.py index b3567425..771e91c4 100644 --- a/tests/data/test_package/infer_types_module.py +++ b/tests/data/test_package/infer_types_module.py @@ -8,7 +8,7 @@ class InferMyTypes: infer_bool = False infer_str = "String" infer_none = None - infer_obj = InferMe # Todo Frage: Ist "static attr inferObj: () -> a: InferMe" richtig? + infer_obj = InferMe def __init__(self, init_param=1): self.init_infer = 3 diff --git a/tests/safeds_stubgen/api_analyzer/test__get_api.py b/tests/safeds_stubgen/api_analyzer/test__get_api.py index 455c96f8..2f990c1f 100644 --- a/tests/safeds_stubgen/api_analyzer/test__get_api.py +++ b/tests/safeds_stubgen/api_analyzer/test__get_api.py @@ -469,7 +469,8 @@ def test_function_parameters( ("float_result", _function_module_name, "", "plaintext"), ("none_result", _function_module_name, "", "plaintext"), ("obj_result", _function_module_name, "", "plaintext"), - ("callexr_result", _function_module_name, "", "plaintext"), + ("callexr_result_class", _function_module_name, "", "plaintext"), + ("callexr_result_function", _function_module_name, "", "plaintext"), ("tuple_results", _function_module_name, "", "plaintext"), ("union_results", _function_module_name, "", "plaintext"), ("list_results", _function_module_name, "", "plaintext"), @@ -506,7 +507,8 @@ def test_function_parameters( "float_result", "none_result", "obj_result", - "callexr_result", + "callexr_result_class", + "callexr_result_function", "tuple_results", "union_results", "list_results", From b654b68ff97ae01f82816abbb207f24663bbf8f3 Mon Sep 17 00:00:00 2001 From: Arsam Date: Thu, 30 Nov 2023 15:18:25 +0100 Subject: [PATCH 067/109] Removed OptionalType class, since it is not in use. --- src/safeds_stubgen/api_analyzer/__init__.py | 2 -- src/safeds_stubgen/api_analyzer/_types.py | 22 +++---------------- .../stubs_generator/_generate_stubs.py | 4 +--- .../safeds_stubgen/api_analyzer/test_types.py | 18 --------------- 4 files changed, 4 insertions(+), 42 deletions(-) diff --git a/src/safeds_stubgen/api_analyzer/__init__.py b/src/safeds_stubgen/api_analyzer/__init__.py index 5f10161b..7f3a9997 100644 --- a/src/safeds_stubgen/api_analyzer/__init__.py +++ b/src/safeds_stubgen/api_analyzer/__init__.py @@ -28,7 +28,6 @@ ListType, LiteralType, NamedType, - OptionalType, SetType, TupleType, UnionType, @@ -56,7 +55,6 @@ "LiteralType", "Module", "NamedType", - "OptionalType", "package_root", "Parameter", "ParameterAssignment", diff --git a/src/safeds_stubgen/api_analyzer/_types.py b/src/safeds_stubgen/api_analyzer/_types.py index 739c2701..c5260aa4 100644 --- a/src/safeds_stubgen/api_analyzer/_types.py +++ b/src/safeds_stubgen/api_analyzer/_types.py @@ -22,8 +22,6 @@ def from_dict(cls, d: dict[str, Any]) -> AbstractType: return DictType.from_dict(d) case SetType.__name__: return SetType.from_dict(d) - case OptionalType.__name__: - return OptionalType.from_dict(d) case LiteralType.__name__: return LiteralType.from_dict(d) case FinalType.__name__: @@ -58,7 +56,9 @@ def from_string(cls, name: str, qname: str = "") -> NamedType: def to_dict(self) -> dict[str, str]: return {"kind": self.__class__.__name__, "name": self.name, "qname": self.qname} - def __eq__(self, other: NamedType) -> bool: + def __eq__(self, other: object) -> bool: + if not isinstance(other, NamedType): + return NotImplemented return self.name == other.name and self.qname == other.qname def __hash__(self) -> int: @@ -339,22 +339,6 @@ def __hash__(self) -> int: return hash(frozenset(self.types)) -# Todo Frage: Wird aktuell nicht benutzt, weil Mypy "Optional[int]" als "Union[int, None]" interpretiert. Remove? -@dataclass(frozen=True) -class OptionalType(AbstractType): - type: AbstractType - - @classmethod - def from_dict(cls, d: dict[str, Any]) -> OptionalType: - return OptionalType(AbstractType.from_dict(d["type"])) - - def to_dict(self) -> dict[str, Any]: - return {"kind": self.__class__.__name__, "type": self.type.to_dict()} - - def __hash__(self) -> int: - return hash(frozenset([self.type])) - - @dataclass(frozen=True) class LiteralType(AbstractType): literal: str | int | float | bool diff --git a/src/safeds_stubgen/stubs_generator/_generate_stubs.py b/src/safeds_stubgen/stubs_generator/_generate_stubs.py index bb67c6d1..dda61c3d 100644 --- a/src/safeds_stubgen/stubs_generator/_generate_stubs.py +++ b/src/safeds_stubgen/stubs_generator/_generate_stubs.py @@ -570,8 +570,6 @@ def _create_type_string(self, type_data: dict | None) -> str: return_type_string = f"{next(name_generator)}: {self._create_type_string(return_type)}" return f"({', '.join(params)}) -> {return_type_string}" - elif kind == "OptionalType": - return f"{self._create_type_string(type_data)}?" elif kind in {"SetType", "ListType"}: types = [ self._create_type_string(type_) @@ -635,7 +633,7 @@ def _create_type_string(self, type_data: dict | None) -> str: literal_type = f'"{literal_type}"' return f"literal<{literal_type}>" - raise ValueError(f"Unexpected type: {kind}") + raise ValueError(f"Unexpected type: {kind}") # pragma: no cover # ############################### Utilities ############################### # diff --git a/tests/safeds_stubgen/api_analyzer/test_types.py b/tests/safeds_stubgen/api_analyzer/test_types.py index ca773e02..5e4b9321 100644 --- a/tests/safeds_stubgen/api_analyzer/test_types.py +++ b/tests/safeds_stubgen/api_analyzer/test_types.py @@ -12,7 +12,6 @@ ListType, LiteralType, NamedType, - OptionalType, Parameter, ParameterAssignment, SetType, @@ -230,23 +229,6 @@ def test_set_type() -> None: assert hash(SetType([NamedType("a")])) != hash(SetType([NamedType("b")])) -def test_optional_type() -> None: - type_ = OptionalType(NamedType("some_type")) - type_dict = { - "kind": "OptionalType", - "type": {"kind": "NamedType", "name": "some_type", "qname": ""}, - } - - assert AbstractType.from_dict(type_dict) == type_ - assert OptionalType.from_dict(type_dict) == type_ - assert type_.to_dict() == type_dict - - assert OptionalType(NamedType("a")) == OptionalType(NamedType("a")) - assert hash(OptionalType(NamedType("a"))) == hash(OptionalType(NamedType("a"))) - assert OptionalType(NamedType("a")) != OptionalType(NamedType("b")) - assert hash(OptionalType(NamedType("a"))) != hash(OptionalType(NamedType("b"))) - - def test_literal_type() -> None: type_ = LiteralType("Literal_1") type_dict = { From 0a2b3cf5fdf108ec8c0613f76ce5ffd8f5286aa8 Mon Sep 17 00:00:00 2001 From: Arsam Date: Thu, 30 Nov 2023 15:39:27 +0100 Subject: [PATCH 068/109] Fixed a bug where "None" could not be set as the default value for parameters --- src/safeds_stubgen/api_analyzer/_api.py | 1 + .../api_analyzer/_ast_visitor.py | 11 ++++++-- .../stubs_generator/_generate_stubs.py | 6 ++++- tests/data/test_main/main_test_module.py | 3 +-- .../safeds_stubgen/api_analyzer/test_types.py | 1 + tests/safeds_stubgen/test_main.py | 25 +++++++++++++++++++ 6 files changed, 42 insertions(+), 5 deletions(-) diff --git a/src/safeds_stubgen/api_analyzer/_api.py b/src/safeds_stubgen/api_analyzer/_api.py index d7ec7b4a..77eefa51 100644 --- a/src/safeds_stubgen/api_analyzer/_api.py +++ b/src/safeds_stubgen/api_analyzer/_api.py @@ -261,6 +261,7 @@ class Parameter: name: str is_optional: bool default_value: str | bool | int | float | None + default_is_none: bool assigned_by: ParameterAssignment docstring: ParameterDocstring type: AbstractType | None diff --git a/src/safeds_stubgen/api_analyzer/_ast_visitor.py b/src/safeds_stubgen/api_analyzer/_ast_visitor.py index a3fdd605..494fa2c8 100644 --- a/src/safeds_stubgen/api_analyzer/_ast_visitor.py +++ b/src/safeds_stubgen/api_analyzer/_ast_visitor.py @@ -679,7 +679,7 @@ def _get_default_parameter_value_and_type( raise ValueError("No value found for parameter") if type(value) in {str, bool, int, float, NoneType}: - default_value = value + default_value = NoneType if value is None else value # Infer the type, if no type hint was found if infer_arg_type: @@ -723,12 +723,18 @@ def _parse_parameter_data(self, node: mp_nodes.FuncDef, function_id: str) -> lis # Get default value and infer type information initializer = argument.initializer default_value = None + default_is_none = False if initializer is not None: infer_arg_type = arg_type is None default_value, inferred_arg_type = self._get_default_parameter_value_and_type( initializer=initializer, infer_arg_type=infer_arg_type, ) + + if default_value == NoneType: + default_is_none = True + default_value = None + if infer_arg_type: arg_type = inferred_arg_type is_type_inferred = True @@ -747,8 +753,9 @@ def _parse_parameter_data(self, node: mp_nodes.FuncDef, function_id: str) -> lis Parameter( id=f"{function_id}/{arg_name}", name=arg_name, - is_optional=default_value is not None, + is_optional=default_value is not None or default_is_none, default_value=default_value, + default_is_none=default_is_none, assigned_by=arg_kind, docstring=docstring, type=arg_type, diff --git a/src/safeds_stubgen/stubs_generator/_generate_stubs.py b/src/safeds_stubgen/stubs_generator/_generate_stubs.py index dda61c3d..ab81179b 100644 --- a/src/safeds_stubgen/stubs_generator/_generate_stubs.py +++ b/src/safeds_stubgen/stubs_generator/_generate_stubs.py @@ -392,10 +392,12 @@ def _create_parameter_string( type_string = "" param_value = "" - # Default value + # Parameter type if parameter.type is not None: param_default_value = parameter.default_value parameter_type_data = parameter.type.to_dict() + + # Default value if param_default_value is not None: if isinstance(param_default_value, str): if parameter_type_data["kind"] == "NamedType" and parameter_type_data["name"] != "str": @@ -413,6 +415,8 @@ def _create_parameter_string( else: default_value = param_default_value param_value = f" = {default_value}" + elif parameter.default_is_none: + param_value = " = null" # Mypy assignes *args parameters the tuple type, which is not supported in Safe-DS. Therefor we # overwrite it and set the type to a list. diff --git a/tests/data/test_main/main_test_module.py b/tests/data/test_main/main_test_module.py index 214e6864..79745306 100644 --- a/tests/data/test_main/main_test_module.py +++ b/tests/data/test_main/main_test_module.py @@ -15,9 +15,8 @@ ac_alias = AnotherClass -# Todo Frage: Ist bei den Stubs param_2 optional? Wird None als default value unterstützt? # noinspection PyUnusedLocal -def global_func(param_1: str = "first param", param_2: ac_alias | None = None) -> ac_alias: +def global_func(main_test_param_1: str = "first param", main_test_param_2: ac_alias | None = None) -> ac_alias: """Docstring 1. Docstring 2. diff --git a/tests/safeds_stubgen/api_analyzer/test_types.py b/tests/safeds_stubgen/api_analyzer/test_types.py index 5e4b9321..b6af69e6 100644 --- a/tests/safeds_stubgen/api_analyzer/test_types.py +++ b/tests/safeds_stubgen/api_analyzer/test_types.py @@ -27,6 +27,7 @@ def test_correct_hash() -> None: name="test_parameter_for_hashing", is_optional=True, default_value="test_str", + default_is_none=False, assigned_by=ParameterAssignment.POSITION_OR_NAME, docstring=ParameterDocstring("'hashvalue'", "r", "r"), type=NamedType("str"), diff --git a/tests/safeds_stubgen/test_main.py b/tests/safeds_stubgen/test_main.py index 15495174..0550186e 100644 --- a/tests/safeds_stubgen/test_main.py +++ b/tests/safeds_stubgen/test_main.py @@ -15,6 +15,31 @@ def test_main(snapshot: SnapshotAssertion) -> None: + # Overwrite system arguments + sys.argv = [ + str(_main_dir), + "-v", + "-p", + str(_test_package_name), + "-s", + str(_test_package_dir), + "-o", + str(_out_dir), + "-tr", + "--docstyle", + "plaintext", + "-ci", + ] + + main() + + with Path.open(_out_file_dir) as f: + json_data = json.load(f) + + assert json_data == snapshot + + +def test_main_dont_conver_identifiers(snapshot: SnapshotAssertion) -> None: # Overwrite system arguments sys.argv = [ str(_main_dir), From 509fb3083ae82421f90549d080829c8d07eb6785 Mon Sep 17 00:00:00 2001 From: Arsam Date: Thu, 30 Nov 2023 15:46:57 +0100 Subject: [PATCH 069/109] Updated snapshot tests --- .../__snapshots__/test_main.ambr | 850 +++++++++++++++++- .../__snapshots__/test__get_api.ambr | 162 +++- .../__snapshots__/test_generate_stubs.ambr | 39 +- tests/safeds_stubgen/test_main.py | 24 - 4 files changed, 1022 insertions(+), 53 deletions(-) diff --git a/tests/safeds_stubgen/__snapshots__/test_main.ambr b/tests/safeds_stubgen/__snapshots__/test_main.ambr index 2375edc6..34417e7e 100644 --- a/tests/safeds_stubgen/__snapshots__/test_main.ambr +++ b/tests/safeds_stubgen/__snapshots__/test_main.ambr @@ -487,8 +487,8 @@ 'is_static': False, 'name': 'global_func', 'parameters': list([ - 'test_main/main_test_module/global_func/param_1', - 'test_main/main_test_module/global_func/param_2', + 'test_main/main_test_module/global_func/main_test_param_1', + 'test_main/main_test_module/global_func/main_test_param_2', ]), 'reexported_by': list([ ]), @@ -706,15 +706,757 @@ 'description': '', 'type': '', }), - 'id': 'test_main/main_test_module/global_func/param_1', + 'id': 'test_main/main_test_module/global_func/main_test_param_1', 'is_optional': True, 'is_type_inferred': False, + 'name': 'main_test_param_1', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'str', + 'qname': 'builtins.str', + }), + }), + dict({ + 'assigned_by': 'POSITION_OR_NAME', + 'default_value': None, + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_main/main_test_module/global_func/main_test_param_2', + 'is_optional': True, + 'is_type_inferred': False, + 'name': 'main_test_param_2', + 'type': dict({ + 'kind': 'UnionType', + 'types': list([ + dict({ + 'kind': 'NamedType', + 'name': 'AnotherClass', + 'qname': 'tests.data.test_main.another_path.another_module.AnotherClass', + }), + dict({ + 'kind': 'NamedType', + 'name': 'None', + 'qname': 'builtins.None', + }), + ]), + }), + }), + ]), + 'results': list([ + dict({ + 'docstring': dict({ + 'description': '', + 'type': '', + }), + 'id': 'test_main/main_test_module/ModuleClass/NestedClass/nested_class_function/result_1', + 'is_type_inferred': False, + 'name': 'result_1', + 'type': dict({ + 'kind': 'SetType', + 'types': list([ + dict({ + 'kind': 'UnionType', + 'types': list([ + dict({ + 'kind': 'NamedType', + 'name': 'bool', + 'qname': 'builtins.bool', + }), + dict({ + 'kind': 'NamedType', + 'name': 'None', + 'qname': 'builtins.None', + }), + ]), + }), + ]), + }), + }), + dict({ + 'docstring': dict({ + 'description': '', + 'type': '', + }), + 'id': 'test_main/main_test_module/ModuleClass/_some_function/result_1', + 'is_type_inferred': False, + 'name': 'result_1', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'AnotherClass', + 'qname': 'tests.data.test_main.another_path.another_module.AnotherClass', + }), + }), + dict({ + 'docstring': dict({ + 'description': '', + 'type': '', + }), + 'id': 'test_main/main_test_module/_private_global_func/result_1', + 'is_type_inferred': False, + 'name': 'result_1', + 'type': dict({ + 'kind': 'UnionType', + 'types': list([ + dict({ + 'kind': 'NamedType', + 'name': 'AnotherClass', + 'qname': 'tests.data.test_main.another_path.another_module.AnotherClass', + }), + dict({ + 'kind': 'NamedType', + 'name': 'AnotherClass', + 'qname': 'tests.data.test_main.another_path.another_module.AnotherClass', + }), + dict({ + 'kind': 'NamedType', + 'name': 'AnotherClass', + 'qname': 'tests.data.test_main.another_path.another_module.AnotherClass', + }), + ]), + }), + }), + dict({ + 'docstring': dict({ + 'description': '', + 'type': '', + }), + 'id': 'test_main/main_test_module/global_func/result_1', + 'is_type_inferred': False, + 'name': 'result_1', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'AnotherClass', + 'qname': 'tests.data.test_main.another_path.another_module.AnotherClass', + }), + }), + ]), + 'schemaVersion': 1, + 'version': '', + }) +# --- +# name: test_main_dont_conver_identifiers + dict({ + 'attributes': list([ + dict({ + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_main/main_test_module/ModuleClass/_init_attr_private', + 'is_public': False, + 'is_static': False, + 'is_type_inferred': False, + 'name': '_init_attr_private', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'float', + 'qname': 'builtins.float', + }), + }), + dict({ + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_main/main_test_module/ModuleClass/attr_1', + 'is_public': True, + 'is_static': True, + 'is_type_inferred': False, + 'name': 'attr_1', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'int', + 'qname': 'builtins.int', + }), + }), + dict({ + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_main/main_test_module/ModuleClass/init_attr', + 'is_public': True, + 'is_static': False, + 'is_type_inferred': False, + 'name': 'init_attr', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'bool', + 'qname': 'builtins.bool', + }), + }), + dict({ + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_main/main_test_module/_PrivateClass/NestedPrivateClass/nested_class_attr', + 'is_public': False, + 'is_static': True, + 'is_type_inferred': True, + 'name': 'nested_class_attr', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'int', + 'qname': 'builtins.int', + }), + }), + dict({ + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_main/main_test_module/_PrivateClass/public_attr_in_private_class', + 'is_public': False, + 'is_static': True, + 'is_type_inferred': True, + 'name': 'public_attr_in_private_class', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'int', + 'qname': 'builtins.int', + }), + }), + dict({ + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_main/main_test_module/_PrivateClass/public_init_attr_in_private_class', + 'is_public': False, + 'is_static': False, + 'is_type_inferred': False, + 'name': 'public_init_attr_in_private_class', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'int', + 'qname': 'builtins.int', + }), + }), + ]), + 'classes': list([ + dict({ + 'attributes': list([ + ]), + 'classes': list([ + ]), + 'constructor': None, + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_main/another_path/another_module/AnotherClass', + 'is_public': True, + 'methods': list([ + ]), + 'name': 'AnotherClass', + 'reexported_by': list([ + ]), + 'superclasses': list([ + ]), + 'variances': list([ + ]), + }), + dict({ + 'attributes': list([ + 'test_main/main_test_module/ModuleClass/attr_1', + 'test_main/main_test_module/ModuleClass/init_attr', + 'test_main/main_test_module/ModuleClass/_init_attr_private', + ]), + 'classes': list([ + 'test_main/main_test_module/ModuleClass/NestedClass', + ]), + 'constructor': dict({ + 'docstring': dict({ + 'description': ''' + Summary of the init description. + + Full init description. + ''', + 'full_docstring': ''' + Summary of the init description. + + Full init description. + ''', + }), + 'id': 'test_main/main_test_module/ModuleClass/__init__', + 'is_class_method': False, + 'is_property': False, + 'is_public': True, + 'is_static': False, + 'name': '__init__', + 'parameters': list([ + 'test_main/main_test_module/ModuleClass/__init__/self', + 'test_main/main_test_module/ModuleClass/__init__/init_param_1', + ]), + 'reexported_by': list([ + ]), + 'results': list([ + ]), + }), + 'docstring': dict({ + 'description': ''' + Summary of the description. + + Full description + ''', + 'full_docstring': ''' + Summary of the description. + + Full description + ''', + }), + 'id': 'test_main/main_test_module/ModuleClass', + 'is_public': True, + 'methods': list([ + 'test_main/main_test_module/ModuleClass/_some_function', + ]), + 'name': 'ModuleClass', + 'reexported_by': list([ + ]), + 'superclasses': list([ + 'tests.data.test_main.main_test_module.AcDoubleAlias', + ]), + 'variances': list([ + ]), + }), + dict({ + 'attributes': list([ + ]), + 'classes': list([ + ]), + 'constructor': None, + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_main/main_test_module/ModuleClass/NestedClass', + 'is_public': True, + 'methods': list([ + 'test_main/main_test_module/ModuleClass/NestedClass/nested_class_function', + ]), + 'name': 'NestedClass', + 'reexported_by': list([ + ]), + 'superclasses': list([ + 'tests.data.test_main.another_path.another_module.AnotherClass', + ]), + 'variances': list([ + ]), + }), + dict({ + 'attributes': list([ + 'test_main/main_test_module/_PrivateClass/public_attr_in_private_class', + 'test_main/main_test_module/_PrivateClass/public_init_attr_in_private_class', + ]), + 'classes': list([ + 'test_main/main_test_module/_PrivateClass/NestedPrivateClass', + ]), + 'constructor': dict({ + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_main/main_test_module/_PrivateClass/__init__', + 'is_class_method': False, + 'is_property': False, + 'is_public': False, + 'is_static': False, + 'name': '__init__', + 'parameters': list([ + 'test_main/main_test_module/_PrivateClass/__init__/self', + ]), + 'reexported_by': list([ + ]), + 'results': list([ + ]), + }), + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_main/main_test_module/_PrivateClass', + 'is_public': False, + 'methods': list([ + 'test_main/main_test_module/_PrivateClass/public_func_in_private_class', + ]), + 'name': '_PrivateClass', + 'reexported_by': list([ + ]), + 'superclasses': list([ + ]), + 'variances': list([ + ]), + }), + dict({ + 'attributes': list([ + 'test_main/main_test_module/_PrivateClass/NestedPrivateClass/nested_class_attr', + ]), + 'classes': list([ + 'test_main/main_test_module/_PrivateClass/NestedPrivateClass/NestedNestedPrivateClass', + ]), + 'constructor': None, + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_main/main_test_module/_PrivateClass/NestedPrivateClass', + 'is_public': True, + 'methods': list([ + 'test_main/main_test_module/_PrivateClass/NestedPrivateClass/static_nested_private_class_function', + ]), + 'name': 'NestedPrivateClass', + 'reexported_by': list([ + ]), + 'superclasses': list([ + ]), + 'variances': list([ + ]), + }), + dict({ + 'attributes': list([ + ]), + 'classes': list([ + ]), + 'constructor': None, + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_main/main_test_module/_PrivateClass/NestedPrivateClass/NestedNestedPrivateClass', + 'is_public': True, + 'methods': list([ + ]), + 'name': 'NestedNestedPrivateClass', + 'reexported_by': list([ + ]), + 'superclasses': list([ + ]), + 'variances': list([ + ]), + }), + ]), + 'distribution': '', + 'enum_instances': list([ + ]), + 'enums': list([ + ]), + 'functions': list([ + dict({ + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_main/main_test_module/ModuleClass/NestedClass/nested_class_function', + 'is_class_method': False, + 'is_property': False, + 'is_public': True, + 'is_static': False, + 'name': 'nested_class_function', + 'parameters': list([ + 'test_main/main_test_module/ModuleClass/NestedClass/nested_class_function/self', + 'test_main/main_test_module/ModuleClass/NestedClass/nested_class_function/param_1', + ]), + 'reexported_by': list([ + ]), + 'results': list([ + 'test_main/main_test_module/ModuleClass/NestedClass/nested_class_function/result_1', + ]), + }), + dict({ + 'docstring': dict({ + 'description': ''' + Summary of the init description. + + Full init description. + ''', + 'full_docstring': ''' + Summary of the init description. + + Full init description. + ''', + }), + 'id': 'test_main/main_test_module/ModuleClass/__init__', + 'is_class_method': False, + 'is_property': False, + 'is_public': True, + 'is_static': False, + 'name': '__init__', + 'parameters': list([ + 'test_main/main_test_module/ModuleClass/__init__/self', + 'test_main/main_test_module/ModuleClass/__init__/init_param_1', + ]), + 'reexported_by': list([ + ]), + 'results': list([ + ]), + }), + dict({ + 'docstring': dict({ + 'description': ''' + Function Docstring. + + param_2: bool. + ''', + 'full_docstring': ''' + Function Docstring. + + param_2: bool. + ''', + }), + 'id': 'test_main/main_test_module/ModuleClass/_some_function', + 'is_class_method': False, + 'is_property': False, + 'is_public': False, + 'is_static': False, + 'name': '_some_function', + 'parameters': list([ + 'test_main/main_test_module/ModuleClass/_some_function/self', + 'test_main/main_test_module/ModuleClass/_some_function/param_1', + 'test_main/main_test_module/ModuleClass/_some_function/param_2', + ]), + 'reexported_by': list([ + ]), + 'results': list([ + 'test_main/main_test_module/ModuleClass/_some_function/result_1', + ]), + }), + dict({ + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_main/main_test_module/_PrivateClass/NestedPrivateClass/static_nested_private_class_function', + 'is_class_method': False, + 'is_property': False, + 'is_public': False, + 'is_static': True, + 'name': 'static_nested_private_class_function', + 'parameters': list([ + ]), + 'reexported_by': list([ + ]), + 'results': list([ + ]), + }), + dict({ + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_main/main_test_module/_PrivateClass/__init__', + 'is_class_method': False, + 'is_property': False, + 'is_public': False, + 'is_static': False, + 'name': '__init__', + 'parameters': list([ + 'test_main/main_test_module/_PrivateClass/__init__/self', + ]), + 'reexported_by': list([ + ]), + 'results': list([ + ]), + }), + dict({ + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_main/main_test_module/_PrivateClass/public_func_in_private_class', + 'is_class_method': False, + 'is_property': False, + 'is_public': False, + 'is_static': False, + 'name': 'public_func_in_private_class', + 'parameters': list([ + 'test_main/main_test_module/_PrivateClass/public_func_in_private_class/self', + ]), + 'reexported_by': list([ + ]), + 'results': list([ + ]), + }), + dict({ + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_main/main_test_module/_private_global_func', + 'is_class_method': False, + 'is_property': False, + 'is_public': False, + 'is_static': False, + 'name': '_private_global_func', + 'parameters': list([ + ]), + 'reexported_by': list([ + ]), + 'results': list([ + 'test_main/main_test_module/_private_global_func/result_1', + ]), + }), + dict({ + 'docstring': dict({ + 'description': ''' + Docstring 1. + + Docstring 2. + ''', + 'full_docstring': ''' + Docstring 1. + + Docstring 2. + ''', + }), + 'id': 'test_main/main_test_module/global_func', + 'is_class_method': False, + 'is_property': False, + 'is_public': True, + 'is_static': False, + 'name': 'global_func', + 'parameters': list([ + 'test_main/main_test_module/global_func/main_test_param_1', + 'test_main/main_test_module/global_func/main_test_param_2', + ]), + 'reexported_by': list([ + ]), + 'results': list([ + 'test_main/main_test_module/global_func/result_1', + ]), + }), + ]), + 'modules': list([ + dict({ + 'classes': list([ + 'test_main/another_path/another_module/AnotherClass', + ]), + 'docstring': ''' + Another Module Docstring. + + Full Docstring Description + + ''', + 'enums': list([ + ]), + 'functions': list([ + ]), + 'id': 'test_main/another_path/another_module', + 'name': 'another_module', + 'qualified_imports': list([ + ]), + 'wildcard_imports': list([ + ]), + }), + dict({ + 'classes': list([ + 'test_main/main_test_module/ModuleClass', + 'test_main/main_test_module/_PrivateClass', + ]), + 'docstring': 'Docstring of the some_class.py module.', + 'enums': list([ + ]), + 'functions': list([ + 'test_main/main_test_module/global_func', + 'test_main/main_test_module/_private_global_func', + ]), + 'id': 'test_main/main_test_module', + 'name': 'main_test_module', + 'qualified_imports': list([ + dict({ + 'alias': 'mathematics', + 'qualified_name': 'math', + }), + dict({ + 'alias': None, + 'qualified_name': 'mypy', + }), + dict({ + 'alias': None, + 'qualified_name': 'another_path.another_module.AnotherClass', + }), + dict({ + 'alias': '_AcImportAlias', + 'qualified_name': 'another_path.another_module.AnotherClass', + }), + ]), + 'wildcard_imports': list([ + dict({ + 'module_name': 'docstring_parser', + }), + ]), + }), + ]), + 'package': 'test_main', + 'parameters': list([ + dict({ + 'assigned_by': 'POSITION_OR_NAME', + 'default_value': None, + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_main/main_test_module/ModuleClass/NestedClass/nested_class_function/param_1', + 'is_optional': False, + 'is_type_inferred': False, 'name': 'param_1', 'type': dict({ 'kind': 'NamedType', - 'name': 'str', - 'qname': 'builtins.str', + 'name': 'int', + 'qname': 'builtins.int', + }), + }), + dict({ + 'assigned_by': 'IMPLICIT', + 'default_value': None, + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_main/main_test_module/ModuleClass/NestedClass/nested_class_function/self', + 'is_optional': False, + 'is_type_inferred': False, + 'name': 'self', + 'type': None, + }), + dict({ + 'assigned_by': 'POSITION_OR_NAME', + 'default_value': None, + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', }), + 'id': 'test_main/main_test_module/ModuleClass/__init__/init_param_1', + 'is_optional': False, + 'is_type_inferred': False, + 'name': 'init_param_1', + 'type': None, + }), + dict({ + 'assigned_by': 'IMPLICIT', + 'default_value': None, + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_main/main_test_module/ModuleClass/__init__/self', + 'is_optional': False, + 'is_type_inferred': False, + 'name': 'self', + 'type': None, }), dict({ 'assigned_by': 'POSITION_OR_NAME', @@ -724,10 +1466,106 @@ 'description': '', 'type': '', }), - 'id': 'test_main/main_test_module/global_func/param_2', + 'id': 'test_main/main_test_module/ModuleClass/_some_function/param_1', 'is_optional': False, 'is_type_inferred': False, + 'name': 'param_1', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'AnotherClass', + 'qname': 'tests.data.test_main.another_path.another_module.AnotherClass', + }), + }), + dict({ + 'assigned_by': 'POSITION_OR_NAME', + 'default_value': False, + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_main/main_test_module/ModuleClass/_some_function/param_2', + 'is_optional': True, + 'is_type_inferred': False, 'name': 'param_2', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'bool', + 'qname': 'builtins.bool', + }), + }), + dict({ + 'assigned_by': 'IMPLICIT', + 'default_value': None, + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_main/main_test_module/ModuleClass/_some_function/self', + 'is_optional': False, + 'is_type_inferred': False, + 'name': 'self', + 'type': None, + }), + dict({ + 'assigned_by': 'IMPLICIT', + 'default_value': None, + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_main/main_test_module/_PrivateClass/__init__/self', + 'is_optional': False, + 'is_type_inferred': False, + 'name': 'self', + 'type': None, + }), + dict({ + 'assigned_by': 'IMPLICIT', + 'default_value': None, + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_main/main_test_module/_PrivateClass/public_func_in_private_class/self', + 'is_optional': False, + 'is_type_inferred': False, + 'name': 'self', + 'type': None, + }), + dict({ + 'assigned_by': 'POSITION_OR_NAME', + 'default_value': 'first param', + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_main/main_test_module/global_func/main_test_param_1', + 'is_optional': True, + 'is_type_inferred': False, + 'name': 'main_test_param_1', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'str', + 'qname': 'builtins.str', + }), + }), + dict({ + 'assigned_by': 'POSITION_OR_NAME', + 'default_value': None, + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_main/main_test_module/global_func/main_test_param_2', + 'is_optional': True, + 'is_type_inferred': False, + 'name': 'main_test_param_2', 'type': dict({ 'kind': 'UnionType', 'types': list([ diff --git a/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr b/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr index d580f8d5..98541edb 100644 --- a/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr +++ b/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr @@ -97,11 +97,24 @@ 'description': '', 'type': '', }), - 'id': 'test_package/attribute_module/AttributesClassB/callexpr_attr', + 'id': 'test_package/attribute_module/AttributesClassB/callexpr_attr_class', 'is_public': True, 'is_static': True, 'is_type_inferred': False, - 'name': 'callexpr_attr', + 'name': 'callexpr_attr_class', + 'type': None, + }), + dict({ + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_package/attribute_module/AttributesClassB/callexpr_attr_function', + 'is_public': True, + 'is_static': True, + 'is_type_inferred': False, + 'name': 'callexpr_attr_function', 'type': None, }), dict({ @@ -660,11 +673,11 @@ 'description': '', 'type': '', }), - 'id': 'test_package/attribute_module/AttributesClassB/set_', + 'id': 'test_package/attribute_module/AttributesClassB/set_attr_1', 'is_public': True, 'is_static': True, 'is_type_inferred': False, - 'name': 'set_', + 'name': 'set_attr_1', 'type': dict({ 'kind': 'SetType', 'types': list([ @@ -676,6 +689,102 @@ ]), }), }), + dict({ + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_package/attribute_module/AttributesClassB/set_attr_2', + 'is_public': True, + 'is_static': True, + 'is_type_inferred': False, + 'name': 'set_attr_2', + 'type': dict({ + 'kind': 'SetType', + 'types': list([ + dict({ + 'kind': 'UnionType', + 'types': list([ + dict({ + 'kind': 'NamedType', + 'name': 'str', + 'qname': 'builtins.str', + }), + dict({ + 'kind': 'NamedType', + 'name': 'AttributesClassA', + 'qname': 'tests.data.test_package.attribute_module.AttributesClassA', + }), + ]), + }), + ]), + }), + }), + dict({ + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_package/attribute_module/AttributesClassB/set_attr_3', + 'is_public': True, + 'is_static': True, + 'is_type_inferred': False, + 'name': 'set_attr_3', + 'type': dict({ + 'kind': 'SetType', + 'types': list([ + dict({ + 'kind': 'NamedType', + 'name': 'str', + 'qname': '', + }), + dict({ + 'kind': 'NamedType', + 'name': 'AttributesClassA', + 'qname': '', + }), + ]), + }), + }), + dict({ + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'test_package/attribute_module/AttributesClassB/set_attr_4', + 'is_public': True, + 'is_static': True, + 'is_type_inferred': False, + 'name': 'set_attr_4', + 'type': dict({ + 'kind': 'SetType', + 'types': list([ + dict({ + 'kind': 'NamedType', + 'name': 'str', + 'qname': '', + }), + dict({ + 'kind': 'UnionType', + 'types': list([ + dict({ + 'kind': 'NamedType', + 'name': 'AttributesClassA', + 'qname': '', + }), + dict({ + 'kind': 'NamedType', + 'name': 'int', + 'qname': '', + }), + ]), + }), + ]), + }), + }), dict({ 'docstring': dict({ 'default_value': '', @@ -3247,21 +3356,17 @@ }), dict({ 'assigned_by': 'NAME_ONLY', - 'default_value': 'FunctionModuleClassA()', + 'default_value': None, 'docstring': dict({ 'default_value': '', 'description': '', 'type': '', }), 'id': 'test_package/function_module/param_position/d', - 'is_optional': True, + 'is_optional': False, 'is_type_inferred': True, 'name': 'd', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'FunctionModuleClassA', - 'qname': 'tests.data.test_package.function_module.FunctionModuleClassA', - }), + 'type': None, }), dict({ 'assigned_by': 'NAME_ONLY', @@ -4055,7 +4160,12 @@ dict({ 'kind': 'NamedType', 'name': 'str', - 'qname': 'builtins.str', + 'qname': '', + }), + dict({ + 'kind': 'NamedType', + 'name': 'int', + 'qname': '', }), ]), }), @@ -4163,7 +4273,11 @@ }), ]) # --- -# name: test_function_results[callexr_result] +# name: test_function_results[callexr_result_class] + list([ + ]) +# --- +# name: test_function_results[callexr_result_function] list([ ]) # --- @@ -5050,12 +5164,30 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/function_module/callexr_result', + 'id': 'test_package/function_module/callexr_result_class', + 'is_class_method': False, + 'is_property': False, + 'is_public': True, + 'is_static': False, + 'name': 'callexr_result_class', + 'parameters': list([ + ]), + 'reexported_by': list([ + ]), + 'results': list([ + ]), + }), + dict({ + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'test_package/function_module/callexr_result_function', 'is_class_method': False, 'is_property': False, 'is_public': True, 'is_static': False, - 'name': 'callexr_result', + 'name': 'callexr_result_function', 'parameters': list([ ]), 'reexported_by': list([ diff --git a/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr b/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr index 7dd379cd..d2562dd9 100644 --- a/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr +++ b/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr @@ -15,12 +15,13 @@ @PythonName("abstract_method") fun abstractMethod() + // TODO List type has to many type arguments. @Pure @PythonName("abstract_method_params") fun abstractMethodParams( @PythonName("param_1") param1: Int, @PythonName("param_2") param2: Boolean = false - ) -> result1: List + ) -> result1: List // TODO Result type information missing. @Pure @@ -55,8 +56,11 @@ @PythonName("object_attr") static attr objectAttr: AttributesClassA // TODO Attribute has no type information. - @PythonName("callexpr_attr") - static attr callexprAttr + @PythonName("callexpr_attr_class") + static attr callexprAttrClass + // TODO Attribute has no type information. + @PythonName("callexpr_attr_function") + static attr callexprAttrFunction // TODO Safe-DS does not support tuple types. @PythonName("tuple_attr_1") static attr tupleAttr1: Tuple @@ -76,6 +80,16 @@ // TODO List type has to many type arguments. @PythonName("list_attr_4") static attr listAttr4: List> + @PythonName("set_attr_1") + static attr setAttr1: Set + @PythonName("set_attr_2") + static attr setAttr2: Set> + // TODO Set type has to many type arguments. + @PythonName("set_attr_3") + static attr setAttr3: Set + // TODO Set type has to many type arguments. + @PythonName("set_attr_4") + static attr setAttr4: Set> @PythonName("dict_attr_1") static attr dictAttr1: Map @PythonName("dict_attr_2") @@ -92,8 +106,6 @@ static attr intOrBoolAttr: union @PythonName("str_attr_with_none_value") static attr strAttrWithNoneValue: String - @PythonName("set_") - static attr set: Set static attr optional: Int? static attr final: String static attr finals: union @@ -114,6 +126,10 @@ static attr multiAttr8: String @PythonName("init_attr") attr initAttr: Boolean + + @Pure + @PythonName("some_func") + static fun someFunc() -> result1: Boolean } ''' @@ -260,6 +276,7 @@ ) // TODO Result type information missing. + // TODO Safe-DS does not support required but name only parameter assignments. // TODO Some parameter have no type information. @Pure @PythonName("param_position") @@ -268,7 +285,7 @@ a, b: Boolean, c: FunctionModuleClassA = FunctionModuleClassA, - d: FunctionModuleClassA = FunctionModuleClassA(), + d, e: Int = 1 ) @@ -294,6 +311,7 @@ // TODO Result type information missing. // TODO Safe-DS does not support variadic parameters. + // TODO Some parameter have no type information. @Pure fun arg( args: List, @@ -336,8 +354,13 @@ // TODO Result type information missing. @Pure - @PythonName("callexr_result") - fun callexrResult() + @PythonName("callexr_result_class") + fun callexrResultClass() + + // TODO Result type information missing. + @Pure + @PythonName("callexr_result_function") + fun callexrResultFunction() @Pure @PythonName("tuple_results") diff --git a/tests/safeds_stubgen/test_main.py b/tests/safeds_stubgen/test_main.py index 0550186e..2079e46f 100644 --- a/tests/safeds_stubgen/test_main.py +++ b/tests/safeds_stubgen/test_main.py @@ -39,30 +39,6 @@ def test_main(snapshot: SnapshotAssertion) -> None: assert json_data == snapshot -def test_main_dont_conver_identifiers(snapshot: SnapshotAssertion) -> None: - # Overwrite system arguments - sys.argv = [ - str(_main_dir), - "-v", - "-p", - str(_test_package_name), - "-s", - str(_test_package_dir), - "-o", - str(_out_dir), - "-tr", - "--docstyle", - "plaintext", - ] - - main() - - with Path.open(_out_file_dir) as f: - json_data = json.load(f) - - assert json_data == snapshot - - def test_main_empty() -> None: # Overwrite system arguments sys.argv = [ From 7e7eb9402b8c68254b4cf47cf16c82803ce2d85c Mon Sep 17 00:00:00 2001 From: Arsam Date: Thu, 30 Nov 2023 15:48:05 +0100 Subject: [PATCH 070/109] Updated snapshot tests --- .../__snapshots__/test_main.ambr | 838 ------------------ 1 file changed, 838 deletions(-) diff --git a/tests/safeds_stubgen/__snapshots__/test_main.ambr b/tests/safeds_stubgen/__snapshots__/test_main.ambr index 34417e7e..ff076cee 100644 --- a/tests/safeds_stubgen/__snapshots__/test_main.ambr +++ b/tests/safeds_stubgen/__snapshots__/test_main.ambr @@ -837,841 +837,3 @@ 'version': '', }) # --- -# name: test_main_dont_conver_identifiers - dict({ - 'attributes': list([ - dict({ - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_main/main_test_module/ModuleClass/_init_attr_private', - 'is_public': False, - 'is_static': False, - 'is_type_inferred': False, - 'name': '_init_attr_private', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'float', - 'qname': 'builtins.float', - }), - }), - dict({ - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_main/main_test_module/ModuleClass/attr_1', - 'is_public': True, - 'is_static': True, - 'is_type_inferred': False, - 'name': 'attr_1', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'int', - 'qname': 'builtins.int', - }), - }), - dict({ - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_main/main_test_module/ModuleClass/init_attr', - 'is_public': True, - 'is_static': False, - 'is_type_inferred': False, - 'name': 'init_attr', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'bool', - 'qname': 'builtins.bool', - }), - }), - dict({ - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_main/main_test_module/_PrivateClass/NestedPrivateClass/nested_class_attr', - 'is_public': False, - 'is_static': True, - 'is_type_inferred': True, - 'name': 'nested_class_attr', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'int', - 'qname': 'builtins.int', - }), - }), - dict({ - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_main/main_test_module/_PrivateClass/public_attr_in_private_class', - 'is_public': False, - 'is_static': True, - 'is_type_inferred': True, - 'name': 'public_attr_in_private_class', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'int', - 'qname': 'builtins.int', - }), - }), - dict({ - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_main/main_test_module/_PrivateClass/public_init_attr_in_private_class', - 'is_public': False, - 'is_static': False, - 'is_type_inferred': False, - 'name': 'public_init_attr_in_private_class', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'int', - 'qname': 'builtins.int', - }), - }), - ]), - 'classes': list([ - dict({ - 'attributes': list([ - ]), - 'classes': list([ - ]), - 'constructor': None, - 'docstring': dict({ - 'description': '', - 'full_docstring': '', - }), - 'id': 'test_main/another_path/another_module/AnotherClass', - 'is_public': True, - 'methods': list([ - ]), - 'name': 'AnotherClass', - 'reexported_by': list([ - ]), - 'superclasses': list([ - ]), - 'variances': list([ - ]), - }), - dict({ - 'attributes': list([ - 'test_main/main_test_module/ModuleClass/attr_1', - 'test_main/main_test_module/ModuleClass/init_attr', - 'test_main/main_test_module/ModuleClass/_init_attr_private', - ]), - 'classes': list([ - 'test_main/main_test_module/ModuleClass/NestedClass', - ]), - 'constructor': dict({ - 'docstring': dict({ - 'description': ''' - Summary of the init description. - - Full init description. - ''', - 'full_docstring': ''' - Summary of the init description. - - Full init description. - ''', - }), - 'id': 'test_main/main_test_module/ModuleClass/__init__', - 'is_class_method': False, - 'is_property': False, - 'is_public': True, - 'is_static': False, - 'name': '__init__', - 'parameters': list([ - 'test_main/main_test_module/ModuleClass/__init__/self', - 'test_main/main_test_module/ModuleClass/__init__/init_param_1', - ]), - 'reexported_by': list([ - ]), - 'results': list([ - ]), - }), - 'docstring': dict({ - 'description': ''' - Summary of the description. - - Full description - ''', - 'full_docstring': ''' - Summary of the description. - - Full description - ''', - }), - 'id': 'test_main/main_test_module/ModuleClass', - 'is_public': True, - 'methods': list([ - 'test_main/main_test_module/ModuleClass/_some_function', - ]), - 'name': 'ModuleClass', - 'reexported_by': list([ - ]), - 'superclasses': list([ - 'tests.data.test_main.main_test_module.AcDoubleAlias', - ]), - 'variances': list([ - ]), - }), - dict({ - 'attributes': list([ - ]), - 'classes': list([ - ]), - 'constructor': None, - 'docstring': dict({ - 'description': '', - 'full_docstring': '', - }), - 'id': 'test_main/main_test_module/ModuleClass/NestedClass', - 'is_public': True, - 'methods': list([ - 'test_main/main_test_module/ModuleClass/NestedClass/nested_class_function', - ]), - 'name': 'NestedClass', - 'reexported_by': list([ - ]), - 'superclasses': list([ - 'tests.data.test_main.another_path.another_module.AnotherClass', - ]), - 'variances': list([ - ]), - }), - dict({ - 'attributes': list([ - 'test_main/main_test_module/_PrivateClass/public_attr_in_private_class', - 'test_main/main_test_module/_PrivateClass/public_init_attr_in_private_class', - ]), - 'classes': list([ - 'test_main/main_test_module/_PrivateClass/NestedPrivateClass', - ]), - 'constructor': dict({ - 'docstring': dict({ - 'description': '', - 'full_docstring': '', - }), - 'id': 'test_main/main_test_module/_PrivateClass/__init__', - 'is_class_method': False, - 'is_property': False, - 'is_public': False, - 'is_static': False, - 'name': '__init__', - 'parameters': list([ - 'test_main/main_test_module/_PrivateClass/__init__/self', - ]), - 'reexported_by': list([ - ]), - 'results': list([ - ]), - }), - 'docstring': dict({ - 'description': '', - 'full_docstring': '', - }), - 'id': 'test_main/main_test_module/_PrivateClass', - 'is_public': False, - 'methods': list([ - 'test_main/main_test_module/_PrivateClass/public_func_in_private_class', - ]), - 'name': '_PrivateClass', - 'reexported_by': list([ - ]), - 'superclasses': list([ - ]), - 'variances': list([ - ]), - }), - dict({ - 'attributes': list([ - 'test_main/main_test_module/_PrivateClass/NestedPrivateClass/nested_class_attr', - ]), - 'classes': list([ - 'test_main/main_test_module/_PrivateClass/NestedPrivateClass/NestedNestedPrivateClass', - ]), - 'constructor': None, - 'docstring': dict({ - 'description': '', - 'full_docstring': '', - }), - 'id': 'test_main/main_test_module/_PrivateClass/NestedPrivateClass', - 'is_public': True, - 'methods': list([ - 'test_main/main_test_module/_PrivateClass/NestedPrivateClass/static_nested_private_class_function', - ]), - 'name': 'NestedPrivateClass', - 'reexported_by': list([ - ]), - 'superclasses': list([ - ]), - 'variances': list([ - ]), - }), - dict({ - 'attributes': list([ - ]), - 'classes': list([ - ]), - 'constructor': None, - 'docstring': dict({ - 'description': '', - 'full_docstring': '', - }), - 'id': 'test_main/main_test_module/_PrivateClass/NestedPrivateClass/NestedNestedPrivateClass', - 'is_public': True, - 'methods': list([ - ]), - 'name': 'NestedNestedPrivateClass', - 'reexported_by': list([ - ]), - 'superclasses': list([ - ]), - 'variances': list([ - ]), - }), - ]), - 'distribution': '', - 'enum_instances': list([ - ]), - 'enums': list([ - ]), - 'functions': list([ - dict({ - 'docstring': dict({ - 'description': '', - 'full_docstring': '', - }), - 'id': 'test_main/main_test_module/ModuleClass/NestedClass/nested_class_function', - 'is_class_method': False, - 'is_property': False, - 'is_public': True, - 'is_static': False, - 'name': 'nested_class_function', - 'parameters': list([ - 'test_main/main_test_module/ModuleClass/NestedClass/nested_class_function/self', - 'test_main/main_test_module/ModuleClass/NestedClass/nested_class_function/param_1', - ]), - 'reexported_by': list([ - ]), - 'results': list([ - 'test_main/main_test_module/ModuleClass/NestedClass/nested_class_function/result_1', - ]), - }), - dict({ - 'docstring': dict({ - 'description': ''' - Summary of the init description. - - Full init description. - ''', - 'full_docstring': ''' - Summary of the init description. - - Full init description. - ''', - }), - 'id': 'test_main/main_test_module/ModuleClass/__init__', - 'is_class_method': False, - 'is_property': False, - 'is_public': True, - 'is_static': False, - 'name': '__init__', - 'parameters': list([ - 'test_main/main_test_module/ModuleClass/__init__/self', - 'test_main/main_test_module/ModuleClass/__init__/init_param_1', - ]), - 'reexported_by': list([ - ]), - 'results': list([ - ]), - }), - dict({ - 'docstring': dict({ - 'description': ''' - Function Docstring. - - param_2: bool. - ''', - 'full_docstring': ''' - Function Docstring. - - param_2: bool. - ''', - }), - 'id': 'test_main/main_test_module/ModuleClass/_some_function', - 'is_class_method': False, - 'is_property': False, - 'is_public': False, - 'is_static': False, - 'name': '_some_function', - 'parameters': list([ - 'test_main/main_test_module/ModuleClass/_some_function/self', - 'test_main/main_test_module/ModuleClass/_some_function/param_1', - 'test_main/main_test_module/ModuleClass/_some_function/param_2', - ]), - 'reexported_by': list([ - ]), - 'results': list([ - 'test_main/main_test_module/ModuleClass/_some_function/result_1', - ]), - }), - dict({ - 'docstring': dict({ - 'description': '', - 'full_docstring': '', - }), - 'id': 'test_main/main_test_module/_PrivateClass/NestedPrivateClass/static_nested_private_class_function', - 'is_class_method': False, - 'is_property': False, - 'is_public': False, - 'is_static': True, - 'name': 'static_nested_private_class_function', - 'parameters': list([ - ]), - 'reexported_by': list([ - ]), - 'results': list([ - ]), - }), - dict({ - 'docstring': dict({ - 'description': '', - 'full_docstring': '', - }), - 'id': 'test_main/main_test_module/_PrivateClass/__init__', - 'is_class_method': False, - 'is_property': False, - 'is_public': False, - 'is_static': False, - 'name': '__init__', - 'parameters': list([ - 'test_main/main_test_module/_PrivateClass/__init__/self', - ]), - 'reexported_by': list([ - ]), - 'results': list([ - ]), - }), - dict({ - 'docstring': dict({ - 'description': '', - 'full_docstring': '', - }), - 'id': 'test_main/main_test_module/_PrivateClass/public_func_in_private_class', - 'is_class_method': False, - 'is_property': False, - 'is_public': False, - 'is_static': False, - 'name': 'public_func_in_private_class', - 'parameters': list([ - 'test_main/main_test_module/_PrivateClass/public_func_in_private_class/self', - ]), - 'reexported_by': list([ - ]), - 'results': list([ - ]), - }), - dict({ - 'docstring': dict({ - 'description': '', - 'full_docstring': '', - }), - 'id': 'test_main/main_test_module/_private_global_func', - 'is_class_method': False, - 'is_property': False, - 'is_public': False, - 'is_static': False, - 'name': '_private_global_func', - 'parameters': list([ - ]), - 'reexported_by': list([ - ]), - 'results': list([ - 'test_main/main_test_module/_private_global_func/result_1', - ]), - }), - dict({ - 'docstring': dict({ - 'description': ''' - Docstring 1. - - Docstring 2. - ''', - 'full_docstring': ''' - Docstring 1. - - Docstring 2. - ''', - }), - 'id': 'test_main/main_test_module/global_func', - 'is_class_method': False, - 'is_property': False, - 'is_public': True, - 'is_static': False, - 'name': 'global_func', - 'parameters': list([ - 'test_main/main_test_module/global_func/main_test_param_1', - 'test_main/main_test_module/global_func/main_test_param_2', - ]), - 'reexported_by': list([ - ]), - 'results': list([ - 'test_main/main_test_module/global_func/result_1', - ]), - }), - ]), - 'modules': list([ - dict({ - 'classes': list([ - 'test_main/another_path/another_module/AnotherClass', - ]), - 'docstring': ''' - Another Module Docstring. - - Full Docstring Description - - ''', - 'enums': list([ - ]), - 'functions': list([ - ]), - 'id': 'test_main/another_path/another_module', - 'name': 'another_module', - 'qualified_imports': list([ - ]), - 'wildcard_imports': list([ - ]), - }), - dict({ - 'classes': list([ - 'test_main/main_test_module/ModuleClass', - 'test_main/main_test_module/_PrivateClass', - ]), - 'docstring': 'Docstring of the some_class.py module.', - 'enums': list([ - ]), - 'functions': list([ - 'test_main/main_test_module/global_func', - 'test_main/main_test_module/_private_global_func', - ]), - 'id': 'test_main/main_test_module', - 'name': 'main_test_module', - 'qualified_imports': list([ - dict({ - 'alias': 'mathematics', - 'qualified_name': 'math', - }), - dict({ - 'alias': None, - 'qualified_name': 'mypy', - }), - dict({ - 'alias': None, - 'qualified_name': 'another_path.another_module.AnotherClass', - }), - dict({ - 'alias': '_AcImportAlias', - 'qualified_name': 'another_path.another_module.AnotherClass', - }), - ]), - 'wildcard_imports': list([ - dict({ - 'module_name': 'docstring_parser', - }), - ]), - }), - ]), - 'package': 'test_main', - 'parameters': list([ - dict({ - 'assigned_by': 'POSITION_OR_NAME', - 'default_value': None, - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_main/main_test_module/ModuleClass/NestedClass/nested_class_function/param_1', - 'is_optional': False, - 'is_type_inferred': False, - 'name': 'param_1', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'int', - 'qname': 'builtins.int', - }), - }), - dict({ - 'assigned_by': 'IMPLICIT', - 'default_value': None, - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_main/main_test_module/ModuleClass/NestedClass/nested_class_function/self', - 'is_optional': False, - 'is_type_inferred': False, - 'name': 'self', - 'type': None, - }), - dict({ - 'assigned_by': 'POSITION_OR_NAME', - 'default_value': None, - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_main/main_test_module/ModuleClass/__init__/init_param_1', - 'is_optional': False, - 'is_type_inferred': False, - 'name': 'init_param_1', - 'type': None, - }), - dict({ - 'assigned_by': 'IMPLICIT', - 'default_value': None, - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_main/main_test_module/ModuleClass/__init__/self', - 'is_optional': False, - 'is_type_inferred': False, - 'name': 'self', - 'type': None, - }), - dict({ - 'assigned_by': 'POSITION_OR_NAME', - 'default_value': None, - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_main/main_test_module/ModuleClass/_some_function/param_1', - 'is_optional': False, - 'is_type_inferred': False, - 'name': 'param_1', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'AnotherClass', - 'qname': 'tests.data.test_main.another_path.another_module.AnotherClass', - }), - }), - dict({ - 'assigned_by': 'POSITION_OR_NAME', - 'default_value': False, - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_main/main_test_module/ModuleClass/_some_function/param_2', - 'is_optional': True, - 'is_type_inferred': False, - 'name': 'param_2', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'bool', - 'qname': 'builtins.bool', - }), - }), - dict({ - 'assigned_by': 'IMPLICIT', - 'default_value': None, - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_main/main_test_module/ModuleClass/_some_function/self', - 'is_optional': False, - 'is_type_inferred': False, - 'name': 'self', - 'type': None, - }), - dict({ - 'assigned_by': 'IMPLICIT', - 'default_value': None, - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_main/main_test_module/_PrivateClass/__init__/self', - 'is_optional': False, - 'is_type_inferred': False, - 'name': 'self', - 'type': None, - }), - dict({ - 'assigned_by': 'IMPLICIT', - 'default_value': None, - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_main/main_test_module/_PrivateClass/public_func_in_private_class/self', - 'is_optional': False, - 'is_type_inferred': False, - 'name': 'self', - 'type': None, - }), - dict({ - 'assigned_by': 'POSITION_OR_NAME', - 'default_value': 'first param', - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_main/main_test_module/global_func/main_test_param_1', - 'is_optional': True, - 'is_type_inferred': False, - 'name': 'main_test_param_1', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'str', - 'qname': 'builtins.str', - }), - }), - dict({ - 'assigned_by': 'POSITION_OR_NAME', - 'default_value': None, - 'docstring': dict({ - 'default_value': '', - 'description': '', - 'type': '', - }), - 'id': 'test_main/main_test_module/global_func/main_test_param_2', - 'is_optional': True, - 'is_type_inferred': False, - 'name': 'main_test_param_2', - 'type': dict({ - 'kind': 'UnionType', - 'types': list([ - dict({ - 'kind': 'NamedType', - 'name': 'AnotherClass', - 'qname': 'tests.data.test_main.another_path.another_module.AnotherClass', - }), - dict({ - 'kind': 'NamedType', - 'name': 'None', - 'qname': 'builtins.None', - }), - ]), - }), - }), - ]), - 'results': list([ - dict({ - 'docstring': dict({ - 'description': '', - 'type': '', - }), - 'id': 'test_main/main_test_module/ModuleClass/NestedClass/nested_class_function/result_1', - 'is_type_inferred': False, - 'name': 'result_1', - 'type': dict({ - 'kind': 'SetType', - 'types': list([ - dict({ - 'kind': 'UnionType', - 'types': list([ - dict({ - 'kind': 'NamedType', - 'name': 'bool', - 'qname': 'builtins.bool', - }), - dict({ - 'kind': 'NamedType', - 'name': 'None', - 'qname': 'builtins.None', - }), - ]), - }), - ]), - }), - }), - dict({ - 'docstring': dict({ - 'description': '', - 'type': '', - }), - 'id': 'test_main/main_test_module/ModuleClass/_some_function/result_1', - 'is_type_inferred': False, - 'name': 'result_1', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'AnotherClass', - 'qname': 'tests.data.test_main.another_path.another_module.AnotherClass', - }), - }), - dict({ - 'docstring': dict({ - 'description': '', - 'type': '', - }), - 'id': 'test_main/main_test_module/_private_global_func/result_1', - 'is_type_inferred': False, - 'name': 'result_1', - 'type': dict({ - 'kind': 'UnionType', - 'types': list([ - dict({ - 'kind': 'NamedType', - 'name': 'AnotherClass', - 'qname': 'tests.data.test_main.another_path.another_module.AnotherClass', - }), - dict({ - 'kind': 'NamedType', - 'name': 'AnotherClass', - 'qname': 'tests.data.test_main.another_path.another_module.AnotherClass', - }), - dict({ - 'kind': 'NamedType', - 'name': 'AnotherClass', - 'qname': 'tests.data.test_main.another_path.another_module.AnotherClass', - }), - ]), - }), - }), - dict({ - 'docstring': dict({ - 'description': '', - 'type': '', - }), - 'id': 'test_main/main_test_module/global_func/result_1', - 'is_type_inferred': False, - 'name': 'result_1', - 'type': dict({ - 'kind': 'NamedType', - 'name': 'AnotherClass', - 'qname': 'tests.data.test_main.another_path.another_module.AnotherClass', - }), - }), - ]), - 'schemaVersion': 1, - 'version': '', - }) -# --- From e5b5b1a8dc2fb1e68dda8b4a2452b99bff28804f Mon Sep 17 00:00:00 2001 From: Arsam Date: Thu, 30 Nov 2023 16:19:11 +0100 Subject: [PATCH 071/109] Linter and bug fixes --- .../api_analyzer/_mypy_helpers.py | 37 +++++++++++-------- tests/data/test_package/infer_types_module.py | 15 ++++++++ .../__snapshots__/test__get_api.ambr | 10 +++++ .../__snapshots__/test_generate_stubs.ambr | 6 ++- 4 files changed, 52 insertions(+), 16 deletions(-) diff --git a/src/safeds_stubgen/api_analyzer/_mypy_helpers.py b/src/safeds_stubgen/api_analyzer/_mypy_helpers.py index 30a9f311..157f37da 100644 --- a/src/safeds_stubgen/api_analyzer/_mypy_helpers.py +++ b/src/safeds_stubgen/api_analyzer/_mypy_helpers.py @@ -50,14 +50,15 @@ def mypy_type_to_abstract_type( elif len(types) == 0: # pragma: no cover raise ValueError("Final type has no type arguments.") return sds_types.FinalType(type_=sds_types.UnionType(types=types)) - elif (unanalyzed_type_name in {"list", "set"} and - len(mypy_type.args) == 1 and - isinstance(mypy_type.args[0], mp_types.AnyType) and - not has_correct_type_of_any(mypy_type.args[0].type_of_any)): - # This case happens if we have a list or set with multiple arguments like "list[str, int]" which is - # not allowed. In this case mypy interprets the type as "list[Any]", but we want the real types - # of the list arguments, which we cant get through the "unanalyzed_type" attribute - return mypy_type_to_abstract_type(unanalyzed_type) + elif unanalyzed_type_name in {"list", "set"}: + type_args = getattr(mypy_type, "args", []) + if (len(type_args) == 1 and + isinstance(type_args[0], mp_types.AnyType) and + not has_correct_type_of_any(type_args[0].type_of_any)): + # This case happens if we have a list or set with multiple arguments like "list[str, int]" which is + # not allowed. In this case mypy interprets the type as "list[Any]", but we want the real types + # of the list arguments, which we cant get through the "unanalyzed_type" attribute + return mypy_type_to_abstract_type(unanalyzed_type) # Iterable mypy types if isinstance(mypy_type, mp_types.TupleType): @@ -110,11 +111,14 @@ def mypy_type_to_abstract_type( mypy_type_to_abstract_type(arg) for arg in mypy_type.args ] - return { - "tuple": sds_types.TupleType, - "list": sds_types.ListType, - "set": sds_types.SetType, - }[type_name](types=types) + match type_name: + case "tuple": + return sds_types.TupleType(types=types) + case "list": + return sds_types.ListType(types=types) + case "set": + return sds_types.SetType(types=types) + raise ValueError("Unexpected outcome.") # pragma: no cover elif type_name == "dict": key_type = mypy_type_to_abstract_type(mypy_type.args[0]) @@ -151,15 +155,18 @@ def get_argument_kind(arg: mp_nodes.Argument) -> ParameterAssignment: raise ValueError("Could not find an appropriate parameter assignment.") -def find_return_stmts_recursive(stmts: list[mp_nodes.Statement]) -> list[mp_nodes.ReturnStmt]: +def find_return_stmts_recursive(stmts: list[mp_nodes.Statement] | list[mp_nodes.Block]) -> list[mp_nodes.ReturnStmt]: return_stmts = [] for stmt in stmts: if isinstance(stmt, mp_nodes.IfStmt): return_stmts += find_return_stmts_recursive(stmt.body) if stmt.else_body: return_stmts += find_return_stmts_recursive(stmt.else_body.body) - elif isinstance(stmt, mp_nodes.Block | mp_nodes.TryStmt): + elif isinstance(stmt, mp_nodes.Block): return_stmts += find_return_stmts_recursive(stmt.body) + elif isinstance(stmt, mp_nodes.TryStmt): + return_stmts += find_return_stmts_recursive([stmt.body]) + return_stmts += find_return_stmts_recursive(stmt.handlers) elif isinstance(stmt, mp_nodes.MatchStmt): return_stmts += find_return_stmts_recursive(stmt.bodies) elif isinstance(stmt, mp_nodes.WhileStmt | mp_nodes.WithStmt | mp_nodes.ForStmt): diff --git a/tests/data/test_package/infer_types_module.py b/tests/data/test_package/infer_types_module.py index 771e91c4..ff0fe707 100644 --- a/tests/data/test_package/infer_types_module.py +++ b/tests/data/test_package/infer_types_module.py @@ -2,6 +2,14 @@ class InferMe: ... +class InferMe2: + ... + + +class InferMe3: + ... + + class InferMyTypes: infer_int = 1 infer_float = 1.2 @@ -44,4 +52,11 @@ def infer_function(infer_param=1, infer_param_2: int = "Something"): if infer_param_2: return InferMe + try: + if infer_param_2: + return InferMe2 + except RuntimeError: + if infer_param_2: + return InferMe3 + return int diff --git a/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr b/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr index 98541edb..17be30d2 100644 --- a/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr +++ b/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr @@ -4492,6 +4492,16 @@ 'name': 'InferMe', 'qname': 'tests.data.test_package.infer_types_module.InferMe', }), + dict({ + 'kind': 'NamedType', + 'name': 'InferMe2', + 'qname': 'tests.data.test_package.infer_types_module.InferMe2', + }), + dict({ + 'kind': 'NamedType', + 'name': 'InferMe3', + 'qname': 'tests.data.test_package.infer_types_module.InferMe3', + }), dict({ 'kind': 'NamedType', 'name': 'InferMyTypes', diff --git a/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr b/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr index d2562dd9..d29bc7b8 100644 --- a/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr +++ b/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr @@ -492,6 +492,10 @@ class InferMe() + class InferMe2() + + class InferMe3() + class InferMyTypes( @PythonName("init_param") initParam: Int = 1 ) { @@ -516,7 +520,7 @@ static fun inferFunction( @PythonName("infer_param") inferParam: Int = 1, @PythonName("infer_param_2") inferParam2: Int = Something - ) -> (result1: union, result2: union, result3: Float) + ) -> (result1: union, result2: union, result3: Float) } ''' From 794020de12cbea152c148c71fefd5cc9bfd24735 Mon Sep 17 00:00:00 2001 From: Arsam Date: Thu, 30 Nov 2023 16:56:01 +0100 Subject: [PATCH 072/109] Linter and bug fixes --- .../api_analyzer/_ast_visitor.py | 44 ++++++++++++------- src/safeds_stubgen/api_analyzer/_types.py | 12 ++--- .../stubs_generator/_generate_stubs.py | 15 +++++-- 3 files changed, 47 insertions(+), 24 deletions(-) diff --git a/src/safeds_stubgen/api_analyzer/_ast_visitor.py b/src/safeds_stubgen/api_analyzer/_ast_visitor.py index 494fa2c8..0abdfed3 100644 --- a/src/safeds_stubgen/api_analyzer/_ast_visitor.py +++ b/src/safeds_stubgen/api_analyzer/_ast_visitor.py @@ -1,7 +1,7 @@ from __future__ import annotations from types import NoneType -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, Any import mypy.types as mp_types from mypy import nodes as mp_nodes @@ -127,18 +127,24 @@ def enter_classdef(self, node: mp_nodes.ClassDef) -> None: # Variance # Special base classes like Generic[...] get moved to "removed_base_type_expr" during semantic analysis of mypy - generic_exprs = [ - removed_base_type_expr - for removed_base_type_expr in node.removed_base_type_exprs - if removed_base_type_expr.base.name == "Generic" - ] + generic_exprs = [] + for removed_base_type_expr in node.removed_base_type_exprs: + base = getattr(removed_base_type_expr, "base", None) + base_name = getattr(base, "name", None) + if base_name == "Generic": + generic_exprs.append(removed_base_type_expr) + variances = [] if generic_exprs: # Can only be one, since a class can inherit "Generic" only one time - generic_expr = generic_exprs[0].index + generic_expr = getattr(generic_exprs[0], "index", None) if isinstance(generic_expr, mp_nodes.TupleExpr): - generic_types = [item.node for item in generic_expr.items] + generic_types = [ + item.node + for item in generic_expr.items + if hasattr(item, "node") + ] elif isinstance(generic_expr, mp_nodes.NameExpr): generic_types = [generic_expr.node] else: # pragma: no cover @@ -146,6 +152,7 @@ def enter_classdef(self, node: mp_nodes.ClassDef) -> None: for generic_type in generic_types: variance_type = mypy_variance_parser(generic_type.variance) + variance_values: sds_types.AbstractType if variance_type == VarianceType.INVARIANT: variance_values = sds_types.UnionType([ mypy_type_to_abstract_type(value) @@ -366,7 +373,7 @@ def _parse_results(self, node: mp_nodes.FuncDef, function_id: str) -> list[Resul return [] # Get type - ret_type = None + ret_type: sds_types.AbstractType | None = None is_type_inferred = False if hasattr(node, "type"): node_type = node.type @@ -382,7 +389,8 @@ def _parse_results(self, node: mp_nodes.FuncDef, function_id: str) -> list[Resul is_type_inferred = ret_type is not None else: # Otherwise, we can parse the type normally - ret_type = mypy_type_to_abstract_type(node_ret_type, node.unanalyzed_type.ret_type) + unanalyzed_ret_type = getattr(node.unanalyzed_type, "ret_type", None) + ret_type = mypy_type_to_abstract_type(node_ret_type, unanalyzed_ret_type) else: # Infer type ret_type = self._infer_type_from_return_stmts(node) @@ -418,6 +426,7 @@ def _infer_type_from_return_stmts(func_node: mp_nodes.FuncDef) -> sds_types.Name types = { mypy_expression_to_sds_type(return_stmt.expr) for return_stmt in return_stmts + if return_stmt.expr is not None } # We have to sort the list for the snapshot tests @@ -461,19 +470,20 @@ def _create_infered_results( A list of Results objects representing the possible results of a funtion. """ result_array: list[list] = [] - type_: sds_types.NamedType | sds_types.TupleType for type_ in results.types: if isinstance(type_, sds_types.NamedType): if result_array: result_array[0].append(type_) else: result_array.append([type_]) - else: + elif isinstance(type_, sds_types.TupleType): for i, type__ in enumerate(type_.types): if len(result_array) > i: result_array[i].append(type__) else: result_array.append([type__]) + else: # pragma: no cover + raise TypeError(f"Expected NamedType or TupleType, received {type(type_)}") inferred_results = [] for i, result_list in enumerate(result_array): @@ -502,7 +512,7 @@ def _create_infered_results( def _parse_attributes( self, - lvalue: mp_nodes.NameExpr | mp_nodes.MemberExpr | mp_nodes.TupleExpr, + lvalue: mp_nodes.Expression, unanalyzed_type: mp_types.Type | None, is_static: bool = True, ) -> list[Attribute]: @@ -648,11 +658,12 @@ def _create_attribute( def _get_default_parameter_value_and_type( self, initializer: mp_nodes.Expression, infer_arg_type: bool = False, - ) -> tuple[None | str | float | int | bool | NoneType, None | sds_types.NamedType]: + ) -> tuple[None | str | float | int | bool | type, None | sds_types.NamedType]: # Get default value information - default_value = None + default_value: None | str | float | int | bool | type = None arg_type = None + value: Any if hasattr(initializer, "value"): value = initializer.value elif isinstance(initializer, mp_nodes.NameExpr): @@ -748,6 +759,9 @@ def _parse_parameter_data(self, node: mp_nodes.FuncDef, function_id: str) -> lis parent_class=parent if isinstance(parent, Class) else None, ) + if isinstance(default_value, type): # pragma: no cover + raise TypeError("default_value has the unexpected type 'type'.") + # Create parameter object arguments.append( Parameter( diff --git a/src/safeds_stubgen/api_analyzer/_types.py b/src/safeds_stubgen/api_analyzer/_types.py index c5260aa4..06db0bde 100644 --- a/src/safeds_stubgen/api_analyzer/_types.py +++ b/src/safeds_stubgen/api_analyzer/_types.py @@ -3,7 +3,7 @@ import re from abc import ABCMeta, abstractmethod from dataclasses import dataclass, field -from typing import Any, ClassVar +from typing import Any, ClassVar, Sequence class AbstractType(metaclass=ABCMeta): @@ -223,7 +223,7 @@ def to_dict(self) -> dict[str, Any]: @dataclass(frozen=True) class UnionType(AbstractType): - types: list[AbstractType] + types: Sequence[AbstractType] @classmethod def from_dict(cls, d: dict[str, Any]) -> UnionType: @@ -247,7 +247,7 @@ def __hash__(self) -> int: @dataclass(frozen=True) class ListType(AbstractType): - types: list[AbstractType] + types: Sequence[AbstractType] @classmethod def from_dict(cls, d: dict[str, Any]) -> ListType: @@ -289,7 +289,7 @@ def __hash__(self) -> int: @dataclass(frozen=True) class CallableType(AbstractType): - parameter_types: list[AbstractType] + parameter_types: Sequence[AbstractType] return_type: AbstractType @classmethod @@ -318,7 +318,7 @@ def __hash__(self) -> int: @dataclass(frozen=True) class SetType(AbstractType): - types: list[AbstractType] + types: Sequence[AbstractType] @classmethod def from_dict(cls, d: dict[str, Any]) -> SetType: @@ -371,7 +371,7 @@ def __hash__(self) -> int: @dataclass(frozen=True) class TupleType(AbstractType): - types: list[AbstractType] + types: Sequence[AbstractType] @classmethod def from_dict(cls, d: dict[str, Any]) -> TupleType: diff --git a/src/safeds_stubgen/stubs_generator/_generate_stubs.py b/src/safeds_stubgen/stubs_generator/_generate_stubs.py index ab81179b..b5821046 100644 --- a/src/safeds_stubgen/stubs_generator/_generate_stubs.py +++ b/src/safeds_stubgen/stubs_generator/_generate_stubs.py @@ -347,8 +347,14 @@ def _create_property_function_string(self, function: Function, indentations: str camel_case_name = self._replace_if_safeds_keyword(camel_case_name) # Create type information - types = UnionType(types=[result.type for result in function.results]).to_dict() - property_type = self._create_type_string(types) + result_types = [ + result.type + for result in function.results + if result.type is not None + ] + result_union = UnionType(types=result_types) + types_data = result_union.to_dict() + property_type = self._create_type_string(types_data) type_string = f": {property_type}" if property_type else "" return ( @@ -360,6 +366,9 @@ def _create_property_function_string(self, function: Function, indentations: str def _create_result_string(self, function_results: list[Result]) -> str: results: list[str] = [] for result in function_results: + if result.type is None: # pragma: no cover + continue + result_type = result.type.to_dict() ret_type = self._create_type_string(result_type) type_string = f": {ret_type}" if ret_type else "" @@ -413,7 +422,7 @@ def _create_parameter_string( # Bool values have to be written in lower case default_value = "true" if param_default_value else "false" else: - default_value = param_default_value + default_value = f"{param_default_value}" param_value = f" = {default_value}" elif parameter.default_is_none: param_value = " = null" From 5f8bfc7448bd38679f80ef22693598d201fd18d3 Mon Sep 17 00:00:00 2001 From: Arsam Date: Thu, 30 Nov 2023 17:11:46 +0100 Subject: [PATCH 073/109] Changed test data directory and file names, since the GitHub test runner has problems with directories and files beginning with "test" but without actual test functions. --- .../__ini__.py | 0 .../epydoc.py} | 0 .../full_docstring.py} | 0 .../googledoc.py} | 0 .../numpydoc.py} | 0 .../plaintext.py} | 0 .../restdoc.py} | 0 .../another_path/another_module.py | 0 .../main_test_module.py | 0 .../__init__.py | 0 .../_reexport_module_1.py | 0 .../_reexport_module_2.py | 0 .../_reexport_module_3.py | 0 .../_reexport_module_4.py | 0 .../abstract_module.py | 0 .../another_path/another_module.py | 0 .../attribute_module.py | 0 .../class_module.py | 0 .../docstring_module.py | 0 .../enum_module.py | 0 .../function_module.py | 0 .../import_module.py | 0 .../infer_types_module.py | 0 .../test_file_creation/__init__.py | 0 .../test_file_creation/_module_2.py | 0 .../test_file_creation/_module_3.py | 0 .../test_file_creation/_module_4.py | 0 .../test_file_creation/_module_6.py | 0 .../test_file_creation/module_1.py | 0 .../test_file_creation/package_1/module_5.py | 0 .../variance_module.py | 0 .../__snapshots__/test_main.ambr | 170 ++-- .../__snapshots__/test__get_api.ambr | 948 +++++++++--------- .../api_analyzer/test__get_api.py | 2 +- .../docstring_parsing/test_epydoc_parser.py | 4 +- .../test_get_full_docstring.py | 4 +- .../test_googledoc_parser.py | 4 +- .../docstring_parsing/test_numpydoc_parser.py | 4 +- .../test_plaintext_docstring_parser.py | 4 +- .../docstring_parsing/test_restdoc_parser.py | 4 +- .../__snapshots__/test_generate_stubs.ambr | 32 +- .../stubs_generator/test_generate_stubs.py | 2 +- tests/safeds_stubgen/test_main.py | 2 +- 43 files changed, 590 insertions(+), 590 deletions(-) rename tests/data/{test_docstring_parser_package => docstring_parser_package}/__ini__.py (100%) rename tests/data/{test_docstring_parser_package/test_epydoc.py => docstring_parser_package/epydoc.py} (100%) rename tests/data/{test_docstring_parser_package/test_full_docstring.py => docstring_parser_package/full_docstring.py} (100%) rename tests/data/{test_docstring_parser_package/test_googledoc.py => docstring_parser_package/googledoc.py} (100%) rename tests/data/{test_docstring_parser_package/test_numpydoc.py => docstring_parser_package/numpydoc.py} (100%) rename tests/data/{test_docstring_parser_package/test_plaintext.py => docstring_parser_package/plaintext.py} (100%) rename tests/data/{test_docstring_parser_package/test_restdoc.py => docstring_parser_package/restdoc.py} (100%) rename tests/data/{test_main => main_package}/another_path/another_module.py (100%) rename tests/data/{test_main => main_package}/main_test_module.py (100%) rename tests/data/{test_package => various_tests_package}/__init__.py (100%) rename tests/data/{test_package => various_tests_package}/_reexport_module_1.py (100%) rename tests/data/{test_package => various_tests_package}/_reexport_module_2.py (100%) rename tests/data/{test_package => various_tests_package}/_reexport_module_3.py (100%) rename tests/data/{test_package => various_tests_package}/_reexport_module_4.py (100%) rename tests/data/{test_package => various_tests_package}/abstract_module.py (100%) rename tests/data/{test_package => various_tests_package}/another_path/another_module.py (100%) rename tests/data/{test_package => various_tests_package}/attribute_module.py (100%) rename tests/data/{test_package => various_tests_package}/class_module.py (100%) rename tests/data/{test_package => various_tests_package}/docstring_module.py (100%) rename tests/data/{test_package => various_tests_package}/enum_module.py (100%) rename tests/data/{test_package => various_tests_package}/function_module.py (100%) rename tests/data/{test_package => various_tests_package}/import_module.py (100%) rename tests/data/{test_package => various_tests_package}/infer_types_module.py (100%) rename tests/data/{test_package => various_tests_package}/test_file_creation/__init__.py (100%) rename tests/data/{test_package => various_tests_package}/test_file_creation/_module_2.py (100%) rename tests/data/{test_package => various_tests_package}/test_file_creation/_module_3.py (100%) rename tests/data/{test_package => various_tests_package}/test_file_creation/_module_4.py (100%) rename tests/data/{test_package => various_tests_package}/test_file_creation/_module_6.py (100%) rename tests/data/{test_package => various_tests_package}/test_file_creation/module_1.py (100%) rename tests/data/{test_package => various_tests_package}/test_file_creation/package_1/module_5.py (100%) rename tests/data/{test_package => various_tests_package}/variance_module.py (100%) diff --git a/tests/data/test_docstring_parser_package/__ini__.py b/tests/data/docstring_parser_package/__ini__.py similarity index 100% rename from tests/data/test_docstring_parser_package/__ini__.py rename to tests/data/docstring_parser_package/__ini__.py diff --git a/tests/data/test_docstring_parser_package/test_epydoc.py b/tests/data/docstring_parser_package/epydoc.py similarity index 100% rename from tests/data/test_docstring_parser_package/test_epydoc.py rename to tests/data/docstring_parser_package/epydoc.py diff --git a/tests/data/test_docstring_parser_package/test_full_docstring.py b/tests/data/docstring_parser_package/full_docstring.py similarity index 100% rename from tests/data/test_docstring_parser_package/test_full_docstring.py rename to tests/data/docstring_parser_package/full_docstring.py diff --git a/tests/data/test_docstring_parser_package/test_googledoc.py b/tests/data/docstring_parser_package/googledoc.py similarity index 100% rename from tests/data/test_docstring_parser_package/test_googledoc.py rename to tests/data/docstring_parser_package/googledoc.py diff --git a/tests/data/test_docstring_parser_package/test_numpydoc.py b/tests/data/docstring_parser_package/numpydoc.py similarity index 100% rename from tests/data/test_docstring_parser_package/test_numpydoc.py rename to tests/data/docstring_parser_package/numpydoc.py diff --git a/tests/data/test_docstring_parser_package/test_plaintext.py b/tests/data/docstring_parser_package/plaintext.py similarity index 100% rename from tests/data/test_docstring_parser_package/test_plaintext.py rename to tests/data/docstring_parser_package/plaintext.py diff --git a/tests/data/test_docstring_parser_package/test_restdoc.py b/tests/data/docstring_parser_package/restdoc.py similarity index 100% rename from tests/data/test_docstring_parser_package/test_restdoc.py rename to tests/data/docstring_parser_package/restdoc.py diff --git a/tests/data/test_main/another_path/another_module.py b/tests/data/main_package/another_path/another_module.py similarity index 100% rename from tests/data/test_main/another_path/another_module.py rename to tests/data/main_package/another_path/another_module.py diff --git a/tests/data/test_main/main_test_module.py b/tests/data/main_package/main_test_module.py similarity index 100% rename from tests/data/test_main/main_test_module.py rename to tests/data/main_package/main_test_module.py diff --git a/tests/data/test_package/__init__.py b/tests/data/various_tests_package/__init__.py similarity index 100% rename from tests/data/test_package/__init__.py rename to tests/data/various_tests_package/__init__.py diff --git a/tests/data/test_package/_reexport_module_1.py b/tests/data/various_tests_package/_reexport_module_1.py similarity index 100% rename from tests/data/test_package/_reexport_module_1.py rename to tests/data/various_tests_package/_reexport_module_1.py diff --git a/tests/data/test_package/_reexport_module_2.py b/tests/data/various_tests_package/_reexport_module_2.py similarity index 100% rename from tests/data/test_package/_reexport_module_2.py rename to tests/data/various_tests_package/_reexport_module_2.py diff --git a/tests/data/test_package/_reexport_module_3.py b/tests/data/various_tests_package/_reexport_module_3.py similarity index 100% rename from tests/data/test_package/_reexport_module_3.py rename to tests/data/various_tests_package/_reexport_module_3.py diff --git a/tests/data/test_package/_reexport_module_4.py b/tests/data/various_tests_package/_reexport_module_4.py similarity index 100% rename from tests/data/test_package/_reexport_module_4.py rename to tests/data/various_tests_package/_reexport_module_4.py diff --git a/tests/data/test_package/abstract_module.py b/tests/data/various_tests_package/abstract_module.py similarity index 100% rename from tests/data/test_package/abstract_module.py rename to tests/data/various_tests_package/abstract_module.py diff --git a/tests/data/test_package/another_path/another_module.py b/tests/data/various_tests_package/another_path/another_module.py similarity index 100% rename from tests/data/test_package/another_path/another_module.py rename to tests/data/various_tests_package/another_path/another_module.py diff --git a/tests/data/test_package/attribute_module.py b/tests/data/various_tests_package/attribute_module.py similarity index 100% rename from tests/data/test_package/attribute_module.py rename to tests/data/various_tests_package/attribute_module.py diff --git a/tests/data/test_package/class_module.py b/tests/data/various_tests_package/class_module.py similarity index 100% rename from tests/data/test_package/class_module.py rename to tests/data/various_tests_package/class_module.py diff --git a/tests/data/test_package/docstring_module.py b/tests/data/various_tests_package/docstring_module.py similarity index 100% rename from tests/data/test_package/docstring_module.py rename to tests/data/various_tests_package/docstring_module.py diff --git a/tests/data/test_package/enum_module.py b/tests/data/various_tests_package/enum_module.py similarity index 100% rename from tests/data/test_package/enum_module.py rename to tests/data/various_tests_package/enum_module.py diff --git a/tests/data/test_package/function_module.py b/tests/data/various_tests_package/function_module.py similarity index 100% rename from tests/data/test_package/function_module.py rename to tests/data/various_tests_package/function_module.py diff --git a/tests/data/test_package/import_module.py b/tests/data/various_tests_package/import_module.py similarity index 100% rename from tests/data/test_package/import_module.py rename to tests/data/various_tests_package/import_module.py diff --git a/tests/data/test_package/infer_types_module.py b/tests/data/various_tests_package/infer_types_module.py similarity index 100% rename from tests/data/test_package/infer_types_module.py rename to tests/data/various_tests_package/infer_types_module.py diff --git a/tests/data/test_package/test_file_creation/__init__.py b/tests/data/various_tests_package/test_file_creation/__init__.py similarity index 100% rename from tests/data/test_package/test_file_creation/__init__.py rename to tests/data/various_tests_package/test_file_creation/__init__.py diff --git a/tests/data/test_package/test_file_creation/_module_2.py b/tests/data/various_tests_package/test_file_creation/_module_2.py similarity index 100% rename from tests/data/test_package/test_file_creation/_module_2.py rename to tests/data/various_tests_package/test_file_creation/_module_2.py diff --git a/tests/data/test_package/test_file_creation/_module_3.py b/tests/data/various_tests_package/test_file_creation/_module_3.py similarity index 100% rename from tests/data/test_package/test_file_creation/_module_3.py rename to tests/data/various_tests_package/test_file_creation/_module_3.py diff --git a/tests/data/test_package/test_file_creation/_module_4.py b/tests/data/various_tests_package/test_file_creation/_module_4.py similarity index 100% rename from tests/data/test_package/test_file_creation/_module_4.py rename to tests/data/various_tests_package/test_file_creation/_module_4.py diff --git a/tests/data/test_package/test_file_creation/_module_6.py b/tests/data/various_tests_package/test_file_creation/_module_6.py similarity index 100% rename from tests/data/test_package/test_file_creation/_module_6.py rename to tests/data/various_tests_package/test_file_creation/_module_6.py diff --git a/tests/data/test_package/test_file_creation/module_1.py b/tests/data/various_tests_package/test_file_creation/module_1.py similarity index 100% rename from tests/data/test_package/test_file_creation/module_1.py rename to tests/data/various_tests_package/test_file_creation/module_1.py diff --git a/tests/data/test_package/test_file_creation/package_1/module_5.py b/tests/data/various_tests_package/test_file_creation/package_1/module_5.py similarity index 100% rename from tests/data/test_package/test_file_creation/package_1/module_5.py rename to tests/data/various_tests_package/test_file_creation/package_1/module_5.py diff --git a/tests/data/test_package/variance_module.py b/tests/data/various_tests_package/variance_module.py similarity index 100% rename from tests/data/test_package/variance_module.py rename to tests/data/various_tests_package/variance_module.py diff --git a/tests/safeds_stubgen/__snapshots__/test_main.ambr b/tests/safeds_stubgen/__snapshots__/test_main.ambr index ff076cee..08167861 100644 --- a/tests/safeds_stubgen/__snapshots__/test_main.ambr +++ b/tests/safeds_stubgen/__snapshots__/test_main.ambr @@ -8,7 +8,7 @@ 'description': '', 'type': '', }), - 'id': 'test_main/main_test_module/ModuleClass/_init_attr_private', + 'id': 'main_package/main_test_module/ModuleClass/_init_attr_private', 'is_public': False, 'is_static': False, 'is_type_inferred': False, @@ -25,7 +25,7 @@ 'description': '', 'type': '', }), - 'id': 'test_main/main_test_module/ModuleClass/attr_1', + 'id': 'main_package/main_test_module/ModuleClass/attr_1', 'is_public': True, 'is_static': True, 'is_type_inferred': False, @@ -42,7 +42,7 @@ 'description': '', 'type': '', }), - 'id': 'test_main/main_test_module/ModuleClass/init_attr', + 'id': 'main_package/main_test_module/ModuleClass/init_attr', 'is_public': True, 'is_static': False, 'is_type_inferred': False, @@ -59,7 +59,7 @@ 'description': '', 'type': '', }), - 'id': 'test_main/main_test_module/_PrivateClass/NestedPrivateClass/nested_class_attr', + 'id': 'main_package/main_test_module/_PrivateClass/NestedPrivateClass/nested_class_attr', 'is_public': False, 'is_static': True, 'is_type_inferred': True, @@ -76,7 +76,7 @@ 'description': '', 'type': '', }), - 'id': 'test_main/main_test_module/_PrivateClass/public_attr_in_private_class', + 'id': 'main_package/main_test_module/_PrivateClass/public_attr_in_private_class', 'is_public': False, 'is_static': True, 'is_type_inferred': True, @@ -93,7 +93,7 @@ 'description': '', 'type': '', }), - 'id': 'test_main/main_test_module/_PrivateClass/public_init_attr_in_private_class', + 'id': 'main_package/main_test_module/_PrivateClass/public_init_attr_in_private_class', 'is_public': False, 'is_static': False, 'is_type_inferred': False, @@ -116,7 +116,7 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_main/another_path/another_module/AnotherClass', + 'id': 'main_package/another_path/another_module/AnotherClass', 'is_public': True, 'methods': list([ ]), @@ -130,12 +130,12 @@ }), dict({ 'attributes': list([ - 'test_main/main_test_module/ModuleClass/attr_1', - 'test_main/main_test_module/ModuleClass/init_attr', - 'test_main/main_test_module/ModuleClass/_init_attr_private', + 'main_package/main_test_module/ModuleClass/attr_1', + 'main_package/main_test_module/ModuleClass/init_attr', + 'main_package/main_test_module/ModuleClass/_init_attr_private', ]), 'classes': list([ - 'test_main/main_test_module/ModuleClass/NestedClass', + 'main_package/main_test_module/ModuleClass/NestedClass', ]), 'constructor': dict({ 'docstring': dict({ @@ -150,15 +150,15 @@ Full init description. ''', }), - 'id': 'test_main/main_test_module/ModuleClass/__init__', + 'id': 'main_package/main_test_module/ModuleClass/__init__', 'is_class_method': False, 'is_property': False, 'is_public': True, 'is_static': False, 'name': '__init__', 'parameters': list([ - 'test_main/main_test_module/ModuleClass/__init__/self', - 'test_main/main_test_module/ModuleClass/__init__/init_param_1', + 'main_package/main_test_module/ModuleClass/__init__/self', + 'main_package/main_test_module/ModuleClass/__init__/init_param_1', ]), 'reexported_by': list([ ]), @@ -177,16 +177,16 @@ Full description ''', }), - 'id': 'test_main/main_test_module/ModuleClass', + 'id': 'main_package/main_test_module/ModuleClass', 'is_public': True, 'methods': list([ - 'test_main/main_test_module/ModuleClass/_some_function', + 'main_package/main_test_module/ModuleClass/_some_function', ]), 'name': 'ModuleClass', 'reexported_by': list([ ]), 'superclasses': list([ - 'tests.data.test_main.main_test_module.AcDoubleAlias', + 'tests.data.main_package.main_test_module.AcDoubleAlias', ]), 'variances': list([ ]), @@ -201,41 +201,41 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_main/main_test_module/ModuleClass/NestedClass', + 'id': 'main_package/main_test_module/ModuleClass/NestedClass', 'is_public': True, 'methods': list([ - 'test_main/main_test_module/ModuleClass/NestedClass/nested_class_function', + 'main_package/main_test_module/ModuleClass/NestedClass/nested_class_function', ]), 'name': 'NestedClass', 'reexported_by': list([ ]), 'superclasses': list([ - 'tests.data.test_main.another_path.another_module.AnotherClass', + 'tests.data.main_package.another_path.another_module.AnotherClass', ]), 'variances': list([ ]), }), dict({ 'attributes': list([ - 'test_main/main_test_module/_PrivateClass/public_attr_in_private_class', - 'test_main/main_test_module/_PrivateClass/public_init_attr_in_private_class', + 'main_package/main_test_module/_PrivateClass/public_attr_in_private_class', + 'main_package/main_test_module/_PrivateClass/public_init_attr_in_private_class', ]), 'classes': list([ - 'test_main/main_test_module/_PrivateClass/NestedPrivateClass', + 'main_package/main_test_module/_PrivateClass/NestedPrivateClass', ]), 'constructor': dict({ 'docstring': dict({ 'description': '', 'full_docstring': '', }), - 'id': 'test_main/main_test_module/_PrivateClass/__init__', + 'id': 'main_package/main_test_module/_PrivateClass/__init__', 'is_class_method': False, 'is_property': False, 'is_public': False, 'is_static': False, 'name': '__init__', 'parameters': list([ - 'test_main/main_test_module/_PrivateClass/__init__/self', + 'main_package/main_test_module/_PrivateClass/__init__/self', ]), 'reexported_by': list([ ]), @@ -246,10 +246,10 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_main/main_test_module/_PrivateClass', + 'id': 'main_package/main_test_module/_PrivateClass', 'is_public': False, 'methods': list([ - 'test_main/main_test_module/_PrivateClass/public_func_in_private_class', + 'main_package/main_test_module/_PrivateClass/public_func_in_private_class', ]), 'name': '_PrivateClass', 'reexported_by': list([ @@ -261,20 +261,20 @@ }), dict({ 'attributes': list([ - 'test_main/main_test_module/_PrivateClass/NestedPrivateClass/nested_class_attr', + 'main_package/main_test_module/_PrivateClass/NestedPrivateClass/nested_class_attr', ]), 'classes': list([ - 'test_main/main_test_module/_PrivateClass/NestedPrivateClass/NestedNestedPrivateClass', + 'main_package/main_test_module/_PrivateClass/NestedPrivateClass/NestedNestedPrivateClass', ]), 'constructor': None, 'docstring': dict({ 'description': '', 'full_docstring': '', }), - 'id': 'test_main/main_test_module/_PrivateClass/NestedPrivateClass', + 'id': 'main_package/main_test_module/_PrivateClass/NestedPrivateClass', 'is_public': True, 'methods': list([ - 'test_main/main_test_module/_PrivateClass/NestedPrivateClass/static_nested_private_class_function', + 'main_package/main_test_module/_PrivateClass/NestedPrivateClass/static_nested_private_class_function', ]), 'name': 'NestedPrivateClass', 'reexported_by': list([ @@ -294,7 +294,7 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_main/main_test_module/_PrivateClass/NestedPrivateClass/NestedNestedPrivateClass', + 'id': 'main_package/main_test_module/_PrivateClass/NestedPrivateClass/NestedNestedPrivateClass', 'is_public': True, 'methods': list([ ]), @@ -318,20 +318,20 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_main/main_test_module/ModuleClass/NestedClass/nested_class_function', + 'id': 'main_package/main_test_module/ModuleClass/NestedClass/nested_class_function', 'is_class_method': False, 'is_property': False, 'is_public': True, 'is_static': False, 'name': 'nested_class_function', 'parameters': list([ - 'test_main/main_test_module/ModuleClass/NestedClass/nested_class_function/self', - 'test_main/main_test_module/ModuleClass/NestedClass/nested_class_function/param_1', + 'main_package/main_test_module/ModuleClass/NestedClass/nested_class_function/self', + 'main_package/main_test_module/ModuleClass/NestedClass/nested_class_function/param_1', ]), 'reexported_by': list([ ]), 'results': list([ - 'test_main/main_test_module/ModuleClass/NestedClass/nested_class_function/result_1', + 'main_package/main_test_module/ModuleClass/NestedClass/nested_class_function/result_1', ]), }), dict({ @@ -347,15 +347,15 @@ Full init description. ''', }), - 'id': 'test_main/main_test_module/ModuleClass/__init__', + 'id': 'main_package/main_test_module/ModuleClass/__init__', 'is_class_method': False, 'is_property': False, 'is_public': True, 'is_static': False, 'name': '__init__', 'parameters': list([ - 'test_main/main_test_module/ModuleClass/__init__/self', - 'test_main/main_test_module/ModuleClass/__init__/init_param_1', + 'main_package/main_test_module/ModuleClass/__init__/self', + 'main_package/main_test_module/ModuleClass/__init__/init_param_1', ]), 'reexported_by': list([ ]), @@ -375,21 +375,21 @@ param_2: bool. ''', }), - 'id': 'test_main/main_test_module/ModuleClass/_some_function', + 'id': 'main_package/main_test_module/ModuleClass/_some_function', 'is_class_method': False, 'is_property': False, 'is_public': False, 'is_static': False, 'name': '_some_function', 'parameters': list([ - 'test_main/main_test_module/ModuleClass/_some_function/self', - 'test_main/main_test_module/ModuleClass/_some_function/param_1', - 'test_main/main_test_module/ModuleClass/_some_function/param_2', + 'main_package/main_test_module/ModuleClass/_some_function/self', + 'main_package/main_test_module/ModuleClass/_some_function/param_1', + 'main_package/main_test_module/ModuleClass/_some_function/param_2', ]), 'reexported_by': list([ ]), 'results': list([ - 'test_main/main_test_module/ModuleClass/_some_function/result_1', + 'main_package/main_test_module/ModuleClass/_some_function/result_1', ]), }), dict({ @@ -397,7 +397,7 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_main/main_test_module/_PrivateClass/NestedPrivateClass/static_nested_private_class_function', + 'id': 'main_package/main_test_module/_PrivateClass/NestedPrivateClass/static_nested_private_class_function', 'is_class_method': False, 'is_property': False, 'is_public': False, @@ -415,14 +415,14 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_main/main_test_module/_PrivateClass/__init__', + 'id': 'main_package/main_test_module/_PrivateClass/__init__', 'is_class_method': False, 'is_property': False, 'is_public': False, 'is_static': False, 'name': '__init__', 'parameters': list([ - 'test_main/main_test_module/_PrivateClass/__init__/self', + 'main_package/main_test_module/_PrivateClass/__init__/self', ]), 'reexported_by': list([ ]), @@ -434,14 +434,14 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_main/main_test_module/_PrivateClass/public_func_in_private_class', + 'id': 'main_package/main_test_module/_PrivateClass/public_func_in_private_class', 'is_class_method': False, 'is_property': False, 'is_public': False, 'is_static': False, 'name': 'public_func_in_private_class', 'parameters': list([ - 'test_main/main_test_module/_PrivateClass/public_func_in_private_class/self', + 'main_package/main_test_module/_PrivateClass/public_func_in_private_class/self', ]), 'reexported_by': list([ ]), @@ -453,7 +453,7 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_main/main_test_module/_private_global_func', + 'id': 'main_package/main_test_module/_private_global_func', 'is_class_method': False, 'is_property': False, 'is_public': False, @@ -464,7 +464,7 @@ 'reexported_by': list([ ]), 'results': list([ - 'test_main/main_test_module/_private_global_func/result_1', + 'main_package/main_test_module/_private_global_func/result_1', ]), }), dict({ @@ -480,27 +480,27 @@ Docstring 2. ''', }), - 'id': 'test_main/main_test_module/global_func', + 'id': 'main_package/main_test_module/global_func', 'is_class_method': False, 'is_property': False, 'is_public': True, 'is_static': False, 'name': 'global_func', 'parameters': list([ - 'test_main/main_test_module/global_func/main_test_param_1', - 'test_main/main_test_module/global_func/main_test_param_2', + 'main_package/main_test_module/global_func/main_test_param_1', + 'main_package/main_test_module/global_func/main_test_param_2', ]), 'reexported_by': list([ ]), 'results': list([ - 'test_main/main_test_module/global_func/result_1', + 'main_package/main_test_module/global_func/result_1', ]), }), ]), 'modules': list([ dict({ 'classes': list([ - 'test_main/another_path/another_module/AnotherClass', + 'main_package/another_path/another_module/AnotherClass', ]), 'docstring': ''' Another Module Docstring. @@ -512,7 +512,7 @@ ]), 'functions': list([ ]), - 'id': 'test_main/another_path/another_module', + 'id': 'main_package/another_path/another_module', 'name': 'another_module', 'qualified_imports': list([ ]), @@ -521,17 +521,17 @@ }), dict({ 'classes': list([ - 'test_main/main_test_module/ModuleClass', - 'test_main/main_test_module/_PrivateClass', + 'main_package/main_test_module/ModuleClass', + 'main_package/main_test_module/_PrivateClass', ]), 'docstring': 'Docstring of the some_class.py module.', 'enums': list([ ]), 'functions': list([ - 'test_main/main_test_module/global_func', - 'test_main/main_test_module/_private_global_func', + 'main_package/main_test_module/global_func', + 'main_package/main_test_module/_private_global_func', ]), - 'id': 'test_main/main_test_module', + 'id': 'main_package/main_test_module', 'name': 'main_test_module', 'qualified_imports': list([ dict({ @@ -558,7 +558,7 @@ ]), }), ]), - 'package': 'test_main', + 'package': 'main_package', 'parameters': list([ dict({ 'assigned_by': 'POSITION_OR_NAME', @@ -568,7 +568,7 @@ 'description': '', 'type': '', }), - 'id': 'test_main/main_test_module/ModuleClass/NestedClass/nested_class_function/param_1', + 'id': 'main_package/main_test_module/ModuleClass/NestedClass/nested_class_function/param_1', 'is_optional': False, 'is_type_inferred': False, 'name': 'param_1', @@ -586,7 +586,7 @@ 'description': '', 'type': '', }), - 'id': 'test_main/main_test_module/ModuleClass/NestedClass/nested_class_function/self', + 'id': 'main_package/main_test_module/ModuleClass/NestedClass/nested_class_function/self', 'is_optional': False, 'is_type_inferred': False, 'name': 'self', @@ -600,7 +600,7 @@ 'description': '', 'type': '', }), - 'id': 'test_main/main_test_module/ModuleClass/__init__/init_param_1', + 'id': 'main_package/main_test_module/ModuleClass/__init__/init_param_1', 'is_optional': False, 'is_type_inferred': False, 'name': 'init_param_1', @@ -614,7 +614,7 @@ 'description': '', 'type': '', }), - 'id': 'test_main/main_test_module/ModuleClass/__init__/self', + 'id': 'main_package/main_test_module/ModuleClass/__init__/self', 'is_optional': False, 'is_type_inferred': False, 'name': 'self', @@ -628,14 +628,14 @@ 'description': '', 'type': '', }), - 'id': 'test_main/main_test_module/ModuleClass/_some_function/param_1', + 'id': 'main_package/main_test_module/ModuleClass/_some_function/param_1', 'is_optional': False, 'is_type_inferred': False, 'name': 'param_1', 'type': dict({ 'kind': 'NamedType', 'name': 'AnotherClass', - 'qname': 'tests.data.test_main.another_path.another_module.AnotherClass', + 'qname': 'tests.data.main_package.another_path.another_module.AnotherClass', }), }), dict({ @@ -646,7 +646,7 @@ 'description': '', 'type': '', }), - 'id': 'test_main/main_test_module/ModuleClass/_some_function/param_2', + 'id': 'main_package/main_test_module/ModuleClass/_some_function/param_2', 'is_optional': True, 'is_type_inferred': False, 'name': 'param_2', @@ -664,7 +664,7 @@ 'description': '', 'type': '', }), - 'id': 'test_main/main_test_module/ModuleClass/_some_function/self', + 'id': 'main_package/main_test_module/ModuleClass/_some_function/self', 'is_optional': False, 'is_type_inferred': False, 'name': 'self', @@ -678,7 +678,7 @@ 'description': '', 'type': '', }), - 'id': 'test_main/main_test_module/_PrivateClass/__init__/self', + 'id': 'main_package/main_test_module/_PrivateClass/__init__/self', 'is_optional': False, 'is_type_inferred': False, 'name': 'self', @@ -692,7 +692,7 @@ 'description': '', 'type': '', }), - 'id': 'test_main/main_test_module/_PrivateClass/public_func_in_private_class/self', + 'id': 'main_package/main_test_module/_PrivateClass/public_func_in_private_class/self', 'is_optional': False, 'is_type_inferred': False, 'name': 'self', @@ -706,7 +706,7 @@ 'description': '', 'type': '', }), - 'id': 'test_main/main_test_module/global_func/main_test_param_1', + 'id': 'main_package/main_test_module/global_func/main_test_param_1', 'is_optional': True, 'is_type_inferred': False, 'name': 'main_test_param_1', @@ -724,7 +724,7 @@ 'description': '', 'type': '', }), - 'id': 'test_main/main_test_module/global_func/main_test_param_2', + 'id': 'main_package/main_test_module/global_func/main_test_param_2', 'is_optional': True, 'is_type_inferred': False, 'name': 'main_test_param_2', @@ -734,7 +734,7 @@ dict({ 'kind': 'NamedType', 'name': 'AnotherClass', - 'qname': 'tests.data.test_main.another_path.another_module.AnotherClass', + 'qname': 'tests.data.main_package.another_path.another_module.AnotherClass', }), dict({ 'kind': 'NamedType', @@ -751,7 +751,7 @@ 'description': '', 'type': '', }), - 'id': 'test_main/main_test_module/ModuleClass/NestedClass/nested_class_function/result_1', + 'id': 'main_package/main_test_module/ModuleClass/NestedClass/nested_class_function/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ @@ -780,13 +780,13 @@ 'description': '', 'type': '', }), - 'id': 'test_main/main_test_module/ModuleClass/_some_function/result_1', + 'id': 'main_package/main_test_module/ModuleClass/_some_function/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ 'kind': 'NamedType', 'name': 'AnotherClass', - 'qname': 'tests.data.test_main.another_path.another_module.AnotherClass', + 'qname': 'tests.data.main_package.another_path.another_module.AnotherClass', }), }), dict({ @@ -794,7 +794,7 @@ 'description': '', 'type': '', }), - 'id': 'test_main/main_test_module/_private_global_func/result_1', + 'id': 'main_package/main_test_module/_private_global_func/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ @@ -803,17 +803,17 @@ dict({ 'kind': 'NamedType', 'name': 'AnotherClass', - 'qname': 'tests.data.test_main.another_path.another_module.AnotherClass', + 'qname': 'tests.data.main_package.another_path.another_module.AnotherClass', }), dict({ 'kind': 'NamedType', 'name': 'AnotherClass', - 'qname': 'tests.data.test_main.another_path.another_module.AnotherClass', + 'qname': 'tests.data.main_package.another_path.another_module.AnotherClass', }), dict({ 'kind': 'NamedType', 'name': 'AnotherClass', - 'qname': 'tests.data.test_main.another_path.another_module.AnotherClass', + 'qname': 'tests.data.main_package.another_path.another_module.AnotherClass', }), ]), }), @@ -823,13 +823,13 @@ 'description': '', 'type': '', }), - 'id': 'test_main/main_test_module/global_func/result_1', + 'id': 'main_package/main_test_module/global_func/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ 'kind': 'NamedType', 'name': 'AnotherClass', - 'qname': 'tests.data.test_main.another_path.another_module.AnotherClass', + 'qname': 'tests.data.main_package.another_path.another_module.AnotherClass', }), }), ]), diff --git a/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr b/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr index 17be30d2..acd7771a 100644 --- a/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr +++ b/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr @@ -7,7 +7,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/attribute_module/AttributesClassB/_multi_attr_2_private', + 'id': 'various_tests_package/attribute_module/AttributesClassB/_multi_attr_2_private', 'is_public': False, 'is_static': True, 'is_type_inferred': True, @@ -24,7 +24,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/attribute_module/AttributesClassB/_multi_attr_4_private', + 'id': 'various_tests_package/attribute_module/AttributesClassB/_multi_attr_4_private', 'is_public': False, 'is_static': True, 'is_type_inferred': True, @@ -46,7 +46,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/attribute_module/AttributesClassB/_no_type_hint_private', + 'id': 'various_tests_package/attribute_module/AttributesClassB/_no_type_hint_private', 'is_public': False, 'is_static': True, 'is_type_inferred': True, @@ -63,7 +63,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/attribute_module/AttributesClassB/_type_hint_private', + 'id': 'various_tests_package/attribute_module/AttributesClassB/_type_hint_private', 'is_public': False, 'is_static': True, 'is_type_inferred': False, @@ -80,7 +80,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/attribute_module/AttributesClassB/bool_attr', + 'id': 'various_tests_package/attribute_module/AttributesClassB/bool_attr', 'is_public': True, 'is_static': True, 'is_type_inferred': False, @@ -97,7 +97,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/attribute_module/AttributesClassB/callexpr_attr_class', + 'id': 'various_tests_package/attribute_module/AttributesClassB/callexpr_attr_class', 'is_public': True, 'is_static': True, 'is_type_inferred': False, @@ -110,7 +110,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/attribute_module/AttributesClassB/callexpr_attr_function', + 'id': 'various_tests_package/attribute_module/AttributesClassB/callexpr_attr_function', 'is_public': True, 'is_static': True, 'is_type_inferred': False, @@ -123,7 +123,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/attribute_module/AttributesClassB/dict_attr_1', + 'id': 'various_tests_package/attribute_module/AttributesClassB/dict_attr_1', 'is_public': True, 'is_static': True, 'is_type_inferred': False, @@ -148,7 +148,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/attribute_module/AttributesClassB/dict_attr_2', + 'id': 'various_tests_package/attribute_module/AttributesClassB/dict_attr_2', 'is_public': True, 'is_static': True, 'is_type_inferred': False, @@ -173,7 +173,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/attribute_module/AttributesClassB/dict_attr_3', + 'id': 'various_tests_package/attribute_module/AttributesClassB/dict_attr_3', 'is_public': True, 'is_static': True, 'is_type_inferred': False, @@ -206,7 +206,7 @@ dict({ 'kind': 'NamedType', 'name': 'AttributesClassA', - 'qname': 'tests.data.test_package.attribute_module.AttributesClassA', + 'qname': 'tests.data.various_tests_package.attribute_module.AttributesClassA', }), ]), }), @@ -218,7 +218,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/attribute_module/AttributesClassB/final', + 'id': 'various_tests_package/attribute_module/AttributesClassB/final', 'is_public': True, 'is_static': True, 'is_type_inferred': False, @@ -238,7 +238,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/attribute_module/AttributesClassB/final_union', + 'id': 'various_tests_package/attribute_module/AttributesClassB/final_union', 'is_public': True, 'is_static': True, 'is_type_inferred': False, @@ -268,7 +268,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/attribute_module/AttributesClassB/finals', + 'id': 'various_tests_package/attribute_module/AttributesClassB/finals', 'is_public': True, 'is_static': True, 'is_type_inferred': False, @@ -298,7 +298,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/attribute_module/AttributesClassB/flaot_attr', + 'id': 'various_tests_package/attribute_module/AttributesClassB/flaot_attr', 'is_public': True, 'is_static': True, 'is_type_inferred': False, @@ -315,7 +315,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/attribute_module/AttributesClassB/init_attr', + 'id': 'various_tests_package/attribute_module/AttributesClassB/init_attr', 'is_public': True, 'is_static': False, 'is_type_inferred': False, @@ -332,7 +332,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/attribute_module/AttributesClassB/int_or_bool_attr', + 'id': 'various_tests_package/attribute_module/AttributesClassB/int_or_bool_attr', 'is_public': True, 'is_static': True, 'is_type_inferred': False, @@ -359,7 +359,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/attribute_module/AttributesClassB/list_attr_1', + 'id': 'various_tests_package/attribute_module/AttributesClassB/list_attr_1', 'is_public': True, 'is_static': True, 'is_type_inferred': False, @@ -376,7 +376,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/attribute_module/AttributesClassB/list_attr_2', + 'id': 'various_tests_package/attribute_module/AttributesClassB/list_attr_2', 'is_public': True, 'is_static': True, 'is_type_inferred': False, @@ -408,7 +408,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/attribute_module/AttributesClassB/list_attr_3', + 'id': 'various_tests_package/attribute_module/AttributesClassB/list_attr_3', 'is_public': True, 'is_static': True, 'is_type_inferred': False, @@ -435,7 +435,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/attribute_module/AttributesClassB/list_attr_4', + 'id': 'various_tests_package/attribute_module/AttributesClassB/list_attr_4', 'is_public': True, 'is_static': True, 'is_type_inferred': False, @@ -472,7 +472,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/attribute_module/AttributesClassB/literal', + 'id': 'various_tests_package/attribute_module/AttributesClassB/literal', 'is_public': True, 'is_static': True, 'is_type_inferred': False, @@ -488,7 +488,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/attribute_module/AttributesClassB/multi_attr_1', + 'id': 'various_tests_package/attribute_module/AttributesClassB/multi_attr_1', 'is_public': True, 'is_static': True, 'is_type_inferred': True, @@ -505,7 +505,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/attribute_module/AttributesClassB/multi_attr_3', + 'id': 'various_tests_package/attribute_module/AttributesClassB/multi_attr_3', 'is_public': True, 'is_static': True, 'is_type_inferred': True, @@ -527,7 +527,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/attribute_module/AttributesClassB/multi_attr_5', + 'id': 'various_tests_package/attribute_module/AttributesClassB/multi_attr_5', 'is_public': True, 'is_static': True, 'is_type_inferred': True, @@ -544,7 +544,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/attribute_module/AttributesClassB/multi_attr_6', + 'id': 'various_tests_package/attribute_module/AttributesClassB/multi_attr_6', 'is_public': True, 'is_static': True, 'is_type_inferred': True, @@ -561,7 +561,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/attribute_module/AttributesClassB/multi_attr_7', + 'id': 'various_tests_package/attribute_module/AttributesClassB/multi_attr_7', 'is_public': True, 'is_static': True, 'is_type_inferred': True, @@ -578,7 +578,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/attribute_module/AttributesClassB/multi_attr_8', + 'id': 'various_tests_package/attribute_module/AttributesClassB/multi_attr_8', 'is_public': True, 'is_static': True, 'is_type_inferred': True, @@ -595,7 +595,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/attribute_module/AttributesClassB/no_type_hint_public', + 'id': 'various_tests_package/attribute_module/AttributesClassB/no_type_hint_public', 'is_public': True, 'is_static': True, 'is_type_inferred': True, @@ -612,7 +612,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/attribute_module/AttributesClassB/none_attr', + 'id': 'various_tests_package/attribute_module/AttributesClassB/none_attr', 'is_public': True, 'is_static': True, 'is_type_inferred': False, @@ -629,7 +629,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/attribute_module/AttributesClassB/object_attr', + 'id': 'various_tests_package/attribute_module/AttributesClassB/object_attr', 'is_public': True, 'is_static': True, 'is_type_inferred': False, @@ -637,7 +637,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'AttributesClassA', - 'qname': 'tests.data.test_package.attribute_module.AttributesClassA', + 'qname': 'tests.data.various_tests_package.attribute_module.AttributesClassA', }), }), dict({ @@ -646,7 +646,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/attribute_module/AttributesClassB/optional', + 'id': 'various_tests_package/attribute_module/AttributesClassB/optional', 'is_public': True, 'is_static': True, 'is_type_inferred': False, @@ -673,7 +673,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/attribute_module/AttributesClassB/set_attr_1', + 'id': 'various_tests_package/attribute_module/AttributesClassB/set_attr_1', 'is_public': True, 'is_static': True, 'is_type_inferred': False, @@ -695,7 +695,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/attribute_module/AttributesClassB/set_attr_2', + 'id': 'various_tests_package/attribute_module/AttributesClassB/set_attr_2', 'is_public': True, 'is_static': True, 'is_type_inferred': False, @@ -714,7 +714,7 @@ dict({ 'kind': 'NamedType', 'name': 'AttributesClassA', - 'qname': 'tests.data.test_package.attribute_module.AttributesClassA', + 'qname': 'tests.data.various_tests_package.attribute_module.AttributesClassA', }), ]), }), @@ -727,7 +727,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/attribute_module/AttributesClassB/set_attr_3', + 'id': 'various_tests_package/attribute_module/AttributesClassB/set_attr_3', 'is_public': True, 'is_static': True, 'is_type_inferred': False, @@ -754,7 +754,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/attribute_module/AttributesClassB/set_attr_4', + 'id': 'various_tests_package/attribute_module/AttributesClassB/set_attr_4', 'is_public': True, 'is_static': True, 'is_type_inferred': False, @@ -791,7 +791,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/attribute_module/AttributesClassB/str_attr_with_none_value', + 'id': 'various_tests_package/attribute_module/AttributesClassB/str_attr_with_none_value', 'is_public': True, 'is_static': True, 'is_type_inferred': False, @@ -808,7 +808,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/attribute_module/AttributesClassB/tuple_attr_1', + 'id': 'various_tests_package/attribute_module/AttributesClassB/tuple_attr_1', 'is_public': True, 'is_static': True, 'is_type_inferred': False, @@ -830,7 +830,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/attribute_module/AttributesClassB/tuple_attr_2', + 'id': 'various_tests_package/attribute_module/AttributesClassB/tuple_attr_2', 'is_public': True, 'is_static': True, 'is_type_inferred': False, @@ -862,7 +862,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/attribute_module/AttributesClassB/tuple_attr_3', + 'id': 'various_tests_package/attribute_module/AttributesClassB/tuple_attr_3', 'is_public': True, 'is_static': True, 'is_type_inferred': False, @@ -889,7 +889,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/attribute_module/AttributesClassB/type_hint_public', + 'id': 'various_tests_package/attribute_module/AttributesClassB/type_hint_public', 'is_public': True, 'is_static': True, 'is_type_inferred': False, @@ -910,7 +910,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/class_module/ClassModuleClassD/ClassModuleNestedClassE/_nested_attr_2', + 'id': 'various_tests_package/class_module/ClassModuleClassD/ClassModuleNestedClassE/_nested_attr_2', 'is_public': False, 'is_static': True, 'is_type_inferred': False, @@ -927,7 +927,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/class_module/ClassModuleClassD/ClassModuleNestedClassE/nested_attr_1', + 'id': 'various_tests_package/class_module/ClassModuleClassD/ClassModuleNestedClassE/nested_attr_1', 'is_public': True, 'is_static': True, 'is_type_inferred': False, @@ -948,7 +948,7 @@ 'description': 'Attribute of the calculator. (Google Style)', 'type': 'str', }), - 'id': 'test_package/docstring_module/GoogleDocstringClass/attr_1', + 'id': 'various_tests_package/docstring_module/GoogleDocstringClass/attr_1', 'is_public': True, 'is_static': True, 'is_type_inferred': False, @@ -969,7 +969,7 @@ 'description': 'Attribute of the calculator. (Numpy)', 'type': 'str', }), - 'id': 'test_package/docstring_module/NumpyDocstringClass/attr_1', + 'id': 'various_tests_package/docstring_module/NumpyDocstringClass/attr_1', 'is_public': True, 'is_static': True, 'is_type_inferred': False, @@ -990,7 +990,7 @@ 'description': 'Attribute of the calculator. (ReST)', 'type': 'str', }), - 'id': 'test_package/docstring_module/RestDocstringClass/attr_1', + 'id': 'various_tests_package/docstring_module/RestDocstringClass/attr_1', 'is_public': True, 'is_static': True, 'is_type_inferred': False, @@ -1011,7 +1011,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/class_module/_ClassModulePrivateClassG/_attr_1', + 'id': 'various_tests_package/class_module/_ClassModulePrivateClassG/_attr_1', 'is_public': False, 'is_static': True, 'is_type_inferred': False, @@ -1028,7 +1028,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/class_module/_ClassModulePrivateClassG/_attr_2', + 'id': 'various_tests_package/class_module/_ClassModulePrivateClassG/_attr_2', 'is_public': False, 'is_static': True, 'is_type_inferred': False, @@ -1048,14 +1048,14 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/abstract_module/AbstractModuleClass/abstract_method', + 'id': 'various_tests_package/abstract_module/AbstractModuleClass/abstract_method', 'is_class_method': False, 'is_property': False, 'is_public': True, 'is_static': False, 'name': 'abstract_method', 'parameters': list([ - 'test_package/abstract_module/AbstractModuleClass/abstract_method/self', + 'various_tests_package/abstract_module/AbstractModuleClass/abstract_method/self', ]), 'reexported_by': list([ ]), @@ -1067,21 +1067,21 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/abstract_module/AbstractModuleClass/abstract_method_params', + 'id': 'various_tests_package/abstract_module/AbstractModuleClass/abstract_method_params', 'is_class_method': False, 'is_property': False, 'is_public': True, 'is_static': False, 'name': 'abstract_method_params', 'parameters': list([ - 'test_package/abstract_module/AbstractModuleClass/abstract_method_params/self', - 'test_package/abstract_module/AbstractModuleClass/abstract_method_params/param_1', - 'test_package/abstract_module/AbstractModuleClass/abstract_method_params/param_2', + 'various_tests_package/abstract_module/AbstractModuleClass/abstract_method_params/self', + 'various_tests_package/abstract_module/AbstractModuleClass/abstract_method_params/param_1', + 'various_tests_package/abstract_module/AbstractModuleClass/abstract_method_params/param_2', ]), 'reexported_by': list([ ]), 'results': list([ - 'test_package/abstract_module/AbstractModuleClass/abstract_method_params/result_1', + 'various_tests_package/abstract_module/AbstractModuleClass/abstract_method_params/result_1', ]), }), dict({ @@ -1089,20 +1089,20 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/abstract_module/AbstractModuleClass/abstract_property_method', + 'id': 'various_tests_package/abstract_module/AbstractModuleClass/abstract_property_method', 'is_class_method': False, 'is_property': True, 'is_public': True, 'is_static': False, 'name': 'abstract_property_method', 'parameters': list([ - 'test_package/abstract_module/AbstractModuleClass/abstract_property_method/self', + 'various_tests_package/abstract_module/AbstractModuleClass/abstract_property_method/self', ]), 'reexported_by': list([ ]), 'results': list([ - 'test_package/abstract_module/AbstractModuleClass/abstract_property_method/result_1', - 'test_package/abstract_module/AbstractModuleClass/abstract_property_method/result_2', + 'various_tests_package/abstract_module/AbstractModuleClass/abstract_property_method/result_1', + 'various_tests_package/abstract_module/AbstractModuleClass/abstract_property_method/result_2', ]), }), dict({ @@ -1110,7 +1110,7 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/abstract_module/AbstractModuleClass/abstract_static_method', + 'id': 'various_tests_package/abstract_module/AbstractModuleClass/abstract_static_method', 'is_class_method': False, 'is_property': False, 'is_public': True, @@ -1128,19 +1128,19 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/abstract_module/AbstractModuleClass/abstract_static_method_params', + 'id': 'various_tests_package/abstract_module/AbstractModuleClass/abstract_static_method_params', 'is_class_method': False, 'is_property': False, 'is_public': True, 'is_static': True, 'name': 'abstract_static_method_params', 'parameters': list([ - 'test_package/abstract_module/AbstractModuleClass/abstract_static_method_params/param', + 'various_tests_package/abstract_module/AbstractModuleClass/abstract_static_method_params/param', ]), 'reexported_by': list([ ]), 'results': list([ - 'test_package/abstract_module/AbstractModuleClass/abstract_static_method_params/result_1', + 'various_tests_package/abstract_module/AbstractModuleClass/abstract_static_method_params/result_1', ]), }), ]) @@ -1152,14 +1152,14 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/class_module/ClassModuleClassB/f', + 'id': 'various_tests_package/class_module/ClassModuleClassB/f', 'is_class_method': False, 'is_property': False, 'is_public': True, 'is_static': False, 'name': 'f', 'parameters': list([ - 'test_package/class_module/ClassModuleClassB/f/self', + 'various_tests_package/class_module/ClassModuleClassB/f/self', ]), 'reexported_by': list([ ]), @@ -1175,14 +1175,14 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/class_module/ClassModuleClassC/f1', + 'id': 'various_tests_package/class_module/ClassModuleClassC/f1', 'is_class_method': False, 'is_property': False, 'is_public': True, 'is_static': False, 'name': 'f1', 'parameters': list([ - 'test_package/class_module/ClassModuleClassC/f1/self', + 'various_tests_package/class_module/ClassModuleClassC/f1/self', ]), 'reexported_by': list([ ]), @@ -1202,14 +1202,14 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/class_module/ClassModuleClassD/ClassModuleNestedClassE/class_e_func', + 'id': 'various_tests_package/class_module/ClassModuleClassD/ClassModuleNestedClassE/class_e_func', 'is_class_method': False, 'is_property': False, 'is_public': True, 'is_static': False, 'name': 'class_e_func', 'parameters': list([ - 'test_package/class_module/ClassModuleClassD/ClassModuleNestedClassE/class_e_func/self', + 'various_tests_package/class_module/ClassModuleClassD/ClassModuleNestedClassE/class_e_func/self', ]), 'reexported_by': list([ ]), @@ -1234,21 +1234,21 @@ @rtype: bool ''', }), - 'id': 'test_package/docstring_module/EpydocDocstringClass/epydoc_docstring_func', + 'id': 'various_tests_package/docstring_module/EpydocDocstringClass/epydoc_docstring_func', 'is_class_method': False, 'is_property': False, 'is_public': True, 'is_static': False, 'name': 'epydoc_docstring_func', 'parameters': list([ - 'test_package/docstring_module/EpydocDocstringClass/epydoc_docstring_func/self', - 'test_package/docstring_module/EpydocDocstringClass/epydoc_docstring_func/x', - 'test_package/docstring_module/EpydocDocstringClass/epydoc_docstring_func/y', + 'various_tests_package/docstring_module/EpydocDocstringClass/epydoc_docstring_func/self', + 'various_tests_package/docstring_module/EpydocDocstringClass/epydoc_docstring_func/x', + 'various_tests_package/docstring_module/EpydocDocstringClass/epydoc_docstring_func/y', ]), 'reexported_by': list([ ]), 'results': list([ - 'test_package/docstring_module/EpydocDocstringClass/epydoc_docstring_func/result_1', + 'various_tests_package/docstring_module/EpydocDocstringClass/epydoc_docstring_func/result_1', ]), }), ]) @@ -1260,14 +1260,14 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/function_module/FunctionModuleClassB/class_method', + 'id': 'various_tests_package/function_module/FunctionModuleClassB/class_method', 'is_class_method': True, 'is_property': False, 'is_public': True, 'is_static': False, 'name': 'class_method', 'parameters': list([ - 'test_package/function_module/FunctionModuleClassB/class_method/cls', + 'various_tests_package/function_module/FunctionModuleClassB/class_method/cls', ]), 'reexported_by': list([ ]), @@ -1279,20 +1279,20 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/function_module/FunctionModuleClassB/class_method_params', + 'id': 'various_tests_package/function_module/FunctionModuleClassB/class_method_params', 'is_class_method': True, 'is_property': False, 'is_public': True, 'is_static': False, 'name': 'class_method_params', 'parameters': list([ - 'test_package/function_module/FunctionModuleClassB/class_method_params/cls', - 'test_package/function_module/FunctionModuleClassB/class_method_params/param_1', + 'various_tests_package/function_module/FunctionModuleClassB/class_method_params/cls', + 'various_tests_package/function_module/FunctionModuleClassB/class_method_params/param_1', ]), 'reexported_by': list([ ]), 'results': list([ - 'test_package/function_module/FunctionModuleClassB/class_method_params/result_1', + 'various_tests_package/function_module/FunctionModuleClassB/class_method_params/result_1', ]), }), dict({ @@ -1300,20 +1300,20 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/function_module/FunctionModuleClassB/instance_method', + 'id': 'various_tests_package/function_module/FunctionModuleClassB/instance_method', 'is_class_method': False, 'is_property': False, 'is_public': True, 'is_static': False, 'name': 'instance_method', 'parameters': list([ - 'test_package/function_module/FunctionModuleClassB/instance_method/self', - 'test_package/function_module/FunctionModuleClassB/instance_method/a', + 'various_tests_package/function_module/FunctionModuleClassB/instance_method/self', + 'various_tests_package/function_module/FunctionModuleClassB/instance_method/a', ]), 'reexported_by': list([ ]), 'results': list([ - 'test_package/function_module/FunctionModuleClassB/instance_method/result_1', + 'various_tests_package/function_module/FunctionModuleClassB/instance_method/result_1', ]), }), dict({ @@ -1321,7 +1321,7 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/function_module/FunctionModuleClassB/static_method', + 'id': 'various_tests_package/function_module/FunctionModuleClassB/static_method', 'is_class_method': False, 'is_property': False, 'is_public': True, @@ -1339,14 +1339,14 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/function_module/FunctionModuleClassB/static_method_params', + 'id': 'various_tests_package/function_module/FunctionModuleClassB/static_method_params', 'is_class_method': False, 'is_property': False, 'is_public': True, 'is_static': True, 'name': 'static_method_params', 'parameters': list([ - 'test_package/function_module/FunctionModuleClassB/static_method_params/param_1', + 'various_tests_package/function_module/FunctionModuleClassB/static_method_params/param_1', ]), 'reexported_by': list([ ]), @@ -1362,20 +1362,20 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/function_module/FunctionModuleClassB/FunctionModuleClassC/nested_class_function', + 'id': 'various_tests_package/function_module/FunctionModuleClassB/FunctionModuleClassC/nested_class_function', 'is_class_method': False, 'is_property': False, 'is_public': True, 'is_static': False, 'name': 'nested_class_function', 'parameters': list([ - 'test_package/function_module/FunctionModuleClassB/FunctionModuleClassC/nested_class_function/self', - 'test_package/function_module/FunctionModuleClassB/FunctionModuleClassC/nested_class_function/param1', + 'various_tests_package/function_module/FunctionModuleClassB/FunctionModuleClassC/nested_class_function/self', + 'various_tests_package/function_module/FunctionModuleClassB/FunctionModuleClassC/nested_class_function/param1', ]), 'reexported_by': list([ ]), 'results': list([ - 'test_package/function_module/FunctionModuleClassB/FunctionModuleClassC/nested_class_function/result_1', + 'various_tests_package/function_module/FunctionModuleClassB/FunctionModuleClassC/nested_class_function/result_1', ]), }), ]) @@ -1387,14 +1387,14 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/function_module/FunctionModulePropertiesClass/property_function', + 'id': 'various_tests_package/function_module/FunctionModulePropertiesClass/property_function', 'is_class_method': False, 'is_property': True, 'is_public': True, 'is_static': False, 'name': 'property_function', 'parameters': list([ - 'test_package/function_module/FunctionModulePropertiesClass/property_function/self', + 'various_tests_package/function_module/FunctionModulePropertiesClass/property_function/self', ]), 'reexported_by': list([ ]), @@ -1406,19 +1406,19 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/function_module/FunctionModulePropertiesClass/property_function_infer', + 'id': 'various_tests_package/function_module/FunctionModulePropertiesClass/property_function_infer', 'is_class_method': False, 'is_property': True, 'is_public': True, 'is_static': False, 'name': 'property_function_infer', 'parameters': list([ - 'test_package/function_module/FunctionModulePropertiesClass/property_function_infer/self', + 'various_tests_package/function_module/FunctionModulePropertiesClass/property_function_infer/self', ]), 'reexported_by': list([ ]), 'results': list([ - 'test_package/function_module/FunctionModulePropertiesClass/property_function_infer/result_1', + 'various_tests_package/function_module/FunctionModulePropertiesClass/property_function_infer/result_1', ]), }), dict({ @@ -1426,19 +1426,19 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/function_module/FunctionModulePropertiesClass/property_function_params', + 'id': 'various_tests_package/function_module/FunctionModulePropertiesClass/property_function_params', 'is_class_method': False, 'is_property': True, 'is_public': True, 'is_static': False, 'name': 'property_function_params', 'parameters': list([ - 'test_package/function_module/FunctionModulePropertiesClass/property_function_params/self', + 'various_tests_package/function_module/FunctionModulePropertiesClass/property_function_params/self', ]), 'reexported_by': list([ ]), 'results': list([ - 'test_package/function_module/FunctionModulePropertiesClass/property_function_params/result_1', + 'various_tests_package/function_module/FunctionModulePropertiesClass/property_function_params/result_1', ]), }), ]) @@ -1468,21 +1468,21 @@ a boolean value. (Google Style) ''', }), - 'id': 'test_package/docstring_module/GoogleDocstringClass/google_docstring_func', + 'id': 'various_tests_package/docstring_module/GoogleDocstringClass/google_docstring_func', 'is_class_method': False, 'is_property': False, 'is_public': True, 'is_static': False, 'name': 'google_docstring_func', 'parameters': list([ - 'test_package/docstring_module/GoogleDocstringClass/google_docstring_func/self', - 'test_package/docstring_module/GoogleDocstringClass/google_docstring_func/x', - 'test_package/docstring_module/GoogleDocstringClass/google_docstring_func/y', + 'various_tests_package/docstring_module/GoogleDocstringClass/google_docstring_func/self', + 'various_tests_package/docstring_module/GoogleDocstringClass/google_docstring_func/x', + 'various_tests_package/docstring_module/GoogleDocstringClass/google_docstring_func/y', ]), 'reexported_by': list([ ]), 'results': list([ - 'test_package/docstring_module/GoogleDocstringClass/google_docstring_func/result_1', + 'various_tests_package/docstring_module/GoogleDocstringClass/google_docstring_func/result_1', ]), }), ]) @@ -1494,22 +1494,22 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/infer_types_module/InferMyTypes/infer_function', + 'id': 'various_tests_package/infer_types_module/InferMyTypes/infer_function', 'is_class_method': False, 'is_property': False, 'is_public': True, 'is_static': True, 'name': 'infer_function', 'parameters': list([ - 'test_package/infer_types_module/InferMyTypes/infer_function/infer_param', - 'test_package/infer_types_module/InferMyTypes/infer_function/infer_param_2', + 'various_tests_package/infer_types_module/InferMyTypes/infer_function/infer_param', + 'various_tests_package/infer_types_module/InferMyTypes/infer_function/infer_param_2', ]), 'reexported_by': list([ ]), 'results': list([ - 'test_package/infer_types_module/InferMyTypes/infer_function/result_1', - 'test_package/infer_types_module/InferMyTypes/infer_function/result_2', - 'test_package/infer_types_module/InferMyTypes/infer_function/result_3', + 'various_tests_package/infer_types_module/InferMyTypes/infer_function/result_1', + 'various_tests_package/infer_types_module/InferMyTypes/infer_function/result_2', + 'various_tests_package/infer_types_module/InferMyTypes/infer_function/result_3', ]), }), ]) @@ -1541,21 +1541,21 @@ Checks if the sum of `x` and `y` is greater than 10. (Numpy) ''', }), - 'id': 'test_package/docstring_module/NumpyDocstringClass/numpy_docstring_func', + 'id': 'various_tests_package/docstring_module/NumpyDocstringClass/numpy_docstring_func', 'is_class_method': False, 'is_property': False, 'is_public': True, 'is_static': False, 'name': 'numpy_docstring_func', 'parameters': list([ - 'test_package/docstring_module/NumpyDocstringClass/numpy_docstring_func/self', - 'test_package/docstring_module/NumpyDocstringClass/numpy_docstring_func/x', - 'test_package/docstring_module/NumpyDocstringClass/numpy_docstring_func/y', + 'various_tests_package/docstring_module/NumpyDocstringClass/numpy_docstring_func/self', + 'various_tests_package/docstring_module/NumpyDocstringClass/numpy_docstring_func/x', + 'various_tests_package/docstring_module/NumpyDocstringClass/numpy_docstring_func/y', ]), 'reexported_by': list([ ]), 'results': list([ - 'test_package/docstring_module/NumpyDocstringClass/numpy_docstring_func/result_1', + 'various_tests_package/docstring_module/NumpyDocstringClass/numpy_docstring_func/result_1', ]), }), ]) @@ -1567,7 +1567,7 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/_reexport_module_1/ReexportClass/_private_class_method_of_reexported_class', + 'id': 'various_tests_package/_reexport_module_1/ReexportClass/_private_class_method_of_reexported_class', 'is_class_method': False, 'is_property': False, 'is_public': False, @@ -1576,7 +1576,7 @@ 'parameters': list([ ]), 'reexported_by': list([ - 'test_package/__init__', + 'various_tests_package/__init__', ]), 'results': list([ ]), @@ -1604,21 +1604,21 @@ :rtype: bool ''', }), - 'id': 'test_package/docstring_module/RestDocstringClass/rest_docstring_func', + 'id': 'various_tests_package/docstring_module/RestDocstringClass/rest_docstring_func', 'is_class_method': False, 'is_property': False, 'is_public': True, 'is_static': False, 'name': 'rest_docstring_func', 'parameters': list([ - 'test_package/docstring_module/RestDocstringClass/rest_docstring_func/self', - 'test_package/docstring_module/RestDocstringClass/rest_docstring_func/x', - 'test_package/docstring_module/RestDocstringClass/rest_docstring_func/y', + 'various_tests_package/docstring_module/RestDocstringClass/rest_docstring_func/self', + 'various_tests_package/docstring_module/RestDocstringClass/rest_docstring_func/x', + 'various_tests_package/docstring_module/RestDocstringClass/rest_docstring_func/y', ]), 'reexported_by': list([ ]), 'results': list([ - 'test_package/docstring_module/RestDocstringClass/rest_docstring_func/result_1', + 'various_tests_package/docstring_module/RestDocstringClass/rest_docstring_func/result_1', ]), }), ]) @@ -1630,14 +1630,14 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/class_module/ClassModuleClassD/ClassModuleNestedClassE/_ClassModulePrivateDoubleNestedClassF/_class_f_func', + 'id': 'various_tests_package/class_module/ClassModuleClassD/ClassModuleNestedClassE/_ClassModulePrivateDoubleNestedClassF/_class_f_func', 'is_class_method': False, 'is_property': False, 'is_public': False, 'is_static': False, 'name': '_class_f_func', 'parameters': list([ - 'test_package/class_module/ClassModuleClassD/ClassModuleNestedClassE/_ClassModulePrivateDoubleNestedClassF/_class_f_func/self', + 'various_tests_package/class_module/ClassModuleClassD/ClassModuleNestedClassE/_ClassModulePrivateDoubleNestedClassF/_class_f_func/self', ]), 'reexported_by': list([ ]), @@ -1657,15 +1657,15 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/abstract_module/AbstractModuleClass/__init__', + 'id': 'various_tests_package/abstract_module/AbstractModuleClass/__init__', 'is_class_method': False, 'is_property': False, 'is_public': True, 'is_static': False, 'name': '__init__', 'parameters': list([ - 'test_package/abstract_module/AbstractModuleClass/__init__/self', - 'test_package/abstract_module/AbstractModuleClass/__init__/param', + 'various_tests_package/abstract_module/AbstractModuleClass/__init__/self', + 'various_tests_package/abstract_module/AbstractModuleClass/__init__/param', ]), 'reexported_by': list([ ]), @@ -1676,14 +1676,14 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/abstract_module/AbstractModuleClass', + 'id': 'various_tests_package/abstract_module/AbstractModuleClass', 'is_public': True, 'methods': list([ - 'test_package/abstract_module/AbstractModuleClass/abstract_method', - 'test_package/abstract_module/AbstractModuleClass/abstract_method_params', - 'test_package/abstract_module/AbstractModuleClass/abstract_static_method', - 'test_package/abstract_module/AbstractModuleClass/abstract_static_method_params', - 'test_package/abstract_module/AbstractModuleClass/abstract_property_method', + 'various_tests_package/abstract_module/AbstractModuleClass/abstract_method', + 'various_tests_package/abstract_module/AbstractModuleClass/abstract_method_params', + 'various_tests_package/abstract_module/AbstractModuleClass/abstract_static_method', + 'various_tests_package/abstract_module/AbstractModuleClass/abstract_static_method_params', + 'various_tests_package/abstract_module/AbstractModuleClass/abstract_property_method', ]), 'name': 'AbstractModuleClass', 'reexported_by': list([ @@ -1706,7 +1706,7 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/_reexport_module_2/AnotherReexportClass', + 'id': 'various_tests_package/_reexport_module_2/AnotherReexportClass', 'is_public': True, 'methods': list([ ]), @@ -1730,16 +1730,16 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/class_module/ClassModuleClassB/__init__', + 'id': 'various_tests_package/class_module/ClassModuleClassB/__init__', 'is_class_method': False, 'is_property': False, 'is_public': True, 'is_static': False, 'name': '__init__', 'parameters': list([ - 'test_package/class_module/ClassModuleClassB/__init__/self', - 'test_package/class_module/ClassModuleClassB/__init__/a', - 'test_package/class_module/ClassModuleClassB/__init__/b', + 'various_tests_package/class_module/ClassModuleClassB/__init__/self', + 'various_tests_package/class_module/ClassModuleClassB/__init__/a', + 'various_tests_package/class_module/ClassModuleClassB/__init__/b', ]), 'reexported_by': list([ ]), @@ -1750,16 +1750,16 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/class_module/ClassModuleClassB', + 'id': 'various_tests_package/class_module/ClassModuleClassB', 'is_public': True, 'methods': list([ - 'test_package/class_module/ClassModuleClassB/f', + 'various_tests_package/class_module/ClassModuleClassB/f', ]), 'name': 'ClassModuleClassB', 'reexported_by': list([ ]), 'superclasses': list([ - 'tests.data.test_package.class_module.ClassModuleEmptyClassA', + 'tests.data.various_tests_package.class_module.ClassModuleEmptyClassA', ]), 'variances': list([ ]), @@ -1768,8 +1768,8 @@ # name: test_classes[ClassModuleClassC] dict({ 'attributes': list([ - 'test_package/class_module/ClassModuleClassC/attr_1', - 'test_package/class_module/ClassModuleClassC/attr_2', + 'various_tests_package/class_module/ClassModuleClassC/attr_1', + 'various_tests_package/class_module/ClassModuleClassC/attr_2', ]), 'classes': list([ ]), @@ -1778,17 +1778,17 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/class_module/ClassModuleClassC', + 'id': 'various_tests_package/class_module/ClassModuleClassC', 'is_public': True, 'methods': list([ - 'test_package/class_module/ClassModuleClassC/f1', + 'various_tests_package/class_module/ClassModuleClassC/f1', ]), 'name': 'ClassModuleClassC', 'reexported_by': list([ ]), 'superclasses': list([ - 'tests.data.test_package.class_module.ClassModuleEmptyClassA', - 'tests.data.test_package.class_module.ClassModuleClassB', + 'tests.data.various_tests_package.class_module.ClassModuleEmptyClassA', + 'tests.data.various_tests_package.class_module.ClassModuleClassB', ]), 'variances': list([ ]), @@ -1799,14 +1799,14 @@ 'attributes': list([ ]), 'classes': list([ - 'test_package/class_module/ClassModuleClassD/ClassModuleNestedClassE', + 'various_tests_package/class_module/ClassModuleClassD/ClassModuleNestedClassE', ]), 'constructor': None, 'docstring': dict({ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/class_module/ClassModuleClassD', + 'id': 'various_tests_package/class_module/ClassModuleClassD', 'is_public': True, 'methods': list([ ]), @@ -1830,7 +1830,7 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/class_module/ClassModuleEmptyClassA', + 'id': 'various_tests_package/class_module/ClassModuleEmptyClassA', 'is_public': True, 'methods': list([ ]), @@ -1846,21 +1846,21 @@ # name: test_classes[ClassModuleNestedClassE] dict({ 'attributes': list([ - 'test_package/class_module/ClassModuleClassD/ClassModuleNestedClassE/nested_attr_1', - 'test_package/class_module/ClassModuleClassD/ClassModuleNestedClassE/_nested_attr_2', + 'various_tests_package/class_module/ClassModuleClassD/ClassModuleNestedClassE/nested_attr_1', + 'various_tests_package/class_module/ClassModuleClassD/ClassModuleNestedClassE/_nested_attr_2', ]), 'classes': list([ - 'test_package/class_module/ClassModuleClassD/ClassModuleNestedClassE/_ClassModulePrivateDoubleNestedClassF', + 'various_tests_package/class_module/ClassModuleClassD/ClassModuleNestedClassE/_ClassModulePrivateDoubleNestedClassF', ]), 'constructor': None, 'docstring': dict({ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/class_module/ClassModuleClassD/ClassModuleNestedClassE', + 'id': 'various_tests_package/class_module/ClassModuleClassD/ClassModuleNestedClassE', 'is_public': True, 'methods': list([ - 'test_package/class_module/ClassModuleClassD/ClassModuleNestedClassE/class_e_func', + 'various_tests_package/class_module/ClassModuleClassD/ClassModuleNestedClassE/class_e_func', ]), 'name': 'ClassModuleNestedClassE', 'reexported_by': list([ @@ -1874,7 +1874,7 @@ # name: test_classes[EpydocDocstringClass] dict({ 'attributes': list([ - 'test_package/docstring_module/EpydocDocstringClass/attr_1', + 'various_tests_package/docstring_module/EpydocDocstringClass/attr_1', ]), 'classes': list([ ]), @@ -1883,15 +1883,15 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/docstring_module/EpydocDocstringClass/__init__', + 'id': 'various_tests_package/docstring_module/EpydocDocstringClass/__init__', 'is_class_method': False, 'is_property': False, 'is_public': True, 'is_static': False, 'name': '__init__', 'parameters': list([ - 'test_package/docstring_module/EpydocDocstringClass/__init__/self', - 'test_package/docstring_module/EpydocDocstringClass/__init__/param_1', + 'various_tests_package/docstring_module/EpydocDocstringClass/__init__/self', + 'various_tests_package/docstring_module/EpydocDocstringClass/__init__/param_1', ]), 'reexported_by': list([ ]), @@ -1909,10 +1909,10 @@ @type param_1: str ''', }), - 'id': 'test_package/docstring_module/EpydocDocstringClass', + 'id': 'various_tests_package/docstring_module/EpydocDocstringClass', 'is_public': True, 'methods': list([ - 'test_package/docstring_module/EpydocDocstringClass/epydoc_docstring_func', + 'various_tests_package/docstring_module/EpydocDocstringClass/epydoc_docstring_func', ]), 'name': 'EpydocDocstringClass', 'reexported_by': list([ @@ -1934,13 +1934,13 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/_reexport_module_4/FourthReexportClass', + 'id': 'various_tests_package/_reexport_module_4/FourthReexportClass', 'is_public': True, 'methods': list([ ]), 'name': 'FourthReexportClass', 'reexported_by': list([ - 'test_package/__init__', + 'various_tests_package/__init__', ]), 'superclasses': list([ ]), @@ -1951,7 +1951,7 @@ # name: test_classes[GoogleDocstringClass] dict({ 'attributes': list([ - 'test_package/docstring_module/GoogleDocstringClass/attr_1', + 'various_tests_package/docstring_module/GoogleDocstringClass/attr_1', ]), 'classes': list([ ]), @@ -1960,15 +1960,15 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/docstring_module/GoogleDocstringClass/__init__', + 'id': 'various_tests_package/docstring_module/GoogleDocstringClass/__init__', 'is_class_method': False, 'is_property': False, 'is_public': True, 'is_static': False, 'name': '__init__', 'parameters': list([ - 'test_package/docstring_module/GoogleDocstringClass/__init__/self', - 'test_package/docstring_module/GoogleDocstringClass/__init__/param_1', + 'various_tests_package/docstring_module/GoogleDocstringClass/__init__/self', + 'various_tests_package/docstring_module/GoogleDocstringClass/__init__/param_1', ]), 'reexported_by': list([ ]), @@ -1993,10 +1993,10 @@ param_1 (str): Parameter of the calculator. (Google Style) ''', }), - 'id': 'test_package/docstring_module/GoogleDocstringClass', + 'id': 'various_tests_package/docstring_module/GoogleDocstringClass', 'is_public': True, 'methods': list([ - 'test_package/docstring_module/GoogleDocstringClass/google_docstring_func', + 'various_tests_package/docstring_module/GoogleDocstringClass/google_docstring_func', ]), 'name': 'GoogleDocstringClass', 'reexported_by': list([ @@ -2010,13 +2010,13 @@ # name: test_classes[InferMyTypes] dict({ 'attributes': list([ - 'test_package/infer_types_module/InferMyTypes/infer_int', - 'test_package/infer_types_module/InferMyTypes/infer_float', - 'test_package/infer_types_module/InferMyTypes/infer_bool', - 'test_package/infer_types_module/InferMyTypes/infer_str', - 'test_package/infer_types_module/InferMyTypes/infer_none', - 'test_package/infer_types_module/InferMyTypes/infer_obj', - 'test_package/infer_types_module/InferMyTypes/init_infer', + 'various_tests_package/infer_types_module/InferMyTypes/infer_int', + 'various_tests_package/infer_types_module/InferMyTypes/infer_float', + 'various_tests_package/infer_types_module/InferMyTypes/infer_bool', + 'various_tests_package/infer_types_module/InferMyTypes/infer_str', + 'various_tests_package/infer_types_module/InferMyTypes/infer_none', + 'various_tests_package/infer_types_module/InferMyTypes/infer_obj', + 'various_tests_package/infer_types_module/InferMyTypes/init_infer', ]), 'classes': list([ ]), @@ -2025,15 +2025,15 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/infer_types_module/InferMyTypes/__init__', + 'id': 'various_tests_package/infer_types_module/InferMyTypes/__init__', 'is_class_method': False, 'is_property': False, 'is_public': True, 'is_static': False, 'name': '__init__', 'parameters': list([ - 'test_package/infer_types_module/InferMyTypes/__init__/self', - 'test_package/infer_types_module/InferMyTypes/__init__/init_param', + 'various_tests_package/infer_types_module/InferMyTypes/__init__/self', + 'various_tests_package/infer_types_module/InferMyTypes/__init__/init_param', ]), 'reexported_by': list([ ]), @@ -2044,10 +2044,10 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/infer_types_module/InferMyTypes', + 'id': 'various_tests_package/infer_types_module/InferMyTypes', 'is_public': True, 'methods': list([ - 'test_package/infer_types_module/InferMyTypes/infer_function', + 'various_tests_package/infer_types_module/InferMyTypes/infer_function', ]), 'name': 'InferMyTypes', 'reexported_by': list([ @@ -2061,7 +2061,7 @@ # name: test_classes[NumpyDocstringClass] dict({ 'attributes': list([ - 'test_package/docstring_module/NumpyDocstringClass/attr_1', + 'various_tests_package/docstring_module/NumpyDocstringClass/attr_1', ]), 'classes': list([ ]), @@ -2070,15 +2070,15 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/docstring_module/NumpyDocstringClass/__init__', + 'id': 'various_tests_package/docstring_module/NumpyDocstringClass/__init__', 'is_class_method': False, 'is_property': False, 'is_public': True, 'is_static': False, 'name': '__init__', 'parameters': list([ - 'test_package/docstring_module/NumpyDocstringClass/__init__/self', - 'test_package/docstring_module/NumpyDocstringClass/__init__/param_1', + 'various_tests_package/docstring_module/NumpyDocstringClass/__init__/self', + 'various_tests_package/docstring_module/NumpyDocstringClass/__init__/param_1', ]), 'reexported_by': list([ ]), @@ -2107,10 +2107,10 @@ Parameter of the calculator. (Numpy) ''', }), - 'id': 'test_package/docstring_module/NumpyDocstringClass', + 'id': 'various_tests_package/docstring_module/NumpyDocstringClass', 'is_public': True, 'methods': list([ - 'test_package/docstring_module/NumpyDocstringClass/numpy_docstring_func', + 'various_tests_package/docstring_module/NumpyDocstringClass/numpy_docstring_func', ]), 'name': 'NumpyDocstringClass', 'reexported_by': list([ @@ -2132,14 +2132,14 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/_reexport_module_1/ReexportClass', + 'id': 'various_tests_package/_reexport_module_1/ReexportClass', 'is_public': True, 'methods': list([ - 'test_package/_reexport_module_1/ReexportClass/_private_class_method_of_reexported_class', + 'various_tests_package/_reexport_module_1/ReexportClass/_private_class_method_of_reexported_class', ]), 'name': 'ReexportClass', 'reexported_by': list([ - 'test_package/__init__', + 'various_tests_package/__init__', ]), 'superclasses': list([ ]), @@ -2150,7 +2150,7 @@ # name: test_classes[RestDocstringClass] dict({ 'attributes': list([ - 'test_package/docstring_module/RestDocstringClass/attr_1', + 'various_tests_package/docstring_module/RestDocstringClass/attr_1', ]), 'classes': list([ ]), @@ -2159,15 +2159,15 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/docstring_module/RestDocstringClass/__init__', + 'id': 'various_tests_package/docstring_module/RestDocstringClass/__init__', 'is_class_method': False, 'is_property': False, 'is_public': True, 'is_static': False, 'name': '__init__', 'parameters': list([ - 'test_package/docstring_module/RestDocstringClass/__init__/self', - 'test_package/docstring_module/RestDocstringClass/__init__/param_1', + 'various_tests_package/docstring_module/RestDocstringClass/__init__/self', + 'various_tests_package/docstring_module/RestDocstringClass/__init__/param_1', ]), 'reexported_by': list([ ]), @@ -2185,10 +2185,10 @@ :type param_1: str ''', }), - 'id': 'test_package/docstring_module/RestDocstringClass', + 'id': 'various_tests_package/docstring_module/RestDocstringClass', 'is_public': True, 'methods': list([ - 'test_package/docstring_module/RestDocstringClass/rest_docstring_func', + 'various_tests_package/docstring_module/RestDocstringClass/rest_docstring_func', ]), 'name': 'RestDocstringClass', 'reexported_by': list([ @@ -2210,7 +2210,7 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/variance_module/VarianceClassAll', + 'id': 'various_tests_package/variance_module/VarianceClassAll', 'is_public': True, 'methods': list([ ]), @@ -2234,7 +2234,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'A', - 'qname': 'tests.data.test_package.variance_module.A', + 'qname': 'tests.data.various_tests_package.variance_module.A', }), 'variance_type': 'CONTRAVARIANT', }), @@ -2279,7 +2279,7 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/variance_module/VarianceClassOnlyInvariance', + 'id': 'various_tests_package/variance_module/VarianceClassOnlyInvariance', 'is_public': True, 'methods': list([ ]), @@ -2322,8 +2322,8 @@ # name: test_classes[_ClassModulePrivateClassG] dict({ 'attributes': list([ - 'test_package/class_module/_ClassModulePrivateClassG/_attr_1', - 'test_package/class_module/_ClassModulePrivateClassG/_attr_2', + 'various_tests_package/class_module/_ClassModulePrivateClassG/_attr_1', + 'various_tests_package/class_module/_ClassModulePrivateClassG/_attr_2', ]), 'classes': list([ ]), @@ -2332,7 +2332,7 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/class_module/_ClassModulePrivateClassG', + 'id': 'various_tests_package/class_module/_ClassModulePrivateClassG', 'is_public': False, 'methods': list([ ]), @@ -2356,10 +2356,10 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/class_module/ClassModuleClassD/ClassModuleNestedClassE/_ClassModulePrivateDoubleNestedClassF', + 'id': 'various_tests_package/class_module/ClassModuleClassD/ClassModuleNestedClassE/_ClassModulePrivateDoubleNestedClassF', 'is_public': False, 'methods': list([ - 'test_package/class_module/ClassModuleClassD/ClassModuleNestedClassE/_ClassModulePrivateDoubleNestedClassF/_class_f_func', + 'various_tests_package/class_module/ClassModuleClassD/ClassModuleNestedClassE/_ClassModulePrivateDoubleNestedClassF/_class_f_func', ]), 'name': '_ClassModulePrivateDoubleNestedClassF', 'reexported_by': list([ @@ -2381,13 +2381,13 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/_reexport_module_3/_ThirdReexportClass', + 'id': 'various_tests_package/_reexport_module_3/_ThirdReexportClass', 'is_public': False, 'methods': list([ ]), 'name': '_ThirdReexportClass', 'reexported_by': list([ - 'test_package/__init__', + 'various_tests_package/__init__', ]), 'superclasses': list([ ]), @@ -2398,7 +2398,7 @@ # name: test_enum_instances[EnumTest3] list([ dict({ - 'id': 'test_package/enum_module/EnumTest3/ELEVEN', + 'id': 'various_tests_package/enum_module/EnumTest3/ELEVEN', 'name': 'ELEVEN', }), ]) @@ -2406,39 +2406,39 @@ # name: test_enum_instances[EnumTest] list([ dict({ - 'id': 'test_package/enum_module/EnumTest/EIGHT', + 'id': 'various_tests_package/enum_module/EnumTest/EIGHT', 'name': 'EIGHT', }), dict({ - 'id': 'test_package/enum_module/EnumTest/FIVE', + 'id': 'various_tests_package/enum_module/EnumTest/FIVE', 'name': 'FIVE', }), dict({ - 'id': 'test_package/enum_module/EnumTest/FOUR', + 'id': 'various_tests_package/enum_module/EnumTest/FOUR', 'name': 'FOUR', }), dict({ - 'id': 'test_package/enum_module/EnumTest/NINE', + 'id': 'various_tests_package/enum_module/EnumTest/NINE', 'name': 'NINE', }), dict({ - 'id': 'test_package/enum_module/EnumTest/ONE', + 'id': 'various_tests_package/enum_module/EnumTest/ONE', 'name': 'ONE', }), dict({ - 'id': 'test_package/enum_module/EnumTest/SEVEN', + 'id': 'various_tests_package/enum_module/EnumTest/SEVEN', 'name': 'SEVEN', }), dict({ - 'id': 'test_package/enum_module/EnumTest/SIX', + 'id': 'various_tests_package/enum_module/EnumTest/SIX', 'name': 'SIX', }), dict({ - 'id': 'test_package/enum_module/EnumTest/THREE', + 'id': 'various_tests_package/enum_module/EnumTest/THREE', 'name': 'THREE', }), dict({ - 'id': 'test_package/enum_module/EnumTest/TWO', + 'id': 'various_tests_package/enum_module/EnumTest/TWO', 'name': 'TWO', }), ]) @@ -2453,9 +2453,9 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/enum_module/EnumTest2', + 'id': 'various_tests_package/enum_module/EnumTest2', 'instances': list([ - 'test_package/enum_module/EnumTest2/TEN', + 'various_tests_package/enum_module/EnumTest2/TEN', ]), 'name': 'EnumTest2', }) @@ -2466,9 +2466,9 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/enum_module/EnumTest3', + 'id': 'various_tests_package/enum_module/EnumTest3', 'instances': list([ - 'test_package/enum_module/EnumTest3/ELEVEN', + 'various_tests_package/enum_module/EnumTest3/ELEVEN', ]), 'name': 'EnumTest3', }) @@ -2487,17 +2487,17 @@ Full Docstring Description ''', }), - 'id': 'test_package/enum_module/EnumTest', + 'id': 'various_tests_package/enum_module/EnumTest', 'instances': list([ - 'test_package/enum_module/EnumTest/ONE', - 'test_package/enum_module/EnumTest/TWO', - 'test_package/enum_module/EnumTest/THREE', - 'test_package/enum_module/EnumTest/FOUR', - 'test_package/enum_module/EnumTest/FIVE', - 'test_package/enum_module/EnumTest/SIX', - 'test_package/enum_module/EnumTest/SEVEN', - 'test_package/enum_module/EnumTest/EIGHT', - 'test_package/enum_module/EnumTest/NINE', + 'various_tests_package/enum_module/EnumTest/ONE', + 'various_tests_package/enum_module/EnumTest/TWO', + 'various_tests_package/enum_module/EnumTest/THREE', + 'various_tests_package/enum_module/EnumTest/FOUR', + 'various_tests_package/enum_module/EnumTest/FIVE', + 'various_tests_package/enum_module/EnumTest/SIX', + 'various_tests_package/enum_module/EnumTest/SEVEN', + 'various_tests_package/enum_module/EnumTest/EIGHT', + 'various_tests_package/enum_module/EnumTest/NINE', ]), 'name': 'EnumTest', }) @@ -2508,7 +2508,7 @@ 'description': "Nothing's here.", 'full_docstring': "Nothing's here.", }), - 'id': 'test_package/enum_module/_ReexportedEmptyEnum', + 'id': 'various_tests_package/enum_module/_ReexportedEmptyEnum', 'instances': list([ ]), 'name': '_ReexportedEmptyEnum', @@ -2524,7 +2524,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/FunctionModuleClassB/__init__/init_param', + 'id': 'various_tests_package/function_module/FunctionModuleClassB/__init__/init_param', 'is_optional': False, 'is_type_inferred': False, 'name': 'init_param', @@ -2538,7 +2538,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/FunctionModuleClassB/__init__/self', + 'id': 'various_tests_package/function_module/FunctionModuleClassB/__init__/self', 'is_optional': False, 'is_type_inferred': False, 'name': 'self', @@ -2556,7 +2556,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/_private/a', + 'id': 'various_tests_package/function_module/_private/a', 'is_optional': False, 'is_type_inferred': False, 'name': 'a', @@ -2574,7 +2574,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/abstract_module/AbstractModuleClass/abstract_method_params/param_1', + 'id': 'various_tests_package/abstract_module/AbstractModuleClass/abstract_method_params/param_1', 'is_optional': False, 'is_type_inferred': False, 'name': 'param_1', @@ -2592,7 +2592,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/abstract_module/AbstractModuleClass/abstract_method_params/param_2', + 'id': 'various_tests_package/abstract_module/AbstractModuleClass/abstract_method_params/param_2', 'is_optional': True, 'is_type_inferred': True, 'name': 'param_2', @@ -2610,7 +2610,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/abstract_module/AbstractModuleClass/abstract_method_params/self', + 'id': 'various_tests_package/abstract_module/AbstractModuleClass/abstract_method_params/self', 'is_optional': False, 'is_type_inferred': False, 'name': 'self', @@ -2628,7 +2628,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/abstract_module/AbstractModuleClass/abstract_property_method/self', + 'id': 'various_tests_package/abstract_module/AbstractModuleClass/abstract_property_method/self', 'is_optional': False, 'is_type_inferred': False, 'name': 'self', @@ -2646,7 +2646,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/abstract_module/AbstractModuleClass/abstract_static_method_params/param', + 'id': 'various_tests_package/abstract_module/AbstractModuleClass/abstract_static_method_params/param', 'is_optional': False, 'is_type_inferred': False, 'name': 'param', @@ -2668,7 +2668,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/arg/args', + 'id': 'various_tests_package/function_module/arg/args', 'is_optional': False, 'is_type_inferred': False, 'name': 'args', @@ -2682,7 +2682,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/arg/kwargs', + 'id': 'various_tests_package/function_module/arg/kwargs', 'is_optional': False, 'is_type_inferred': False, 'name': 'kwargs', @@ -2700,7 +2700,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/args_type/args', + 'id': 'various_tests_package/function_module/args_type/args', 'is_optional': False, 'is_type_inferred': False, 'name': 'args', @@ -2723,7 +2723,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/args_type/kwargs', + 'id': 'various_tests_package/function_module/args_type/kwargs', 'is_optional': False, 'is_type_inferred': False, 'name': 'kwargs', @@ -2753,7 +2753,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/callable_type/param', + 'id': 'various_tests_package/function_module/callable_type/param', 'is_optional': False, 'is_type_inferred': False, 'name': 'param', @@ -2795,7 +2795,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/FunctionModuleClassB/class_method/cls', + 'id': 'various_tests_package/function_module/FunctionModuleClassB/class_method/cls', 'is_optional': False, 'is_type_inferred': False, 'name': 'cls', @@ -2813,7 +2813,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/FunctionModuleClassB/class_method_params/cls', + 'id': 'various_tests_package/function_module/FunctionModuleClassB/class_method_params/cls', 'is_optional': False, 'is_type_inferred': False, 'name': 'cls', @@ -2827,7 +2827,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/FunctionModuleClassB/class_method_params/param_1', + 'id': 'various_tests_package/function_module/FunctionModuleClassB/class_method_params/param_1', 'is_optional': False, 'is_type_inferred': False, 'name': 'param_1', @@ -2849,7 +2849,7 @@ 'description': 'Parameter of the calculator. (Epydoc)', 'type': 'str', }), - 'id': 'test_package/docstring_module/EpydocDocstringClass/__init__/param_1', + 'id': 'various_tests_package/docstring_module/EpydocDocstringClass/__init__/param_1', 'is_optional': False, 'is_type_inferred': False, 'name': 'param_1', @@ -2867,7 +2867,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/docstring_module/EpydocDocstringClass/__init__/self', + 'id': 'various_tests_package/docstring_module/EpydocDocstringClass/__init__/self', 'is_optional': False, 'is_type_inferred': False, 'name': 'self', @@ -2885,7 +2885,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/docstring_module/EpydocDocstringClass/epydoc_docstring_func/self', + 'id': 'various_tests_package/docstring_module/EpydocDocstringClass/epydoc_docstring_func/self', 'is_optional': False, 'is_type_inferred': False, 'name': 'self', @@ -2899,7 +2899,7 @@ 'description': 'First integer value for the calculation. (Epydoc)', 'type': 'int', }), - 'id': 'test_package/docstring_module/EpydocDocstringClass/epydoc_docstring_func/x', + 'id': 'various_tests_package/docstring_module/EpydocDocstringClass/epydoc_docstring_func/x', 'is_optional': False, 'is_type_inferred': False, 'name': 'x', @@ -2917,7 +2917,7 @@ 'description': 'Second integer value for the calculation. (Epydoc)', 'type': 'int', }), - 'id': 'test_package/docstring_module/EpydocDocstringClass/epydoc_docstring_func/y', + 'id': 'various_tests_package/docstring_module/EpydocDocstringClass/epydoc_docstring_func/y', 'is_optional': False, 'is_type_inferred': False, 'name': 'y', @@ -2939,7 +2939,7 @@ 'description': 'Parameter of the calculator. (Google Style)', 'type': 'str', }), - 'id': 'test_package/docstring_module/GoogleDocstringClass/__init__/param_1', + 'id': 'various_tests_package/docstring_module/GoogleDocstringClass/__init__/param_1', 'is_optional': False, 'is_type_inferred': False, 'name': 'param_1', @@ -2957,7 +2957,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/docstring_module/GoogleDocstringClass/__init__/self', + 'id': 'various_tests_package/docstring_module/GoogleDocstringClass/__init__/self', 'is_optional': False, 'is_type_inferred': False, 'name': 'self', @@ -2975,7 +2975,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/docstring_module/GoogleDocstringClass/google_docstring_func/self', + 'id': 'various_tests_package/docstring_module/GoogleDocstringClass/google_docstring_func/self', 'is_optional': False, 'is_type_inferred': False, 'name': 'self', @@ -2989,7 +2989,7 @@ 'description': 'First integer value for the calculation. (Google Style)', 'type': 'int', }), - 'id': 'test_package/docstring_module/GoogleDocstringClass/google_docstring_func/x', + 'id': 'various_tests_package/docstring_module/GoogleDocstringClass/google_docstring_func/x', 'is_optional': False, 'is_type_inferred': False, 'name': 'x', @@ -3007,7 +3007,7 @@ 'description': 'Second integer value for the calculation. (Google Style)', 'type': 'int', }), - 'id': 'test_package/docstring_module/GoogleDocstringClass/google_docstring_func/y', + 'id': 'various_tests_package/docstring_module/GoogleDocstringClass/google_docstring_func/y', 'is_optional': False, 'is_type_inferred': False, 'name': 'y', @@ -3029,7 +3029,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/illegal_params/_', + 'id': 'various_tests_package/function_module/illegal_params/_', 'is_optional': True, 'is_type_inferred': False, 'name': '_', @@ -3047,7 +3047,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/illegal_params/lst', + 'id': 'various_tests_package/function_module/illegal_params/lst', 'is_optional': False, 'is_type_inferred': False, 'name': 'lst', @@ -3075,7 +3075,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/illegal_params/lst_2', + 'id': 'various_tests_package/function_module/illegal_params/lst_2', 'is_optional': False, 'is_type_inferred': False, 'name': 'lst_2', @@ -3108,7 +3108,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/illegal_params/tpl', + 'id': 'various_tests_package/function_module/illegal_params/tpl', 'is_optional': False, 'is_type_inferred': False, 'name': 'tpl', @@ -3150,7 +3150,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/FunctionModuleClassB/FunctionModuleClassC/nested_class_function/param1', + 'id': 'various_tests_package/function_module/FunctionModuleClassB/FunctionModuleClassC/nested_class_function/param1', 'is_optional': False, 'is_type_inferred': False, 'name': 'param1', @@ -3168,7 +3168,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/FunctionModuleClassB/FunctionModuleClassC/nested_class_function/self', + 'id': 'various_tests_package/function_module/FunctionModuleClassB/FunctionModuleClassC/nested_class_function/self', 'is_optional': False, 'is_type_inferred': False, 'name': 'self', @@ -3186,7 +3186,7 @@ 'description': 'Parameter of the calculator. (Numpy)', 'type': 'str', }), - 'id': 'test_package/docstring_module/NumpyDocstringClass/__init__/param_1', + 'id': 'various_tests_package/docstring_module/NumpyDocstringClass/__init__/param_1', 'is_optional': False, 'is_type_inferred': False, 'name': 'param_1', @@ -3204,7 +3204,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/docstring_module/NumpyDocstringClass/__init__/self', + 'id': 'various_tests_package/docstring_module/NumpyDocstringClass/__init__/self', 'is_optional': False, 'is_type_inferred': False, 'name': 'self', @@ -3222,7 +3222,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/docstring_module/NumpyDocstringClass/numpy_docstring_func/self', + 'id': 'various_tests_package/docstring_module/NumpyDocstringClass/numpy_docstring_func/self', 'is_optional': False, 'is_type_inferred': False, 'name': 'self', @@ -3236,7 +3236,7 @@ 'description': 'First integer value for the calculation. (Numpy)', 'type': 'int', }), - 'id': 'test_package/docstring_module/NumpyDocstringClass/numpy_docstring_func/x', + 'id': 'various_tests_package/docstring_module/NumpyDocstringClass/numpy_docstring_func/x', 'is_optional': False, 'is_type_inferred': False, 'name': 'x', @@ -3254,7 +3254,7 @@ 'description': 'Second integer value for the calculation. (Numpy)', 'type': 'int', }), - 'id': 'test_package/docstring_module/NumpyDocstringClass/numpy_docstring_func/y', + 'id': 'various_tests_package/docstring_module/NumpyDocstringClass/numpy_docstring_func/y', 'is_optional': False, 'is_type_inferred': False, 'name': 'y', @@ -3276,7 +3276,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/opt_pos_only/optional', + 'id': 'various_tests_package/function_module/opt_pos_only/optional', 'is_optional': True, 'is_type_inferred': True, 'name': 'optional', @@ -3294,7 +3294,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/opt_pos_only/required', + 'id': 'various_tests_package/function_module/opt_pos_only/required', 'is_optional': False, 'is_type_inferred': False, 'name': 'required', @@ -3312,7 +3312,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/param_position/a', + 'id': 'various_tests_package/function_module/param_position/a', 'is_optional': False, 'is_type_inferred': False, 'name': 'a', @@ -3326,7 +3326,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/param_position/b', + 'id': 'various_tests_package/function_module/param_position/b', 'is_optional': False, 'is_type_inferred': False, 'name': 'b', @@ -3344,14 +3344,14 @@ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/param_position/c', + 'id': 'various_tests_package/function_module/param_position/c', 'is_optional': True, 'is_type_inferred': True, 'name': 'c', 'type': dict({ 'kind': 'NamedType', 'name': 'FunctionModuleClassA', - 'qname': 'tests.data.test_package.function_module.FunctionModuleClassA', + 'qname': 'tests.data.various_tests_package.function_module.FunctionModuleClassA', }), }), dict({ @@ -3362,7 +3362,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/param_position/d', + 'id': 'various_tests_package/function_module/param_position/d', 'is_optional': False, 'is_type_inferred': True, 'name': 'd', @@ -3376,7 +3376,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/param_position/e', + 'id': 'various_tests_package/function_module/param_position/e', 'is_optional': True, 'is_type_inferred': False, 'name': 'e', @@ -3394,7 +3394,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/param_position/self', + 'id': 'various_tests_package/function_module/param_position/self', 'is_optional': False, 'is_type_inferred': False, 'name': 'self', @@ -3412,7 +3412,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/params/any_', + 'id': 'various_tests_package/function_module/params/any_', 'is_optional': False, 'is_type_inferred': False, 'name': 'any_', @@ -3430,7 +3430,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/params/boolean', + 'id': 'various_tests_package/function_module/params/boolean', 'is_optional': False, 'is_type_inferred': False, 'name': 'boolean', @@ -3448,7 +3448,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/params/callexpr', + 'id': 'various_tests_package/function_module/params/callexpr', 'is_optional': False, 'is_type_inferred': False, 'name': 'callexpr', @@ -3462,7 +3462,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/params/dictionary', + 'id': 'various_tests_package/function_module/params/dictionary', 'is_optional': False, 'is_type_inferred': False, 'name': 'dictionary', @@ -3498,7 +3498,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/params/float_', + 'id': 'various_tests_package/function_module/params/float_', 'is_optional': False, 'is_type_inferred': False, 'name': 'float_', @@ -3516,7 +3516,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/params/integer', + 'id': 'various_tests_package/function_module/params/integer', 'is_optional': False, 'is_type_inferred': False, 'name': 'integer', @@ -3534,7 +3534,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/params/list_', + 'id': 'various_tests_package/function_module/params/list_', 'is_optional': False, 'is_type_inferred': False, 'name': 'list_', @@ -3557,7 +3557,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/params/literal', + 'id': 'various_tests_package/function_module/params/literal', 'is_optional': False, 'is_type_inferred': False, 'name': 'literal', @@ -3574,7 +3574,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/params/none', + 'id': 'various_tests_package/function_module/params/none', 'is_optional': False, 'is_type_inferred': False, 'name': 'none', @@ -3592,14 +3592,14 @@ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/params/obj', + 'id': 'various_tests_package/function_module/params/obj', 'is_optional': False, 'is_type_inferred': False, 'name': 'obj', 'type': dict({ 'kind': 'NamedType', 'name': 'FunctionModuleClassA', - 'qname': 'tests.data.test_package.function_module.FunctionModuleClassA', + 'qname': 'tests.data.various_tests_package.function_module.FunctionModuleClassA', }), }), dict({ @@ -3610,7 +3610,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/params/optional', + 'id': 'various_tests_package/function_module/params/optional', 'is_optional': False, 'is_type_inferred': False, 'name': 'optional', @@ -3638,7 +3638,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/params/set_', + 'id': 'various_tests_package/function_module/params/set_', 'is_optional': False, 'is_type_inferred': False, 'name': 'set_', @@ -3661,7 +3661,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/params/string', + 'id': 'various_tests_package/function_module/params/string', 'is_optional': False, 'is_type_inferred': False, 'name': 'string', @@ -3679,7 +3679,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/params/tuple_', + 'id': 'various_tests_package/function_module/params/tuple_', 'is_optional': False, 'is_type_inferred': False, 'name': 'tuple_', @@ -3712,7 +3712,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/params/union', + 'id': 'various_tests_package/function_module/params/union', 'is_optional': False, 'is_type_inferred': False, 'name': 'union', @@ -3748,7 +3748,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/req_name_only/optional', + 'id': 'various_tests_package/function_module/req_name_only/optional', 'is_optional': True, 'is_type_inferred': True, 'name': 'optional', @@ -3766,7 +3766,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/req_name_only/required', + 'id': 'various_tests_package/function_module/req_name_only/required', 'is_optional': False, 'is_type_inferred': False, 'name': 'required', @@ -3784,7 +3784,7 @@ 'description': 'Parameter of the calculator. (ReST)', 'type': 'str', }), - 'id': 'test_package/docstring_module/RestDocstringClass/__init__/param_1', + 'id': 'various_tests_package/docstring_module/RestDocstringClass/__init__/param_1', 'is_optional': False, 'is_type_inferred': False, 'name': 'param_1', @@ -3802,7 +3802,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/docstring_module/RestDocstringClass/__init__/self', + 'id': 'various_tests_package/docstring_module/RestDocstringClass/__init__/self', 'is_optional': False, 'is_type_inferred': False, 'name': 'self', @@ -3820,7 +3820,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/docstring_module/RestDocstringClass/rest_docstring_func/self', + 'id': 'various_tests_package/docstring_module/RestDocstringClass/rest_docstring_func/self', 'is_optional': False, 'is_type_inferred': False, 'name': 'self', @@ -3834,7 +3834,7 @@ 'description': 'First integer value for the calculation. (ReST)', 'type': 'int', }), - 'id': 'test_package/docstring_module/RestDocstringClass/rest_docstring_func/x', + 'id': 'various_tests_package/docstring_module/RestDocstringClass/rest_docstring_func/x', 'is_optional': False, 'is_type_inferred': False, 'name': 'x', @@ -3852,7 +3852,7 @@ 'description': 'Second integer value for the calculation. (ReST)', 'type': 'int', }), - 'id': 'test_package/docstring_module/RestDocstringClass/rest_docstring_func/y', + 'id': 'various_tests_package/docstring_module/RestDocstringClass/rest_docstring_func/y', 'is_optional': False, 'is_type_inferred': False, 'name': 'y', @@ -3874,7 +3874,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/special_params/bool_none_union', + 'id': 'various_tests_package/function_module/special_params/bool_none_union', 'is_optional': False, 'is_type_inferred': False, 'name': 'bool_none_union', @@ -3902,7 +3902,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/special_params/none', + 'id': 'various_tests_package/function_module/special_params/none', 'is_optional': False, 'is_type_inferred': False, 'name': 'none', @@ -3920,7 +3920,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/special_params/none_bool_int_union', + 'id': 'various_tests_package/function_module/special_params/none_bool_int_union', 'is_optional': False, 'is_type_inferred': False, 'name': 'none_bool_int_union', @@ -3953,7 +3953,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/special_params/none_bool_none_union', + 'id': 'various_tests_package/function_module/special_params/none_bool_none_union', 'is_optional': False, 'is_type_inferred': False, 'name': 'none_bool_none_union', @@ -3986,7 +3986,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/special_params/none_bool_union', + 'id': 'various_tests_package/function_module/special_params/none_bool_union', 'is_optional': False, 'is_type_inferred': False, 'name': 'none_bool_union', @@ -4014,7 +4014,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/special_params/none_list_union_none_none', + 'id': 'various_tests_package/function_module/special_params/none_list_union_none_none', 'is_optional': False, 'is_type_inferred': False, 'name': 'none_list_union_none_none', @@ -4062,7 +4062,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/special_params/none_none_bool_none_union', + 'id': 'various_tests_package/function_module/special_params/none_none_bool_none_union', 'is_optional': False, 'is_type_inferred': False, 'name': 'none_none_bool_none_union', @@ -4100,7 +4100,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/special_params/none_union', + 'id': 'various_tests_package/function_module/special_params/none_union', 'is_optional': False, 'is_type_inferred': False, 'name': 'none_union', @@ -4132,7 +4132,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/FunctionModuleClassB/static_method_params/param_1', + 'id': 'various_tests_package/function_module/FunctionModuleClassB/static_method_params/param_1', 'is_optional': False, 'is_type_inferred': False, 'name': 'param_1', @@ -4151,7 +4151,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/abstract_module/AbstractModuleClass/abstract_method_params/result_1', + 'id': 'various_tests_package/abstract_module/AbstractModuleClass/abstract_method_params/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ @@ -4179,7 +4179,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/abstract_module/AbstractModuleClass/abstract_property_method/result_1', + 'id': 'various_tests_package/abstract_module/AbstractModuleClass/abstract_property_method/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ @@ -4193,7 +4193,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/abstract_module/AbstractModuleClass/abstract_property_method/result_2', + 'id': 'various_tests_package/abstract_module/AbstractModuleClass/abstract_property_method/result_2', 'is_type_inferred': False, 'name': 'result_2', 'type': dict({ @@ -4211,7 +4211,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/abstract_module/AbstractModuleClass/abstract_static_method_params/result_1', + 'id': 'various_tests_package/abstract_module/AbstractModuleClass/abstract_static_method_params/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ @@ -4229,7 +4229,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/any_results/result_1', + 'id': 'various_tests_package/function_module/any_results/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ @@ -4247,7 +4247,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/callable_type/result_1', + 'id': 'various_tests_package/function_module/callable_type/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ @@ -4288,7 +4288,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/FunctionModuleClassB/class_method_params/result_1', + 'id': 'various_tests_package/function_module/FunctionModuleClassB/class_method_params/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ @@ -4306,7 +4306,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/dictionary_results/result_1', + 'id': 'various_tests_package/function_module/dictionary_results/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ @@ -4319,7 +4319,7 @@ 'value_type': dict({ 'kind': 'NamedType', 'name': 'FunctionModuleClassA', - 'qname': 'tests.data.test_package.function_module.FunctionModuleClassA', + 'qname': 'tests.data.various_tests_package.function_module.FunctionModuleClassA', }), }), }), @@ -4332,7 +4332,7 @@ 'description': 'Checks if the sum of x and y is greater than 10. (Epydoc)', 'type': 'bool', }), - 'id': 'test_package/docstring_module/EpydocDocstringClass/epydoc_docstring_func/result_1', + 'id': 'various_tests_package/docstring_module/EpydocDocstringClass/epydoc_docstring_func/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ @@ -4350,7 +4350,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/float_result/result_1', + 'id': 'various_tests_package/function_module/float_result/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ @@ -4371,7 +4371,7 @@ ''', 'type': 'bool', }), - 'id': 'test_package/docstring_module/GoogleDocstringClass/google_docstring_func/result_1', + 'id': 'various_tests_package/docstring_module/GoogleDocstringClass/google_docstring_func/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ @@ -4389,7 +4389,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/illegal_dictionary_results/result_1', + 'id': 'various_tests_package/function_module/illegal_dictionary_results/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ @@ -4415,7 +4415,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/illegal_list_results/result_1', + 'id': 'various_tests_package/function_module/illegal_list_results/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ @@ -4443,7 +4443,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/illegal_set_results/result_1', + 'id': 'various_tests_package/function_module/illegal_set_results/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ @@ -4471,7 +4471,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/infer_types_module/InferMyTypes/infer_function/result_1', + 'id': 'various_tests_package/infer_types_module/InferMyTypes/infer_function/result_1', 'is_type_inferred': True, 'name': 'result_1', 'type': dict({ @@ -4490,22 +4490,22 @@ dict({ 'kind': 'NamedType', 'name': 'InferMe', - 'qname': 'tests.data.test_package.infer_types_module.InferMe', + 'qname': 'tests.data.various_tests_package.infer_types_module.InferMe', }), dict({ 'kind': 'NamedType', 'name': 'InferMe2', - 'qname': 'tests.data.test_package.infer_types_module.InferMe2', + 'qname': 'tests.data.various_tests_package.infer_types_module.InferMe2', }), dict({ 'kind': 'NamedType', 'name': 'InferMe3', - 'qname': 'tests.data.test_package.infer_types_module.InferMe3', + 'qname': 'tests.data.various_tests_package.infer_types_module.InferMe3', }), dict({ 'kind': 'NamedType', 'name': 'InferMyTypes', - 'qname': 'tests.data.test_package.infer_types_module.InferMyTypes', + 'qname': 'tests.data.various_tests_package.infer_types_module.InferMyTypes', }), dict({ 'kind': 'NamedType', @@ -4535,7 +4535,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/infer_types_module/InferMyTypes/infer_function/result_2', + 'id': 'various_tests_package/infer_types_module/InferMyTypes/infer_function/result_2', 'is_type_inferred': True, 'name': 'result_2', 'type': dict({ @@ -4559,7 +4559,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/infer_types_module/InferMyTypes/infer_function/result_3', + 'id': 'various_tests_package/infer_types_module/InferMyTypes/infer_function/result_3', 'is_type_inferred': True, 'name': 'result_3', 'type': dict({ @@ -4577,13 +4577,13 @@ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/FunctionModuleClassB/instance_method/result_1', + 'id': 'various_tests_package/function_module/FunctionModuleClassB/instance_method/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ 'kind': 'NamedType', 'name': 'FunctionModuleClassA', - 'qname': 'tests.data.test_package.function_module.FunctionModuleClassA', + 'qname': 'tests.data.various_tests_package.function_module.FunctionModuleClassA', }), }), ]) @@ -4595,7 +4595,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/int_result/result_1', + 'id': 'various_tests_package/function_module/int_result/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ @@ -4613,7 +4613,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/list_results/result_1', + 'id': 'various_tests_package/function_module/list_results/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ @@ -4636,7 +4636,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/literal_results/result_1', + 'id': 'various_tests_package/function_module/literal_results/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ @@ -4653,7 +4653,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/FunctionModuleClassB/FunctionModuleClassC/nested_class_function/result_1', + 'id': 'various_tests_package/function_module/FunctionModuleClassB/FunctionModuleClassC/nested_class_function/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ @@ -4675,7 +4675,7 @@ 'description': 'Checks if the sum of `x` and `y` is greater than 10. (Numpy)', 'type': 'bool', }), - 'id': 'test_package/docstring_module/NumpyDocstringClass/numpy_docstring_func/result_1', + 'id': 'various_tests_package/docstring_module/NumpyDocstringClass/numpy_docstring_func/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ @@ -4693,13 +4693,13 @@ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/obj_result/result_1', + 'id': 'various_tests_package/function_module/obj_result/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ 'kind': 'NamedType', 'name': 'FunctionModuleClassA', - 'qname': 'tests.data.test_package.function_module.FunctionModuleClassA', + 'qname': 'tests.data.various_tests_package.function_module.FunctionModuleClassA', }), }), ]) @@ -4711,7 +4711,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/optional_results/result_1', + 'id': 'various_tests_package/function_module/optional_results/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ @@ -4743,7 +4743,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/FunctionModulePropertiesClass/property_function_infer/result_1', + 'id': 'various_tests_package/function_module/FunctionModulePropertiesClass/property_function_infer/result_1', 'is_type_inferred': True, 'name': 'result_1', 'type': dict({ @@ -4761,7 +4761,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/FunctionModulePropertiesClass/property_function_params/result_1', + 'id': 'various_tests_package/function_module/FunctionModulePropertiesClass/property_function_params/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ @@ -4779,7 +4779,7 @@ 'description': 'Checks if the sum of x and y is greater than 10. (ReST)', 'type': 'bool', }), - 'id': 'test_package/docstring_module/RestDocstringClass/rest_docstring_func/result_1', + 'id': 'various_tests_package/docstring_module/RestDocstringClass/rest_docstring_func/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ @@ -4797,7 +4797,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/set_results/result_1', + 'id': 'various_tests_package/function_module/set_results/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ @@ -4824,7 +4824,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/str_result/result_1', + 'id': 'various_tests_package/function_module/str_result/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ @@ -4842,7 +4842,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/tuple_results/result_1', + 'id': 'various_tests_package/function_module/tuple_results/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ @@ -4856,13 +4856,13 @@ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/tuple_results/result_2', + 'id': 'various_tests_package/function_module/tuple_results/result_2', 'is_type_inferred': False, 'name': 'result_2', 'type': dict({ 'kind': 'NamedType', 'name': 'FunctionModuleClassA', - 'qname': 'tests.data.test_package.function_module.FunctionModuleClassA', + 'qname': 'tests.data.various_tests_package.function_module.FunctionModuleClassA', }), }), ]) @@ -4874,7 +4874,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/union_dictionary_results/result_1', + 'id': 'various_tests_package/function_module/union_dictionary_results/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ @@ -4920,7 +4920,7 @@ 'description': '', 'type': '', }), - 'id': 'test_package/function_module/union_results/result_1', + 'id': 'various_tests_package/function_module/union_results/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ @@ -4948,7 +4948,7 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/_reexport_module_1/reexported_function', + 'id': 'various_tests_package/_reexport_module_1/reexported_function', 'is_class_method': False, 'is_property': False, 'is_public': False, @@ -4970,7 +4970,7 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/_reexport_module_2/reexported_function_2', + 'id': 'various_tests_package/_reexport_module_2/reexported_function_2', 'is_class_method': False, 'is_property': False, 'is_public': True, @@ -4979,7 +4979,7 @@ 'parameters': list([ ]), 'reexported_by': list([ - 'test_package/__init__', + 'various_tests_package/__init__', ]), 'results': list([ ]), @@ -4993,7 +4993,7 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/_reexport_module_3/reexported_function_3', + 'id': 'various_tests_package/_reexport_module_3/reexported_function_3', 'is_class_method': False, 'is_property': False, 'is_public': False, @@ -5002,7 +5002,7 @@ 'parameters': list([ ]), 'reexported_by': list([ - 'test_package/__init__', + 'various_tests_package/__init__', ]), 'results': list([ ]), @@ -5016,7 +5016,7 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/_reexport_module_4/_reexported_function_4', + 'id': 'various_tests_package/_reexport_module_4/_reexported_function_4', 'is_class_method': False, 'is_property': False, 'is_public': False, @@ -5025,7 +5025,7 @@ 'parameters': list([ ]), 'reexported_by': list([ - 'test_package/__init__', + 'various_tests_package/__init__', ]), 'results': list([ ]), @@ -5035,7 +5035,7 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/_reexport_module_4/_unreexported_function', + 'id': 'various_tests_package/_reexport_module_4/_unreexported_function', 'is_class_method': False, 'is_property': False, 'is_public': False, @@ -5057,14 +5057,14 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/function_module/_private', + 'id': 'various_tests_package/function_module/_private', 'is_class_method': False, 'is_property': False, 'is_public': False, 'is_static': False, 'name': '_private', 'parameters': list([ - 'test_package/function_module/_private/a', + 'various_tests_package/function_module/_private/a', ]), 'reexported_by': list([ ]), @@ -5076,7 +5076,7 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/function_module/any_results', + 'id': 'various_tests_package/function_module/any_results', 'is_class_method': False, 'is_property': False, 'is_public': True, @@ -5087,7 +5087,7 @@ 'reexported_by': list([ ]), 'results': list([ - 'test_package/function_module/any_results/result_1', + 'various_tests_package/function_module/any_results/result_1', ]), }), dict({ @@ -5095,15 +5095,15 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/function_module/arg', + 'id': 'various_tests_package/function_module/arg', 'is_class_method': False, 'is_property': False, 'is_public': True, 'is_static': False, 'name': 'arg', 'parameters': list([ - 'test_package/function_module/arg/args', - 'test_package/function_module/arg/kwargs', + 'various_tests_package/function_module/arg/args', + 'various_tests_package/function_module/arg/kwargs', ]), 'reexported_by': list([ ]), @@ -5115,15 +5115,15 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/function_module/args_type', + 'id': 'various_tests_package/function_module/args_type', 'is_class_method': False, 'is_property': False, 'is_public': True, 'is_static': False, 'name': 'args_type', 'parameters': list([ - 'test_package/function_module/args_type/args', - 'test_package/function_module/args_type/kwargs', + 'various_tests_package/function_module/args_type/args', + 'various_tests_package/function_module/args_type/kwargs', ]), 'reexported_by': list([ ]), @@ -5135,7 +5135,7 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/function_module/bool_result', + 'id': 'various_tests_package/function_module/bool_result', 'is_class_method': False, 'is_property': False, 'is_public': True, @@ -5146,7 +5146,7 @@ 'reexported_by': list([ ]), 'results': list([ - 'test_package/function_module/bool_result/result_1', + 'various_tests_package/function_module/bool_result/result_1', ]), }), dict({ @@ -5154,19 +5154,19 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/function_module/callable_type', + 'id': 'various_tests_package/function_module/callable_type', 'is_class_method': False, 'is_property': False, 'is_public': True, 'is_static': False, 'name': 'callable_type', 'parameters': list([ - 'test_package/function_module/callable_type/param', + 'various_tests_package/function_module/callable_type/param', ]), 'reexported_by': list([ ]), 'results': list([ - 'test_package/function_module/callable_type/result_1', + 'various_tests_package/function_module/callable_type/result_1', ]), }), dict({ @@ -5174,7 +5174,7 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/function_module/callexr_result_class', + 'id': 'various_tests_package/function_module/callexr_result_class', 'is_class_method': False, 'is_property': False, 'is_public': True, @@ -5192,7 +5192,7 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/function_module/callexr_result_function', + 'id': 'various_tests_package/function_module/callexr_result_function', 'is_class_method': False, 'is_property': False, 'is_public': True, @@ -5210,7 +5210,7 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/function_module/dictionary_results', + 'id': 'various_tests_package/function_module/dictionary_results', 'is_class_method': False, 'is_property': False, 'is_public': True, @@ -5221,7 +5221,7 @@ 'reexported_by': list([ ]), 'results': list([ - 'test_package/function_module/dictionary_results/result_1', + 'various_tests_package/function_module/dictionary_results/result_1', ]), }), dict({ @@ -5229,7 +5229,7 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/function_module/float_result', + 'id': 'various_tests_package/function_module/float_result', 'is_class_method': False, 'is_property': False, 'is_public': True, @@ -5240,7 +5240,7 @@ 'reexported_by': list([ ]), 'results': list([ - 'test_package/function_module/float_result/result_1', + 'various_tests_package/function_module/float_result/result_1', ]), }), dict({ @@ -5248,7 +5248,7 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/function_module/illegal_dictionary_results', + 'id': 'various_tests_package/function_module/illegal_dictionary_results', 'is_class_method': False, 'is_property': False, 'is_public': True, @@ -5259,7 +5259,7 @@ 'reexported_by': list([ ]), 'results': list([ - 'test_package/function_module/illegal_dictionary_results/result_1', + 'various_tests_package/function_module/illegal_dictionary_results/result_1', ]), }), dict({ @@ -5267,7 +5267,7 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/function_module/illegal_list_results', + 'id': 'various_tests_package/function_module/illegal_list_results', 'is_class_method': False, 'is_property': False, 'is_public': True, @@ -5278,7 +5278,7 @@ 'reexported_by': list([ ]), 'results': list([ - 'test_package/function_module/illegal_list_results/result_1', + 'various_tests_package/function_module/illegal_list_results/result_1', ]), }), dict({ @@ -5286,17 +5286,17 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/function_module/illegal_params', + 'id': 'various_tests_package/function_module/illegal_params', 'is_class_method': False, 'is_property': False, 'is_public': True, 'is_static': False, 'name': 'illegal_params', 'parameters': list([ - 'test_package/function_module/illegal_params/lst', - 'test_package/function_module/illegal_params/lst_2', - 'test_package/function_module/illegal_params/tpl', - 'test_package/function_module/illegal_params/_', + 'various_tests_package/function_module/illegal_params/lst', + 'various_tests_package/function_module/illegal_params/lst_2', + 'various_tests_package/function_module/illegal_params/tpl', + 'various_tests_package/function_module/illegal_params/_', ]), 'reexported_by': list([ ]), @@ -5308,7 +5308,7 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/function_module/illegal_set_results', + 'id': 'various_tests_package/function_module/illegal_set_results', 'is_class_method': False, 'is_property': False, 'is_public': True, @@ -5319,7 +5319,7 @@ 'reexported_by': list([ ]), 'results': list([ - 'test_package/function_module/illegal_set_results/result_1', + 'various_tests_package/function_module/illegal_set_results/result_1', ]), }), dict({ @@ -5327,7 +5327,7 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/function_module/int_result', + 'id': 'various_tests_package/function_module/int_result', 'is_class_method': False, 'is_property': False, 'is_public': True, @@ -5338,7 +5338,7 @@ 'reexported_by': list([ ]), 'results': list([ - 'test_package/function_module/int_result/result_1', + 'various_tests_package/function_module/int_result/result_1', ]), }), dict({ @@ -5346,7 +5346,7 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/function_module/list_results', + 'id': 'various_tests_package/function_module/list_results', 'is_class_method': False, 'is_property': False, 'is_public': True, @@ -5357,7 +5357,7 @@ 'reexported_by': list([ ]), 'results': list([ - 'test_package/function_module/list_results/result_1', + 'various_tests_package/function_module/list_results/result_1', ]), }), dict({ @@ -5365,7 +5365,7 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/function_module/literal_results', + 'id': 'various_tests_package/function_module/literal_results', 'is_class_method': False, 'is_property': False, 'is_public': True, @@ -5376,7 +5376,7 @@ 'reexported_by': list([ ]), 'results': list([ - 'test_package/function_module/literal_results/result_1', + 'various_tests_package/function_module/literal_results/result_1', ]), }), dict({ @@ -5384,7 +5384,7 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/function_module/none_result', + 'id': 'various_tests_package/function_module/none_result', 'is_class_method': False, 'is_property': False, 'is_public': True, @@ -5402,7 +5402,7 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/function_module/obj_result', + 'id': 'various_tests_package/function_module/obj_result', 'is_class_method': False, 'is_property': False, 'is_public': True, @@ -5413,7 +5413,7 @@ 'reexported_by': list([ ]), 'results': list([ - 'test_package/function_module/obj_result/result_1', + 'various_tests_package/function_module/obj_result/result_1', ]), }), dict({ @@ -5421,15 +5421,15 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/function_module/opt_pos_only', + 'id': 'various_tests_package/function_module/opt_pos_only', 'is_class_method': False, 'is_property': False, 'is_public': True, 'is_static': False, 'name': 'opt_pos_only', 'parameters': list([ - 'test_package/function_module/opt_pos_only/required', - 'test_package/function_module/opt_pos_only/optional', + 'various_tests_package/function_module/opt_pos_only/required', + 'various_tests_package/function_module/opt_pos_only/optional', ]), 'reexported_by': list([ ]), @@ -5441,7 +5441,7 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/function_module/optional_results', + 'id': 'various_tests_package/function_module/optional_results', 'is_class_method': False, 'is_property': False, 'is_public': True, @@ -5452,7 +5452,7 @@ 'reexported_by': list([ ]), 'results': list([ - 'test_package/function_module/optional_results/result_1', + 'various_tests_package/function_module/optional_results/result_1', ]), }), dict({ @@ -5460,19 +5460,19 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/function_module/param_position', + 'id': 'various_tests_package/function_module/param_position', 'is_class_method': False, 'is_property': False, 'is_public': True, 'is_static': False, 'name': 'param_position', 'parameters': list([ - 'test_package/function_module/param_position/self', - 'test_package/function_module/param_position/a', - 'test_package/function_module/param_position/b', - 'test_package/function_module/param_position/c', - 'test_package/function_module/param_position/d', - 'test_package/function_module/param_position/e', + 'various_tests_package/function_module/param_position/self', + 'various_tests_package/function_module/param_position/a', + 'various_tests_package/function_module/param_position/b', + 'various_tests_package/function_module/param_position/c', + 'various_tests_package/function_module/param_position/d', + 'various_tests_package/function_module/param_position/e', ]), 'reexported_by': list([ ]), @@ -5484,28 +5484,28 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/function_module/params', + 'id': 'various_tests_package/function_module/params', 'is_class_method': False, 'is_property': False, 'is_public': True, 'is_static': False, 'name': 'params', 'parameters': list([ - 'test_package/function_module/params/integer', - 'test_package/function_module/params/boolean', - 'test_package/function_module/params/float_', - 'test_package/function_module/params/none', - 'test_package/function_module/params/string', - 'test_package/function_module/params/obj', - 'test_package/function_module/params/callexpr', - 'test_package/function_module/params/union', - 'test_package/function_module/params/list_', - 'test_package/function_module/params/dictionary', - 'test_package/function_module/params/set_', - 'test_package/function_module/params/optional', - 'test_package/function_module/params/tuple_', - 'test_package/function_module/params/literal', - 'test_package/function_module/params/any_', + 'various_tests_package/function_module/params/integer', + 'various_tests_package/function_module/params/boolean', + 'various_tests_package/function_module/params/float_', + 'various_tests_package/function_module/params/none', + 'various_tests_package/function_module/params/string', + 'various_tests_package/function_module/params/obj', + 'various_tests_package/function_module/params/callexpr', + 'various_tests_package/function_module/params/union', + 'various_tests_package/function_module/params/list_', + 'various_tests_package/function_module/params/dictionary', + 'various_tests_package/function_module/params/set_', + 'various_tests_package/function_module/params/optional', + 'various_tests_package/function_module/params/tuple_', + 'various_tests_package/function_module/params/literal', + 'various_tests_package/function_module/params/any_', ]), 'reexported_by': list([ ]), @@ -5517,7 +5517,7 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/function_module/public_no_params_no_result', + 'id': 'various_tests_package/function_module/public_no_params_no_result', 'is_class_method': False, 'is_property': False, 'is_public': True, @@ -5535,15 +5535,15 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/function_module/req_name_only', + 'id': 'various_tests_package/function_module/req_name_only', 'is_class_method': False, 'is_property': False, 'is_public': True, 'is_static': False, 'name': 'req_name_only', 'parameters': list([ - 'test_package/function_module/req_name_only/required', - 'test_package/function_module/req_name_only/optional', + 'various_tests_package/function_module/req_name_only/required', + 'various_tests_package/function_module/req_name_only/optional', ]), 'reexported_by': list([ ]), @@ -5555,7 +5555,7 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/function_module/set_results', + 'id': 'various_tests_package/function_module/set_results', 'is_class_method': False, 'is_property': False, 'is_public': True, @@ -5566,7 +5566,7 @@ 'reexported_by': list([ ]), 'results': list([ - 'test_package/function_module/set_results/result_1', + 'various_tests_package/function_module/set_results/result_1', ]), }), dict({ @@ -5574,21 +5574,21 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/function_module/special_params', + 'id': 'various_tests_package/function_module/special_params', 'is_class_method': False, 'is_property': False, 'is_public': True, 'is_static': False, 'name': 'special_params', 'parameters': list([ - 'test_package/function_module/special_params/none_union', - 'test_package/function_module/special_params/none_bool_union', - 'test_package/function_module/special_params/bool_none_union', - 'test_package/function_module/special_params/none_bool_none_union', - 'test_package/function_module/special_params/none_bool_int_union', - 'test_package/function_module/special_params/none_none_bool_none_union', - 'test_package/function_module/special_params/none_list_union_none_none', - 'test_package/function_module/special_params/none', + 'various_tests_package/function_module/special_params/none_union', + 'various_tests_package/function_module/special_params/none_bool_union', + 'various_tests_package/function_module/special_params/bool_none_union', + 'various_tests_package/function_module/special_params/none_bool_none_union', + 'various_tests_package/function_module/special_params/none_bool_int_union', + 'various_tests_package/function_module/special_params/none_none_bool_none_union', + 'various_tests_package/function_module/special_params/none_list_union_none_none', + 'various_tests_package/function_module/special_params/none', ]), 'reexported_by': list([ ]), @@ -5600,7 +5600,7 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/function_module/str_result', + 'id': 'various_tests_package/function_module/str_result', 'is_class_method': False, 'is_property': False, 'is_public': True, @@ -5611,7 +5611,7 @@ 'reexported_by': list([ ]), 'results': list([ - 'test_package/function_module/str_result/result_1', + 'various_tests_package/function_module/str_result/result_1', ]), }), dict({ @@ -5619,7 +5619,7 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/function_module/tuple_results', + 'id': 'various_tests_package/function_module/tuple_results', 'is_class_method': False, 'is_property': False, 'is_public': True, @@ -5630,8 +5630,8 @@ 'reexported_by': list([ ]), 'results': list([ - 'test_package/function_module/tuple_results/result_1', - 'test_package/function_module/tuple_results/result_2', + 'various_tests_package/function_module/tuple_results/result_1', + 'various_tests_package/function_module/tuple_results/result_2', ]), }), dict({ @@ -5639,7 +5639,7 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/function_module/union_dictionary_results', + 'id': 'various_tests_package/function_module/union_dictionary_results', 'is_class_method': False, 'is_property': False, 'is_public': True, @@ -5650,7 +5650,7 @@ 'reexported_by': list([ ]), 'results': list([ - 'test_package/function_module/union_dictionary_results/result_1', + 'various_tests_package/function_module/union_dictionary_results/result_1', ]), }), dict({ @@ -5658,7 +5658,7 @@ 'description': '', 'full_docstring': '', }), - 'id': 'test_package/function_module/union_results', + 'id': 'various_tests_package/function_module/union_results', 'is_class_method': False, 'is_property': False, 'is_public': True, @@ -5669,7 +5669,7 @@ 'reexported_by': list([ ]), 'results': list([ - 'test_package/function_module/union_results/result_1', + 'various_tests_package/function_module/union_results/result_1', ]), }), ]) @@ -5765,7 +5765,7 @@ ]), 'functions': list([ ]), - 'id': 'test_package/__init__', + 'id': 'various_tests_package/__init__', 'name': '__init__', 'qualified_imports': list([ dict({ @@ -5803,7 +5803,7 @@ # name: test_modules[another_module] dict({ 'classes': list([ - 'test_package/another_path/another_module/AnotherClass', + 'various_tests_package/another_path/another_module/AnotherClass', ]), 'docstring': ''' Another Module Docstring. @@ -5815,7 +5815,7 @@ ]), 'functions': list([ ]), - 'id': 'test_package/another_path/another_module', + 'id': 'various_tests_package/another_path/another_module', 'name': 'another_module', 'qualified_imports': list([ ]), @@ -5826,18 +5826,18 @@ # name: test_modules[class_module] dict({ 'classes': list([ - 'test_package/class_module/ClassModuleEmptyClassA', - 'test_package/class_module/ClassModuleClassB', - 'test_package/class_module/ClassModuleClassC', - 'test_package/class_module/ClassModuleClassD', - 'test_package/class_module/_ClassModulePrivateClassG', + 'various_tests_package/class_module/ClassModuleEmptyClassA', + 'various_tests_package/class_module/ClassModuleClassB', + 'various_tests_package/class_module/ClassModuleClassC', + 'various_tests_package/class_module/ClassModuleClassD', + 'various_tests_package/class_module/_ClassModulePrivateClassG', ]), 'docstring': '', 'enums': list([ ]), 'functions': list([ ]), - 'id': 'test_package/class_module', + 'id': 'various_tests_package/class_module', 'name': 'class_module', 'qualified_imports': list([ ]), @@ -5848,10 +5848,10 @@ # name: test_modules[docstring_module] dict({ 'classes': list([ - 'test_package/docstring_module/EpydocDocstringClass', - 'test_package/docstring_module/RestDocstringClass', - 'test_package/docstring_module/NumpyDocstringClass', - 'test_package/docstring_module/GoogleDocstringClass', + 'various_tests_package/docstring_module/EpydocDocstringClass', + 'various_tests_package/docstring_module/RestDocstringClass', + 'various_tests_package/docstring_module/NumpyDocstringClass', + 'various_tests_package/docstring_module/GoogleDocstringClass', ]), 'docstring': ''' Test module for docstring tests. @@ -5863,7 +5863,7 @@ ]), 'functions': list([ ]), - 'id': 'test_package/docstring_module', + 'id': 'various_tests_package/docstring_module', 'name': 'docstring_module', 'qualified_imports': list([ ]), @@ -5877,15 +5877,15 @@ ]), 'docstring': '', 'enums': list([ - 'test_package/enum_module/_ReexportedEmptyEnum', - 'test_package/enum_module/EnumTest', - 'test_package/enum_module/EnumTest2', - 'test_package/enum_module/EnumTest3', - 'test_package/enum_module/EmptyEnum', + 'various_tests_package/enum_module/_ReexportedEmptyEnum', + 'various_tests_package/enum_module/EnumTest', + 'various_tests_package/enum_module/EnumTest2', + 'various_tests_package/enum_module/EnumTest3', + 'various_tests_package/enum_module/EmptyEnum', ]), 'functions': list([ ]), - 'id': 'test_package/enum_module', + 'id': 'various_tests_package/enum_module', 'name': 'enum_module', 'qualified_imports': list([ dict({ diff --git a/tests/safeds_stubgen/api_analyzer/test__get_api.py b/tests/safeds_stubgen/api_analyzer/test__get_api.py index 2f990c1f..39f6dc78 100644 --- a/tests/safeds_stubgen/api_analyzer/test__get_api.py +++ b/tests/safeds_stubgen/api_analyzer/test__get_api.py @@ -12,7 +12,7 @@ # Setup: API data _test_dir = Path(__file__).parent.parent.parent -_test_package_name = "test_package" +_test_package_name = "various_tests_package" api_data_paintext = get_api( package_name=_test_package_name, diff --git a/tests/safeds_stubgen/docstring_parsing/test_epydoc_parser.py b/tests/safeds_stubgen/docstring_parsing/test_epydoc_parser.py index 954a4dc9..0a001ff0 100644 --- a/tests/safeds_stubgen/docstring_parsing/test_epydoc_parser.py +++ b/tests/safeds_stubgen/docstring_parsing/test_epydoc_parser.py @@ -22,10 +22,10 @@ _test_dir = Path(__file__).parent.parent.parent mypy_file = _get_mypy_ast( files=[ - str(Path(_test_dir / "data" / "test_docstring_parser_package" / "test_epydoc.py")), + str(Path(_test_dir / "data" / "docstring_parser_package" / "epydoc.py")), ], package_paths=[], - root=Path(_test_dir / "data" / "test_docstring_parser_package"), + root=Path(_test_dir / "data" / "docstring_parser_package"), )[0] diff --git a/tests/safeds_stubgen/docstring_parsing/test_get_full_docstring.py b/tests/safeds_stubgen/docstring_parsing/test_get_full_docstring.py index fcbbe0ff..9db26201 100644 --- a/tests/safeds_stubgen/docstring_parsing/test_get_full_docstring.py +++ b/tests/safeds_stubgen/docstring_parsing/test_get_full_docstring.py @@ -17,10 +17,10 @@ _test_dir = Path(__file__).parent.parent.parent mypy_file = _get_mypy_ast( files=[ - str(Path(_test_dir / "data" / "test_docstring_parser_package" / "test_full_docstring.py")), + str(Path(_test_dir / "data" / "docstring_parser_package" / "full_docstring.py")), ], package_paths=[], - root=Path(_test_dir / "data" / "test_docstring_parser_package"), + root=Path(_test_dir / "data" / "docstring_parser_package"), )[0] diff --git a/tests/safeds_stubgen/docstring_parsing/test_googledoc_parser.py b/tests/safeds_stubgen/docstring_parsing/test_googledoc_parser.py index a4255b2d..e8d95a2a 100644 --- a/tests/safeds_stubgen/docstring_parsing/test_googledoc_parser.py +++ b/tests/safeds_stubgen/docstring_parsing/test_googledoc_parser.py @@ -25,10 +25,10 @@ _test_dir = Path(__file__).parent.parent.parent mypy_file = _get_mypy_ast( files=[ - str(Path(_test_dir / "data" / "test_docstring_parser_package" / "test_googledoc.py")), + str(Path(_test_dir / "data" / "docstring_parser_package" / "googledoc.py")), ], package_paths=[], - root=Path(_test_dir / "data" / "test_docstring_parser_package"), + root=Path(_test_dir / "data" / "docstring_parser_package"), )[0] diff --git a/tests/safeds_stubgen/docstring_parsing/test_numpydoc_parser.py b/tests/safeds_stubgen/docstring_parsing/test_numpydoc_parser.py index ff2ac332..f517c668 100644 --- a/tests/safeds_stubgen/docstring_parsing/test_numpydoc_parser.py +++ b/tests/safeds_stubgen/docstring_parsing/test_numpydoc_parser.py @@ -23,10 +23,10 @@ # Setup _test_dir = Path(__file__).parent.parent.parent -_test_package_name = "test_docstring_parser_package" +_test_package_name = "docstring_parser_package" mypy_file = _get_mypy_ast( files=[ - str(Path(_test_dir / "data" / _test_package_name / "test_numpydoc.py")), + str(Path(_test_dir / "data" / _test_package_name / "numpydoc.py")), ], package_paths=[], root=Path(_test_dir / "data" / _test_package_name), diff --git a/tests/safeds_stubgen/docstring_parsing/test_plaintext_docstring_parser.py b/tests/safeds_stubgen/docstring_parsing/test_plaintext_docstring_parser.py index 709d428e..87a93c31 100644 --- a/tests/safeds_stubgen/docstring_parsing/test_plaintext_docstring_parser.py +++ b/tests/safeds_stubgen/docstring_parsing/test_plaintext_docstring_parser.py @@ -24,10 +24,10 @@ _test_dir = Path(__file__).parent.parent.parent mypy_file = _get_mypy_ast( files=[ - str(Path(_test_dir / "data" / "test_docstring_parser_package" / "test_plaintext.py")), + str(Path(_test_dir / "data" / "docstring_parser_package" / "plaintext.py")), ], package_paths=[], - root=Path(_test_dir / "data" / "test_docstring_parser_package"), + root=Path(_test_dir / "data" / "docstring_parser_package"), )[0] diff --git a/tests/safeds_stubgen/docstring_parsing/test_restdoc_parser.py b/tests/safeds_stubgen/docstring_parsing/test_restdoc_parser.py index cdd35229..8f8fff51 100644 --- a/tests/safeds_stubgen/docstring_parsing/test_restdoc_parser.py +++ b/tests/safeds_stubgen/docstring_parsing/test_restdoc_parser.py @@ -22,10 +22,10 @@ _test_dir = Path(__file__).parent.parent.parent mypy_file = _get_mypy_ast( files=[ - str(Path(_test_dir / "data" / "test_docstring_parser_package" / "test_restdoc.py")), + str(Path(_test_dir / "data" / "docstring_parser_package" / "restdoc.py")), ], package_paths=[], - root=Path(_test_dir / "data" / "test_docstring_parser_package"), + root=Path(_test_dir / "data" / "docstring_parser_package"), )[0] diff --git a/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr b/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr index d29bc7b8..7ff8ddaa 100644 --- a/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr +++ b/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr @@ -1,8 +1,8 @@ # serializer version: 1 # name: test_abstract_creation ''' - @PythonModule("test_package.abstract_module") - package testPackage.abstractModule + @PythonModule("various_tests_package.abstract_module") + package variousTestsPackage.abstractModule from abc import ABC from abc import abstractmethod @@ -39,8 +39,8 @@ # --- # name: test_class_attribute_creation ''' - @PythonModule("test_package.attribute_module") - package testPackage.attributeModule + @PythonModule("various_tests_package.attribute_module") + package variousTestsPackage.attributeModule from typing import Optional from typing import Final @@ -136,8 +136,8 @@ # --- # name: test_class_creation ''' - @PythonModule("test_package.class_module") - package testPackage.classModule + @PythonModule("various_tests_package.class_module") + package variousTestsPackage.classModule class ClassModuleEmptyClassA() @@ -181,8 +181,8 @@ # --- # name: test_enum_creation ''' - @PythonModule("test_package.enum_module") - package testPackage.enumModule + @PythonModule("various_tests_package.enum_module") + package variousTestsPackage.enumModule from another_path.another_module import AnotherClass as _AcImportAlias @@ -214,8 +214,8 @@ # --- # name: test_function_creation ''' - @PythonModule("test_package.function_module") - package testPackage.functionModule + @PythonModule("various_tests_package.function_module") + package variousTestsPackage.functionModule from typing import Callable from typing import Optional @@ -476,8 +476,8 @@ # --- # name: test_import_creation ''' - @PythonModule("test_package.import_module") - package testPackage.importModule + @PythonModule("various_tests_package.import_module") + package variousTestsPackage.importModule import mypy as `static` @@ -487,8 +487,8 @@ # --- # name: test_type_inference ''' - @PythonModule("test_package.infer_types_module") - package testPackage.inferTypesModule + @PythonModule("various_tests_package.infer_types_module") + package variousTestsPackage.inferTypesModule class InferMe() @@ -527,8 +527,8 @@ # --- # name: test_variance_creation ''' - @PythonModule("test_package.variance_module") - package testPackage.varianceModule + @PythonModule("various_tests_package.variance_module") + package variousTestsPackage.varianceModule from typing import Generic from typing import TypeVar diff --git a/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py b/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py index e45996e1..1c51e88f 100644 --- a/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py +++ b/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py @@ -15,7 +15,7 @@ # Setup - Run API to create stub files _lib_dir = Path(__file__).parent.parent.parent -_test_package_name = "test_package" +_test_package_name = "various_tests_package" _test_package_dir = Path(_lib_dir / "data" / _test_package_name) _out_dir = Path(_lib_dir / "data" / "out") _out_dir_stubs = Path(_out_dir / _test_package_name) diff --git a/tests/safeds_stubgen/test_main.py b/tests/safeds_stubgen/test_main.py index 2079e46f..0016547d 100644 --- a/tests/safeds_stubgen/test_main.py +++ b/tests/safeds_stubgen/test_main.py @@ -7,7 +7,7 @@ from syrupy import SnapshotAssertion _lib_dir = Path(__file__).parent.parent.parent -_test_package_name = "test_main" +_test_package_name = "main_package" _main_dir = Path(_lib_dir / "src" / "main.py") _test_package_dir = Path(_lib_dir / "tests" / "data" / _test_package_name) _out_dir = Path(_lib_dir / "tests" / "data" / "out") From 71090e43683eec0de6a5fa1ff2cd4a27e4772ee9 Mon Sep 17 00:00:00 2001 From: Arsam Date: Thu, 30 Nov 2023 17:16:20 +0100 Subject: [PATCH 074/109] Changed test data directory and file names, since the GitHub test runner has problems with directories and files beginning with "test" but without actual test functions. --- .../{main_test_module.py => main_module.py} | 0 .../__init__.py | 0 .../_reexport_module_1.py | 0 .../_reexport_module_2.py | 0 .../_reexport_module_3.py | 0 .../_reexport_module_4.py | 0 .../abstract_module.py | 0 .../another_path/another_module.py | 0 .../attribute_module.py | 0 .../class_module.py | 0 .../docstring_module.py | 0 .../enum_module.py | 0 .../file_creation}/__init__.py | 0 .../file_creation}/_module_2.py | 0 .../file_creation}/_module_3.py | 0 .../file_creation}/_module_4.py | 0 .../file_creation}/_module_6.py | 0 .../file_creation}/module_1.py | 0 .../file_creation}/package_1/module_5.py | 0 .../function_module.py | 0 .../import_module.py | 0 .../infer_types_module.py | 0 .../variance_module.py | 0 .../__snapshots__/test_main.ambr | 148 +-- .../__snapshots__/test__get_api.ambr | 948 +++++++++--------- .../api_analyzer/test__get_api.py | 2 +- .../__snapshots__/test_generate_stubs.ambr | 32 +- .../stubs_generator/test_generate_stubs.py | 6 +- 28 files changed, 568 insertions(+), 568 deletions(-) rename tests/data/main_package/{main_test_module.py => main_module.py} (100%) rename tests/data/{various_tests_package => various_modules_package}/__init__.py (100%) rename tests/data/{various_tests_package => various_modules_package}/_reexport_module_1.py (100%) rename tests/data/{various_tests_package => various_modules_package}/_reexport_module_2.py (100%) rename tests/data/{various_tests_package => various_modules_package}/_reexport_module_3.py (100%) rename tests/data/{various_tests_package => various_modules_package}/_reexport_module_4.py (100%) rename tests/data/{various_tests_package => various_modules_package}/abstract_module.py (100%) rename tests/data/{various_tests_package => various_modules_package}/another_path/another_module.py (100%) rename tests/data/{various_tests_package => various_modules_package}/attribute_module.py (100%) rename tests/data/{various_tests_package => various_modules_package}/class_module.py (100%) rename tests/data/{various_tests_package => various_modules_package}/docstring_module.py (100%) rename tests/data/{various_tests_package => various_modules_package}/enum_module.py (100%) rename tests/data/{various_tests_package/test_file_creation => various_modules_package/file_creation}/__init__.py (100%) rename tests/data/{various_tests_package/test_file_creation => various_modules_package/file_creation}/_module_2.py (100%) rename tests/data/{various_tests_package/test_file_creation => various_modules_package/file_creation}/_module_3.py (100%) rename tests/data/{various_tests_package/test_file_creation => various_modules_package/file_creation}/_module_4.py (100%) rename tests/data/{various_tests_package/test_file_creation => various_modules_package/file_creation}/_module_6.py (100%) rename tests/data/{various_tests_package/test_file_creation => various_modules_package/file_creation}/module_1.py (100%) rename tests/data/{various_tests_package/test_file_creation => various_modules_package/file_creation}/package_1/module_5.py (100%) rename tests/data/{various_tests_package => various_modules_package}/function_module.py (100%) rename tests/data/{various_tests_package => various_modules_package}/import_module.py (100%) rename tests/data/{various_tests_package => various_modules_package}/infer_types_module.py (100%) rename tests/data/{various_tests_package => various_modules_package}/variance_module.py (100%) diff --git a/tests/data/main_package/main_test_module.py b/tests/data/main_package/main_module.py similarity index 100% rename from tests/data/main_package/main_test_module.py rename to tests/data/main_package/main_module.py diff --git a/tests/data/various_tests_package/__init__.py b/tests/data/various_modules_package/__init__.py similarity index 100% rename from tests/data/various_tests_package/__init__.py rename to tests/data/various_modules_package/__init__.py diff --git a/tests/data/various_tests_package/_reexport_module_1.py b/tests/data/various_modules_package/_reexport_module_1.py similarity index 100% rename from tests/data/various_tests_package/_reexport_module_1.py rename to tests/data/various_modules_package/_reexport_module_1.py diff --git a/tests/data/various_tests_package/_reexport_module_2.py b/tests/data/various_modules_package/_reexport_module_2.py similarity index 100% rename from tests/data/various_tests_package/_reexport_module_2.py rename to tests/data/various_modules_package/_reexport_module_2.py diff --git a/tests/data/various_tests_package/_reexport_module_3.py b/tests/data/various_modules_package/_reexport_module_3.py similarity index 100% rename from tests/data/various_tests_package/_reexport_module_3.py rename to tests/data/various_modules_package/_reexport_module_3.py diff --git a/tests/data/various_tests_package/_reexport_module_4.py b/tests/data/various_modules_package/_reexport_module_4.py similarity index 100% rename from tests/data/various_tests_package/_reexport_module_4.py rename to tests/data/various_modules_package/_reexport_module_4.py diff --git a/tests/data/various_tests_package/abstract_module.py b/tests/data/various_modules_package/abstract_module.py similarity index 100% rename from tests/data/various_tests_package/abstract_module.py rename to tests/data/various_modules_package/abstract_module.py diff --git a/tests/data/various_tests_package/another_path/another_module.py b/tests/data/various_modules_package/another_path/another_module.py similarity index 100% rename from tests/data/various_tests_package/another_path/another_module.py rename to tests/data/various_modules_package/another_path/another_module.py diff --git a/tests/data/various_tests_package/attribute_module.py b/tests/data/various_modules_package/attribute_module.py similarity index 100% rename from tests/data/various_tests_package/attribute_module.py rename to tests/data/various_modules_package/attribute_module.py diff --git a/tests/data/various_tests_package/class_module.py b/tests/data/various_modules_package/class_module.py similarity index 100% rename from tests/data/various_tests_package/class_module.py rename to tests/data/various_modules_package/class_module.py diff --git a/tests/data/various_tests_package/docstring_module.py b/tests/data/various_modules_package/docstring_module.py similarity index 100% rename from tests/data/various_tests_package/docstring_module.py rename to tests/data/various_modules_package/docstring_module.py diff --git a/tests/data/various_tests_package/enum_module.py b/tests/data/various_modules_package/enum_module.py similarity index 100% rename from tests/data/various_tests_package/enum_module.py rename to tests/data/various_modules_package/enum_module.py diff --git a/tests/data/various_tests_package/test_file_creation/__init__.py b/tests/data/various_modules_package/file_creation/__init__.py similarity index 100% rename from tests/data/various_tests_package/test_file_creation/__init__.py rename to tests/data/various_modules_package/file_creation/__init__.py diff --git a/tests/data/various_tests_package/test_file_creation/_module_2.py b/tests/data/various_modules_package/file_creation/_module_2.py similarity index 100% rename from tests/data/various_tests_package/test_file_creation/_module_2.py rename to tests/data/various_modules_package/file_creation/_module_2.py diff --git a/tests/data/various_tests_package/test_file_creation/_module_3.py b/tests/data/various_modules_package/file_creation/_module_3.py similarity index 100% rename from tests/data/various_tests_package/test_file_creation/_module_3.py rename to tests/data/various_modules_package/file_creation/_module_3.py diff --git a/tests/data/various_tests_package/test_file_creation/_module_4.py b/tests/data/various_modules_package/file_creation/_module_4.py similarity index 100% rename from tests/data/various_tests_package/test_file_creation/_module_4.py rename to tests/data/various_modules_package/file_creation/_module_4.py diff --git a/tests/data/various_tests_package/test_file_creation/_module_6.py b/tests/data/various_modules_package/file_creation/_module_6.py similarity index 100% rename from tests/data/various_tests_package/test_file_creation/_module_6.py rename to tests/data/various_modules_package/file_creation/_module_6.py diff --git a/tests/data/various_tests_package/test_file_creation/module_1.py b/tests/data/various_modules_package/file_creation/module_1.py similarity index 100% rename from tests/data/various_tests_package/test_file_creation/module_1.py rename to tests/data/various_modules_package/file_creation/module_1.py diff --git a/tests/data/various_tests_package/test_file_creation/package_1/module_5.py b/tests/data/various_modules_package/file_creation/package_1/module_5.py similarity index 100% rename from tests/data/various_tests_package/test_file_creation/package_1/module_5.py rename to tests/data/various_modules_package/file_creation/package_1/module_5.py diff --git a/tests/data/various_tests_package/function_module.py b/tests/data/various_modules_package/function_module.py similarity index 100% rename from tests/data/various_tests_package/function_module.py rename to tests/data/various_modules_package/function_module.py diff --git a/tests/data/various_tests_package/import_module.py b/tests/data/various_modules_package/import_module.py similarity index 100% rename from tests/data/various_tests_package/import_module.py rename to tests/data/various_modules_package/import_module.py diff --git a/tests/data/various_tests_package/infer_types_module.py b/tests/data/various_modules_package/infer_types_module.py similarity index 100% rename from tests/data/various_tests_package/infer_types_module.py rename to tests/data/various_modules_package/infer_types_module.py diff --git a/tests/data/various_tests_package/variance_module.py b/tests/data/various_modules_package/variance_module.py similarity index 100% rename from tests/data/various_tests_package/variance_module.py rename to tests/data/various_modules_package/variance_module.py diff --git a/tests/safeds_stubgen/__snapshots__/test_main.ambr b/tests/safeds_stubgen/__snapshots__/test_main.ambr index 08167861..90fcc10f 100644 --- a/tests/safeds_stubgen/__snapshots__/test_main.ambr +++ b/tests/safeds_stubgen/__snapshots__/test_main.ambr @@ -8,7 +8,7 @@ 'description': '', 'type': '', }), - 'id': 'main_package/main_test_module/ModuleClass/_init_attr_private', + 'id': 'main_package/main_module/ModuleClass/_init_attr_private', 'is_public': False, 'is_static': False, 'is_type_inferred': False, @@ -25,7 +25,7 @@ 'description': '', 'type': '', }), - 'id': 'main_package/main_test_module/ModuleClass/attr_1', + 'id': 'main_package/main_module/ModuleClass/attr_1', 'is_public': True, 'is_static': True, 'is_type_inferred': False, @@ -42,7 +42,7 @@ 'description': '', 'type': '', }), - 'id': 'main_package/main_test_module/ModuleClass/init_attr', + 'id': 'main_package/main_module/ModuleClass/init_attr', 'is_public': True, 'is_static': False, 'is_type_inferred': False, @@ -59,7 +59,7 @@ 'description': '', 'type': '', }), - 'id': 'main_package/main_test_module/_PrivateClass/NestedPrivateClass/nested_class_attr', + 'id': 'main_package/main_module/_PrivateClass/NestedPrivateClass/nested_class_attr', 'is_public': False, 'is_static': True, 'is_type_inferred': True, @@ -76,7 +76,7 @@ 'description': '', 'type': '', }), - 'id': 'main_package/main_test_module/_PrivateClass/public_attr_in_private_class', + 'id': 'main_package/main_module/_PrivateClass/public_attr_in_private_class', 'is_public': False, 'is_static': True, 'is_type_inferred': True, @@ -93,7 +93,7 @@ 'description': '', 'type': '', }), - 'id': 'main_package/main_test_module/_PrivateClass/public_init_attr_in_private_class', + 'id': 'main_package/main_module/_PrivateClass/public_init_attr_in_private_class', 'is_public': False, 'is_static': False, 'is_type_inferred': False, @@ -130,12 +130,12 @@ }), dict({ 'attributes': list([ - 'main_package/main_test_module/ModuleClass/attr_1', - 'main_package/main_test_module/ModuleClass/init_attr', - 'main_package/main_test_module/ModuleClass/_init_attr_private', + 'main_package/main_module/ModuleClass/attr_1', + 'main_package/main_module/ModuleClass/init_attr', + 'main_package/main_module/ModuleClass/_init_attr_private', ]), 'classes': list([ - 'main_package/main_test_module/ModuleClass/NestedClass', + 'main_package/main_module/ModuleClass/NestedClass', ]), 'constructor': dict({ 'docstring': dict({ @@ -150,15 +150,15 @@ Full init description. ''', }), - 'id': 'main_package/main_test_module/ModuleClass/__init__', + 'id': 'main_package/main_module/ModuleClass/__init__', 'is_class_method': False, 'is_property': False, 'is_public': True, 'is_static': False, 'name': '__init__', 'parameters': list([ - 'main_package/main_test_module/ModuleClass/__init__/self', - 'main_package/main_test_module/ModuleClass/__init__/init_param_1', + 'main_package/main_module/ModuleClass/__init__/self', + 'main_package/main_module/ModuleClass/__init__/init_param_1', ]), 'reexported_by': list([ ]), @@ -177,16 +177,16 @@ Full description ''', }), - 'id': 'main_package/main_test_module/ModuleClass', + 'id': 'main_package/main_module/ModuleClass', 'is_public': True, 'methods': list([ - 'main_package/main_test_module/ModuleClass/_some_function', + 'main_package/main_module/ModuleClass/_some_function', ]), 'name': 'ModuleClass', 'reexported_by': list([ ]), 'superclasses': list([ - 'tests.data.main_package.main_test_module.AcDoubleAlias', + 'tests.data.main_package.main_module.AcDoubleAlias', ]), 'variances': list([ ]), @@ -201,10 +201,10 @@ 'description': '', 'full_docstring': '', }), - 'id': 'main_package/main_test_module/ModuleClass/NestedClass', + 'id': 'main_package/main_module/ModuleClass/NestedClass', 'is_public': True, 'methods': list([ - 'main_package/main_test_module/ModuleClass/NestedClass/nested_class_function', + 'main_package/main_module/ModuleClass/NestedClass/nested_class_function', ]), 'name': 'NestedClass', 'reexported_by': list([ @@ -217,25 +217,25 @@ }), dict({ 'attributes': list([ - 'main_package/main_test_module/_PrivateClass/public_attr_in_private_class', - 'main_package/main_test_module/_PrivateClass/public_init_attr_in_private_class', + 'main_package/main_module/_PrivateClass/public_attr_in_private_class', + 'main_package/main_module/_PrivateClass/public_init_attr_in_private_class', ]), 'classes': list([ - 'main_package/main_test_module/_PrivateClass/NestedPrivateClass', + 'main_package/main_module/_PrivateClass/NestedPrivateClass', ]), 'constructor': dict({ 'docstring': dict({ 'description': '', 'full_docstring': '', }), - 'id': 'main_package/main_test_module/_PrivateClass/__init__', + 'id': 'main_package/main_module/_PrivateClass/__init__', 'is_class_method': False, 'is_property': False, 'is_public': False, 'is_static': False, 'name': '__init__', 'parameters': list([ - 'main_package/main_test_module/_PrivateClass/__init__/self', + 'main_package/main_module/_PrivateClass/__init__/self', ]), 'reexported_by': list([ ]), @@ -246,10 +246,10 @@ 'description': '', 'full_docstring': '', }), - 'id': 'main_package/main_test_module/_PrivateClass', + 'id': 'main_package/main_module/_PrivateClass', 'is_public': False, 'methods': list([ - 'main_package/main_test_module/_PrivateClass/public_func_in_private_class', + 'main_package/main_module/_PrivateClass/public_func_in_private_class', ]), 'name': '_PrivateClass', 'reexported_by': list([ @@ -261,20 +261,20 @@ }), dict({ 'attributes': list([ - 'main_package/main_test_module/_PrivateClass/NestedPrivateClass/nested_class_attr', + 'main_package/main_module/_PrivateClass/NestedPrivateClass/nested_class_attr', ]), 'classes': list([ - 'main_package/main_test_module/_PrivateClass/NestedPrivateClass/NestedNestedPrivateClass', + 'main_package/main_module/_PrivateClass/NestedPrivateClass/NestedNestedPrivateClass', ]), 'constructor': None, 'docstring': dict({ 'description': '', 'full_docstring': '', }), - 'id': 'main_package/main_test_module/_PrivateClass/NestedPrivateClass', + 'id': 'main_package/main_module/_PrivateClass/NestedPrivateClass', 'is_public': True, 'methods': list([ - 'main_package/main_test_module/_PrivateClass/NestedPrivateClass/static_nested_private_class_function', + 'main_package/main_module/_PrivateClass/NestedPrivateClass/static_nested_private_class_function', ]), 'name': 'NestedPrivateClass', 'reexported_by': list([ @@ -294,7 +294,7 @@ 'description': '', 'full_docstring': '', }), - 'id': 'main_package/main_test_module/_PrivateClass/NestedPrivateClass/NestedNestedPrivateClass', + 'id': 'main_package/main_module/_PrivateClass/NestedPrivateClass/NestedNestedPrivateClass', 'is_public': True, 'methods': list([ ]), @@ -318,20 +318,20 @@ 'description': '', 'full_docstring': '', }), - 'id': 'main_package/main_test_module/ModuleClass/NestedClass/nested_class_function', + 'id': 'main_package/main_module/ModuleClass/NestedClass/nested_class_function', 'is_class_method': False, 'is_property': False, 'is_public': True, 'is_static': False, 'name': 'nested_class_function', 'parameters': list([ - 'main_package/main_test_module/ModuleClass/NestedClass/nested_class_function/self', - 'main_package/main_test_module/ModuleClass/NestedClass/nested_class_function/param_1', + 'main_package/main_module/ModuleClass/NestedClass/nested_class_function/self', + 'main_package/main_module/ModuleClass/NestedClass/nested_class_function/param_1', ]), 'reexported_by': list([ ]), 'results': list([ - 'main_package/main_test_module/ModuleClass/NestedClass/nested_class_function/result_1', + 'main_package/main_module/ModuleClass/NestedClass/nested_class_function/result_1', ]), }), dict({ @@ -347,15 +347,15 @@ Full init description. ''', }), - 'id': 'main_package/main_test_module/ModuleClass/__init__', + 'id': 'main_package/main_module/ModuleClass/__init__', 'is_class_method': False, 'is_property': False, 'is_public': True, 'is_static': False, 'name': '__init__', 'parameters': list([ - 'main_package/main_test_module/ModuleClass/__init__/self', - 'main_package/main_test_module/ModuleClass/__init__/init_param_1', + 'main_package/main_module/ModuleClass/__init__/self', + 'main_package/main_module/ModuleClass/__init__/init_param_1', ]), 'reexported_by': list([ ]), @@ -375,21 +375,21 @@ param_2: bool. ''', }), - 'id': 'main_package/main_test_module/ModuleClass/_some_function', + 'id': 'main_package/main_module/ModuleClass/_some_function', 'is_class_method': False, 'is_property': False, 'is_public': False, 'is_static': False, 'name': '_some_function', 'parameters': list([ - 'main_package/main_test_module/ModuleClass/_some_function/self', - 'main_package/main_test_module/ModuleClass/_some_function/param_1', - 'main_package/main_test_module/ModuleClass/_some_function/param_2', + 'main_package/main_module/ModuleClass/_some_function/self', + 'main_package/main_module/ModuleClass/_some_function/param_1', + 'main_package/main_module/ModuleClass/_some_function/param_2', ]), 'reexported_by': list([ ]), 'results': list([ - 'main_package/main_test_module/ModuleClass/_some_function/result_1', + 'main_package/main_module/ModuleClass/_some_function/result_1', ]), }), dict({ @@ -397,7 +397,7 @@ 'description': '', 'full_docstring': '', }), - 'id': 'main_package/main_test_module/_PrivateClass/NestedPrivateClass/static_nested_private_class_function', + 'id': 'main_package/main_module/_PrivateClass/NestedPrivateClass/static_nested_private_class_function', 'is_class_method': False, 'is_property': False, 'is_public': False, @@ -415,14 +415,14 @@ 'description': '', 'full_docstring': '', }), - 'id': 'main_package/main_test_module/_PrivateClass/__init__', + 'id': 'main_package/main_module/_PrivateClass/__init__', 'is_class_method': False, 'is_property': False, 'is_public': False, 'is_static': False, 'name': '__init__', 'parameters': list([ - 'main_package/main_test_module/_PrivateClass/__init__/self', + 'main_package/main_module/_PrivateClass/__init__/self', ]), 'reexported_by': list([ ]), @@ -434,14 +434,14 @@ 'description': '', 'full_docstring': '', }), - 'id': 'main_package/main_test_module/_PrivateClass/public_func_in_private_class', + 'id': 'main_package/main_module/_PrivateClass/public_func_in_private_class', 'is_class_method': False, 'is_property': False, 'is_public': False, 'is_static': False, 'name': 'public_func_in_private_class', 'parameters': list([ - 'main_package/main_test_module/_PrivateClass/public_func_in_private_class/self', + 'main_package/main_module/_PrivateClass/public_func_in_private_class/self', ]), 'reexported_by': list([ ]), @@ -453,7 +453,7 @@ 'description': '', 'full_docstring': '', }), - 'id': 'main_package/main_test_module/_private_global_func', + 'id': 'main_package/main_module/_private_global_func', 'is_class_method': False, 'is_property': False, 'is_public': False, @@ -464,7 +464,7 @@ 'reexported_by': list([ ]), 'results': list([ - 'main_package/main_test_module/_private_global_func/result_1', + 'main_package/main_module/_private_global_func/result_1', ]), }), dict({ @@ -480,20 +480,20 @@ Docstring 2. ''', }), - 'id': 'main_package/main_test_module/global_func', + 'id': 'main_package/main_module/global_func', 'is_class_method': False, 'is_property': False, 'is_public': True, 'is_static': False, 'name': 'global_func', 'parameters': list([ - 'main_package/main_test_module/global_func/main_test_param_1', - 'main_package/main_test_module/global_func/main_test_param_2', + 'main_package/main_module/global_func/main_test_param_1', + 'main_package/main_module/global_func/main_test_param_2', ]), 'reexported_by': list([ ]), 'results': list([ - 'main_package/main_test_module/global_func/result_1', + 'main_package/main_module/global_func/result_1', ]), }), ]), @@ -521,18 +521,18 @@ }), dict({ 'classes': list([ - 'main_package/main_test_module/ModuleClass', - 'main_package/main_test_module/_PrivateClass', + 'main_package/main_module/ModuleClass', + 'main_package/main_module/_PrivateClass', ]), 'docstring': 'Docstring of the some_class.py module.', 'enums': list([ ]), 'functions': list([ - 'main_package/main_test_module/global_func', - 'main_package/main_test_module/_private_global_func', + 'main_package/main_module/global_func', + 'main_package/main_module/_private_global_func', ]), - 'id': 'main_package/main_test_module', - 'name': 'main_test_module', + 'id': 'main_package/main_module', + 'name': 'main_module', 'qualified_imports': list([ dict({ 'alias': 'mathematics', @@ -568,7 +568,7 @@ 'description': '', 'type': '', }), - 'id': 'main_package/main_test_module/ModuleClass/NestedClass/nested_class_function/param_1', + 'id': 'main_package/main_module/ModuleClass/NestedClass/nested_class_function/param_1', 'is_optional': False, 'is_type_inferred': False, 'name': 'param_1', @@ -586,7 +586,7 @@ 'description': '', 'type': '', }), - 'id': 'main_package/main_test_module/ModuleClass/NestedClass/nested_class_function/self', + 'id': 'main_package/main_module/ModuleClass/NestedClass/nested_class_function/self', 'is_optional': False, 'is_type_inferred': False, 'name': 'self', @@ -600,7 +600,7 @@ 'description': '', 'type': '', }), - 'id': 'main_package/main_test_module/ModuleClass/__init__/init_param_1', + 'id': 'main_package/main_module/ModuleClass/__init__/init_param_1', 'is_optional': False, 'is_type_inferred': False, 'name': 'init_param_1', @@ -614,7 +614,7 @@ 'description': '', 'type': '', }), - 'id': 'main_package/main_test_module/ModuleClass/__init__/self', + 'id': 'main_package/main_module/ModuleClass/__init__/self', 'is_optional': False, 'is_type_inferred': False, 'name': 'self', @@ -628,7 +628,7 @@ 'description': '', 'type': '', }), - 'id': 'main_package/main_test_module/ModuleClass/_some_function/param_1', + 'id': 'main_package/main_module/ModuleClass/_some_function/param_1', 'is_optional': False, 'is_type_inferred': False, 'name': 'param_1', @@ -646,7 +646,7 @@ 'description': '', 'type': '', }), - 'id': 'main_package/main_test_module/ModuleClass/_some_function/param_2', + 'id': 'main_package/main_module/ModuleClass/_some_function/param_2', 'is_optional': True, 'is_type_inferred': False, 'name': 'param_2', @@ -664,7 +664,7 @@ 'description': '', 'type': '', }), - 'id': 'main_package/main_test_module/ModuleClass/_some_function/self', + 'id': 'main_package/main_module/ModuleClass/_some_function/self', 'is_optional': False, 'is_type_inferred': False, 'name': 'self', @@ -678,7 +678,7 @@ 'description': '', 'type': '', }), - 'id': 'main_package/main_test_module/_PrivateClass/__init__/self', + 'id': 'main_package/main_module/_PrivateClass/__init__/self', 'is_optional': False, 'is_type_inferred': False, 'name': 'self', @@ -692,7 +692,7 @@ 'description': '', 'type': '', }), - 'id': 'main_package/main_test_module/_PrivateClass/public_func_in_private_class/self', + 'id': 'main_package/main_module/_PrivateClass/public_func_in_private_class/self', 'is_optional': False, 'is_type_inferred': False, 'name': 'self', @@ -706,7 +706,7 @@ 'description': '', 'type': '', }), - 'id': 'main_package/main_test_module/global_func/main_test_param_1', + 'id': 'main_package/main_module/global_func/main_test_param_1', 'is_optional': True, 'is_type_inferred': False, 'name': 'main_test_param_1', @@ -724,7 +724,7 @@ 'description': '', 'type': '', }), - 'id': 'main_package/main_test_module/global_func/main_test_param_2', + 'id': 'main_package/main_module/global_func/main_test_param_2', 'is_optional': True, 'is_type_inferred': False, 'name': 'main_test_param_2', @@ -751,7 +751,7 @@ 'description': '', 'type': '', }), - 'id': 'main_package/main_test_module/ModuleClass/NestedClass/nested_class_function/result_1', + 'id': 'main_package/main_module/ModuleClass/NestedClass/nested_class_function/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ @@ -780,7 +780,7 @@ 'description': '', 'type': '', }), - 'id': 'main_package/main_test_module/ModuleClass/_some_function/result_1', + 'id': 'main_package/main_module/ModuleClass/_some_function/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ @@ -794,7 +794,7 @@ 'description': '', 'type': '', }), - 'id': 'main_package/main_test_module/_private_global_func/result_1', + 'id': 'main_package/main_module/_private_global_func/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ @@ -823,7 +823,7 @@ 'description': '', 'type': '', }), - 'id': 'main_package/main_test_module/global_func/result_1', + 'id': 'main_package/main_module/global_func/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ diff --git a/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr b/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr index acd7771a..3968b268 100644 --- a/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr +++ b/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr @@ -7,7 +7,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/attribute_module/AttributesClassB/_multi_attr_2_private', + 'id': 'various_modules_package/attribute_module/AttributesClassB/_multi_attr_2_private', 'is_public': False, 'is_static': True, 'is_type_inferred': True, @@ -24,7 +24,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/attribute_module/AttributesClassB/_multi_attr_4_private', + 'id': 'various_modules_package/attribute_module/AttributesClassB/_multi_attr_4_private', 'is_public': False, 'is_static': True, 'is_type_inferred': True, @@ -46,7 +46,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/attribute_module/AttributesClassB/_no_type_hint_private', + 'id': 'various_modules_package/attribute_module/AttributesClassB/_no_type_hint_private', 'is_public': False, 'is_static': True, 'is_type_inferred': True, @@ -63,7 +63,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/attribute_module/AttributesClassB/_type_hint_private', + 'id': 'various_modules_package/attribute_module/AttributesClassB/_type_hint_private', 'is_public': False, 'is_static': True, 'is_type_inferred': False, @@ -80,7 +80,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/attribute_module/AttributesClassB/bool_attr', + 'id': 'various_modules_package/attribute_module/AttributesClassB/bool_attr', 'is_public': True, 'is_static': True, 'is_type_inferred': False, @@ -97,7 +97,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/attribute_module/AttributesClassB/callexpr_attr_class', + 'id': 'various_modules_package/attribute_module/AttributesClassB/callexpr_attr_class', 'is_public': True, 'is_static': True, 'is_type_inferred': False, @@ -110,7 +110,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/attribute_module/AttributesClassB/callexpr_attr_function', + 'id': 'various_modules_package/attribute_module/AttributesClassB/callexpr_attr_function', 'is_public': True, 'is_static': True, 'is_type_inferred': False, @@ -123,7 +123,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/attribute_module/AttributesClassB/dict_attr_1', + 'id': 'various_modules_package/attribute_module/AttributesClassB/dict_attr_1', 'is_public': True, 'is_static': True, 'is_type_inferred': False, @@ -148,7 +148,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/attribute_module/AttributesClassB/dict_attr_2', + 'id': 'various_modules_package/attribute_module/AttributesClassB/dict_attr_2', 'is_public': True, 'is_static': True, 'is_type_inferred': False, @@ -173,7 +173,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/attribute_module/AttributesClassB/dict_attr_3', + 'id': 'various_modules_package/attribute_module/AttributesClassB/dict_attr_3', 'is_public': True, 'is_static': True, 'is_type_inferred': False, @@ -206,7 +206,7 @@ dict({ 'kind': 'NamedType', 'name': 'AttributesClassA', - 'qname': 'tests.data.various_tests_package.attribute_module.AttributesClassA', + 'qname': 'tests.data.various_modules_package.attribute_module.AttributesClassA', }), ]), }), @@ -218,7 +218,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/attribute_module/AttributesClassB/final', + 'id': 'various_modules_package/attribute_module/AttributesClassB/final', 'is_public': True, 'is_static': True, 'is_type_inferred': False, @@ -238,7 +238,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/attribute_module/AttributesClassB/final_union', + 'id': 'various_modules_package/attribute_module/AttributesClassB/final_union', 'is_public': True, 'is_static': True, 'is_type_inferred': False, @@ -268,7 +268,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/attribute_module/AttributesClassB/finals', + 'id': 'various_modules_package/attribute_module/AttributesClassB/finals', 'is_public': True, 'is_static': True, 'is_type_inferred': False, @@ -298,7 +298,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/attribute_module/AttributesClassB/flaot_attr', + 'id': 'various_modules_package/attribute_module/AttributesClassB/flaot_attr', 'is_public': True, 'is_static': True, 'is_type_inferred': False, @@ -315,7 +315,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/attribute_module/AttributesClassB/init_attr', + 'id': 'various_modules_package/attribute_module/AttributesClassB/init_attr', 'is_public': True, 'is_static': False, 'is_type_inferred': False, @@ -332,7 +332,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/attribute_module/AttributesClassB/int_or_bool_attr', + 'id': 'various_modules_package/attribute_module/AttributesClassB/int_or_bool_attr', 'is_public': True, 'is_static': True, 'is_type_inferred': False, @@ -359,7 +359,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/attribute_module/AttributesClassB/list_attr_1', + 'id': 'various_modules_package/attribute_module/AttributesClassB/list_attr_1', 'is_public': True, 'is_static': True, 'is_type_inferred': False, @@ -376,7 +376,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/attribute_module/AttributesClassB/list_attr_2', + 'id': 'various_modules_package/attribute_module/AttributesClassB/list_attr_2', 'is_public': True, 'is_static': True, 'is_type_inferred': False, @@ -408,7 +408,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/attribute_module/AttributesClassB/list_attr_3', + 'id': 'various_modules_package/attribute_module/AttributesClassB/list_attr_3', 'is_public': True, 'is_static': True, 'is_type_inferred': False, @@ -435,7 +435,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/attribute_module/AttributesClassB/list_attr_4', + 'id': 'various_modules_package/attribute_module/AttributesClassB/list_attr_4', 'is_public': True, 'is_static': True, 'is_type_inferred': False, @@ -472,7 +472,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/attribute_module/AttributesClassB/literal', + 'id': 'various_modules_package/attribute_module/AttributesClassB/literal', 'is_public': True, 'is_static': True, 'is_type_inferred': False, @@ -488,7 +488,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/attribute_module/AttributesClassB/multi_attr_1', + 'id': 'various_modules_package/attribute_module/AttributesClassB/multi_attr_1', 'is_public': True, 'is_static': True, 'is_type_inferred': True, @@ -505,7 +505,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/attribute_module/AttributesClassB/multi_attr_3', + 'id': 'various_modules_package/attribute_module/AttributesClassB/multi_attr_3', 'is_public': True, 'is_static': True, 'is_type_inferred': True, @@ -527,7 +527,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/attribute_module/AttributesClassB/multi_attr_5', + 'id': 'various_modules_package/attribute_module/AttributesClassB/multi_attr_5', 'is_public': True, 'is_static': True, 'is_type_inferred': True, @@ -544,7 +544,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/attribute_module/AttributesClassB/multi_attr_6', + 'id': 'various_modules_package/attribute_module/AttributesClassB/multi_attr_6', 'is_public': True, 'is_static': True, 'is_type_inferred': True, @@ -561,7 +561,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/attribute_module/AttributesClassB/multi_attr_7', + 'id': 'various_modules_package/attribute_module/AttributesClassB/multi_attr_7', 'is_public': True, 'is_static': True, 'is_type_inferred': True, @@ -578,7 +578,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/attribute_module/AttributesClassB/multi_attr_8', + 'id': 'various_modules_package/attribute_module/AttributesClassB/multi_attr_8', 'is_public': True, 'is_static': True, 'is_type_inferred': True, @@ -595,7 +595,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/attribute_module/AttributesClassB/no_type_hint_public', + 'id': 'various_modules_package/attribute_module/AttributesClassB/no_type_hint_public', 'is_public': True, 'is_static': True, 'is_type_inferred': True, @@ -612,7 +612,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/attribute_module/AttributesClassB/none_attr', + 'id': 'various_modules_package/attribute_module/AttributesClassB/none_attr', 'is_public': True, 'is_static': True, 'is_type_inferred': False, @@ -629,7 +629,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/attribute_module/AttributesClassB/object_attr', + 'id': 'various_modules_package/attribute_module/AttributesClassB/object_attr', 'is_public': True, 'is_static': True, 'is_type_inferred': False, @@ -637,7 +637,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'AttributesClassA', - 'qname': 'tests.data.various_tests_package.attribute_module.AttributesClassA', + 'qname': 'tests.data.various_modules_package.attribute_module.AttributesClassA', }), }), dict({ @@ -646,7 +646,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/attribute_module/AttributesClassB/optional', + 'id': 'various_modules_package/attribute_module/AttributesClassB/optional', 'is_public': True, 'is_static': True, 'is_type_inferred': False, @@ -673,7 +673,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/attribute_module/AttributesClassB/set_attr_1', + 'id': 'various_modules_package/attribute_module/AttributesClassB/set_attr_1', 'is_public': True, 'is_static': True, 'is_type_inferred': False, @@ -695,7 +695,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/attribute_module/AttributesClassB/set_attr_2', + 'id': 'various_modules_package/attribute_module/AttributesClassB/set_attr_2', 'is_public': True, 'is_static': True, 'is_type_inferred': False, @@ -714,7 +714,7 @@ dict({ 'kind': 'NamedType', 'name': 'AttributesClassA', - 'qname': 'tests.data.various_tests_package.attribute_module.AttributesClassA', + 'qname': 'tests.data.various_modules_package.attribute_module.AttributesClassA', }), ]), }), @@ -727,7 +727,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/attribute_module/AttributesClassB/set_attr_3', + 'id': 'various_modules_package/attribute_module/AttributesClassB/set_attr_3', 'is_public': True, 'is_static': True, 'is_type_inferred': False, @@ -754,7 +754,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/attribute_module/AttributesClassB/set_attr_4', + 'id': 'various_modules_package/attribute_module/AttributesClassB/set_attr_4', 'is_public': True, 'is_static': True, 'is_type_inferred': False, @@ -791,7 +791,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/attribute_module/AttributesClassB/str_attr_with_none_value', + 'id': 'various_modules_package/attribute_module/AttributesClassB/str_attr_with_none_value', 'is_public': True, 'is_static': True, 'is_type_inferred': False, @@ -808,7 +808,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/attribute_module/AttributesClassB/tuple_attr_1', + 'id': 'various_modules_package/attribute_module/AttributesClassB/tuple_attr_1', 'is_public': True, 'is_static': True, 'is_type_inferred': False, @@ -830,7 +830,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/attribute_module/AttributesClassB/tuple_attr_2', + 'id': 'various_modules_package/attribute_module/AttributesClassB/tuple_attr_2', 'is_public': True, 'is_static': True, 'is_type_inferred': False, @@ -862,7 +862,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/attribute_module/AttributesClassB/tuple_attr_3', + 'id': 'various_modules_package/attribute_module/AttributesClassB/tuple_attr_3', 'is_public': True, 'is_static': True, 'is_type_inferred': False, @@ -889,7 +889,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/attribute_module/AttributesClassB/type_hint_public', + 'id': 'various_modules_package/attribute_module/AttributesClassB/type_hint_public', 'is_public': True, 'is_static': True, 'is_type_inferred': False, @@ -910,7 +910,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/class_module/ClassModuleClassD/ClassModuleNestedClassE/_nested_attr_2', + 'id': 'various_modules_package/class_module/ClassModuleClassD/ClassModuleNestedClassE/_nested_attr_2', 'is_public': False, 'is_static': True, 'is_type_inferred': False, @@ -927,7 +927,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/class_module/ClassModuleClassD/ClassModuleNestedClassE/nested_attr_1', + 'id': 'various_modules_package/class_module/ClassModuleClassD/ClassModuleNestedClassE/nested_attr_1', 'is_public': True, 'is_static': True, 'is_type_inferred': False, @@ -948,7 +948,7 @@ 'description': 'Attribute of the calculator. (Google Style)', 'type': 'str', }), - 'id': 'various_tests_package/docstring_module/GoogleDocstringClass/attr_1', + 'id': 'various_modules_package/docstring_module/GoogleDocstringClass/attr_1', 'is_public': True, 'is_static': True, 'is_type_inferred': False, @@ -969,7 +969,7 @@ 'description': 'Attribute of the calculator. (Numpy)', 'type': 'str', }), - 'id': 'various_tests_package/docstring_module/NumpyDocstringClass/attr_1', + 'id': 'various_modules_package/docstring_module/NumpyDocstringClass/attr_1', 'is_public': True, 'is_static': True, 'is_type_inferred': False, @@ -990,7 +990,7 @@ 'description': 'Attribute of the calculator. (ReST)', 'type': 'str', }), - 'id': 'various_tests_package/docstring_module/RestDocstringClass/attr_1', + 'id': 'various_modules_package/docstring_module/RestDocstringClass/attr_1', 'is_public': True, 'is_static': True, 'is_type_inferred': False, @@ -1011,7 +1011,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/class_module/_ClassModulePrivateClassG/_attr_1', + 'id': 'various_modules_package/class_module/_ClassModulePrivateClassG/_attr_1', 'is_public': False, 'is_static': True, 'is_type_inferred': False, @@ -1028,7 +1028,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/class_module/_ClassModulePrivateClassG/_attr_2', + 'id': 'various_modules_package/class_module/_ClassModulePrivateClassG/_attr_2', 'is_public': False, 'is_static': True, 'is_type_inferred': False, @@ -1048,14 +1048,14 @@ 'description': '', 'full_docstring': '', }), - 'id': 'various_tests_package/abstract_module/AbstractModuleClass/abstract_method', + 'id': 'various_modules_package/abstract_module/AbstractModuleClass/abstract_method', 'is_class_method': False, 'is_property': False, 'is_public': True, 'is_static': False, 'name': 'abstract_method', 'parameters': list([ - 'various_tests_package/abstract_module/AbstractModuleClass/abstract_method/self', + 'various_modules_package/abstract_module/AbstractModuleClass/abstract_method/self', ]), 'reexported_by': list([ ]), @@ -1067,21 +1067,21 @@ 'description': '', 'full_docstring': '', }), - 'id': 'various_tests_package/abstract_module/AbstractModuleClass/abstract_method_params', + 'id': 'various_modules_package/abstract_module/AbstractModuleClass/abstract_method_params', 'is_class_method': False, 'is_property': False, 'is_public': True, 'is_static': False, 'name': 'abstract_method_params', 'parameters': list([ - 'various_tests_package/abstract_module/AbstractModuleClass/abstract_method_params/self', - 'various_tests_package/abstract_module/AbstractModuleClass/abstract_method_params/param_1', - 'various_tests_package/abstract_module/AbstractModuleClass/abstract_method_params/param_2', + 'various_modules_package/abstract_module/AbstractModuleClass/abstract_method_params/self', + 'various_modules_package/abstract_module/AbstractModuleClass/abstract_method_params/param_1', + 'various_modules_package/abstract_module/AbstractModuleClass/abstract_method_params/param_2', ]), 'reexported_by': list([ ]), 'results': list([ - 'various_tests_package/abstract_module/AbstractModuleClass/abstract_method_params/result_1', + 'various_modules_package/abstract_module/AbstractModuleClass/abstract_method_params/result_1', ]), }), dict({ @@ -1089,20 +1089,20 @@ 'description': '', 'full_docstring': '', }), - 'id': 'various_tests_package/abstract_module/AbstractModuleClass/abstract_property_method', + 'id': 'various_modules_package/abstract_module/AbstractModuleClass/abstract_property_method', 'is_class_method': False, 'is_property': True, 'is_public': True, 'is_static': False, 'name': 'abstract_property_method', 'parameters': list([ - 'various_tests_package/abstract_module/AbstractModuleClass/abstract_property_method/self', + 'various_modules_package/abstract_module/AbstractModuleClass/abstract_property_method/self', ]), 'reexported_by': list([ ]), 'results': list([ - 'various_tests_package/abstract_module/AbstractModuleClass/abstract_property_method/result_1', - 'various_tests_package/abstract_module/AbstractModuleClass/abstract_property_method/result_2', + 'various_modules_package/abstract_module/AbstractModuleClass/abstract_property_method/result_1', + 'various_modules_package/abstract_module/AbstractModuleClass/abstract_property_method/result_2', ]), }), dict({ @@ -1110,7 +1110,7 @@ 'description': '', 'full_docstring': '', }), - 'id': 'various_tests_package/abstract_module/AbstractModuleClass/abstract_static_method', + 'id': 'various_modules_package/abstract_module/AbstractModuleClass/abstract_static_method', 'is_class_method': False, 'is_property': False, 'is_public': True, @@ -1128,19 +1128,19 @@ 'description': '', 'full_docstring': '', }), - 'id': 'various_tests_package/abstract_module/AbstractModuleClass/abstract_static_method_params', + 'id': 'various_modules_package/abstract_module/AbstractModuleClass/abstract_static_method_params', 'is_class_method': False, 'is_property': False, 'is_public': True, 'is_static': True, 'name': 'abstract_static_method_params', 'parameters': list([ - 'various_tests_package/abstract_module/AbstractModuleClass/abstract_static_method_params/param', + 'various_modules_package/abstract_module/AbstractModuleClass/abstract_static_method_params/param', ]), 'reexported_by': list([ ]), 'results': list([ - 'various_tests_package/abstract_module/AbstractModuleClass/abstract_static_method_params/result_1', + 'various_modules_package/abstract_module/AbstractModuleClass/abstract_static_method_params/result_1', ]), }), ]) @@ -1152,14 +1152,14 @@ 'description': '', 'full_docstring': '', }), - 'id': 'various_tests_package/class_module/ClassModuleClassB/f', + 'id': 'various_modules_package/class_module/ClassModuleClassB/f', 'is_class_method': False, 'is_property': False, 'is_public': True, 'is_static': False, 'name': 'f', 'parameters': list([ - 'various_tests_package/class_module/ClassModuleClassB/f/self', + 'various_modules_package/class_module/ClassModuleClassB/f/self', ]), 'reexported_by': list([ ]), @@ -1175,14 +1175,14 @@ 'description': '', 'full_docstring': '', }), - 'id': 'various_tests_package/class_module/ClassModuleClassC/f1', + 'id': 'various_modules_package/class_module/ClassModuleClassC/f1', 'is_class_method': False, 'is_property': False, 'is_public': True, 'is_static': False, 'name': 'f1', 'parameters': list([ - 'various_tests_package/class_module/ClassModuleClassC/f1/self', + 'various_modules_package/class_module/ClassModuleClassC/f1/self', ]), 'reexported_by': list([ ]), @@ -1202,14 +1202,14 @@ 'description': '', 'full_docstring': '', }), - 'id': 'various_tests_package/class_module/ClassModuleClassD/ClassModuleNestedClassE/class_e_func', + 'id': 'various_modules_package/class_module/ClassModuleClassD/ClassModuleNestedClassE/class_e_func', 'is_class_method': False, 'is_property': False, 'is_public': True, 'is_static': False, 'name': 'class_e_func', 'parameters': list([ - 'various_tests_package/class_module/ClassModuleClassD/ClassModuleNestedClassE/class_e_func/self', + 'various_modules_package/class_module/ClassModuleClassD/ClassModuleNestedClassE/class_e_func/self', ]), 'reexported_by': list([ ]), @@ -1234,21 +1234,21 @@ @rtype: bool ''', }), - 'id': 'various_tests_package/docstring_module/EpydocDocstringClass/epydoc_docstring_func', + 'id': 'various_modules_package/docstring_module/EpydocDocstringClass/epydoc_docstring_func', 'is_class_method': False, 'is_property': False, 'is_public': True, 'is_static': False, 'name': 'epydoc_docstring_func', 'parameters': list([ - 'various_tests_package/docstring_module/EpydocDocstringClass/epydoc_docstring_func/self', - 'various_tests_package/docstring_module/EpydocDocstringClass/epydoc_docstring_func/x', - 'various_tests_package/docstring_module/EpydocDocstringClass/epydoc_docstring_func/y', + 'various_modules_package/docstring_module/EpydocDocstringClass/epydoc_docstring_func/self', + 'various_modules_package/docstring_module/EpydocDocstringClass/epydoc_docstring_func/x', + 'various_modules_package/docstring_module/EpydocDocstringClass/epydoc_docstring_func/y', ]), 'reexported_by': list([ ]), 'results': list([ - 'various_tests_package/docstring_module/EpydocDocstringClass/epydoc_docstring_func/result_1', + 'various_modules_package/docstring_module/EpydocDocstringClass/epydoc_docstring_func/result_1', ]), }), ]) @@ -1260,14 +1260,14 @@ 'description': '', 'full_docstring': '', }), - 'id': 'various_tests_package/function_module/FunctionModuleClassB/class_method', + 'id': 'various_modules_package/function_module/FunctionModuleClassB/class_method', 'is_class_method': True, 'is_property': False, 'is_public': True, 'is_static': False, 'name': 'class_method', 'parameters': list([ - 'various_tests_package/function_module/FunctionModuleClassB/class_method/cls', + 'various_modules_package/function_module/FunctionModuleClassB/class_method/cls', ]), 'reexported_by': list([ ]), @@ -1279,20 +1279,20 @@ 'description': '', 'full_docstring': '', }), - 'id': 'various_tests_package/function_module/FunctionModuleClassB/class_method_params', + 'id': 'various_modules_package/function_module/FunctionModuleClassB/class_method_params', 'is_class_method': True, 'is_property': False, 'is_public': True, 'is_static': False, 'name': 'class_method_params', 'parameters': list([ - 'various_tests_package/function_module/FunctionModuleClassB/class_method_params/cls', - 'various_tests_package/function_module/FunctionModuleClassB/class_method_params/param_1', + 'various_modules_package/function_module/FunctionModuleClassB/class_method_params/cls', + 'various_modules_package/function_module/FunctionModuleClassB/class_method_params/param_1', ]), 'reexported_by': list([ ]), 'results': list([ - 'various_tests_package/function_module/FunctionModuleClassB/class_method_params/result_1', + 'various_modules_package/function_module/FunctionModuleClassB/class_method_params/result_1', ]), }), dict({ @@ -1300,20 +1300,20 @@ 'description': '', 'full_docstring': '', }), - 'id': 'various_tests_package/function_module/FunctionModuleClassB/instance_method', + 'id': 'various_modules_package/function_module/FunctionModuleClassB/instance_method', 'is_class_method': False, 'is_property': False, 'is_public': True, 'is_static': False, 'name': 'instance_method', 'parameters': list([ - 'various_tests_package/function_module/FunctionModuleClassB/instance_method/self', - 'various_tests_package/function_module/FunctionModuleClassB/instance_method/a', + 'various_modules_package/function_module/FunctionModuleClassB/instance_method/self', + 'various_modules_package/function_module/FunctionModuleClassB/instance_method/a', ]), 'reexported_by': list([ ]), 'results': list([ - 'various_tests_package/function_module/FunctionModuleClassB/instance_method/result_1', + 'various_modules_package/function_module/FunctionModuleClassB/instance_method/result_1', ]), }), dict({ @@ -1321,7 +1321,7 @@ 'description': '', 'full_docstring': '', }), - 'id': 'various_tests_package/function_module/FunctionModuleClassB/static_method', + 'id': 'various_modules_package/function_module/FunctionModuleClassB/static_method', 'is_class_method': False, 'is_property': False, 'is_public': True, @@ -1339,14 +1339,14 @@ 'description': '', 'full_docstring': '', }), - 'id': 'various_tests_package/function_module/FunctionModuleClassB/static_method_params', + 'id': 'various_modules_package/function_module/FunctionModuleClassB/static_method_params', 'is_class_method': False, 'is_property': False, 'is_public': True, 'is_static': True, 'name': 'static_method_params', 'parameters': list([ - 'various_tests_package/function_module/FunctionModuleClassB/static_method_params/param_1', + 'various_modules_package/function_module/FunctionModuleClassB/static_method_params/param_1', ]), 'reexported_by': list([ ]), @@ -1362,20 +1362,20 @@ 'description': '', 'full_docstring': '', }), - 'id': 'various_tests_package/function_module/FunctionModuleClassB/FunctionModuleClassC/nested_class_function', + 'id': 'various_modules_package/function_module/FunctionModuleClassB/FunctionModuleClassC/nested_class_function', 'is_class_method': False, 'is_property': False, 'is_public': True, 'is_static': False, 'name': 'nested_class_function', 'parameters': list([ - 'various_tests_package/function_module/FunctionModuleClassB/FunctionModuleClassC/nested_class_function/self', - 'various_tests_package/function_module/FunctionModuleClassB/FunctionModuleClassC/nested_class_function/param1', + 'various_modules_package/function_module/FunctionModuleClassB/FunctionModuleClassC/nested_class_function/self', + 'various_modules_package/function_module/FunctionModuleClassB/FunctionModuleClassC/nested_class_function/param1', ]), 'reexported_by': list([ ]), 'results': list([ - 'various_tests_package/function_module/FunctionModuleClassB/FunctionModuleClassC/nested_class_function/result_1', + 'various_modules_package/function_module/FunctionModuleClassB/FunctionModuleClassC/nested_class_function/result_1', ]), }), ]) @@ -1387,14 +1387,14 @@ 'description': '', 'full_docstring': '', }), - 'id': 'various_tests_package/function_module/FunctionModulePropertiesClass/property_function', + 'id': 'various_modules_package/function_module/FunctionModulePropertiesClass/property_function', 'is_class_method': False, 'is_property': True, 'is_public': True, 'is_static': False, 'name': 'property_function', 'parameters': list([ - 'various_tests_package/function_module/FunctionModulePropertiesClass/property_function/self', + 'various_modules_package/function_module/FunctionModulePropertiesClass/property_function/self', ]), 'reexported_by': list([ ]), @@ -1406,19 +1406,19 @@ 'description': '', 'full_docstring': '', }), - 'id': 'various_tests_package/function_module/FunctionModulePropertiesClass/property_function_infer', + 'id': 'various_modules_package/function_module/FunctionModulePropertiesClass/property_function_infer', 'is_class_method': False, 'is_property': True, 'is_public': True, 'is_static': False, 'name': 'property_function_infer', 'parameters': list([ - 'various_tests_package/function_module/FunctionModulePropertiesClass/property_function_infer/self', + 'various_modules_package/function_module/FunctionModulePropertiesClass/property_function_infer/self', ]), 'reexported_by': list([ ]), 'results': list([ - 'various_tests_package/function_module/FunctionModulePropertiesClass/property_function_infer/result_1', + 'various_modules_package/function_module/FunctionModulePropertiesClass/property_function_infer/result_1', ]), }), dict({ @@ -1426,19 +1426,19 @@ 'description': '', 'full_docstring': '', }), - 'id': 'various_tests_package/function_module/FunctionModulePropertiesClass/property_function_params', + 'id': 'various_modules_package/function_module/FunctionModulePropertiesClass/property_function_params', 'is_class_method': False, 'is_property': True, 'is_public': True, 'is_static': False, 'name': 'property_function_params', 'parameters': list([ - 'various_tests_package/function_module/FunctionModulePropertiesClass/property_function_params/self', + 'various_modules_package/function_module/FunctionModulePropertiesClass/property_function_params/self', ]), 'reexported_by': list([ ]), 'results': list([ - 'various_tests_package/function_module/FunctionModulePropertiesClass/property_function_params/result_1', + 'various_modules_package/function_module/FunctionModulePropertiesClass/property_function_params/result_1', ]), }), ]) @@ -1468,21 +1468,21 @@ a boolean value. (Google Style) ''', }), - 'id': 'various_tests_package/docstring_module/GoogleDocstringClass/google_docstring_func', + 'id': 'various_modules_package/docstring_module/GoogleDocstringClass/google_docstring_func', 'is_class_method': False, 'is_property': False, 'is_public': True, 'is_static': False, 'name': 'google_docstring_func', 'parameters': list([ - 'various_tests_package/docstring_module/GoogleDocstringClass/google_docstring_func/self', - 'various_tests_package/docstring_module/GoogleDocstringClass/google_docstring_func/x', - 'various_tests_package/docstring_module/GoogleDocstringClass/google_docstring_func/y', + 'various_modules_package/docstring_module/GoogleDocstringClass/google_docstring_func/self', + 'various_modules_package/docstring_module/GoogleDocstringClass/google_docstring_func/x', + 'various_modules_package/docstring_module/GoogleDocstringClass/google_docstring_func/y', ]), 'reexported_by': list([ ]), 'results': list([ - 'various_tests_package/docstring_module/GoogleDocstringClass/google_docstring_func/result_1', + 'various_modules_package/docstring_module/GoogleDocstringClass/google_docstring_func/result_1', ]), }), ]) @@ -1494,22 +1494,22 @@ 'description': '', 'full_docstring': '', }), - 'id': 'various_tests_package/infer_types_module/InferMyTypes/infer_function', + 'id': 'various_modules_package/infer_types_module/InferMyTypes/infer_function', 'is_class_method': False, 'is_property': False, 'is_public': True, 'is_static': True, 'name': 'infer_function', 'parameters': list([ - 'various_tests_package/infer_types_module/InferMyTypes/infer_function/infer_param', - 'various_tests_package/infer_types_module/InferMyTypes/infer_function/infer_param_2', + 'various_modules_package/infer_types_module/InferMyTypes/infer_function/infer_param', + 'various_modules_package/infer_types_module/InferMyTypes/infer_function/infer_param_2', ]), 'reexported_by': list([ ]), 'results': list([ - 'various_tests_package/infer_types_module/InferMyTypes/infer_function/result_1', - 'various_tests_package/infer_types_module/InferMyTypes/infer_function/result_2', - 'various_tests_package/infer_types_module/InferMyTypes/infer_function/result_3', + 'various_modules_package/infer_types_module/InferMyTypes/infer_function/result_1', + 'various_modules_package/infer_types_module/InferMyTypes/infer_function/result_2', + 'various_modules_package/infer_types_module/InferMyTypes/infer_function/result_3', ]), }), ]) @@ -1541,21 +1541,21 @@ Checks if the sum of `x` and `y` is greater than 10. (Numpy) ''', }), - 'id': 'various_tests_package/docstring_module/NumpyDocstringClass/numpy_docstring_func', + 'id': 'various_modules_package/docstring_module/NumpyDocstringClass/numpy_docstring_func', 'is_class_method': False, 'is_property': False, 'is_public': True, 'is_static': False, 'name': 'numpy_docstring_func', 'parameters': list([ - 'various_tests_package/docstring_module/NumpyDocstringClass/numpy_docstring_func/self', - 'various_tests_package/docstring_module/NumpyDocstringClass/numpy_docstring_func/x', - 'various_tests_package/docstring_module/NumpyDocstringClass/numpy_docstring_func/y', + 'various_modules_package/docstring_module/NumpyDocstringClass/numpy_docstring_func/self', + 'various_modules_package/docstring_module/NumpyDocstringClass/numpy_docstring_func/x', + 'various_modules_package/docstring_module/NumpyDocstringClass/numpy_docstring_func/y', ]), 'reexported_by': list([ ]), 'results': list([ - 'various_tests_package/docstring_module/NumpyDocstringClass/numpy_docstring_func/result_1', + 'various_modules_package/docstring_module/NumpyDocstringClass/numpy_docstring_func/result_1', ]), }), ]) @@ -1567,7 +1567,7 @@ 'description': '', 'full_docstring': '', }), - 'id': 'various_tests_package/_reexport_module_1/ReexportClass/_private_class_method_of_reexported_class', + 'id': 'various_modules_package/_reexport_module_1/ReexportClass/_private_class_method_of_reexported_class', 'is_class_method': False, 'is_property': False, 'is_public': False, @@ -1576,7 +1576,7 @@ 'parameters': list([ ]), 'reexported_by': list([ - 'various_tests_package/__init__', + 'various_modules_package/__init__', ]), 'results': list([ ]), @@ -1604,21 +1604,21 @@ :rtype: bool ''', }), - 'id': 'various_tests_package/docstring_module/RestDocstringClass/rest_docstring_func', + 'id': 'various_modules_package/docstring_module/RestDocstringClass/rest_docstring_func', 'is_class_method': False, 'is_property': False, 'is_public': True, 'is_static': False, 'name': 'rest_docstring_func', 'parameters': list([ - 'various_tests_package/docstring_module/RestDocstringClass/rest_docstring_func/self', - 'various_tests_package/docstring_module/RestDocstringClass/rest_docstring_func/x', - 'various_tests_package/docstring_module/RestDocstringClass/rest_docstring_func/y', + 'various_modules_package/docstring_module/RestDocstringClass/rest_docstring_func/self', + 'various_modules_package/docstring_module/RestDocstringClass/rest_docstring_func/x', + 'various_modules_package/docstring_module/RestDocstringClass/rest_docstring_func/y', ]), 'reexported_by': list([ ]), 'results': list([ - 'various_tests_package/docstring_module/RestDocstringClass/rest_docstring_func/result_1', + 'various_modules_package/docstring_module/RestDocstringClass/rest_docstring_func/result_1', ]), }), ]) @@ -1630,14 +1630,14 @@ 'description': '', 'full_docstring': '', }), - 'id': 'various_tests_package/class_module/ClassModuleClassD/ClassModuleNestedClassE/_ClassModulePrivateDoubleNestedClassF/_class_f_func', + 'id': 'various_modules_package/class_module/ClassModuleClassD/ClassModuleNestedClassE/_ClassModulePrivateDoubleNestedClassF/_class_f_func', 'is_class_method': False, 'is_property': False, 'is_public': False, 'is_static': False, 'name': '_class_f_func', 'parameters': list([ - 'various_tests_package/class_module/ClassModuleClassD/ClassModuleNestedClassE/_ClassModulePrivateDoubleNestedClassF/_class_f_func/self', + 'various_modules_package/class_module/ClassModuleClassD/ClassModuleNestedClassE/_ClassModulePrivateDoubleNestedClassF/_class_f_func/self', ]), 'reexported_by': list([ ]), @@ -1657,15 +1657,15 @@ 'description': '', 'full_docstring': '', }), - 'id': 'various_tests_package/abstract_module/AbstractModuleClass/__init__', + 'id': 'various_modules_package/abstract_module/AbstractModuleClass/__init__', 'is_class_method': False, 'is_property': False, 'is_public': True, 'is_static': False, 'name': '__init__', 'parameters': list([ - 'various_tests_package/abstract_module/AbstractModuleClass/__init__/self', - 'various_tests_package/abstract_module/AbstractModuleClass/__init__/param', + 'various_modules_package/abstract_module/AbstractModuleClass/__init__/self', + 'various_modules_package/abstract_module/AbstractModuleClass/__init__/param', ]), 'reexported_by': list([ ]), @@ -1676,14 +1676,14 @@ 'description': '', 'full_docstring': '', }), - 'id': 'various_tests_package/abstract_module/AbstractModuleClass', + 'id': 'various_modules_package/abstract_module/AbstractModuleClass', 'is_public': True, 'methods': list([ - 'various_tests_package/abstract_module/AbstractModuleClass/abstract_method', - 'various_tests_package/abstract_module/AbstractModuleClass/abstract_method_params', - 'various_tests_package/abstract_module/AbstractModuleClass/abstract_static_method', - 'various_tests_package/abstract_module/AbstractModuleClass/abstract_static_method_params', - 'various_tests_package/abstract_module/AbstractModuleClass/abstract_property_method', + 'various_modules_package/abstract_module/AbstractModuleClass/abstract_method', + 'various_modules_package/abstract_module/AbstractModuleClass/abstract_method_params', + 'various_modules_package/abstract_module/AbstractModuleClass/abstract_static_method', + 'various_modules_package/abstract_module/AbstractModuleClass/abstract_static_method_params', + 'various_modules_package/abstract_module/AbstractModuleClass/abstract_property_method', ]), 'name': 'AbstractModuleClass', 'reexported_by': list([ @@ -1706,7 +1706,7 @@ 'description': '', 'full_docstring': '', }), - 'id': 'various_tests_package/_reexport_module_2/AnotherReexportClass', + 'id': 'various_modules_package/_reexport_module_2/AnotherReexportClass', 'is_public': True, 'methods': list([ ]), @@ -1730,16 +1730,16 @@ 'description': '', 'full_docstring': '', }), - 'id': 'various_tests_package/class_module/ClassModuleClassB/__init__', + 'id': 'various_modules_package/class_module/ClassModuleClassB/__init__', 'is_class_method': False, 'is_property': False, 'is_public': True, 'is_static': False, 'name': '__init__', 'parameters': list([ - 'various_tests_package/class_module/ClassModuleClassB/__init__/self', - 'various_tests_package/class_module/ClassModuleClassB/__init__/a', - 'various_tests_package/class_module/ClassModuleClassB/__init__/b', + 'various_modules_package/class_module/ClassModuleClassB/__init__/self', + 'various_modules_package/class_module/ClassModuleClassB/__init__/a', + 'various_modules_package/class_module/ClassModuleClassB/__init__/b', ]), 'reexported_by': list([ ]), @@ -1750,16 +1750,16 @@ 'description': '', 'full_docstring': '', }), - 'id': 'various_tests_package/class_module/ClassModuleClassB', + 'id': 'various_modules_package/class_module/ClassModuleClassB', 'is_public': True, 'methods': list([ - 'various_tests_package/class_module/ClassModuleClassB/f', + 'various_modules_package/class_module/ClassModuleClassB/f', ]), 'name': 'ClassModuleClassB', 'reexported_by': list([ ]), 'superclasses': list([ - 'tests.data.various_tests_package.class_module.ClassModuleEmptyClassA', + 'tests.data.various_modules_package.class_module.ClassModuleEmptyClassA', ]), 'variances': list([ ]), @@ -1768,8 +1768,8 @@ # name: test_classes[ClassModuleClassC] dict({ 'attributes': list([ - 'various_tests_package/class_module/ClassModuleClassC/attr_1', - 'various_tests_package/class_module/ClassModuleClassC/attr_2', + 'various_modules_package/class_module/ClassModuleClassC/attr_1', + 'various_modules_package/class_module/ClassModuleClassC/attr_2', ]), 'classes': list([ ]), @@ -1778,17 +1778,17 @@ 'description': '', 'full_docstring': '', }), - 'id': 'various_tests_package/class_module/ClassModuleClassC', + 'id': 'various_modules_package/class_module/ClassModuleClassC', 'is_public': True, 'methods': list([ - 'various_tests_package/class_module/ClassModuleClassC/f1', + 'various_modules_package/class_module/ClassModuleClassC/f1', ]), 'name': 'ClassModuleClassC', 'reexported_by': list([ ]), 'superclasses': list([ - 'tests.data.various_tests_package.class_module.ClassModuleEmptyClassA', - 'tests.data.various_tests_package.class_module.ClassModuleClassB', + 'tests.data.various_modules_package.class_module.ClassModuleEmptyClassA', + 'tests.data.various_modules_package.class_module.ClassModuleClassB', ]), 'variances': list([ ]), @@ -1799,14 +1799,14 @@ 'attributes': list([ ]), 'classes': list([ - 'various_tests_package/class_module/ClassModuleClassD/ClassModuleNestedClassE', + 'various_modules_package/class_module/ClassModuleClassD/ClassModuleNestedClassE', ]), 'constructor': None, 'docstring': dict({ 'description': '', 'full_docstring': '', }), - 'id': 'various_tests_package/class_module/ClassModuleClassD', + 'id': 'various_modules_package/class_module/ClassModuleClassD', 'is_public': True, 'methods': list([ ]), @@ -1830,7 +1830,7 @@ 'description': '', 'full_docstring': '', }), - 'id': 'various_tests_package/class_module/ClassModuleEmptyClassA', + 'id': 'various_modules_package/class_module/ClassModuleEmptyClassA', 'is_public': True, 'methods': list([ ]), @@ -1846,21 +1846,21 @@ # name: test_classes[ClassModuleNestedClassE] dict({ 'attributes': list([ - 'various_tests_package/class_module/ClassModuleClassD/ClassModuleNestedClassE/nested_attr_1', - 'various_tests_package/class_module/ClassModuleClassD/ClassModuleNestedClassE/_nested_attr_2', + 'various_modules_package/class_module/ClassModuleClassD/ClassModuleNestedClassE/nested_attr_1', + 'various_modules_package/class_module/ClassModuleClassD/ClassModuleNestedClassE/_nested_attr_2', ]), 'classes': list([ - 'various_tests_package/class_module/ClassModuleClassD/ClassModuleNestedClassE/_ClassModulePrivateDoubleNestedClassF', + 'various_modules_package/class_module/ClassModuleClassD/ClassModuleNestedClassE/_ClassModulePrivateDoubleNestedClassF', ]), 'constructor': None, 'docstring': dict({ 'description': '', 'full_docstring': '', }), - 'id': 'various_tests_package/class_module/ClassModuleClassD/ClassModuleNestedClassE', + 'id': 'various_modules_package/class_module/ClassModuleClassD/ClassModuleNestedClassE', 'is_public': True, 'methods': list([ - 'various_tests_package/class_module/ClassModuleClassD/ClassModuleNestedClassE/class_e_func', + 'various_modules_package/class_module/ClassModuleClassD/ClassModuleNestedClassE/class_e_func', ]), 'name': 'ClassModuleNestedClassE', 'reexported_by': list([ @@ -1874,7 +1874,7 @@ # name: test_classes[EpydocDocstringClass] dict({ 'attributes': list([ - 'various_tests_package/docstring_module/EpydocDocstringClass/attr_1', + 'various_modules_package/docstring_module/EpydocDocstringClass/attr_1', ]), 'classes': list([ ]), @@ -1883,15 +1883,15 @@ 'description': '', 'full_docstring': '', }), - 'id': 'various_tests_package/docstring_module/EpydocDocstringClass/__init__', + 'id': 'various_modules_package/docstring_module/EpydocDocstringClass/__init__', 'is_class_method': False, 'is_property': False, 'is_public': True, 'is_static': False, 'name': '__init__', 'parameters': list([ - 'various_tests_package/docstring_module/EpydocDocstringClass/__init__/self', - 'various_tests_package/docstring_module/EpydocDocstringClass/__init__/param_1', + 'various_modules_package/docstring_module/EpydocDocstringClass/__init__/self', + 'various_modules_package/docstring_module/EpydocDocstringClass/__init__/param_1', ]), 'reexported_by': list([ ]), @@ -1909,10 +1909,10 @@ @type param_1: str ''', }), - 'id': 'various_tests_package/docstring_module/EpydocDocstringClass', + 'id': 'various_modules_package/docstring_module/EpydocDocstringClass', 'is_public': True, 'methods': list([ - 'various_tests_package/docstring_module/EpydocDocstringClass/epydoc_docstring_func', + 'various_modules_package/docstring_module/EpydocDocstringClass/epydoc_docstring_func', ]), 'name': 'EpydocDocstringClass', 'reexported_by': list([ @@ -1934,13 +1934,13 @@ 'description': '', 'full_docstring': '', }), - 'id': 'various_tests_package/_reexport_module_4/FourthReexportClass', + 'id': 'various_modules_package/_reexport_module_4/FourthReexportClass', 'is_public': True, 'methods': list([ ]), 'name': 'FourthReexportClass', 'reexported_by': list([ - 'various_tests_package/__init__', + 'various_modules_package/__init__', ]), 'superclasses': list([ ]), @@ -1951,7 +1951,7 @@ # name: test_classes[GoogleDocstringClass] dict({ 'attributes': list([ - 'various_tests_package/docstring_module/GoogleDocstringClass/attr_1', + 'various_modules_package/docstring_module/GoogleDocstringClass/attr_1', ]), 'classes': list([ ]), @@ -1960,15 +1960,15 @@ 'description': '', 'full_docstring': '', }), - 'id': 'various_tests_package/docstring_module/GoogleDocstringClass/__init__', + 'id': 'various_modules_package/docstring_module/GoogleDocstringClass/__init__', 'is_class_method': False, 'is_property': False, 'is_public': True, 'is_static': False, 'name': '__init__', 'parameters': list([ - 'various_tests_package/docstring_module/GoogleDocstringClass/__init__/self', - 'various_tests_package/docstring_module/GoogleDocstringClass/__init__/param_1', + 'various_modules_package/docstring_module/GoogleDocstringClass/__init__/self', + 'various_modules_package/docstring_module/GoogleDocstringClass/__init__/param_1', ]), 'reexported_by': list([ ]), @@ -1993,10 +1993,10 @@ param_1 (str): Parameter of the calculator. (Google Style) ''', }), - 'id': 'various_tests_package/docstring_module/GoogleDocstringClass', + 'id': 'various_modules_package/docstring_module/GoogleDocstringClass', 'is_public': True, 'methods': list([ - 'various_tests_package/docstring_module/GoogleDocstringClass/google_docstring_func', + 'various_modules_package/docstring_module/GoogleDocstringClass/google_docstring_func', ]), 'name': 'GoogleDocstringClass', 'reexported_by': list([ @@ -2010,13 +2010,13 @@ # name: test_classes[InferMyTypes] dict({ 'attributes': list([ - 'various_tests_package/infer_types_module/InferMyTypes/infer_int', - 'various_tests_package/infer_types_module/InferMyTypes/infer_float', - 'various_tests_package/infer_types_module/InferMyTypes/infer_bool', - 'various_tests_package/infer_types_module/InferMyTypes/infer_str', - 'various_tests_package/infer_types_module/InferMyTypes/infer_none', - 'various_tests_package/infer_types_module/InferMyTypes/infer_obj', - 'various_tests_package/infer_types_module/InferMyTypes/init_infer', + 'various_modules_package/infer_types_module/InferMyTypes/infer_int', + 'various_modules_package/infer_types_module/InferMyTypes/infer_float', + 'various_modules_package/infer_types_module/InferMyTypes/infer_bool', + 'various_modules_package/infer_types_module/InferMyTypes/infer_str', + 'various_modules_package/infer_types_module/InferMyTypes/infer_none', + 'various_modules_package/infer_types_module/InferMyTypes/infer_obj', + 'various_modules_package/infer_types_module/InferMyTypes/init_infer', ]), 'classes': list([ ]), @@ -2025,15 +2025,15 @@ 'description': '', 'full_docstring': '', }), - 'id': 'various_tests_package/infer_types_module/InferMyTypes/__init__', + 'id': 'various_modules_package/infer_types_module/InferMyTypes/__init__', 'is_class_method': False, 'is_property': False, 'is_public': True, 'is_static': False, 'name': '__init__', 'parameters': list([ - 'various_tests_package/infer_types_module/InferMyTypes/__init__/self', - 'various_tests_package/infer_types_module/InferMyTypes/__init__/init_param', + 'various_modules_package/infer_types_module/InferMyTypes/__init__/self', + 'various_modules_package/infer_types_module/InferMyTypes/__init__/init_param', ]), 'reexported_by': list([ ]), @@ -2044,10 +2044,10 @@ 'description': '', 'full_docstring': '', }), - 'id': 'various_tests_package/infer_types_module/InferMyTypes', + 'id': 'various_modules_package/infer_types_module/InferMyTypes', 'is_public': True, 'methods': list([ - 'various_tests_package/infer_types_module/InferMyTypes/infer_function', + 'various_modules_package/infer_types_module/InferMyTypes/infer_function', ]), 'name': 'InferMyTypes', 'reexported_by': list([ @@ -2061,7 +2061,7 @@ # name: test_classes[NumpyDocstringClass] dict({ 'attributes': list([ - 'various_tests_package/docstring_module/NumpyDocstringClass/attr_1', + 'various_modules_package/docstring_module/NumpyDocstringClass/attr_1', ]), 'classes': list([ ]), @@ -2070,15 +2070,15 @@ 'description': '', 'full_docstring': '', }), - 'id': 'various_tests_package/docstring_module/NumpyDocstringClass/__init__', + 'id': 'various_modules_package/docstring_module/NumpyDocstringClass/__init__', 'is_class_method': False, 'is_property': False, 'is_public': True, 'is_static': False, 'name': '__init__', 'parameters': list([ - 'various_tests_package/docstring_module/NumpyDocstringClass/__init__/self', - 'various_tests_package/docstring_module/NumpyDocstringClass/__init__/param_1', + 'various_modules_package/docstring_module/NumpyDocstringClass/__init__/self', + 'various_modules_package/docstring_module/NumpyDocstringClass/__init__/param_1', ]), 'reexported_by': list([ ]), @@ -2107,10 +2107,10 @@ Parameter of the calculator. (Numpy) ''', }), - 'id': 'various_tests_package/docstring_module/NumpyDocstringClass', + 'id': 'various_modules_package/docstring_module/NumpyDocstringClass', 'is_public': True, 'methods': list([ - 'various_tests_package/docstring_module/NumpyDocstringClass/numpy_docstring_func', + 'various_modules_package/docstring_module/NumpyDocstringClass/numpy_docstring_func', ]), 'name': 'NumpyDocstringClass', 'reexported_by': list([ @@ -2132,14 +2132,14 @@ 'description': '', 'full_docstring': '', }), - 'id': 'various_tests_package/_reexport_module_1/ReexportClass', + 'id': 'various_modules_package/_reexport_module_1/ReexportClass', 'is_public': True, 'methods': list([ - 'various_tests_package/_reexport_module_1/ReexportClass/_private_class_method_of_reexported_class', + 'various_modules_package/_reexport_module_1/ReexportClass/_private_class_method_of_reexported_class', ]), 'name': 'ReexportClass', 'reexported_by': list([ - 'various_tests_package/__init__', + 'various_modules_package/__init__', ]), 'superclasses': list([ ]), @@ -2150,7 +2150,7 @@ # name: test_classes[RestDocstringClass] dict({ 'attributes': list([ - 'various_tests_package/docstring_module/RestDocstringClass/attr_1', + 'various_modules_package/docstring_module/RestDocstringClass/attr_1', ]), 'classes': list([ ]), @@ -2159,15 +2159,15 @@ 'description': '', 'full_docstring': '', }), - 'id': 'various_tests_package/docstring_module/RestDocstringClass/__init__', + 'id': 'various_modules_package/docstring_module/RestDocstringClass/__init__', 'is_class_method': False, 'is_property': False, 'is_public': True, 'is_static': False, 'name': '__init__', 'parameters': list([ - 'various_tests_package/docstring_module/RestDocstringClass/__init__/self', - 'various_tests_package/docstring_module/RestDocstringClass/__init__/param_1', + 'various_modules_package/docstring_module/RestDocstringClass/__init__/self', + 'various_modules_package/docstring_module/RestDocstringClass/__init__/param_1', ]), 'reexported_by': list([ ]), @@ -2185,10 +2185,10 @@ :type param_1: str ''', }), - 'id': 'various_tests_package/docstring_module/RestDocstringClass', + 'id': 'various_modules_package/docstring_module/RestDocstringClass', 'is_public': True, 'methods': list([ - 'various_tests_package/docstring_module/RestDocstringClass/rest_docstring_func', + 'various_modules_package/docstring_module/RestDocstringClass/rest_docstring_func', ]), 'name': 'RestDocstringClass', 'reexported_by': list([ @@ -2210,7 +2210,7 @@ 'description': '', 'full_docstring': '', }), - 'id': 'various_tests_package/variance_module/VarianceClassAll', + 'id': 'various_modules_package/variance_module/VarianceClassAll', 'is_public': True, 'methods': list([ ]), @@ -2234,7 +2234,7 @@ 'type': dict({ 'kind': 'NamedType', 'name': 'A', - 'qname': 'tests.data.various_tests_package.variance_module.A', + 'qname': 'tests.data.various_modules_package.variance_module.A', }), 'variance_type': 'CONTRAVARIANT', }), @@ -2279,7 +2279,7 @@ 'description': '', 'full_docstring': '', }), - 'id': 'various_tests_package/variance_module/VarianceClassOnlyInvariance', + 'id': 'various_modules_package/variance_module/VarianceClassOnlyInvariance', 'is_public': True, 'methods': list([ ]), @@ -2322,8 +2322,8 @@ # name: test_classes[_ClassModulePrivateClassG] dict({ 'attributes': list([ - 'various_tests_package/class_module/_ClassModulePrivateClassG/_attr_1', - 'various_tests_package/class_module/_ClassModulePrivateClassG/_attr_2', + 'various_modules_package/class_module/_ClassModulePrivateClassG/_attr_1', + 'various_modules_package/class_module/_ClassModulePrivateClassG/_attr_2', ]), 'classes': list([ ]), @@ -2332,7 +2332,7 @@ 'description': '', 'full_docstring': '', }), - 'id': 'various_tests_package/class_module/_ClassModulePrivateClassG', + 'id': 'various_modules_package/class_module/_ClassModulePrivateClassG', 'is_public': False, 'methods': list([ ]), @@ -2356,10 +2356,10 @@ 'description': '', 'full_docstring': '', }), - 'id': 'various_tests_package/class_module/ClassModuleClassD/ClassModuleNestedClassE/_ClassModulePrivateDoubleNestedClassF', + 'id': 'various_modules_package/class_module/ClassModuleClassD/ClassModuleNestedClassE/_ClassModulePrivateDoubleNestedClassF', 'is_public': False, 'methods': list([ - 'various_tests_package/class_module/ClassModuleClassD/ClassModuleNestedClassE/_ClassModulePrivateDoubleNestedClassF/_class_f_func', + 'various_modules_package/class_module/ClassModuleClassD/ClassModuleNestedClassE/_ClassModulePrivateDoubleNestedClassF/_class_f_func', ]), 'name': '_ClassModulePrivateDoubleNestedClassF', 'reexported_by': list([ @@ -2381,13 +2381,13 @@ 'description': '', 'full_docstring': '', }), - 'id': 'various_tests_package/_reexport_module_3/_ThirdReexportClass', + 'id': 'various_modules_package/_reexport_module_3/_ThirdReexportClass', 'is_public': False, 'methods': list([ ]), 'name': '_ThirdReexportClass', 'reexported_by': list([ - 'various_tests_package/__init__', + 'various_modules_package/__init__', ]), 'superclasses': list([ ]), @@ -2398,7 +2398,7 @@ # name: test_enum_instances[EnumTest3] list([ dict({ - 'id': 'various_tests_package/enum_module/EnumTest3/ELEVEN', + 'id': 'various_modules_package/enum_module/EnumTest3/ELEVEN', 'name': 'ELEVEN', }), ]) @@ -2406,39 +2406,39 @@ # name: test_enum_instances[EnumTest] list([ dict({ - 'id': 'various_tests_package/enum_module/EnumTest/EIGHT', + 'id': 'various_modules_package/enum_module/EnumTest/EIGHT', 'name': 'EIGHT', }), dict({ - 'id': 'various_tests_package/enum_module/EnumTest/FIVE', + 'id': 'various_modules_package/enum_module/EnumTest/FIVE', 'name': 'FIVE', }), dict({ - 'id': 'various_tests_package/enum_module/EnumTest/FOUR', + 'id': 'various_modules_package/enum_module/EnumTest/FOUR', 'name': 'FOUR', }), dict({ - 'id': 'various_tests_package/enum_module/EnumTest/NINE', + 'id': 'various_modules_package/enum_module/EnumTest/NINE', 'name': 'NINE', }), dict({ - 'id': 'various_tests_package/enum_module/EnumTest/ONE', + 'id': 'various_modules_package/enum_module/EnumTest/ONE', 'name': 'ONE', }), dict({ - 'id': 'various_tests_package/enum_module/EnumTest/SEVEN', + 'id': 'various_modules_package/enum_module/EnumTest/SEVEN', 'name': 'SEVEN', }), dict({ - 'id': 'various_tests_package/enum_module/EnumTest/SIX', + 'id': 'various_modules_package/enum_module/EnumTest/SIX', 'name': 'SIX', }), dict({ - 'id': 'various_tests_package/enum_module/EnumTest/THREE', + 'id': 'various_modules_package/enum_module/EnumTest/THREE', 'name': 'THREE', }), dict({ - 'id': 'various_tests_package/enum_module/EnumTest/TWO', + 'id': 'various_modules_package/enum_module/EnumTest/TWO', 'name': 'TWO', }), ]) @@ -2453,9 +2453,9 @@ 'description': '', 'full_docstring': '', }), - 'id': 'various_tests_package/enum_module/EnumTest2', + 'id': 'various_modules_package/enum_module/EnumTest2', 'instances': list([ - 'various_tests_package/enum_module/EnumTest2/TEN', + 'various_modules_package/enum_module/EnumTest2/TEN', ]), 'name': 'EnumTest2', }) @@ -2466,9 +2466,9 @@ 'description': '', 'full_docstring': '', }), - 'id': 'various_tests_package/enum_module/EnumTest3', + 'id': 'various_modules_package/enum_module/EnumTest3', 'instances': list([ - 'various_tests_package/enum_module/EnumTest3/ELEVEN', + 'various_modules_package/enum_module/EnumTest3/ELEVEN', ]), 'name': 'EnumTest3', }) @@ -2487,17 +2487,17 @@ Full Docstring Description ''', }), - 'id': 'various_tests_package/enum_module/EnumTest', + 'id': 'various_modules_package/enum_module/EnumTest', 'instances': list([ - 'various_tests_package/enum_module/EnumTest/ONE', - 'various_tests_package/enum_module/EnumTest/TWO', - 'various_tests_package/enum_module/EnumTest/THREE', - 'various_tests_package/enum_module/EnumTest/FOUR', - 'various_tests_package/enum_module/EnumTest/FIVE', - 'various_tests_package/enum_module/EnumTest/SIX', - 'various_tests_package/enum_module/EnumTest/SEVEN', - 'various_tests_package/enum_module/EnumTest/EIGHT', - 'various_tests_package/enum_module/EnumTest/NINE', + 'various_modules_package/enum_module/EnumTest/ONE', + 'various_modules_package/enum_module/EnumTest/TWO', + 'various_modules_package/enum_module/EnumTest/THREE', + 'various_modules_package/enum_module/EnumTest/FOUR', + 'various_modules_package/enum_module/EnumTest/FIVE', + 'various_modules_package/enum_module/EnumTest/SIX', + 'various_modules_package/enum_module/EnumTest/SEVEN', + 'various_modules_package/enum_module/EnumTest/EIGHT', + 'various_modules_package/enum_module/EnumTest/NINE', ]), 'name': 'EnumTest', }) @@ -2508,7 +2508,7 @@ 'description': "Nothing's here.", 'full_docstring': "Nothing's here.", }), - 'id': 'various_tests_package/enum_module/_ReexportedEmptyEnum', + 'id': 'various_modules_package/enum_module/_ReexportedEmptyEnum', 'instances': list([ ]), 'name': '_ReexportedEmptyEnum', @@ -2524,7 +2524,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/function_module/FunctionModuleClassB/__init__/init_param', + 'id': 'various_modules_package/function_module/FunctionModuleClassB/__init__/init_param', 'is_optional': False, 'is_type_inferred': False, 'name': 'init_param', @@ -2538,7 +2538,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/function_module/FunctionModuleClassB/__init__/self', + 'id': 'various_modules_package/function_module/FunctionModuleClassB/__init__/self', 'is_optional': False, 'is_type_inferred': False, 'name': 'self', @@ -2556,7 +2556,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/function_module/_private/a', + 'id': 'various_modules_package/function_module/_private/a', 'is_optional': False, 'is_type_inferred': False, 'name': 'a', @@ -2574,7 +2574,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/abstract_module/AbstractModuleClass/abstract_method_params/param_1', + 'id': 'various_modules_package/abstract_module/AbstractModuleClass/abstract_method_params/param_1', 'is_optional': False, 'is_type_inferred': False, 'name': 'param_1', @@ -2592,7 +2592,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/abstract_module/AbstractModuleClass/abstract_method_params/param_2', + 'id': 'various_modules_package/abstract_module/AbstractModuleClass/abstract_method_params/param_2', 'is_optional': True, 'is_type_inferred': True, 'name': 'param_2', @@ -2610,7 +2610,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/abstract_module/AbstractModuleClass/abstract_method_params/self', + 'id': 'various_modules_package/abstract_module/AbstractModuleClass/abstract_method_params/self', 'is_optional': False, 'is_type_inferred': False, 'name': 'self', @@ -2628,7 +2628,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/abstract_module/AbstractModuleClass/abstract_property_method/self', + 'id': 'various_modules_package/abstract_module/AbstractModuleClass/abstract_property_method/self', 'is_optional': False, 'is_type_inferred': False, 'name': 'self', @@ -2646,7 +2646,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/abstract_module/AbstractModuleClass/abstract_static_method_params/param', + 'id': 'various_modules_package/abstract_module/AbstractModuleClass/abstract_static_method_params/param', 'is_optional': False, 'is_type_inferred': False, 'name': 'param', @@ -2668,7 +2668,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/function_module/arg/args', + 'id': 'various_modules_package/function_module/arg/args', 'is_optional': False, 'is_type_inferred': False, 'name': 'args', @@ -2682,7 +2682,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/function_module/arg/kwargs', + 'id': 'various_modules_package/function_module/arg/kwargs', 'is_optional': False, 'is_type_inferred': False, 'name': 'kwargs', @@ -2700,7 +2700,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/function_module/args_type/args', + 'id': 'various_modules_package/function_module/args_type/args', 'is_optional': False, 'is_type_inferred': False, 'name': 'args', @@ -2723,7 +2723,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/function_module/args_type/kwargs', + 'id': 'various_modules_package/function_module/args_type/kwargs', 'is_optional': False, 'is_type_inferred': False, 'name': 'kwargs', @@ -2753,7 +2753,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/function_module/callable_type/param', + 'id': 'various_modules_package/function_module/callable_type/param', 'is_optional': False, 'is_type_inferred': False, 'name': 'param', @@ -2795,7 +2795,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/function_module/FunctionModuleClassB/class_method/cls', + 'id': 'various_modules_package/function_module/FunctionModuleClassB/class_method/cls', 'is_optional': False, 'is_type_inferred': False, 'name': 'cls', @@ -2813,7 +2813,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/function_module/FunctionModuleClassB/class_method_params/cls', + 'id': 'various_modules_package/function_module/FunctionModuleClassB/class_method_params/cls', 'is_optional': False, 'is_type_inferred': False, 'name': 'cls', @@ -2827,7 +2827,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/function_module/FunctionModuleClassB/class_method_params/param_1', + 'id': 'various_modules_package/function_module/FunctionModuleClassB/class_method_params/param_1', 'is_optional': False, 'is_type_inferred': False, 'name': 'param_1', @@ -2849,7 +2849,7 @@ 'description': 'Parameter of the calculator. (Epydoc)', 'type': 'str', }), - 'id': 'various_tests_package/docstring_module/EpydocDocstringClass/__init__/param_1', + 'id': 'various_modules_package/docstring_module/EpydocDocstringClass/__init__/param_1', 'is_optional': False, 'is_type_inferred': False, 'name': 'param_1', @@ -2867,7 +2867,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/docstring_module/EpydocDocstringClass/__init__/self', + 'id': 'various_modules_package/docstring_module/EpydocDocstringClass/__init__/self', 'is_optional': False, 'is_type_inferred': False, 'name': 'self', @@ -2885,7 +2885,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/docstring_module/EpydocDocstringClass/epydoc_docstring_func/self', + 'id': 'various_modules_package/docstring_module/EpydocDocstringClass/epydoc_docstring_func/self', 'is_optional': False, 'is_type_inferred': False, 'name': 'self', @@ -2899,7 +2899,7 @@ 'description': 'First integer value for the calculation. (Epydoc)', 'type': 'int', }), - 'id': 'various_tests_package/docstring_module/EpydocDocstringClass/epydoc_docstring_func/x', + 'id': 'various_modules_package/docstring_module/EpydocDocstringClass/epydoc_docstring_func/x', 'is_optional': False, 'is_type_inferred': False, 'name': 'x', @@ -2917,7 +2917,7 @@ 'description': 'Second integer value for the calculation. (Epydoc)', 'type': 'int', }), - 'id': 'various_tests_package/docstring_module/EpydocDocstringClass/epydoc_docstring_func/y', + 'id': 'various_modules_package/docstring_module/EpydocDocstringClass/epydoc_docstring_func/y', 'is_optional': False, 'is_type_inferred': False, 'name': 'y', @@ -2939,7 +2939,7 @@ 'description': 'Parameter of the calculator. (Google Style)', 'type': 'str', }), - 'id': 'various_tests_package/docstring_module/GoogleDocstringClass/__init__/param_1', + 'id': 'various_modules_package/docstring_module/GoogleDocstringClass/__init__/param_1', 'is_optional': False, 'is_type_inferred': False, 'name': 'param_1', @@ -2957,7 +2957,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/docstring_module/GoogleDocstringClass/__init__/self', + 'id': 'various_modules_package/docstring_module/GoogleDocstringClass/__init__/self', 'is_optional': False, 'is_type_inferred': False, 'name': 'self', @@ -2975,7 +2975,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/docstring_module/GoogleDocstringClass/google_docstring_func/self', + 'id': 'various_modules_package/docstring_module/GoogleDocstringClass/google_docstring_func/self', 'is_optional': False, 'is_type_inferred': False, 'name': 'self', @@ -2989,7 +2989,7 @@ 'description': 'First integer value for the calculation. (Google Style)', 'type': 'int', }), - 'id': 'various_tests_package/docstring_module/GoogleDocstringClass/google_docstring_func/x', + 'id': 'various_modules_package/docstring_module/GoogleDocstringClass/google_docstring_func/x', 'is_optional': False, 'is_type_inferred': False, 'name': 'x', @@ -3007,7 +3007,7 @@ 'description': 'Second integer value for the calculation. (Google Style)', 'type': 'int', }), - 'id': 'various_tests_package/docstring_module/GoogleDocstringClass/google_docstring_func/y', + 'id': 'various_modules_package/docstring_module/GoogleDocstringClass/google_docstring_func/y', 'is_optional': False, 'is_type_inferred': False, 'name': 'y', @@ -3029,7 +3029,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/function_module/illegal_params/_', + 'id': 'various_modules_package/function_module/illegal_params/_', 'is_optional': True, 'is_type_inferred': False, 'name': '_', @@ -3047,7 +3047,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/function_module/illegal_params/lst', + 'id': 'various_modules_package/function_module/illegal_params/lst', 'is_optional': False, 'is_type_inferred': False, 'name': 'lst', @@ -3075,7 +3075,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/function_module/illegal_params/lst_2', + 'id': 'various_modules_package/function_module/illegal_params/lst_2', 'is_optional': False, 'is_type_inferred': False, 'name': 'lst_2', @@ -3108,7 +3108,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/function_module/illegal_params/tpl', + 'id': 'various_modules_package/function_module/illegal_params/tpl', 'is_optional': False, 'is_type_inferred': False, 'name': 'tpl', @@ -3150,7 +3150,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/function_module/FunctionModuleClassB/FunctionModuleClassC/nested_class_function/param1', + 'id': 'various_modules_package/function_module/FunctionModuleClassB/FunctionModuleClassC/nested_class_function/param1', 'is_optional': False, 'is_type_inferred': False, 'name': 'param1', @@ -3168,7 +3168,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/function_module/FunctionModuleClassB/FunctionModuleClassC/nested_class_function/self', + 'id': 'various_modules_package/function_module/FunctionModuleClassB/FunctionModuleClassC/nested_class_function/self', 'is_optional': False, 'is_type_inferred': False, 'name': 'self', @@ -3186,7 +3186,7 @@ 'description': 'Parameter of the calculator. (Numpy)', 'type': 'str', }), - 'id': 'various_tests_package/docstring_module/NumpyDocstringClass/__init__/param_1', + 'id': 'various_modules_package/docstring_module/NumpyDocstringClass/__init__/param_1', 'is_optional': False, 'is_type_inferred': False, 'name': 'param_1', @@ -3204,7 +3204,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/docstring_module/NumpyDocstringClass/__init__/self', + 'id': 'various_modules_package/docstring_module/NumpyDocstringClass/__init__/self', 'is_optional': False, 'is_type_inferred': False, 'name': 'self', @@ -3222,7 +3222,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/docstring_module/NumpyDocstringClass/numpy_docstring_func/self', + 'id': 'various_modules_package/docstring_module/NumpyDocstringClass/numpy_docstring_func/self', 'is_optional': False, 'is_type_inferred': False, 'name': 'self', @@ -3236,7 +3236,7 @@ 'description': 'First integer value for the calculation. (Numpy)', 'type': 'int', }), - 'id': 'various_tests_package/docstring_module/NumpyDocstringClass/numpy_docstring_func/x', + 'id': 'various_modules_package/docstring_module/NumpyDocstringClass/numpy_docstring_func/x', 'is_optional': False, 'is_type_inferred': False, 'name': 'x', @@ -3254,7 +3254,7 @@ 'description': 'Second integer value for the calculation. (Numpy)', 'type': 'int', }), - 'id': 'various_tests_package/docstring_module/NumpyDocstringClass/numpy_docstring_func/y', + 'id': 'various_modules_package/docstring_module/NumpyDocstringClass/numpy_docstring_func/y', 'is_optional': False, 'is_type_inferred': False, 'name': 'y', @@ -3276,7 +3276,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/function_module/opt_pos_only/optional', + 'id': 'various_modules_package/function_module/opt_pos_only/optional', 'is_optional': True, 'is_type_inferred': True, 'name': 'optional', @@ -3294,7 +3294,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/function_module/opt_pos_only/required', + 'id': 'various_modules_package/function_module/opt_pos_only/required', 'is_optional': False, 'is_type_inferred': False, 'name': 'required', @@ -3312,7 +3312,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/function_module/param_position/a', + 'id': 'various_modules_package/function_module/param_position/a', 'is_optional': False, 'is_type_inferred': False, 'name': 'a', @@ -3326,7 +3326,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/function_module/param_position/b', + 'id': 'various_modules_package/function_module/param_position/b', 'is_optional': False, 'is_type_inferred': False, 'name': 'b', @@ -3344,14 +3344,14 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/function_module/param_position/c', + 'id': 'various_modules_package/function_module/param_position/c', 'is_optional': True, 'is_type_inferred': True, 'name': 'c', 'type': dict({ 'kind': 'NamedType', 'name': 'FunctionModuleClassA', - 'qname': 'tests.data.various_tests_package.function_module.FunctionModuleClassA', + 'qname': 'tests.data.various_modules_package.function_module.FunctionModuleClassA', }), }), dict({ @@ -3362,7 +3362,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/function_module/param_position/d', + 'id': 'various_modules_package/function_module/param_position/d', 'is_optional': False, 'is_type_inferred': True, 'name': 'd', @@ -3376,7 +3376,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/function_module/param_position/e', + 'id': 'various_modules_package/function_module/param_position/e', 'is_optional': True, 'is_type_inferred': False, 'name': 'e', @@ -3394,7 +3394,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/function_module/param_position/self', + 'id': 'various_modules_package/function_module/param_position/self', 'is_optional': False, 'is_type_inferred': False, 'name': 'self', @@ -3412,7 +3412,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/function_module/params/any_', + 'id': 'various_modules_package/function_module/params/any_', 'is_optional': False, 'is_type_inferred': False, 'name': 'any_', @@ -3430,7 +3430,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/function_module/params/boolean', + 'id': 'various_modules_package/function_module/params/boolean', 'is_optional': False, 'is_type_inferred': False, 'name': 'boolean', @@ -3448,7 +3448,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/function_module/params/callexpr', + 'id': 'various_modules_package/function_module/params/callexpr', 'is_optional': False, 'is_type_inferred': False, 'name': 'callexpr', @@ -3462,7 +3462,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/function_module/params/dictionary', + 'id': 'various_modules_package/function_module/params/dictionary', 'is_optional': False, 'is_type_inferred': False, 'name': 'dictionary', @@ -3498,7 +3498,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/function_module/params/float_', + 'id': 'various_modules_package/function_module/params/float_', 'is_optional': False, 'is_type_inferred': False, 'name': 'float_', @@ -3516,7 +3516,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/function_module/params/integer', + 'id': 'various_modules_package/function_module/params/integer', 'is_optional': False, 'is_type_inferred': False, 'name': 'integer', @@ -3534,7 +3534,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/function_module/params/list_', + 'id': 'various_modules_package/function_module/params/list_', 'is_optional': False, 'is_type_inferred': False, 'name': 'list_', @@ -3557,7 +3557,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/function_module/params/literal', + 'id': 'various_modules_package/function_module/params/literal', 'is_optional': False, 'is_type_inferred': False, 'name': 'literal', @@ -3574,7 +3574,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/function_module/params/none', + 'id': 'various_modules_package/function_module/params/none', 'is_optional': False, 'is_type_inferred': False, 'name': 'none', @@ -3592,14 +3592,14 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/function_module/params/obj', + 'id': 'various_modules_package/function_module/params/obj', 'is_optional': False, 'is_type_inferred': False, 'name': 'obj', 'type': dict({ 'kind': 'NamedType', 'name': 'FunctionModuleClassA', - 'qname': 'tests.data.various_tests_package.function_module.FunctionModuleClassA', + 'qname': 'tests.data.various_modules_package.function_module.FunctionModuleClassA', }), }), dict({ @@ -3610,7 +3610,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/function_module/params/optional', + 'id': 'various_modules_package/function_module/params/optional', 'is_optional': False, 'is_type_inferred': False, 'name': 'optional', @@ -3638,7 +3638,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/function_module/params/set_', + 'id': 'various_modules_package/function_module/params/set_', 'is_optional': False, 'is_type_inferred': False, 'name': 'set_', @@ -3661,7 +3661,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/function_module/params/string', + 'id': 'various_modules_package/function_module/params/string', 'is_optional': False, 'is_type_inferred': False, 'name': 'string', @@ -3679,7 +3679,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/function_module/params/tuple_', + 'id': 'various_modules_package/function_module/params/tuple_', 'is_optional': False, 'is_type_inferred': False, 'name': 'tuple_', @@ -3712,7 +3712,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/function_module/params/union', + 'id': 'various_modules_package/function_module/params/union', 'is_optional': False, 'is_type_inferred': False, 'name': 'union', @@ -3748,7 +3748,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/function_module/req_name_only/optional', + 'id': 'various_modules_package/function_module/req_name_only/optional', 'is_optional': True, 'is_type_inferred': True, 'name': 'optional', @@ -3766,7 +3766,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/function_module/req_name_only/required', + 'id': 'various_modules_package/function_module/req_name_only/required', 'is_optional': False, 'is_type_inferred': False, 'name': 'required', @@ -3784,7 +3784,7 @@ 'description': 'Parameter of the calculator. (ReST)', 'type': 'str', }), - 'id': 'various_tests_package/docstring_module/RestDocstringClass/__init__/param_1', + 'id': 'various_modules_package/docstring_module/RestDocstringClass/__init__/param_1', 'is_optional': False, 'is_type_inferred': False, 'name': 'param_1', @@ -3802,7 +3802,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/docstring_module/RestDocstringClass/__init__/self', + 'id': 'various_modules_package/docstring_module/RestDocstringClass/__init__/self', 'is_optional': False, 'is_type_inferred': False, 'name': 'self', @@ -3820,7 +3820,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/docstring_module/RestDocstringClass/rest_docstring_func/self', + 'id': 'various_modules_package/docstring_module/RestDocstringClass/rest_docstring_func/self', 'is_optional': False, 'is_type_inferred': False, 'name': 'self', @@ -3834,7 +3834,7 @@ 'description': 'First integer value for the calculation. (ReST)', 'type': 'int', }), - 'id': 'various_tests_package/docstring_module/RestDocstringClass/rest_docstring_func/x', + 'id': 'various_modules_package/docstring_module/RestDocstringClass/rest_docstring_func/x', 'is_optional': False, 'is_type_inferred': False, 'name': 'x', @@ -3852,7 +3852,7 @@ 'description': 'Second integer value for the calculation. (ReST)', 'type': 'int', }), - 'id': 'various_tests_package/docstring_module/RestDocstringClass/rest_docstring_func/y', + 'id': 'various_modules_package/docstring_module/RestDocstringClass/rest_docstring_func/y', 'is_optional': False, 'is_type_inferred': False, 'name': 'y', @@ -3874,7 +3874,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/function_module/special_params/bool_none_union', + 'id': 'various_modules_package/function_module/special_params/bool_none_union', 'is_optional': False, 'is_type_inferred': False, 'name': 'bool_none_union', @@ -3902,7 +3902,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/function_module/special_params/none', + 'id': 'various_modules_package/function_module/special_params/none', 'is_optional': False, 'is_type_inferred': False, 'name': 'none', @@ -3920,7 +3920,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/function_module/special_params/none_bool_int_union', + 'id': 'various_modules_package/function_module/special_params/none_bool_int_union', 'is_optional': False, 'is_type_inferred': False, 'name': 'none_bool_int_union', @@ -3953,7 +3953,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/function_module/special_params/none_bool_none_union', + 'id': 'various_modules_package/function_module/special_params/none_bool_none_union', 'is_optional': False, 'is_type_inferred': False, 'name': 'none_bool_none_union', @@ -3986,7 +3986,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/function_module/special_params/none_bool_union', + 'id': 'various_modules_package/function_module/special_params/none_bool_union', 'is_optional': False, 'is_type_inferred': False, 'name': 'none_bool_union', @@ -4014,7 +4014,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/function_module/special_params/none_list_union_none_none', + 'id': 'various_modules_package/function_module/special_params/none_list_union_none_none', 'is_optional': False, 'is_type_inferred': False, 'name': 'none_list_union_none_none', @@ -4062,7 +4062,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/function_module/special_params/none_none_bool_none_union', + 'id': 'various_modules_package/function_module/special_params/none_none_bool_none_union', 'is_optional': False, 'is_type_inferred': False, 'name': 'none_none_bool_none_union', @@ -4100,7 +4100,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/function_module/special_params/none_union', + 'id': 'various_modules_package/function_module/special_params/none_union', 'is_optional': False, 'is_type_inferred': False, 'name': 'none_union', @@ -4132,7 +4132,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/function_module/FunctionModuleClassB/static_method_params/param_1', + 'id': 'various_modules_package/function_module/FunctionModuleClassB/static_method_params/param_1', 'is_optional': False, 'is_type_inferred': False, 'name': 'param_1', @@ -4151,7 +4151,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/abstract_module/AbstractModuleClass/abstract_method_params/result_1', + 'id': 'various_modules_package/abstract_module/AbstractModuleClass/abstract_method_params/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ @@ -4179,7 +4179,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/abstract_module/AbstractModuleClass/abstract_property_method/result_1', + 'id': 'various_modules_package/abstract_module/AbstractModuleClass/abstract_property_method/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ @@ -4193,7 +4193,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/abstract_module/AbstractModuleClass/abstract_property_method/result_2', + 'id': 'various_modules_package/abstract_module/AbstractModuleClass/abstract_property_method/result_2', 'is_type_inferred': False, 'name': 'result_2', 'type': dict({ @@ -4211,7 +4211,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/abstract_module/AbstractModuleClass/abstract_static_method_params/result_1', + 'id': 'various_modules_package/abstract_module/AbstractModuleClass/abstract_static_method_params/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ @@ -4229,7 +4229,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/function_module/any_results/result_1', + 'id': 'various_modules_package/function_module/any_results/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ @@ -4247,7 +4247,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/function_module/callable_type/result_1', + 'id': 'various_modules_package/function_module/callable_type/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ @@ -4288,7 +4288,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/function_module/FunctionModuleClassB/class_method_params/result_1', + 'id': 'various_modules_package/function_module/FunctionModuleClassB/class_method_params/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ @@ -4306,7 +4306,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/function_module/dictionary_results/result_1', + 'id': 'various_modules_package/function_module/dictionary_results/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ @@ -4319,7 +4319,7 @@ 'value_type': dict({ 'kind': 'NamedType', 'name': 'FunctionModuleClassA', - 'qname': 'tests.data.various_tests_package.function_module.FunctionModuleClassA', + 'qname': 'tests.data.various_modules_package.function_module.FunctionModuleClassA', }), }), }), @@ -4332,7 +4332,7 @@ 'description': 'Checks if the sum of x and y is greater than 10. (Epydoc)', 'type': 'bool', }), - 'id': 'various_tests_package/docstring_module/EpydocDocstringClass/epydoc_docstring_func/result_1', + 'id': 'various_modules_package/docstring_module/EpydocDocstringClass/epydoc_docstring_func/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ @@ -4350,7 +4350,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/function_module/float_result/result_1', + 'id': 'various_modules_package/function_module/float_result/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ @@ -4371,7 +4371,7 @@ ''', 'type': 'bool', }), - 'id': 'various_tests_package/docstring_module/GoogleDocstringClass/google_docstring_func/result_1', + 'id': 'various_modules_package/docstring_module/GoogleDocstringClass/google_docstring_func/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ @@ -4389,7 +4389,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/function_module/illegal_dictionary_results/result_1', + 'id': 'various_modules_package/function_module/illegal_dictionary_results/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ @@ -4415,7 +4415,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/function_module/illegal_list_results/result_1', + 'id': 'various_modules_package/function_module/illegal_list_results/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ @@ -4443,7 +4443,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/function_module/illegal_set_results/result_1', + 'id': 'various_modules_package/function_module/illegal_set_results/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ @@ -4471,7 +4471,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/infer_types_module/InferMyTypes/infer_function/result_1', + 'id': 'various_modules_package/infer_types_module/InferMyTypes/infer_function/result_1', 'is_type_inferred': True, 'name': 'result_1', 'type': dict({ @@ -4490,22 +4490,22 @@ dict({ 'kind': 'NamedType', 'name': 'InferMe', - 'qname': 'tests.data.various_tests_package.infer_types_module.InferMe', + 'qname': 'tests.data.various_modules_package.infer_types_module.InferMe', }), dict({ 'kind': 'NamedType', 'name': 'InferMe2', - 'qname': 'tests.data.various_tests_package.infer_types_module.InferMe2', + 'qname': 'tests.data.various_modules_package.infer_types_module.InferMe2', }), dict({ 'kind': 'NamedType', 'name': 'InferMe3', - 'qname': 'tests.data.various_tests_package.infer_types_module.InferMe3', + 'qname': 'tests.data.various_modules_package.infer_types_module.InferMe3', }), dict({ 'kind': 'NamedType', 'name': 'InferMyTypes', - 'qname': 'tests.data.various_tests_package.infer_types_module.InferMyTypes', + 'qname': 'tests.data.various_modules_package.infer_types_module.InferMyTypes', }), dict({ 'kind': 'NamedType', @@ -4535,7 +4535,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/infer_types_module/InferMyTypes/infer_function/result_2', + 'id': 'various_modules_package/infer_types_module/InferMyTypes/infer_function/result_2', 'is_type_inferred': True, 'name': 'result_2', 'type': dict({ @@ -4559,7 +4559,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/infer_types_module/InferMyTypes/infer_function/result_3', + 'id': 'various_modules_package/infer_types_module/InferMyTypes/infer_function/result_3', 'is_type_inferred': True, 'name': 'result_3', 'type': dict({ @@ -4577,13 +4577,13 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/function_module/FunctionModuleClassB/instance_method/result_1', + 'id': 'various_modules_package/function_module/FunctionModuleClassB/instance_method/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ 'kind': 'NamedType', 'name': 'FunctionModuleClassA', - 'qname': 'tests.data.various_tests_package.function_module.FunctionModuleClassA', + 'qname': 'tests.data.various_modules_package.function_module.FunctionModuleClassA', }), }), ]) @@ -4595,7 +4595,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/function_module/int_result/result_1', + 'id': 'various_modules_package/function_module/int_result/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ @@ -4613,7 +4613,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/function_module/list_results/result_1', + 'id': 'various_modules_package/function_module/list_results/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ @@ -4636,7 +4636,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/function_module/literal_results/result_1', + 'id': 'various_modules_package/function_module/literal_results/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ @@ -4653,7 +4653,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/function_module/FunctionModuleClassB/FunctionModuleClassC/nested_class_function/result_1', + 'id': 'various_modules_package/function_module/FunctionModuleClassB/FunctionModuleClassC/nested_class_function/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ @@ -4675,7 +4675,7 @@ 'description': 'Checks if the sum of `x` and `y` is greater than 10. (Numpy)', 'type': 'bool', }), - 'id': 'various_tests_package/docstring_module/NumpyDocstringClass/numpy_docstring_func/result_1', + 'id': 'various_modules_package/docstring_module/NumpyDocstringClass/numpy_docstring_func/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ @@ -4693,13 +4693,13 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/function_module/obj_result/result_1', + 'id': 'various_modules_package/function_module/obj_result/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ 'kind': 'NamedType', 'name': 'FunctionModuleClassA', - 'qname': 'tests.data.various_tests_package.function_module.FunctionModuleClassA', + 'qname': 'tests.data.various_modules_package.function_module.FunctionModuleClassA', }), }), ]) @@ -4711,7 +4711,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/function_module/optional_results/result_1', + 'id': 'various_modules_package/function_module/optional_results/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ @@ -4743,7 +4743,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/function_module/FunctionModulePropertiesClass/property_function_infer/result_1', + 'id': 'various_modules_package/function_module/FunctionModulePropertiesClass/property_function_infer/result_1', 'is_type_inferred': True, 'name': 'result_1', 'type': dict({ @@ -4761,7 +4761,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/function_module/FunctionModulePropertiesClass/property_function_params/result_1', + 'id': 'various_modules_package/function_module/FunctionModulePropertiesClass/property_function_params/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ @@ -4779,7 +4779,7 @@ 'description': 'Checks if the sum of x and y is greater than 10. (ReST)', 'type': 'bool', }), - 'id': 'various_tests_package/docstring_module/RestDocstringClass/rest_docstring_func/result_1', + 'id': 'various_modules_package/docstring_module/RestDocstringClass/rest_docstring_func/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ @@ -4797,7 +4797,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/function_module/set_results/result_1', + 'id': 'various_modules_package/function_module/set_results/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ @@ -4824,7 +4824,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/function_module/str_result/result_1', + 'id': 'various_modules_package/function_module/str_result/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ @@ -4842,7 +4842,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/function_module/tuple_results/result_1', + 'id': 'various_modules_package/function_module/tuple_results/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ @@ -4856,13 +4856,13 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/function_module/tuple_results/result_2', + 'id': 'various_modules_package/function_module/tuple_results/result_2', 'is_type_inferred': False, 'name': 'result_2', 'type': dict({ 'kind': 'NamedType', 'name': 'FunctionModuleClassA', - 'qname': 'tests.data.various_tests_package.function_module.FunctionModuleClassA', + 'qname': 'tests.data.various_modules_package.function_module.FunctionModuleClassA', }), }), ]) @@ -4874,7 +4874,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/function_module/union_dictionary_results/result_1', + 'id': 'various_modules_package/function_module/union_dictionary_results/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ @@ -4920,7 +4920,7 @@ 'description': '', 'type': '', }), - 'id': 'various_tests_package/function_module/union_results/result_1', + 'id': 'various_modules_package/function_module/union_results/result_1', 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ @@ -4948,7 +4948,7 @@ 'description': '', 'full_docstring': '', }), - 'id': 'various_tests_package/_reexport_module_1/reexported_function', + 'id': 'various_modules_package/_reexport_module_1/reexported_function', 'is_class_method': False, 'is_property': False, 'is_public': False, @@ -4970,7 +4970,7 @@ 'description': '', 'full_docstring': '', }), - 'id': 'various_tests_package/_reexport_module_2/reexported_function_2', + 'id': 'various_modules_package/_reexport_module_2/reexported_function_2', 'is_class_method': False, 'is_property': False, 'is_public': True, @@ -4979,7 +4979,7 @@ 'parameters': list([ ]), 'reexported_by': list([ - 'various_tests_package/__init__', + 'various_modules_package/__init__', ]), 'results': list([ ]), @@ -4993,7 +4993,7 @@ 'description': '', 'full_docstring': '', }), - 'id': 'various_tests_package/_reexport_module_3/reexported_function_3', + 'id': 'various_modules_package/_reexport_module_3/reexported_function_3', 'is_class_method': False, 'is_property': False, 'is_public': False, @@ -5002,7 +5002,7 @@ 'parameters': list([ ]), 'reexported_by': list([ - 'various_tests_package/__init__', + 'various_modules_package/__init__', ]), 'results': list([ ]), @@ -5016,7 +5016,7 @@ 'description': '', 'full_docstring': '', }), - 'id': 'various_tests_package/_reexport_module_4/_reexported_function_4', + 'id': 'various_modules_package/_reexport_module_4/_reexported_function_4', 'is_class_method': False, 'is_property': False, 'is_public': False, @@ -5025,7 +5025,7 @@ 'parameters': list([ ]), 'reexported_by': list([ - 'various_tests_package/__init__', + 'various_modules_package/__init__', ]), 'results': list([ ]), @@ -5035,7 +5035,7 @@ 'description': '', 'full_docstring': '', }), - 'id': 'various_tests_package/_reexport_module_4/_unreexported_function', + 'id': 'various_modules_package/_reexport_module_4/_unreexported_function', 'is_class_method': False, 'is_property': False, 'is_public': False, @@ -5057,14 +5057,14 @@ 'description': '', 'full_docstring': '', }), - 'id': 'various_tests_package/function_module/_private', + 'id': 'various_modules_package/function_module/_private', 'is_class_method': False, 'is_property': False, 'is_public': False, 'is_static': False, 'name': '_private', 'parameters': list([ - 'various_tests_package/function_module/_private/a', + 'various_modules_package/function_module/_private/a', ]), 'reexported_by': list([ ]), @@ -5076,7 +5076,7 @@ 'description': '', 'full_docstring': '', }), - 'id': 'various_tests_package/function_module/any_results', + 'id': 'various_modules_package/function_module/any_results', 'is_class_method': False, 'is_property': False, 'is_public': True, @@ -5087,7 +5087,7 @@ 'reexported_by': list([ ]), 'results': list([ - 'various_tests_package/function_module/any_results/result_1', + 'various_modules_package/function_module/any_results/result_1', ]), }), dict({ @@ -5095,15 +5095,15 @@ 'description': '', 'full_docstring': '', }), - 'id': 'various_tests_package/function_module/arg', + 'id': 'various_modules_package/function_module/arg', 'is_class_method': False, 'is_property': False, 'is_public': True, 'is_static': False, 'name': 'arg', 'parameters': list([ - 'various_tests_package/function_module/arg/args', - 'various_tests_package/function_module/arg/kwargs', + 'various_modules_package/function_module/arg/args', + 'various_modules_package/function_module/arg/kwargs', ]), 'reexported_by': list([ ]), @@ -5115,15 +5115,15 @@ 'description': '', 'full_docstring': '', }), - 'id': 'various_tests_package/function_module/args_type', + 'id': 'various_modules_package/function_module/args_type', 'is_class_method': False, 'is_property': False, 'is_public': True, 'is_static': False, 'name': 'args_type', 'parameters': list([ - 'various_tests_package/function_module/args_type/args', - 'various_tests_package/function_module/args_type/kwargs', + 'various_modules_package/function_module/args_type/args', + 'various_modules_package/function_module/args_type/kwargs', ]), 'reexported_by': list([ ]), @@ -5135,7 +5135,7 @@ 'description': '', 'full_docstring': '', }), - 'id': 'various_tests_package/function_module/bool_result', + 'id': 'various_modules_package/function_module/bool_result', 'is_class_method': False, 'is_property': False, 'is_public': True, @@ -5146,7 +5146,7 @@ 'reexported_by': list([ ]), 'results': list([ - 'various_tests_package/function_module/bool_result/result_1', + 'various_modules_package/function_module/bool_result/result_1', ]), }), dict({ @@ -5154,19 +5154,19 @@ 'description': '', 'full_docstring': '', }), - 'id': 'various_tests_package/function_module/callable_type', + 'id': 'various_modules_package/function_module/callable_type', 'is_class_method': False, 'is_property': False, 'is_public': True, 'is_static': False, 'name': 'callable_type', 'parameters': list([ - 'various_tests_package/function_module/callable_type/param', + 'various_modules_package/function_module/callable_type/param', ]), 'reexported_by': list([ ]), 'results': list([ - 'various_tests_package/function_module/callable_type/result_1', + 'various_modules_package/function_module/callable_type/result_1', ]), }), dict({ @@ -5174,7 +5174,7 @@ 'description': '', 'full_docstring': '', }), - 'id': 'various_tests_package/function_module/callexr_result_class', + 'id': 'various_modules_package/function_module/callexr_result_class', 'is_class_method': False, 'is_property': False, 'is_public': True, @@ -5192,7 +5192,7 @@ 'description': '', 'full_docstring': '', }), - 'id': 'various_tests_package/function_module/callexr_result_function', + 'id': 'various_modules_package/function_module/callexr_result_function', 'is_class_method': False, 'is_property': False, 'is_public': True, @@ -5210,7 +5210,7 @@ 'description': '', 'full_docstring': '', }), - 'id': 'various_tests_package/function_module/dictionary_results', + 'id': 'various_modules_package/function_module/dictionary_results', 'is_class_method': False, 'is_property': False, 'is_public': True, @@ -5221,7 +5221,7 @@ 'reexported_by': list([ ]), 'results': list([ - 'various_tests_package/function_module/dictionary_results/result_1', + 'various_modules_package/function_module/dictionary_results/result_1', ]), }), dict({ @@ -5229,7 +5229,7 @@ 'description': '', 'full_docstring': '', }), - 'id': 'various_tests_package/function_module/float_result', + 'id': 'various_modules_package/function_module/float_result', 'is_class_method': False, 'is_property': False, 'is_public': True, @@ -5240,7 +5240,7 @@ 'reexported_by': list([ ]), 'results': list([ - 'various_tests_package/function_module/float_result/result_1', + 'various_modules_package/function_module/float_result/result_1', ]), }), dict({ @@ -5248,7 +5248,7 @@ 'description': '', 'full_docstring': '', }), - 'id': 'various_tests_package/function_module/illegal_dictionary_results', + 'id': 'various_modules_package/function_module/illegal_dictionary_results', 'is_class_method': False, 'is_property': False, 'is_public': True, @@ -5259,7 +5259,7 @@ 'reexported_by': list([ ]), 'results': list([ - 'various_tests_package/function_module/illegal_dictionary_results/result_1', + 'various_modules_package/function_module/illegal_dictionary_results/result_1', ]), }), dict({ @@ -5267,7 +5267,7 @@ 'description': '', 'full_docstring': '', }), - 'id': 'various_tests_package/function_module/illegal_list_results', + 'id': 'various_modules_package/function_module/illegal_list_results', 'is_class_method': False, 'is_property': False, 'is_public': True, @@ -5278,7 +5278,7 @@ 'reexported_by': list([ ]), 'results': list([ - 'various_tests_package/function_module/illegal_list_results/result_1', + 'various_modules_package/function_module/illegal_list_results/result_1', ]), }), dict({ @@ -5286,17 +5286,17 @@ 'description': '', 'full_docstring': '', }), - 'id': 'various_tests_package/function_module/illegal_params', + 'id': 'various_modules_package/function_module/illegal_params', 'is_class_method': False, 'is_property': False, 'is_public': True, 'is_static': False, 'name': 'illegal_params', 'parameters': list([ - 'various_tests_package/function_module/illegal_params/lst', - 'various_tests_package/function_module/illegal_params/lst_2', - 'various_tests_package/function_module/illegal_params/tpl', - 'various_tests_package/function_module/illegal_params/_', + 'various_modules_package/function_module/illegal_params/lst', + 'various_modules_package/function_module/illegal_params/lst_2', + 'various_modules_package/function_module/illegal_params/tpl', + 'various_modules_package/function_module/illegal_params/_', ]), 'reexported_by': list([ ]), @@ -5308,7 +5308,7 @@ 'description': '', 'full_docstring': '', }), - 'id': 'various_tests_package/function_module/illegal_set_results', + 'id': 'various_modules_package/function_module/illegal_set_results', 'is_class_method': False, 'is_property': False, 'is_public': True, @@ -5319,7 +5319,7 @@ 'reexported_by': list([ ]), 'results': list([ - 'various_tests_package/function_module/illegal_set_results/result_1', + 'various_modules_package/function_module/illegal_set_results/result_1', ]), }), dict({ @@ -5327,7 +5327,7 @@ 'description': '', 'full_docstring': '', }), - 'id': 'various_tests_package/function_module/int_result', + 'id': 'various_modules_package/function_module/int_result', 'is_class_method': False, 'is_property': False, 'is_public': True, @@ -5338,7 +5338,7 @@ 'reexported_by': list([ ]), 'results': list([ - 'various_tests_package/function_module/int_result/result_1', + 'various_modules_package/function_module/int_result/result_1', ]), }), dict({ @@ -5346,7 +5346,7 @@ 'description': '', 'full_docstring': '', }), - 'id': 'various_tests_package/function_module/list_results', + 'id': 'various_modules_package/function_module/list_results', 'is_class_method': False, 'is_property': False, 'is_public': True, @@ -5357,7 +5357,7 @@ 'reexported_by': list([ ]), 'results': list([ - 'various_tests_package/function_module/list_results/result_1', + 'various_modules_package/function_module/list_results/result_1', ]), }), dict({ @@ -5365,7 +5365,7 @@ 'description': '', 'full_docstring': '', }), - 'id': 'various_tests_package/function_module/literal_results', + 'id': 'various_modules_package/function_module/literal_results', 'is_class_method': False, 'is_property': False, 'is_public': True, @@ -5376,7 +5376,7 @@ 'reexported_by': list([ ]), 'results': list([ - 'various_tests_package/function_module/literal_results/result_1', + 'various_modules_package/function_module/literal_results/result_1', ]), }), dict({ @@ -5384,7 +5384,7 @@ 'description': '', 'full_docstring': '', }), - 'id': 'various_tests_package/function_module/none_result', + 'id': 'various_modules_package/function_module/none_result', 'is_class_method': False, 'is_property': False, 'is_public': True, @@ -5402,7 +5402,7 @@ 'description': '', 'full_docstring': '', }), - 'id': 'various_tests_package/function_module/obj_result', + 'id': 'various_modules_package/function_module/obj_result', 'is_class_method': False, 'is_property': False, 'is_public': True, @@ -5413,7 +5413,7 @@ 'reexported_by': list([ ]), 'results': list([ - 'various_tests_package/function_module/obj_result/result_1', + 'various_modules_package/function_module/obj_result/result_1', ]), }), dict({ @@ -5421,15 +5421,15 @@ 'description': '', 'full_docstring': '', }), - 'id': 'various_tests_package/function_module/opt_pos_only', + 'id': 'various_modules_package/function_module/opt_pos_only', 'is_class_method': False, 'is_property': False, 'is_public': True, 'is_static': False, 'name': 'opt_pos_only', 'parameters': list([ - 'various_tests_package/function_module/opt_pos_only/required', - 'various_tests_package/function_module/opt_pos_only/optional', + 'various_modules_package/function_module/opt_pos_only/required', + 'various_modules_package/function_module/opt_pos_only/optional', ]), 'reexported_by': list([ ]), @@ -5441,7 +5441,7 @@ 'description': '', 'full_docstring': '', }), - 'id': 'various_tests_package/function_module/optional_results', + 'id': 'various_modules_package/function_module/optional_results', 'is_class_method': False, 'is_property': False, 'is_public': True, @@ -5452,7 +5452,7 @@ 'reexported_by': list([ ]), 'results': list([ - 'various_tests_package/function_module/optional_results/result_1', + 'various_modules_package/function_module/optional_results/result_1', ]), }), dict({ @@ -5460,19 +5460,19 @@ 'description': '', 'full_docstring': '', }), - 'id': 'various_tests_package/function_module/param_position', + 'id': 'various_modules_package/function_module/param_position', 'is_class_method': False, 'is_property': False, 'is_public': True, 'is_static': False, 'name': 'param_position', 'parameters': list([ - 'various_tests_package/function_module/param_position/self', - 'various_tests_package/function_module/param_position/a', - 'various_tests_package/function_module/param_position/b', - 'various_tests_package/function_module/param_position/c', - 'various_tests_package/function_module/param_position/d', - 'various_tests_package/function_module/param_position/e', + 'various_modules_package/function_module/param_position/self', + 'various_modules_package/function_module/param_position/a', + 'various_modules_package/function_module/param_position/b', + 'various_modules_package/function_module/param_position/c', + 'various_modules_package/function_module/param_position/d', + 'various_modules_package/function_module/param_position/e', ]), 'reexported_by': list([ ]), @@ -5484,28 +5484,28 @@ 'description': '', 'full_docstring': '', }), - 'id': 'various_tests_package/function_module/params', + 'id': 'various_modules_package/function_module/params', 'is_class_method': False, 'is_property': False, 'is_public': True, 'is_static': False, 'name': 'params', 'parameters': list([ - 'various_tests_package/function_module/params/integer', - 'various_tests_package/function_module/params/boolean', - 'various_tests_package/function_module/params/float_', - 'various_tests_package/function_module/params/none', - 'various_tests_package/function_module/params/string', - 'various_tests_package/function_module/params/obj', - 'various_tests_package/function_module/params/callexpr', - 'various_tests_package/function_module/params/union', - 'various_tests_package/function_module/params/list_', - 'various_tests_package/function_module/params/dictionary', - 'various_tests_package/function_module/params/set_', - 'various_tests_package/function_module/params/optional', - 'various_tests_package/function_module/params/tuple_', - 'various_tests_package/function_module/params/literal', - 'various_tests_package/function_module/params/any_', + 'various_modules_package/function_module/params/integer', + 'various_modules_package/function_module/params/boolean', + 'various_modules_package/function_module/params/float_', + 'various_modules_package/function_module/params/none', + 'various_modules_package/function_module/params/string', + 'various_modules_package/function_module/params/obj', + 'various_modules_package/function_module/params/callexpr', + 'various_modules_package/function_module/params/union', + 'various_modules_package/function_module/params/list_', + 'various_modules_package/function_module/params/dictionary', + 'various_modules_package/function_module/params/set_', + 'various_modules_package/function_module/params/optional', + 'various_modules_package/function_module/params/tuple_', + 'various_modules_package/function_module/params/literal', + 'various_modules_package/function_module/params/any_', ]), 'reexported_by': list([ ]), @@ -5517,7 +5517,7 @@ 'description': '', 'full_docstring': '', }), - 'id': 'various_tests_package/function_module/public_no_params_no_result', + 'id': 'various_modules_package/function_module/public_no_params_no_result', 'is_class_method': False, 'is_property': False, 'is_public': True, @@ -5535,15 +5535,15 @@ 'description': '', 'full_docstring': '', }), - 'id': 'various_tests_package/function_module/req_name_only', + 'id': 'various_modules_package/function_module/req_name_only', 'is_class_method': False, 'is_property': False, 'is_public': True, 'is_static': False, 'name': 'req_name_only', 'parameters': list([ - 'various_tests_package/function_module/req_name_only/required', - 'various_tests_package/function_module/req_name_only/optional', + 'various_modules_package/function_module/req_name_only/required', + 'various_modules_package/function_module/req_name_only/optional', ]), 'reexported_by': list([ ]), @@ -5555,7 +5555,7 @@ 'description': '', 'full_docstring': '', }), - 'id': 'various_tests_package/function_module/set_results', + 'id': 'various_modules_package/function_module/set_results', 'is_class_method': False, 'is_property': False, 'is_public': True, @@ -5566,7 +5566,7 @@ 'reexported_by': list([ ]), 'results': list([ - 'various_tests_package/function_module/set_results/result_1', + 'various_modules_package/function_module/set_results/result_1', ]), }), dict({ @@ -5574,21 +5574,21 @@ 'description': '', 'full_docstring': '', }), - 'id': 'various_tests_package/function_module/special_params', + 'id': 'various_modules_package/function_module/special_params', 'is_class_method': False, 'is_property': False, 'is_public': True, 'is_static': False, 'name': 'special_params', 'parameters': list([ - 'various_tests_package/function_module/special_params/none_union', - 'various_tests_package/function_module/special_params/none_bool_union', - 'various_tests_package/function_module/special_params/bool_none_union', - 'various_tests_package/function_module/special_params/none_bool_none_union', - 'various_tests_package/function_module/special_params/none_bool_int_union', - 'various_tests_package/function_module/special_params/none_none_bool_none_union', - 'various_tests_package/function_module/special_params/none_list_union_none_none', - 'various_tests_package/function_module/special_params/none', + 'various_modules_package/function_module/special_params/none_union', + 'various_modules_package/function_module/special_params/none_bool_union', + 'various_modules_package/function_module/special_params/bool_none_union', + 'various_modules_package/function_module/special_params/none_bool_none_union', + 'various_modules_package/function_module/special_params/none_bool_int_union', + 'various_modules_package/function_module/special_params/none_none_bool_none_union', + 'various_modules_package/function_module/special_params/none_list_union_none_none', + 'various_modules_package/function_module/special_params/none', ]), 'reexported_by': list([ ]), @@ -5600,7 +5600,7 @@ 'description': '', 'full_docstring': '', }), - 'id': 'various_tests_package/function_module/str_result', + 'id': 'various_modules_package/function_module/str_result', 'is_class_method': False, 'is_property': False, 'is_public': True, @@ -5611,7 +5611,7 @@ 'reexported_by': list([ ]), 'results': list([ - 'various_tests_package/function_module/str_result/result_1', + 'various_modules_package/function_module/str_result/result_1', ]), }), dict({ @@ -5619,7 +5619,7 @@ 'description': '', 'full_docstring': '', }), - 'id': 'various_tests_package/function_module/tuple_results', + 'id': 'various_modules_package/function_module/tuple_results', 'is_class_method': False, 'is_property': False, 'is_public': True, @@ -5630,8 +5630,8 @@ 'reexported_by': list([ ]), 'results': list([ - 'various_tests_package/function_module/tuple_results/result_1', - 'various_tests_package/function_module/tuple_results/result_2', + 'various_modules_package/function_module/tuple_results/result_1', + 'various_modules_package/function_module/tuple_results/result_2', ]), }), dict({ @@ -5639,7 +5639,7 @@ 'description': '', 'full_docstring': '', }), - 'id': 'various_tests_package/function_module/union_dictionary_results', + 'id': 'various_modules_package/function_module/union_dictionary_results', 'is_class_method': False, 'is_property': False, 'is_public': True, @@ -5650,7 +5650,7 @@ 'reexported_by': list([ ]), 'results': list([ - 'various_tests_package/function_module/union_dictionary_results/result_1', + 'various_modules_package/function_module/union_dictionary_results/result_1', ]), }), dict({ @@ -5658,7 +5658,7 @@ 'description': '', 'full_docstring': '', }), - 'id': 'various_tests_package/function_module/union_results', + 'id': 'various_modules_package/function_module/union_results', 'is_class_method': False, 'is_property': False, 'is_public': True, @@ -5669,7 +5669,7 @@ 'reexported_by': list([ ]), 'results': list([ - 'various_tests_package/function_module/union_results/result_1', + 'various_modules_package/function_module/union_results/result_1', ]), }), ]) @@ -5765,7 +5765,7 @@ ]), 'functions': list([ ]), - 'id': 'various_tests_package/__init__', + 'id': 'various_modules_package/__init__', 'name': '__init__', 'qualified_imports': list([ dict({ @@ -5803,7 +5803,7 @@ # name: test_modules[another_module] dict({ 'classes': list([ - 'various_tests_package/another_path/another_module/AnotherClass', + 'various_modules_package/another_path/another_module/AnotherClass', ]), 'docstring': ''' Another Module Docstring. @@ -5815,7 +5815,7 @@ ]), 'functions': list([ ]), - 'id': 'various_tests_package/another_path/another_module', + 'id': 'various_modules_package/another_path/another_module', 'name': 'another_module', 'qualified_imports': list([ ]), @@ -5826,18 +5826,18 @@ # name: test_modules[class_module] dict({ 'classes': list([ - 'various_tests_package/class_module/ClassModuleEmptyClassA', - 'various_tests_package/class_module/ClassModuleClassB', - 'various_tests_package/class_module/ClassModuleClassC', - 'various_tests_package/class_module/ClassModuleClassD', - 'various_tests_package/class_module/_ClassModulePrivateClassG', + 'various_modules_package/class_module/ClassModuleEmptyClassA', + 'various_modules_package/class_module/ClassModuleClassB', + 'various_modules_package/class_module/ClassModuleClassC', + 'various_modules_package/class_module/ClassModuleClassD', + 'various_modules_package/class_module/_ClassModulePrivateClassG', ]), 'docstring': '', 'enums': list([ ]), 'functions': list([ ]), - 'id': 'various_tests_package/class_module', + 'id': 'various_modules_package/class_module', 'name': 'class_module', 'qualified_imports': list([ ]), @@ -5848,10 +5848,10 @@ # name: test_modules[docstring_module] dict({ 'classes': list([ - 'various_tests_package/docstring_module/EpydocDocstringClass', - 'various_tests_package/docstring_module/RestDocstringClass', - 'various_tests_package/docstring_module/NumpyDocstringClass', - 'various_tests_package/docstring_module/GoogleDocstringClass', + 'various_modules_package/docstring_module/EpydocDocstringClass', + 'various_modules_package/docstring_module/RestDocstringClass', + 'various_modules_package/docstring_module/NumpyDocstringClass', + 'various_modules_package/docstring_module/GoogleDocstringClass', ]), 'docstring': ''' Test module for docstring tests. @@ -5863,7 +5863,7 @@ ]), 'functions': list([ ]), - 'id': 'various_tests_package/docstring_module', + 'id': 'various_modules_package/docstring_module', 'name': 'docstring_module', 'qualified_imports': list([ ]), @@ -5877,15 +5877,15 @@ ]), 'docstring': '', 'enums': list([ - 'various_tests_package/enum_module/_ReexportedEmptyEnum', - 'various_tests_package/enum_module/EnumTest', - 'various_tests_package/enum_module/EnumTest2', - 'various_tests_package/enum_module/EnumTest3', - 'various_tests_package/enum_module/EmptyEnum', + 'various_modules_package/enum_module/_ReexportedEmptyEnum', + 'various_modules_package/enum_module/EnumTest', + 'various_modules_package/enum_module/EnumTest2', + 'various_modules_package/enum_module/EnumTest3', + 'various_modules_package/enum_module/EmptyEnum', ]), 'functions': list([ ]), - 'id': 'various_tests_package/enum_module', + 'id': 'various_modules_package/enum_module', 'name': 'enum_module', 'qualified_imports': list([ dict({ diff --git a/tests/safeds_stubgen/api_analyzer/test__get_api.py b/tests/safeds_stubgen/api_analyzer/test__get_api.py index 39f6dc78..fb2ee445 100644 --- a/tests/safeds_stubgen/api_analyzer/test__get_api.py +++ b/tests/safeds_stubgen/api_analyzer/test__get_api.py @@ -12,7 +12,7 @@ # Setup: API data _test_dir = Path(__file__).parent.parent.parent -_test_package_name = "various_tests_package" +_test_package_name = "various_modules_package" api_data_paintext = get_api( package_name=_test_package_name, diff --git a/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr b/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr index 7ff8ddaa..c5b31851 100644 --- a/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr +++ b/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr @@ -1,8 +1,8 @@ # serializer version: 1 # name: test_abstract_creation ''' - @PythonModule("various_tests_package.abstract_module") - package variousTestsPackage.abstractModule + @PythonModule("various_modules_package.abstract_module") + package variousModulesPackage.abstractModule from abc import ABC from abc import abstractmethod @@ -39,8 +39,8 @@ # --- # name: test_class_attribute_creation ''' - @PythonModule("various_tests_package.attribute_module") - package variousTestsPackage.attributeModule + @PythonModule("various_modules_package.attribute_module") + package variousModulesPackage.attributeModule from typing import Optional from typing import Final @@ -136,8 +136,8 @@ # --- # name: test_class_creation ''' - @PythonModule("various_tests_package.class_module") - package variousTestsPackage.classModule + @PythonModule("various_modules_package.class_module") + package variousModulesPackage.classModule class ClassModuleEmptyClassA() @@ -181,8 +181,8 @@ # --- # name: test_enum_creation ''' - @PythonModule("various_tests_package.enum_module") - package variousTestsPackage.enumModule + @PythonModule("various_modules_package.enum_module") + package variousModulesPackage.enumModule from another_path.another_module import AnotherClass as _AcImportAlias @@ -214,8 +214,8 @@ # --- # name: test_function_creation ''' - @PythonModule("various_tests_package.function_module") - package variousTestsPackage.functionModule + @PythonModule("various_modules_package.function_module") + package variousModulesPackage.functionModule from typing import Callable from typing import Optional @@ -476,8 +476,8 @@ # --- # name: test_import_creation ''' - @PythonModule("various_tests_package.import_module") - package variousTestsPackage.importModule + @PythonModule("various_modules_package.import_module") + package variousModulesPackage.importModule import mypy as `static` @@ -487,8 +487,8 @@ # --- # name: test_type_inference ''' - @PythonModule("various_tests_package.infer_types_module") - package variousTestsPackage.inferTypesModule + @PythonModule("various_modules_package.infer_types_module") + package variousModulesPackage.inferTypesModule class InferMe() @@ -527,8 +527,8 @@ # --- # name: test_variance_creation ''' - @PythonModule("various_tests_package.variance_module") - package variousTestsPackage.varianceModule + @PythonModule("various_modules_package.variance_module") + package variousModulesPackage.varianceModule from typing import Generic from typing import TypeVar diff --git a/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py b/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py index 1c51e88f..38e512f8 100644 --- a/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py +++ b/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py @@ -15,7 +15,7 @@ # Setup - Run API to create stub files _lib_dir = Path(__file__).parent.parent.parent -_test_package_name = "various_tests_package" +_test_package_name = "various_modules_package" _test_package_dir = Path(_lib_dir / "data" / _test_package_name) _out_dir = Path(_lib_dir / "data" / "out") _out_dir_stubs = Path(_out_dir / _test_package_name) @@ -59,8 +59,8 @@ def assert_stubs_snapshot(filename: str, snapshot: SnapshotAssertion) -> None: # ############################## Tests ############################## # def test_file_creation() -> None: _assert_file_creation_recursive( - python_path=Path(_test_package_dir / "test_file_creation"), - stub_path=Path(_out_dir_stubs / "test_file_creation") + python_path=Path(_test_package_dir / "file_creation"), + stub_path=Path(_out_dir_stubs / "file_creation") ) From c680399e78aa975922357243404e8f219a714d83 Mon Sep 17 00:00:00 2001 From: Arsam Date: Thu, 30 Nov 2023 17:22:28 +0100 Subject: [PATCH 075/109] Added .pytest.ini for pytest to ignore tests/data directory while searching for test --- .pytest.ini | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .pytest.ini diff --git a/.pytest.ini b/.pytest.ini new file mode 100644 index 00000000..1f9cf2a8 --- /dev/null +++ b/.pytest.ini @@ -0,0 +1,2 @@ +[pytest] +addopts = --ignore=./tests/data From 6a5720552838d981c96de7bc4d8fe9e965dfc67c Mon Sep 17 00:00:00 2001 From: Arsam Date: Thu, 30 Nov 2023 17:36:52 +0100 Subject: [PATCH 076/109] Added a temporary raise for the github test runner --- .../safeds_stubgen/stubs_generator/test_generate_stubs.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py b/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py index 38e512f8..a4321712 100644 --- a/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py +++ b/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py @@ -35,10 +35,14 @@ def _assert_file_creation_recursive(python_path: Path, stub_path: Path) -> None: # Remove __init__ files and private files without public reexported content. # We reexport public content from _module_3 and _module_6, not from empty_module, _module_2 and _module_4. for i, item in enumerate(python_files): - if item.is_file() and item.stem in {"__init__", "_module_2", "_module_4", "empty_module"}: + if item.is_file() and item.stem in {"__init__", "_module_2", "_module_4", "module_5"}: python_files.pop(i) - assert len(python_files) == len(stub_files) + try: + assert len(python_files) == len(stub_files) + except AssertionError as e: + item_names = [item.stem for item in python_files] + raise AssertionError(f"Got those items: {item_names}") from e for py_item, stub_item in zip(python_files, stub_files, strict=True): if py_item.is_file(): From d7bd3b965ef733b607abaede517152d43ecf5f85 Mon Sep 17 00:00:00 2001 From: Arsam Date: Thu, 30 Nov 2023 17:39:44 +0100 Subject: [PATCH 077/109] Changed test for github test runner --- .../stubs_generator/test_generate_stubs.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py b/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py index a4321712..013c9607 100644 --- a/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py +++ b/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py @@ -34,15 +34,12 @@ def _assert_file_creation_recursive(python_path: Path, stub_path: Path) -> None: # Remove __init__ files and private files without public reexported content. # We reexport public content from _module_3 and _module_6, not from empty_module, _module_2 and _module_4. - for i, item in enumerate(python_files): - if item.is_file() and item.stem in {"__init__", "_module_2", "_module_4", "module_5"}: - python_files.pop(i) - - try: - assert len(python_files) == len(stub_files) - except AssertionError as e: - item_names = [item.stem for item in python_files] - raise AssertionError(f"Got those items: {item_names}") from e + actual_python_files = [] + for item in python_files: + if not (item.is_file() and item.stem in {"__init__", "_module_2", "_module_4", "module_5"}): + actual_python_files.append(item) + + assert len(python_files) == len(stub_files) for py_item, stub_item in zip(python_files, stub_files, strict=True): if py_item.is_file(): From 8a665571c2298ce93c8ae35bc2cb70b804d08576 Mon Sep 17 00:00:00 2001 From: Arsam Date: Thu, 30 Nov 2023 17:40:04 +0100 Subject: [PATCH 078/109] Changed test for github test runner --- tests/safeds_stubgen/stubs_generator/test_generate_stubs.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py b/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py index 013c9607..87ecc136 100644 --- a/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py +++ b/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py @@ -39,9 +39,9 @@ def _assert_file_creation_recursive(python_path: Path, stub_path: Path) -> None: if not (item.is_file() and item.stem in {"__init__", "_module_2", "_module_4", "module_5"}): actual_python_files.append(item) - assert len(python_files) == len(stub_files) + assert len(actual_python_files) == len(stub_files) - for py_item, stub_item in zip(python_files, stub_files, strict=True): + for py_item, stub_item in zip(actual_python_files, stub_files, strict=True): if py_item.is_file(): assert stub_item.is_dir() stub_files = list(stub_item.iterdir()) From 876cb953f51a541ac081900e6345ddc99fce7256 Mon Sep 17 00:00:00 2001 From: Arsam Date: Thu, 30 Nov 2023 17:50:34 +0100 Subject: [PATCH 079/109] Changed test for github test runner --- tests/safeds_stubgen/stubs_generator/test_generate_stubs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py b/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py index 87ecc136..5e7625e5 100644 --- a/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py +++ b/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py @@ -36,7 +36,7 @@ def _assert_file_creation_recursive(python_path: Path, stub_path: Path) -> None: # We reexport public content from _module_3 and _module_6, not from empty_module, _module_2 and _module_4. actual_python_files = [] for item in python_files: - if not (item.is_file() and item.stem in {"__init__", "_module_2", "_module_4", "module_5"}): + if not (item.is_file() and item.stem in {"__init__", "_module_2", "_module_4"}): actual_python_files.append(item) assert len(actual_python_files) == len(stub_files) From 70539423cd9548d56e74f0235eef7f3de894c6c8 Mon Sep 17 00:00:00 2001 From: Arsam Date: Thu, 30 Nov 2023 17:52:11 +0100 Subject: [PATCH 080/109] Changed test for github test runner --- tests/safeds_stubgen/stubs_generator/test_generate_stubs.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py b/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py index 5e7625e5..ccf0a500 100644 --- a/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py +++ b/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py @@ -41,6 +41,9 @@ def _assert_file_creation_recursive(python_path: Path, stub_path: Path) -> None: assert len(actual_python_files) == len(stub_files) + actual_python_files.sort(key=lambda x: x.stem) + stub_files.sort(key=lambda x: x.stem) + for py_item, stub_item in zip(actual_python_files, stub_files, strict=True): if py_item.is_file(): assert stub_item.is_dir() From 3435a5410e68e1b0f479b1fb0f791d59ce0cc84c Mon Sep 17 00:00:00 2001 From: Arsam Date: Thu, 30 Nov 2023 18:10:24 +0100 Subject: [PATCH 081/109] Linter fixes --- src/safeds_stubgen/api_analyzer/_api.py | 2 +- src/safeds_stubgen/api_analyzer/_types.py | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/safeds_stubgen/api_analyzer/_api.py b/src/safeds_stubgen/api_analyzer/_api.py index 77eefa51..f5d12521 100644 --- a/src/safeds_stubgen/api_analyzer/_api.py +++ b/src/safeds_stubgen/api_analyzer/_api.py @@ -315,7 +315,7 @@ class Variance: type: AbstractType variance_type: VarianceType - def to_dict(self): + def to_dict(self) -> dict[str, Any]: return { "name": self.name, "type": self.type.to_dict(), diff --git a/src/safeds_stubgen/api_analyzer/_types.py b/src/safeds_stubgen/api_analyzer/_types.py index 06db0bde..282f98fd 100644 --- a/src/safeds_stubgen/api_analyzer/_types.py +++ b/src/safeds_stubgen/api_analyzer/_types.py @@ -3,7 +3,10 @@ import re from abc import ABCMeta, abstractmethod from dataclasses import dataclass, field -from typing import Any, ClassVar, Sequence +from typing import TYPE_CHECKING, Any, ClassVar + +if TYPE_CHECKING: + from collections.abc import Sequence class AbstractType(metaclass=ABCMeta): From b9d8fa2602ab300cdae06ce0d7dd0cae629b9e5e Mon Sep 17 00:00:00 2001 From: megalinter-bot <129584137+megalinter-bot@users.noreply.github.com> Date: Thu, 30 Nov 2023 17:12:16 +0000 Subject: [PATCH 082/109] style: apply automated linter fixes --- src/safeds_stubgen/api_analyzer/__init__.py | 1 + src/safeds_stubgen/api_analyzer/_api.py | 6 +- .../api_analyzer/_ast_visitor.py | 53 ++++----- .../api_analyzer/_mypy_helpers.py | 45 +++----- src/safeds_stubgen/api_analyzer/_types.py | 5 +- src/safeds_stubgen/api_analyzer/cli/_cli.py | 6 +- .../stubs_generator/__init__.py | 1 + .../stubs_generator/_generate_stubs.py | 107 +++++++++--------- .../api_analyzer/test__get_api.py | 40 ++----- .../safeds_stubgen/api_analyzer/test_types.py | 41 +++---- .../stubs_generator/test_generate_stubs.py | 96 +++------------- 11 files changed, 141 insertions(+), 260 deletions(-) diff --git a/src/safeds_stubgen/api_analyzer/__init__.py b/src/safeds_stubgen/api_analyzer/__init__.py index 7f3a9997..05414a9f 100644 --- a/src/safeds_stubgen/api_analyzer/__init__.py +++ b/src/safeds_stubgen/api_analyzer/__init__.py @@ -1,4 +1,5 @@ """API-Analyzer for the Safe-DS stubs generator.""" + from __future__ import annotations from ._api import ( diff --git a/src/safeds_stubgen/api_analyzer/_api.py b/src/safeds_stubgen/api_analyzer/_api.py index f5d12521..8e68840f 100644 --- a/src/safeds_stubgen/api_analyzer/_api.py +++ b/src/safeds_stubgen/api_analyzer/_api.py @@ -316,11 +316,7 @@ class Variance: variance_type: VarianceType def to_dict(self) -> dict[str, Any]: - return { - "name": self.name, - "type": self.type.to_dict(), - "variance_type": self.variance_type.name - } + return {"name": self.name, "type": self.type.to_dict(), "variance_type": self.variance_type.name} class VarianceType(PythonEnum): diff --git a/src/safeds_stubgen/api_analyzer/_ast_visitor.py b/src/safeds_stubgen/api_analyzer/_ast_visitor.py index 0abdfed3..51b95028 100644 --- a/src/safeds_stubgen/api_analyzer/_ast_visitor.py +++ b/src/safeds_stubgen/api_analyzer/_ast_visitor.py @@ -140,11 +140,7 @@ def enter_classdef(self, node: mp_nodes.ClassDef) -> None: generic_expr = getattr(generic_exprs[0], "index", None) if isinstance(generic_expr, mp_nodes.TupleExpr): - generic_types = [ - item.node - for item in generic_expr.items - if hasattr(item, "node") - ] + generic_types = [item.node for item in generic_expr.items if hasattr(item, "node")] elif isinstance(generic_expr, mp_nodes.NameExpr): generic_types = [generic_expr.node] else: # pragma: no cover @@ -155,17 +151,18 @@ def enter_classdef(self, node: mp_nodes.ClassDef) -> None: variance_values: sds_types.AbstractType if variance_type == VarianceType.INVARIANT: variance_values = sds_types.UnionType([ - mypy_type_to_abstract_type(value) - for value in generic_type.values + mypy_type_to_abstract_type(value) for value in generic_type.values ]) else: variance_values = mypy_type_to_abstract_type(generic_type.upper_bound) - variances.append(Variance( - name=generic_type.name, - type=variance_values, - variance_type=variance_type, - )) + variances.append( + Variance( + name=generic_type.name, + type=variance_values, + variance_type=variance_type, + ), + ) # superclasses # Todo Aliasing: Werden noch nicht aufgelöst @@ -381,8 +378,9 @@ def _parse_results(self, node: mp_nodes.FuncDef, function_id: str) -> list[Resul node_ret_type = node_type.ret_type if not isinstance(node_ret_type, mp_types.NoneType): - if (isinstance(node_ret_type, mp_types.AnyType) and - not has_correct_type_of_any(node_ret_type.type_of_any)): + if isinstance(node_ret_type, mp_types.AnyType) and not has_correct_type_of_any( + node_ret_type.type_of_any, + ): # In this case, the "Any" type was given because it was not explicitly annotated. # Therefor we have to try to infer the type. ret_type = self._infer_type_from_return_stmts(node) @@ -432,11 +430,7 @@ def _infer_type_from_return_stmts(func_node: mp_nodes.FuncDef) -> sds_types.Name # We have to sort the list for the snapshot tests return_stmt_types = list(types) return_stmt_types.sort( - key=lambda x: ( - x.name - if isinstance(x, sds_types.NamedType) - else str(len(x.types)) - ), + key=lambda x: (x.name if isinstance(x, sds_types.NamedType) else str(len(x.types))), ) if len(return_stmt_types) >= 2: @@ -446,7 +440,9 @@ def _infer_type_from_return_stmts(func_node: mp_nodes.FuncDef) -> sds_types.Name @staticmethod def _create_infered_results( - results: sds_types.TupleType, result_docstring: ResultDocstring, function_id: str, + results: sds_types.TupleType, + result_docstring: ResultDocstring, + function_id: str, ) -> list[Result]: """Create Result objects with inferred results. @@ -629,8 +625,9 @@ def _create_attribute( type_ = None # Ignore types that are special mypy any types - if (attribute_type is not None and not (isinstance(attribute_type, mp_types.AnyType) and - not has_correct_type_of_any(attribute_type.type_of_any))): + if attribute_type is not None and not ( + isinstance(attribute_type, mp_types.AnyType) and not has_correct_type_of_any(attribute_type.type_of_any) + ): # noinspection PyTypeChecker type_ = mypy_type_to_abstract_type(attribute_type, unanalyzed_type) @@ -657,7 +654,9 @@ def _create_attribute( # #### Parameter utilities def _get_default_parameter_value_and_type( - self, initializer: mp_nodes.Expression, infer_arg_type: bool = False, + self, + initializer: mp_nodes.Expression, + infer_arg_type: bool = False, ) -> tuple[None | str | float | int | bool | type, None | sds_types.NamedType]: # Get default value information default_value: None | str | float | int | bool | type = None @@ -721,9 +720,11 @@ def _parse_parameter_data(self, node: mp_nodes.FuncDef, function_id: str) -> lis elif isinstance(mypy_type, mp_types.AnyType) and not has_correct_type_of_any(mypy_type.type_of_any): # We try to infer the type through the default value later, if possible pass - elif (isinstance(type_annotation, mp_types.UnboundType) and - type_annotation.name in {"list", "set"} and - len(type_annotation.args) >= 2): + elif ( + isinstance(type_annotation, mp_types.UnboundType) + and type_annotation.name in {"list", "set"} + and len(type_annotation.args) >= 2 + ): # A special case where the argument is a list with multiple types. We have to handle this case like this # b/c something like list[int, str] is not allowed according to PEP and therefore not handled the normal # way in Mypy. diff --git a/src/safeds_stubgen/api_analyzer/_mypy_helpers.py b/src/safeds_stubgen/api_analyzer/_mypy_helpers.py index 157f37da..dcd74a70 100644 --- a/src/safeds_stubgen/api_analyzer/_mypy_helpers.py +++ b/src/safeds_stubgen/api_analyzer/_mypy_helpers.py @@ -41,10 +41,7 @@ def mypy_type_to_abstract_type( unanalyzed_type_name = unanalyzed_type.name if unanalyzed_type_name == "Final": # Final type - types = [ - mypy_type_to_abstract_type(arg) - for arg in getattr(unanalyzed_type, "args", []) - ] + types = [mypy_type_to_abstract_type(arg) for arg in getattr(unanalyzed_type, "args", [])] if len(types) == 1: return sds_types.FinalType(type_=types[0]) elif len(types) == 0: # pragma: no cover @@ -52,9 +49,11 @@ def mypy_type_to_abstract_type( return sds_types.FinalType(type_=sds_types.UnionType(types=types)) elif unanalyzed_type_name in {"list", "set"}: type_args = getattr(mypy_type, "args", []) - if (len(type_args) == 1 and - isinstance(type_args[0], mp_types.AnyType) and - not has_correct_type_of_any(type_args[0].type_of_any)): + if ( + len(type_args) == 1 + and isinstance(type_args[0], mp_types.AnyType) + and not has_correct_type_of_any(type_args[0].type_of_any) + ): # This case happens if we have a list or set with multiple arguments like "list[str, int]" which is # not allowed. In this case mypy interprets the type as "list[Any]", but we want the real types # of the list arguments, which we cant get through the "unanalyzed_type" attribute @@ -62,23 +61,14 @@ def mypy_type_to_abstract_type( # Iterable mypy types if isinstance(mypy_type, mp_types.TupleType): - return sds_types.TupleType(types=[ - mypy_type_to_abstract_type(item) - for item in mypy_type.items - ]) + return sds_types.TupleType(types=[mypy_type_to_abstract_type(item) for item in mypy_type.items]) elif isinstance(mypy_type, mp_types.UnionType): - return sds_types.UnionType(types=[ - mypy_type_to_abstract_type(item) - for item in mypy_type.items - ]) + return sds_types.UnionType(types=[mypy_type_to_abstract_type(item) for item in mypy_type.items]) # Special Cases elif isinstance(mypy_type, mp_types.CallableType): return sds_types.CallableType( - parameter_types=[ - mypy_type_to_abstract_type(arg_type) - for arg_type in mypy_type.arg_types - ], + parameter_types=[mypy_type_to_abstract_type(arg_type) for arg_type in mypy_type.arg_types], return_type=mypy_type_to_abstract_type(mypy_type.ret_type), ) elif isinstance(mypy_type, mp_types.AnyType): @@ -92,10 +82,9 @@ def mypy_type_to_abstract_type( return { "list": sds_types.ListType, "set": sds_types.SetType, - }[mypy_type.name](types=[ - mypy_type_to_abstract_type(arg) - for arg in mypy_type.args - ]) + }[ + mypy_type.name + ](types=[mypy_type_to_abstract_type(arg) for arg in mypy_type.args]) # Todo Aliasing: Import auflösen, wir können hier keinen fullname (qname) bekommen return sds_types.NamedType(name=mypy_type.name) @@ -107,10 +96,7 @@ def mypy_type_to_abstract_type( # Iterable builtins elif type_name in {"tuple", "list", "set"}: - types = [ - mypy_type_to_abstract_type(arg) - for arg in mypy_type.args - ] + types = [mypy_type_to_abstract_type(arg) for arg in mypy_type.args] match type_name: case "tuple": return sds_types.TupleType(types=types) @@ -211,9 +197,6 @@ def mypy_expression_to_sds_type(expr: mp_nodes.Expression) -> sds_types.NamedTyp elif isinstance(expr, mp_nodes.StrExpr): return sds_types.NamedType(name="str", qname="builtins.str") elif isinstance(expr, mp_nodes.TupleExpr): - return sds_types.TupleType(types=[ - mypy_expression_to_sds_type(item) - for item in expr.items - ]) + return sds_types.TupleType(types=[mypy_expression_to_sds_type(item) for item in expr.items]) else: # pragma: no cover raise TypeError("Unexpected expression type for return type.") diff --git a/src/safeds_stubgen/api_analyzer/_types.py b/src/safeds_stubgen/api_analyzer/_types.py index 282f98fd..f3325cd6 100644 --- a/src/safeds_stubgen/api_analyzer/_types.py +++ b/src/safeds_stubgen/api_analyzer/_types.py @@ -303,10 +303,7 @@ def from_dict(cls, d: dict[str, Any]) -> CallableType: if type_ is not None: params.append(type_) - return CallableType( - params, - AbstractType.from_dict(d["return_type"]) - ) + return CallableType(params, AbstractType.from_dict(d["return_type"])) def to_dict(self) -> dict[str, Any]: return { diff --git a/src/safeds_stubgen/api_analyzer/cli/_cli.py b/src/safeds_stubgen/api_analyzer/cli/_cli.py index 72246b25..e411188e 100644 --- a/src/safeds_stubgen/api_analyzer/cli/_cli.py +++ b/src/safeds_stubgen/api_analyzer/cli/_cli.py @@ -63,8 +63,10 @@ def _get_args() -> argparse.Namespace: parser.add_argument( "-ci", "--convert_identifiers", - help="Set this flag if the identifiers should be converted to Safe-DS standard (UpperCamelCase for classes and " - "camelCase for everything else).", + help=( + "Set this flag if the identifiers should be converted to Safe-DS standard (UpperCamelCase for classes and " + "camelCase for everything else)." + ), required=False, action="store_true", ) diff --git a/src/safeds_stubgen/stubs_generator/__init__.py b/src/safeds_stubgen/stubs_generator/__init__.py index 8065b081..c4a21e9a 100644 --- a/src/safeds_stubgen/stubs_generator/__init__.py +++ b/src/safeds_stubgen/stubs_generator/__init__.py @@ -1,4 +1,5 @@ """API-Analyzer for the Safe-DS stubs generator.""" + from __future__ import annotations from ._generate_stubs import generate_stubs diff --git a/src/safeds_stubgen/stubs_generator/_generate_stubs.py b/src/safeds_stubgen/stubs_generator/_generate_stubs.py index b5821046..1b91904c 100644 --- a/src/safeds_stubgen/stubs_generator/_generate_stubs.py +++ b/src/safeds_stubgen/stubs_generator/_generate_stubs.py @@ -109,13 +109,9 @@ def create_module_string(self, module: Module) -> str: for function in module.global_functions: if function.is_public: if function.is_property: - module_properties.append( - f"\n{self._create_property_function_string(function)}\n" - ) + module_properties.append(f"\n{self._create_property_function_string(function)}\n") else: - module_functions.append( - f"\n{self._create_function_string(function, is_method=False)}\n" - ) + module_functions.append(f"\n{self._create_function_string(function, is_method=False)}\n") # We want the properties first, then the functions for item in module_properties + module_functions: @@ -145,7 +141,7 @@ def _create_class_string(self, class_: Class, class_indentation: str = "") -> st parameter_info = "" if constructor: parameter_info = self._create_parameter_string( - constructor.parameters, class_indentation, is_instance_method=True + constructor.parameters, class_indentation, is_instance_method=True, ) constructor_info = f"({parameter_info})" @@ -154,10 +150,7 @@ def _create_class_string(self, class_: Class, class_indentation: str = "") -> st superclasses = class_.superclasses superclass_info = "" if superclasses and not class_.is_abstract: - superclass_names = [ - self._split_import_id(superclass)[1] - for superclass in superclasses - ] + superclass_names = [self._split_import_id(superclass)[1] for superclass in superclasses] superclass_info = f" sub {', '.join(superclass_names)}" if len(superclasses) > 1: @@ -190,9 +183,9 @@ def _create_class_string(self, class_: Class, class_indentation: str = "") -> st variances.append(f"{variance_direction}{variance_name_camel_case}") if variance_inheritance: constraints.append( - f"{variance_name_camel_case} {variance_inheritance} " - f"{self._create_type_string(variance.type.to_dict())}" - ) + f"{variance_name_camel_case} {variance_inheritance} " + f"{self._create_type_string(variance.type.to_dict())}", + ) if variances: variance_info = f"<{', '.join(variances)}>" @@ -306,9 +299,7 @@ def _create_function_string(self, function: Function, indentations: str = "", is # Parameters func_params = self._create_parameter_string( - parameters=function.parameters, - indentations=indentations, - is_instance_method=not is_static and is_method + parameters=function.parameters, indentations=indentations, is_instance_method=not is_static and is_method, ) # Convert function name to camelCase @@ -347,11 +338,7 @@ def _create_property_function_string(self, function: Function, indentations: str camel_case_name = self._replace_if_safeds_keyword(camel_case_name) # Create type information - result_types = [ - result.type - for result in function.results - if result.type is not None - ] + result_types = [result.type for result in function.results if result.type is not None] result_union = UnionType(types=result_types) types_data = result_union.to_dict() property_type = self._create_type_string(types_data) @@ -375,8 +362,7 @@ def _create_result_string(self, function_results: list[Result]) -> str: result_name = self._convert_snake_to_camel_case(result.name) result_name = self._replace_if_safeds_keyword(result_name) results.append( - f"{result_name}" - f"{type_string}", + f"{result_name}{type_string}", ) if results: @@ -387,7 +373,7 @@ def _create_result_string(self, function_results: list[Result]) -> str: return "" def _create_parameter_string( - self, parameters: list[Parameter], indentations: str, is_instance_method: bool = False + self, parameters: list[Parameter], indentations: str, is_instance_method: bool = False, ) -> str: parameters_data: list[str] = [] first_loop_skipped = False @@ -466,8 +452,7 @@ def _create_parameter_string( # Create string and append to the list parameters_data.append( - f"{name_annotation}{camel_case_name}" - f"{type_string}{param_value}", + f"{name_annotation}{camel_case_name}{type_string}{param_value}", ) inner_indentations = indentations + "\t" @@ -575,8 +560,7 @@ def _create_type_string(self, type_data: dict | None) -> str: return_type = type_data["return_type"] if return_type["kind"] == "TupleType": return_types = [ - f"{next(name_generator)}: {self._create_type_string(type_)}" - for type_ in return_type["types"] + f"{next(name_generator)}: {self._create_type_string(type_)}" for type_ in return_type["types"] ] return_type_string = f"({', '.join(return_types)})" else: @@ -584,10 +568,7 @@ def _create_type_string(self, type_data: dict | None) -> str: return f"({', '.join(params)}) -> {return_type_string}" elif kind in {"SetType", "ListType"}: - types = [ - self._create_type_string(type_) - for type_ in type_data["types"] - ] + types = [self._create_type_string(type_) for type_ in type_data["types"]] # Cut out the "Type" in the kind name name = kind[0:-4] @@ -600,10 +581,7 @@ def _create_type_string(self, type_data: dict | None) -> str: elif kind == "UnionType": # Union items have to be unique. 'types' has to be a sorted list, since otherwise the snapshot tests would # fail b/c element order in sets is non-deterministic. - types = list({ - self._create_type_string(type_) - for type_ in type_data["types"] - }) + types = list({self._create_type_string(type_) for type_ in type_data["types"]}) types.sort() if types: @@ -624,10 +602,7 @@ def _create_type_string(self, type_data: dict | None) -> str: return "" elif kind == "TupleType": self._current_todo_msgs.add("Tuple") - types = [ - self._create_type_string(type_) - for type_ in type_data["types"] - ] + types = [self._create_type_string(type_) for type_ in type_data["types"]] if types: return f"Tuple<{', '.join(types)}>" @@ -665,7 +640,8 @@ def _create_todo_msg(self, indentations: str) -> str: return "" todo_msgs = [ - "// TODO " + { + "// TODO " + + { "Tuple": "Safe-DS does not support tuple types.", "List": "List type has to many type arguments.", "Set": "Set type has to many type arguments.", @@ -704,9 +680,38 @@ def _create_name_annotation(name: str) -> str: @staticmethod def _replace_if_safeds_keyword(keyword: str) -> str: if keyword in { - "as", "from", "import", "literal", "union", "where", "yield", "false", "null", "true", "annotation", "attr", - "class", "enum", "fun", "package", "pipeline", "schema", "segment", "val", "const", "in", "internal", "out", - "private", "static", "and", "not", "or", "sub", "super", "_" + "as", + "from", + "import", + "literal", + "union", + "where", + "yield", + "false", + "null", + "true", + "annotation", + "attr", + "class", + "enum", + "fun", + "package", + "pipeline", + "schema", + "segment", + "val", + "const", + "in", + "internal", + "out", + "private", + "static", + "and", + "not", + "or", + "sub", + "super", + "_", }: return f"`{keyword}`" return keyword @@ -732,15 +737,7 @@ def _convert_snake_to_camel_case(self, name: str, is_class_name: bool = False) - # UpperCamelCase for class names if is_class_name: - return "".join( - part[0].upper() + part[1:] - for part in name_parts - if part - ) + return "".join(part[0].upper() + part[1:] for part in name_parts if part) # Normal camelCase for everything else - return name_parts[0] + "".join( - part[0].upper() + part[1:] - for part in name_parts[1:] - if part - ) + return name_parts[0] + "".join(part[0].upper() + part[1:] for part in name_parts[1:] if part) diff --git a/tests/safeds_stubgen/api_analyzer/test__get_api.py b/tests/safeds_stubgen/api_analyzer/test__get_api.py index fb2ee445..6f424db0 100644 --- a/tests/safeds_stubgen/api_analyzer/test__get_api.py +++ b/tests/safeds_stubgen/api_analyzer/test__get_api.py @@ -60,10 +60,7 @@ def _get_specific_module_data(module_name: str, docstring_style: str = "plaintex def _get_specific_class_data( - module_name: str, - class_name: str, - docstring_style: str = "plaintext", - is_enum: bool = False + module_name: str, class_name: str, docstring_style: str = "plaintext", is_enum: bool = False, ) -> dict: data_type = "enums" if is_enum else "classes" api_data = get_api_data(docstring_style) @@ -237,11 +234,7 @@ def test_class_attributes(module_name: str, class_name: str, docstring_style: st api_data = get_api_data(docstring_style) # Sort out the class attribute data we need and return - class_attribute_data = [ - attr - for attr in api_data["attributes"] - if attr["id"] in class_attr_ids - ] + class_attribute_data = [attr for attr in api_data["attributes"] if attr["id"] in class_attr_ids] assert class_attribute_data == snapshot @@ -271,7 +264,7 @@ def test_enums(module_name: str, class_name: str, snapshot: SnapshotAssertion) - argvalues=[ ("EnumTest", _enum_module_name), ("_ReexportedEmptyEnum", _enum_module_name), - ("EnumTest3", _enum_module_name) + ("EnumTest3", _enum_module_name), ], ids=[ "EnumTest", @@ -319,11 +312,7 @@ def test_global_functions(module_name: str, snapshot: SnapshotAssertion) -> None all_functions: list[dict] = api_data_paintext["functions"] # Sort out the functions we need and return - global_function_data = [ - function - for function in all_functions - if function["id"] in global_function_ids - ] + global_function_data = [function for function in all_functions if function["id"] in global_function_ids] assert global_function_data == snapshot @@ -373,11 +362,7 @@ def test_class_methods(module_name: str, class_name: str, docstring_style: str, all_functions: list[dict] = api_data["functions"] # Sort out the functions we need and return - class_methods_data = [ - method - for method in all_functions - if method["id"] in class_method_ids - ] + class_methods_data = [method for method in all_functions if method["id"] in class_method_ids] assert class_methods_data == snapshot @@ -444,7 +429,7 @@ def test_class_methods(module_name: str, class_name: str, docstring_style: str, ], ) def test_function_parameters( - function_name: str, module_name: str, parent_class_name: str, docstring_style: str, snapshot: SnapshotAssertion + function_name: str, module_name: str, parent_class_name: str, docstring_style: str, snapshot: SnapshotAssertion, ) -> None: function_data: dict = _get_specific_function_data(module_name, function_name, parent_class_name, docstring_style) function_parameter_ids: list[str] = function_data["parameters"] @@ -453,9 +438,7 @@ def test_function_parameters( # Sort out the parameters we need and return function_parameter_data = [ - parameter - for parameter in api_data["parameters"] - if parameter["id"] in function_parameter_ids + parameter for parameter in api_data["parameters"] if parameter["id"] in function_parameter_ids ] assert function_parameter_data == snapshot @@ -499,7 +482,6 @@ def test_function_parameters( ("rest_docstring_func", _docstring_module_name, "RestDocstringClass", "rest"), ("numpy_docstring_func", _docstring_module_name, "NumpyDocstringClass", "numpydoc"), ("google_docstring_func", _docstring_module_name, "GoogleDocstringClass", "google"), - ], ids=[ "int_result", @@ -540,17 +522,13 @@ def test_function_parameters( ], ) def test_function_results( - function_name: str, module_name: str, parent_class_name: str, docstring_style: str, snapshot: SnapshotAssertion + function_name: str, module_name: str, parent_class_name: str, docstring_style: str, snapshot: SnapshotAssertion, ) -> None: function_data: dict = _get_specific_function_data(module_name, function_name, parent_class_name, docstring_style) function_result_ids: list[str] = function_data["results"] api_data = get_api_data(docstring_style) # Sort out the results we need and return - function_result_data = [ - result - for result in api_data["results"] - if result["id"] in function_result_ids - ] + function_result_data = [result for result in api_data["results"] if result["id"] in function_result_ids] assert function_result_data == snapshot diff --git a/tests/safeds_stubgen/api_analyzer/test_types.py b/tests/safeds_stubgen/api_analyzer/test_types.py index b6af69e6..e2601f05 100644 --- a/tests/safeds_stubgen/api_analyzer/test_types.py +++ b/tests/safeds_stubgen/api_analyzer/test_types.py @@ -31,7 +31,7 @@ def test_correct_hash() -> None: assigned_by=ParameterAssignment.POSITION_OR_NAME, docstring=ParameterDocstring("'hashvalue'", "r", "r"), type=NamedType("str"), - is_type_inferred=False + is_type_inferred=False, ) assert hash(parameter) == hash(deepcopy(parameter)) enum_values = frozenset({"a", "b", "c"}) @@ -114,10 +114,7 @@ def test_union_type() -> None: union_type = UnionType([NamedType("str"), NamedType("int")]) union_type_dict = { "kind": "UnionType", - "types": [ - {"kind": "NamedType", "name": "str", "qname": ""}, - {"kind": "NamedType", "name": "int", "qname": ""} - ], + "types": [{"kind": "NamedType", "name": "str", "qname": ""}, {"kind": "NamedType", "name": "int", "qname": ""}], } assert AbstractType.from_dict(union_type_dict) == union_type @@ -133,18 +130,21 @@ def test_union_type() -> None: def test_callable_type() -> None: callable_type = CallableType( parameter_types=[NamedType("str"), NamedType("int")], - return_type=TupleType(types=[NamedType("bool"), NamedType("None")]) + return_type=TupleType(types=[NamedType("bool"), NamedType("None")]), ) callable_type_dict = { "kind": "CallableType", "parameter_types": [ {"kind": "NamedType", "name": "str", "qname": ""}, - {"kind": "NamedType", "name": "int", "qname": ""} + {"kind": "NamedType", "name": "int", "qname": ""}, ], - "return_type": {"kind": "TupleType", "types": [ - {"kind": "NamedType", "name": "bool", "qname": ""}, - {"kind": "NamedType", "name": "None", "qname": ""} - ]}, + "return_type": { + "kind": "TupleType", + "types": [ + {"kind": "NamedType", "name": "bool", "qname": ""}, + {"kind": "NamedType", "name": "None", "qname": ""}, + ], + }, } assert AbstractType.from_dict(callable_type_dict) == callable_type @@ -161,10 +161,7 @@ def test_list_type() -> None: list_type = ListType([NamedType("str"), NamedType("int")]) list_type_dict = { "kind": "ListType", - "types": [ - {"kind": "NamedType", "name": "str", "qname": ""}, - {"kind": "NamedType", "name": "int", "qname": ""} - ], + "types": [{"kind": "NamedType", "name": "str", "qname": ""}, {"kind": "NamedType", "name": "int", "qname": ""}], } assert AbstractType.from_dict(list_type_dict) == list_type @@ -188,14 +185,14 @@ def test_dict_type() -> None: "kind": "UnionType", "types": [ {"kind": "NamedType", "name": "str", "qname": ""}, - {"kind": "NamedType", "name": "int", "qname": ""} + {"kind": "NamedType", "name": "int", "qname": ""}, ], }, "value_type": { "kind": "UnionType", "types": [ {"kind": "NamedType", "name": "str", "qname": ""}, - {"kind": "NamedType", "name": "int", "qname": ""} + {"kind": "NamedType", "name": "int", "qname": ""}, ], }, } @@ -214,10 +211,7 @@ def test_set_type() -> None: set_type = SetType([NamedType("str"), NamedType("int")]) set_type_dict = { "kind": "SetType", - "types": [ - {"kind": "NamedType", "name": "str", "qname": ""}, - {"kind": "NamedType", "name": "int", "qname": ""} - ], + "types": [{"kind": "NamedType", "name": "str", "qname": ""}, {"kind": "NamedType", "name": "int", "qname": ""}], } assert AbstractType.from_dict(set_type_dict) == set_type @@ -268,10 +262,7 @@ def test_tuple_type() -> None: set_type = TupleType([NamedType("str"), NamedType("int")]) set_type_dict = { "kind": "TupleType", - "types": [ - {"kind": "NamedType", "name": "str", "qname": ""}, - {"kind": "NamedType", "name": "int", "qname": ""} - ], + "types": [{"kind": "NamedType", "name": "str", "qname": ""}, {"kind": "NamedType", "name": "int", "qname": ""}], } assert AbstractType.from_dict(set_type_dict) == set_type diff --git a/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py b/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py index ccf0a500..0ab0f71e 100644 --- a/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py +++ b/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py @@ -63,8 +63,7 @@ def assert_stubs_snapshot(filename: str, snapshot: SnapshotAssertion) -> None: # ############################## Tests ############################## # def test_file_creation() -> None: _assert_file_creation_recursive( - python_path=Path(_test_package_dir / "file_creation"), - stub_path=Path(_out_dir_stubs / "file_creation") + python_path=Path(_test_package_dir / "file_creation"), stub_path=Path(_out_dir_stubs / "file_creation"), ) @@ -115,88 +114,23 @@ def test_docstring_creation() -> None: ... @pytest.mark.parametrize( ("name", "expected_result", "is_class_name", "convert_identifiers"), [ - ( - "", - "", - False, - True - ), - ( - "_", - "_", - False, - True - ), - ( - "__get_function_name__", - "getFunctionName", - False, - True - ), - ( - "__get_function_name", - "getFunctionName", - False, - True - ), - ( - "get_function_name__", - "getFunctionName", - False, - True - ), - ( - "__getFunction_name__", - "getFunctionName", - False, - True - ), - ( - "__get__function___name__", - "getFunctionName", - False, - True - ), - ( - "__get_funCtion_NamE__", - "getFunCtionNamE", - False, - True - ), - ( - "getFunctionName", - "getFunctionName", - False, - True - ), - ( - "a_a_A_aAAaA_1_1_2_aAa", - "aAAAAAaA112AAa", - False, - True - ), - ( - "some_class_name", - "SomeClassName", - True, - True - ), - ( - "some_function_name", - "some_function_name", - False, - False - ), - ( - "some_class_name", - "some_class_name", - True, - False - ), + ("", "", False, True), + ("_", "_", False, True), + ("__get_function_name__", "getFunctionName", False, True), + ("__get_function_name", "getFunctionName", False, True), + ("get_function_name__", "getFunctionName", False, True), + ("__getFunction_name__", "getFunctionName", False, True), + ("__get__function___name__", "getFunctionName", False, True), + ("__get_funCtion_NamE__", "getFunCtionNamE", False, True), + ("getFunctionName", "getFunctionName", False, True), + ("a_a_A_aAAaA_1_1_2_aAa", "aAAAAAaA112AAa", False, True), + ("some_class_name", "SomeClassName", True, True), + ("some_function_name", "some_function_name", False, False), + ("some_class_name", "some_class_name", True, False), ], ) def test_convert_snake_to_camel_case( - name: str, expected_result: str, is_class_name: bool, convert_identifiers: bool + name: str, expected_result: str, is_class_name: bool, convert_identifiers: bool, ) -> None: stubs_string_generator = StubsStringGenerator(convert_identifiers=convert_identifiers) assert stubs_string_generator._convert_snake_to_camel_case(name, is_class_name) == expected_result From 944c8635c381c88d7b17930e895dba4972cc8497 Mon Sep 17 00:00:00 2001 From: megalinter-bot <129584137+megalinter-bot@users.noreply.github.com> Date: Thu, 30 Nov 2023 17:13:51 +0000 Subject: [PATCH 083/109] style: apply automated linter fixes --- .../stubs_generator/_generate_stubs.py | 13 ++++++++++--- .../api_analyzer/test__get_api.py | 17 ++++++++++++++--- .../stubs_generator/test_generate_stubs.py | 8 ++++++-- 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/safeds_stubgen/stubs_generator/_generate_stubs.py b/src/safeds_stubgen/stubs_generator/_generate_stubs.py index 1b91904c..5a426c5d 100644 --- a/src/safeds_stubgen/stubs_generator/_generate_stubs.py +++ b/src/safeds_stubgen/stubs_generator/_generate_stubs.py @@ -141,7 +141,9 @@ def _create_class_string(self, class_: Class, class_indentation: str = "") -> st parameter_info = "" if constructor: parameter_info = self._create_parameter_string( - constructor.parameters, class_indentation, is_instance_method=True, + constructor.parameters, + class_indentation, + is_instance_method=True, ) constructor_info = f"({parameter_info})" @@ -299,7 +301,9 @@ def _create_function_string(self, function: Function, indentations: str = "", is # Parameters func_params = self._create_parameter_string( - parameters=function.parameters, indentations=indentations, is_instance_method=not is_static and is_method, + parameters=function.parameters, + indentations=indentations, + is_instance_method=not is_static and is_method, ) # Convert function name to camelCase @@ -373,7 +377,10 @@ def _create_result_string(self, function_results: list[Result]) -> str: return "" def _create_parameter_string( - self, parameters: list[Parameter], indentations: str, is_instance_method: bool = False, + self, + parameters: list[Parameter], + indentations: str, + is_instance_method: bool = False, ) -> str: parameters_data: list[str] = [] first_loop_skipped = False diff --git a/tests/safeds_stubgen/api_analyzer/test__get_api.py b/tests/safeds_stubgen/api_analyzer/test__get_api.py index 6f424db0..73c8932b 100644 --- a/tests/safeds_stubgen/api_analyzer/test__get_api.py +++ b/tests/safeds_stubgen/api_analyzer/test__get_api.py @@ -60,7 +60,10 @@ def _get_specific_module_data(module_name: str, docstring_style: str = "plaintex def _get_specific_class_data( - module_name: str, class_name: str, docstring_style: str = "plaintext", is_enum: bool = False, + module_name: str, + class_name: str, + docstring_style: str = "plaintext", + is_enum: bool = False, ) -> dict: data_type = "enums" if is_enum else "classes" api_data = get_api_data(docstring_style) @@ -429,7 +432,11 @@ def test_class_methods(module_name: str, class_name: str, docstring_style: str, ], ) def test_function_parameters( - function_name: str, module_name: str, parent_class_name: str, docstring_style: str, snapshot: SnapshotAssertion, + function_name: str, + module_name: str, + parent_class_name: str, + docstring_style: str, + snapshot: SnapshotAssertion, ) -> None: function_data: dict = _get_specific_function_data(module_name, function_name, parent_class_name, docstring_style) function_parameter_ids: list[str] = function_data["parameters"] @@ -522,7 +529,11 @@ def test_function_parameters( ], ) def test_function_results( - function_name: str, module_name: str, parent_class_name: str, docstring_style: str, snapshot: SnapshotAssertion, + function_name: str, + module_name: str, + parent_class_name: str, + docstring_style: str, + snapshot: SnapshotAssertion, ) -> None: function_data: dict = _get_specific_function_data(module_name, function_name, parent_class_name, docstring_style) function_result_ids: list[str] = function_data["results"] diff --git a/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py b/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py index 0ab0f71e..84a3a91d 100644 --- a/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py +++ b/tests/safeds_stubgen/stubs_generator/test_generate_stubs.py @@ -63,7 +63,8 @@ def assert_stubs_snapshot(filename: str, snapshot: SnapshotAssertion) -> None: # ############################## Tests ############################## # def test_file_creation() -> None: _assert_file_creation_recursive( - python_path=Path(_test_package_dir / "file_creation"), stub_path=Path(_out_dir_stubs / "file_creation"), + python_path=Path(_test_package_dir / "file_creation"), + stub_path=Path(_out_dir_stubs / "file_creation"), ) @@ -130,7 +131,10 @@ def test_docstring_creation() -> None: ... ], ) def test_convert_snake_to_camel_case( - name: str, expected_result: str, is_class_name: bool, convert_identifiers: bool, + name: str, + expected_result: str, + is_class_name: bool, + convert_identifiers: bool, ) -> None: stubs_string_generator = StubsStringGenerator(convert_identifiers=convert_identifiers) assert stubs_string_generator._convert_snake_to_camel_case(name, is_class_name) == expected_result From e78a3a53f8567f2f45589b153bbd89a4c9b179f2 Mon Sep 17 00:00:00 2001 From: Arsam Date: Thu, 30 Nov 2023 18:43:00 +0100 Subject: [PATCH 084/109] codecov & refactoring --- .../stubs_generator/_generate_stubs.py | 35 ++----------- .../various_modules_package/enum_module.py | 2 +- .../function_module.py | 3 ++ .../__snapshots__/test__get_api.ambr | 51 +++++++++++++++++-- .../api_analyzer/test__get_api.py | 2 + .../__snapshots__/test_generate_stubs.ambr | 6 ++- 6 files changed, 64 insertions(+), 35 deletions(-) diff --git a/src/safeds_stubgen/stubs_generator/_generate_stubs.py b/src/safeds_stubgen/stubs_generator/_generate_stubs.py index b5821046..b853e0a7 100644 --- a/src/safeds_stubgen/stubs_generator/_generate_stubs.py +++ b/src/safeds_stubgen/stubs_generator/_generate_stubs.py @@ -40,8 +40,6 @@ def generate_stubs(api: API, out_path: Path, convert_identifiers: bool) -> None: camelCase for everything else). """ modules = api.modules.values() - if not modules: - return Path(out_path / api.package).mkdir(parents=True, exist_ok=True) generator = StubsStringGenerator(convert_identifiers) @@ -104,22 +102,9 @@ def create_module_string(self, module: Module) -> str: module_text += f"\n{wildcard_imports}\n" # Create global functions and properties - module_properties = [] - module_functions = [] for function in module.global_functions: if function.is_public: - if function.is_property: - module_properties.append( - f"\n{self._create_property_function_string(function)}\n" - ) - else: - module_functions.append( - f"\n{self._create_function_string(function, is_method=False)}\n" - ) - - # We want the properties first, then the functions - for item in module_properties + module_functions: - module_text += item + module_text += f"\n{self._create_function_string(function, is_method=False)}\n" # Create classes, class attr. & class methods for class_ in module.classes: @@ -410,12 +395,7 @@ def _create_parameter_string( if param_default_value is not None: if isinstance(param_default_value, str): if parameter_type_data["kind"] == "NamedType" and parameter_type_data["name"] != "str": - if param_default_value == "False": - default_value = "false" - elif param_default_value == "True": - default_value = "true" - else: - default_value = f"{param_default_value}" + default_value = f"{param_default_value}" else: default_value = f'"{param_default_value}"' elif isinstance(param_default_value, bool): @@ -527,12 +507,12 @@ def _create_enum_string(self, enum_data: Enum) -> str: camel_case_name = self._convert_snake_to_camel_case(name) annotation = "" if camel_case_name != name: - annotation = f"\t{self._create_name_annotation(name)}\n" + annotation = f"{self._create_name_annotation(name)} " # Check if the name is a Safe-DS keyword and escape it camel_case_name = self._replace_if_safeds_keyword(camel_case_name) - enum_text += f"{annotation}\t{camel_case_name}\n" + enum_text += f"\t{annotation}{camel_case_name}\n" return f"{enum_signature} {{{enum_text}}}" return enum_signature @@ -547,9 +527,6 @@ def _create_type_string(self, type_data: dict | None) -> str: if kind == "NamedType": name = type_data["name"] match name: - case "tuple": - self._current_todo_msgs.add("Tuple") - return "Tuple" case "int": return "Int" case "str": @@ -629,9 +606,7 @@ def _create_type_string(self, type_data: dict | None) -> str: for type_ in type_data["types"] ] - if types: - return f"Tuple<{', '.join(types)}>" - return "Tuple" + return f"Tuple<{', '.join(types)}>" elif kind == "DictType": key_data = self._create_type_string(type_data["key_type"]) value_data = self._create_type_string(type_data["value_type"]) diff --git a/tests/data/various_modules_package/enum_module.py b/tests/data/various_modules_package/enum_module.py index f42c0661..5600555e 100644 --- a/tests/data/various_modules_package/enum_module.py +++ b/tests/data/various_modules_package/enum_module.py @@ -26,7 +26,7 @@ class EnumTest2(_Enum): class EnumTest3(IntEnum): - ELEVEN = 11 + ele_ven = 11 class EmptyEnum(Enum, IntEnum): diff --git a/tests/data/various_modules_package/function_module.py b/tests/data/various_modules_package/function_module.py index d1cb1d72..3b6a59e0 100644 --- a/tests/data/various_modules_package/function_module.py +++ b/tests/data/various_modules_package/function_module.py @@ -129,6 +129,9 @@ def illegal_list_results() -> list[int, str]: ... def dictionary_results() -> dict[str, FunctionModuleClassA]: ... +def dictionary_results_no_key_no_value() -> dict: ... + + def illegal_dictionary_results() -> dict[int, str, FunctionModuleClassA]: ... diff --git a/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr b/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr index 3968b268..e10c4e44 100644 --- a/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr +++ b/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr @@ -2398,8 +2398,8 @@ # name: test_enum_instances[EnumTest3] list([ dict({ - 'id': 'various_modules_package/enum_module/EnumTest3/ELEVEN', - 'name': 'ELEVEN', + 'id': 'various_modules_package/enum_module/EnumTest3/ele_ven', + 'name': 'ele_ven', }), ]) # --- @@ -2468,7 +2468,7 @@ }), 'id': 'various_modules_package/enum_module/EnumTest3', 'instances': list([ - 'various_modules_package/enum_module/EnumTest3/ELEVEN', + 'various_modules_package/enum_module/EnumTest3/ele_ven', ]), 'name': 'EnumTest3', }) @@ -4325,6 +4325,32 @@ }), ]) # --- +# name: test_function_results[dictionary_results_no_key_no_value] + list([ + dict({ + 'docstring': dict({ + 'description': '', + 'type': '', + }), + 'id': 'various_modules_package/function_module/dictionary_results_no_key_no_value/result_1', + 'is_type_inferred': False, + 'name': 'result_1', + 'type': dict({ + 'key_type': dict({ + 'kind': 'NamedType', + 'name': 'Any', + 'qname': '', + }), + 'kind': 'DictType', + 'value_type': dict({ + 'kind': 'NamedType', + 'name': 'Any', + 'qname': '', + }), + }), + }), + ]) +# --- # name: test_function_results[epydoc_docstring_func] list([ dict({ @@ -5224,6 +5250,25 @@ 'various_modules_package/function_module/dictionary_results/result_1', ]), }), + dict({ + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'various_modules_package/function_module/dictionary_results_no_key_no_value', + 'is_class_method': False, + 'is_property': False, + 'is_public': True, + 'is_static': False, + 'name': 'dictionary_results_no_key_no_value', + 'parameters': list([ + ]), + 'reexported_by': list([ + ]), + 'results': list([ + 'various_modules_package/function_module/dictionary_results_no_key_no_value/result_1', + ]), + }), dict({ 'docstring': dict({ 'description': '', diff --git a/tests/safeds_stubgen/api_analyzer/test__get_api.py b/tests/safeds_stubgen/api_analyzer/test__get_api.py index fb2ee445..798158ae 100644 --- a/tests/safeds_stubgen/api_analyzer/test__get_api.py +++ b/tests/safeds_stubgen/api_analyzer/test__get_api.py @@ -476,6 +476,7 @@ def test_function_parameters( ("list_results", _function_module_name, "", "plaintext"), ("illegal_list_results", _function_module_name, "", "plaintext"), ("dictionary_results", _function_module_name, "", "plaintext"), + ("dictionary_results_no_key_no_value", _function_module_name, "", "plaintext"), ("illegal_dictionary_results", _function_module_name, "", "plaintext"), ("union_dictionary_results", _function_module_name, "", "plaintext"), ("set_results", _function_module_name, "", "plaintext"), @@ -514,6 +515,7 @@ def test_function_parameters( "list_results", "illegal_list_results", "dictionary_results", + "dictionary_results_no_key_no_value", "illegal_dictionary_results", "union_dictionary_results", "set_results", diff --git a/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr b/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr index c5b31851..cd062beb 100644 --- a/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr +++ b/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr @@ -205,7 +205,7 @@ } enum EnumTest3 { - ELEVEN + @PythonName("ele_ven") eleVen } enum EmptyEnum @@ -383,6 +383,10 @@ @PythonName("dictionary_results") fun dictionaryResults() -> result1: Map + @Pure + @PythonName("dictionary_results_no_key_no_value") + fun dictionaryResultsNoKeyNoValue() -> result1: Map + @Pure @PythonName("illegal_dictionary_results") fun illegalDictionaryResults() -> result1: Map From bd4a5ffaf85ce11e02eef4297b711fb73eb65d3c Mon Sep 17 00:00:00 2001 From: Arsam Date: Thu, 30 Nov 2023 18:52:02 +0100 Subject: [PATCH 085/109] codecov & refactoring --- .../stubs_generator/_generate_stubs.py | 8 +-- .../function_module.py | 2 + .../__snapshots__/test__get_api.ambr | 58 +++++++++++++++++++ .../__snapshots__/test_generate_stubs.ambr | 2 + 4 files changed, 64 insertions(+), 6 deletions(-) diff --git a/src/safeds_stubgen/stubs_generator/_generate_stubs.py b/src/safeds_stubgen/stubs_generator/_generate_stubs.py index d51d0741..872d656b 100644 --- a/src/safeds_stubgen/stubs_generator/_generate_stubs.py +++ b/src/safeds_stubgen/stubs_generator/_generate_stubs.py @@ -596,11 +596,7 @@ def _create_type_string(self, type_data: dict | None) -> str: elif kind == "DictType": key_data = self._create_type_string(type_data["key_type"]) value_data = self._create_type_string(type_data["value_type"]) - if key_data: - if value_data: - return f"Map<{key_data}, {value_data}>" - return f"Map<{key_data}>" - return "Map" + return f"Map<{key_data}, {value_data}>" elif kind == "LiteralType": literal_type = type_data["literal"] if isinstance(literal_type, str): @@ -617,7 +613,7 @@ def _callable_type_name_generator() -> Generator: while True: for x in range(1, 27): yield string.ascii_lowercase[x - 1] - for x in range(1, 27): + for x in range(1, 27): # pragma: no cover for y in range(1, 27): yield string.ascii_lowercase[x - 1] + string.ascii_lowercase[y - 1] diff --git a/tests/data/various_modules_package/function_module.py b/tests/data/various_modules_package/function_module.py index 3b6a59e0..361e2734 100644 --- a/tests/data/various_modules_package/function_module.py +++ b/tests/data/various_modules_package/function_module.py @@ -45,6 +45,8 @@ def params( obj: FunctionModuleClassA, callexpr: FunctionModuleClassA(), union: int | bool, + union_with_none_1: int | None, + union_with_none_2: None | int, list_: list[int], dictionary: dict[str, int | float], set_: set[str], diff --git a/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr b/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr index e10c4e44..c6922ce9 100644 --- a/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr +++ b/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr @@ -3732,6 +3732,62 @@ ]), }), }), + dict({ + 'assigned_by': 'POSITION_OR_NAME', + 'default_value': None, + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'various_modules_package/function_module/params/union_with_none_1', + 'is_optional': False, + 'is_type_inferred': False, + 'name': 'union_with_none_1', + 'type': dict({ + 'kind': 'UnionType', + 'types': list([ + dict({ + 'kind': 'NamedType', + 'name': 'int', + 'qname': 'builtins.int', + }), + dict({ + 'kind': 'NamedType', + 'name': 'None', + 'qname': 'builtins.None', + }), + ]), + }), + }), + dict({ + 'assigned_by': 'POSITION_OR_NAME', + 'default_value': None, + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'various_modules_package/function_module/params/union_with_none_2', + 'is_optional': False, + 'is_type_inferred': False, + 'name': 'union_with_none_2', + 'type': dict({ + 'kind': 'UnionType', + 'types': list([ + dict({ + 'kind': 'NamedType', + 'name': 'None', + 'qname': 'builtins.None', + }), + dict({ + 'kind': 'NamedType', + 'name': 'int', + 'qname': 'builtins.int', + }), + ]), + }), + }), ]) # --- # name: test_function_parameters[public_no_params_no_result] @@ -5544,6 +5600,8 @@ 'various_modules_package/function_module/params/obj', 'various_modules_package/function_module/params/callexpr', 'various_modules_package/function_module/params/union', + 'various_modules_package/function_module/params/union_with_none_1', + 'various_modules_package/function_module/params/union_with_none_2', 'various_modules_package/function_module/params/list_', 'various_modules_package/function_module/params/dictionary', 'various_modules_package/function_module/params/set_', diff --git a/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr b/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr index cd062beb..dd607619 100644 --- a/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr +++ b/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr @@ -240,6 +240,8 @@ obj: FunctionModuleClassA, callexpr, `union`: union, + @PythonName("union_with_none_1") unionWithNone1: Int?, + @PythonName("union_with_none_2") unionWithNone2: Int?, @PythonName("list_") list: List, dictionary: Map>, @PythonName("set_") set: Set, From df1a98663c0a3528d154a02cbf0c1465de4467aa Mon Sep 17 00:00:00 2001 From: Arsam Date: Thu, 30 Nov 2023 19:39:07 +0100 Subject: [PATCH 086/109] codecov & refactoring --- .../api_analyzer/_ast_visitor.py | 34 ++++++------------- .../attribute_module.py | 4 +++ .../__snapshots__/test__get_api.ambr | 34 +++++++++++++++++++ .../__snapshots__/test_generate_stubs.ambr | 2 ++ 4 files changed, 50 insertions(+), 24 deletions(-) diff --git a/src/safeds_stubgen/api_analyzer/_ast_visitor.py b/src/safeds_stubgen/api_analyzer/_ast_visitor.py index 51b95028..a0b6a11a 100644 --- a/src/safeds_stubgen/api_analyzer/_ast_visitor.py +++ b/src/safeds_stubgen/api_analyzer/_ast_visitor.py @@ -484,9 +484,7 @@ def _create_infered_results( inferred_results = [] for i, result_list in enumerate(result_array): result_count = len(result_list) - if result_count == 0: - break - elif result_count == 1: + if result_count == 1: result_type = result_list[0] else: result_type = sds_types.UnionType(result_list) @@ -516,7 +514,7 @@ def _parse_attributes( attributes: list[Attribute] = [] if hasattr(lvalue, "name"): - if self._is_attribute_already_defined(lvalue, lvalue.name): + if self._is_attribute_already_defined(lvalue.name): return attributes attributes.append( @@ -529,7 +527,7 @@ def _parse_attributes( if not hasattr(lvalue_, "name"): # pragma: no cover raise AttributeError("Expected value to have attribute 'name'.") - if self._is_attribute_already_defined(lvalue_, lvalue_.name): + if self._is_attribute_already_defined(lvalue_.name): continue attributes.append( @@ -538,28 +536,16 @@ def _parse_attributes( return attributes - def _is_attribute_already_defined(self, lvalue: mp_nodes.Expression, value_name: str) -> bool: - assert isinstance(lvalue, mp_nodes.NameExpr | mp_nodes.MemberExpr | mp_nodes.TupleExpr) - if hasattr(lvalue, "node"): - node = lvalue.node - else: # pragma: no cover - raise AttributeError("Expected value to have attribute 'node'.") - + def _is_attribute_already_defined(self, value_name: str) -> bool: # If node is None, it's possible that the attribute was already defined once - if node is None: - parent = self.__declaration_stack[-1] - if isinstance(parent, Function): - parent = self.__declaration_stack[-2] - - if not isinstance(parent, Class): # pragma: no cover - raise TypeError("Parent has the wrong class, cannot get attribute values.") + parent = self.__declaration_stack[-1] + if isinstance(parent, Function): + parent = self.__declaration_stack[-2] - for attribute in parent.attributes: - if value_name == attribute.name: - return True + if not isinstance(parent, Class): # pragma: no cover + raise TypeError("Parent has the wrong class, cannot get attribute values.") - raise ValueError(f"The attribute {value_name} has no value.") # pragma: no cover - return False + return any(value_name == attribute.name for attribute in parent.attributes) def _create_attribute( self, diff --git a/tests/data/various_modules_package/attribute_module.py b/tests/data/various_modules_package/attribute_module.py index 7a271561..b6d38769 100644 --- a/tests/data/various_modules_package/attribute_module.py +++ b/tests/data/various_modules_package/attribute_module.py @@ -25,6 +25,10 @@ def some_func() -> bool: tuple_attr_2: tuple[str | int] tuple_attr_3: tuple[str, int] + defined_three_times: int + defined_three_times: str + defined_three_times, _ignore_me = (0, 0) + list_attr_1: list list_attr_2: list[str | AttributesClassA] list_attr_3: list[str, AttributesClassA] diff --git a/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr b/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr index c6922ce9..d5b3ca3e 100644 --- a/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr +++ b/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr @@ -1,6 +1,23 @@ # serializer version: 1 # name: test_class_attributes[AttributesClassB] list([ + dict({ + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'various_modules_package/attribute_module/AttributesClassB/_ignore_me', + 'is_public': False, + 'is_static': True, + 'is_type_inferred': True, + 'name': '_ignore_me', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'int', + 'qname': 'builtins.int', + }), + }), dict({ 'docstring': dict({ 'default_value': '', @@ -117,6 +134,23 @@ 'name': 'callexpr_attr_function', 'type': None, }), + dict({ + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'various_modules_package/attribute_module/AttributesClassB/defined_three_times', + 'is_public': True, + 'is_static': True, + 'is_type_inferred': False, + 'name': 'defined_three_times', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'int', + 'qname': 'builtins.int', + }), + }), dict({ 'docstring': dict({ 'default_value': '', diff --git a/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr b/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr index dd607619..60f2b154 100644 --- a/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr +++ b/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr @@ -70,6 +70,8 @@ // TODO Safe-DS does not support tuple types. @PythonName("tuple_attr_3") static attr tupleAttr3: Tuple + @PythonName("defined_three_times") + static attr definedThreeTimes: Int @PythonName("list_attr_1") static attr listAttr1: List @PythonName("list_attr_2") From 64e26a27c4d6afc360f4d4e58a24f61fd538fd17 Mon Sep 17 00:00:00 2001 From: Arsam Date: Thu, 30 Nov 2023 19:51:25 +0100 Subject: [PATCH 087/109] codecov & refactoring --- .../api_analyzer/_mypy_helpers.py | 4 ++-- src/safeds_stubgen/api_analyzer/_types.py | 2 +- .../abstract_module.py | 2 +- .../__snapshots__/test__get_api.ambr | 19 +++++++++++++++++++ .../__snapshots__/test_generate_stubs.ambr | 3 ++- 5 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/safeds_stubgen/api_analyzer/_mypy_helpers.py b/src/safeds_stubgen/api_analyzer/_mypy_helpers.py index dcd74a70..5d02b61a 100644 --- a/src/safeds_stubgen/api_analyzer/_mypy_helpers.py +++ b/src/safeds_stubgen/api_analyzer/_mypy_helpers.py @@ -121,7 +121,7 @@ def mypy_type_to_abstract_type( return sds_types.DictType(key_type=key_type, value_type=value_type) else: return sds_types.NamedType(name=type_name, qname=mypy_type.type.fullname) - raise ValueError("Unexpected type.") + raise ValueError("Unexpected type.") # pragma: no cover def get_argument_kind(arg: mp_nodes.Argument) -> ParameterAssignment: @@ -137,7 +137,7 @@ def get_argument_kind(arg: mp_nodes.Argument) -> ParameterAssignment: return ParameterAssignment.NAME_ONLY elif arg.kind == ArgKind.ARG_STAR2: return ParameterAssignment.NAMED_VARARG - else: + else: # pragma: no cover raise ValueError("Could not find an appropriate parameter assignment.") diff --git a/src/safeds_stubgen/api_analyzer/_types.py b/src/safeds_stubgen/api_analyzer/_types.py index f3325cd6..744a3954 100644 --- a/src/safeds_stubgen/api_analyzer/_types.py +++ b/src/safeds_stubgen/api_analyzer/_types.py @@ -60,7 +60,7 @@ def to_dict(self) -> dict[str, str]: return {"kind": self.__class__.__name__, "name": self.name, "qname": self.qname} def __eq__(self, other: object) -> bool: - if not isinstance(other, NamedType): + if not isinstance(other, NamedType): # pragma: no cover return NotImplemented return self.name == other.name and self.qname == other.qname diff --git a/tests/data/various_modules_package/abstract_module.py b/tests/data/various_modules_package/abstract_module.py index 67f77afe..09476f65 100644 --- a/tests/data/various_modules_package/abstract_module.py +++ b/tests/data/various_modules_package/abstract_module.py @@ -9,7 +9,7 @@ def __init__(self, param): def abstract_method(self): ... @abstractmethod - def abstract_method_params(self, param_1: int, param_2=False) -> list[str, int]: ... + def abstract_method_params(self, param_1: int, param_2=False, param_3=True) -> list[str, int]: ... @staticmethod @abstractmethod diff --git a/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr b/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr index d5b3ca3e..789225bd 100644 --- a/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr +++ b/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr @@ -1111,6 +1111,7 @@ 'various_modules_package/abstract_module/AbstractModuleClass/abstract_method_params/self', 'various_modules_package/abstract_module/AbstractModuleClass/abstract_method_params/param_1', 'various_modules_package/abstract_module/AbstractModuleClass/abstract_method_params/param_2', + 'various_modules_package/abstract_module/AbstractModuleClass/abstract_method_params/param_3', ]), 'reexported_by': list([ ]), @@ -2636,6 +2637,24 @@ 'qname': 'builtins.bool', }), }), + dict({ + 'assigned_by': 'POSITION_OR_NAME', + 'default_value': True, + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'various_modules_package/abstract_module/AbstractModuleClass/abstract_method_params/param_3', + 'is_optional': True, + 'is_type_inferred': True, + 'name': 'param_3', + 'type': dict({ + 'kind': 'NamedType', + 'name': 'bool', + 'qname': 'builtins.bool', + }), + }), dict({ 'assigned_by': 'IMPLICIT', 'default_value': None, diff --git a/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr b/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr index 60f2b154..99ccf0c2 100644 --- a/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr +++ b/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr @@ -20,7 +20,8 @@ @PythonName("abstract_method_params") fun abstractMethodParams( @PythonName("param_1") param1: Int, - @PythonName("param_2") param2: Boolean = false + @PythonName("param_2") param2: Boolean = false, + @PythonName("param_3") param3: Boolean = true ) -> result1: List // TODO Result type information missing. From 93bc3ccda622871b8bdd807cc0f734a4f0466b98 Mon Sep 17 00:00:00 2001 From: Arsam Date: Thu, 30 Nov 2023 19:59:30 +0100 Subject: [PATCH 088/109] codecov & refactoring --- src/safeds_stubgen/stubs_generator/_generate_stubs.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/safeds_stubgen/stubs_generator/_generate_stubs.py b/src/safeds_stubgen/stubs_generator/_generate_stubs.py index 872d656b..9ad00dd4 100644 --- a/src/safeds_stubgen/stubs_generator/_generate_stubs.py +++ b/src/safeds_stubgen/stubs_generator/_generate_stubs.py @@ -574,12 +574,8 @@ def _create_type_string(self, type_data: dict | None) -> str: if types: if len(types) == 2 and none_type_name in types: - # if None is one of the two possible types, we can remove the None and just return the other - # type with a question mark - if types[0] == types[1] == none_type_name: - return none_type_name - elif types[0] == none_type_name: - return f"{types[1]}?" + # if None is at least one of the two possible types, we can remove the None and just return the + # other type with a question mark return f"{types[0]}?" # If the union contains only one type, return the type instead of creating a union From 6de83ce098cb7a5fb01c9cc61b1db473fd8d513b Mon Sep 17 00:00:00 2001 From: Lars Reimann Date: Fri, 1 Dec 2023 15:42:42 +0100 Subject: [PATCH 089/109] chore: swap two config sections --- .editorconfig | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.editorconfig b/.editorconfig index 3fe87d19..9b5c459b 100644 --- a/.editorconfig +++ b/.editorconfig @@ -8,8 +8,8 @@ charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true -[{*.yaml,*.yml}] -indent_size = 2 - [*.ambr] trim_trailing_whitespace = false + +[{*.yaml,*.yml}] +indent_size = 2 From 2be7ef4d602d15507548a1f8b871781f51256a59 Mon Sep 17 00:00:00 2001 From: Lars Reimann Date: Fri, 1 Dec 2023 15:50:22 +0100 Subject: [PATCH 090/109] chore: move pytest config into `pyproject.toml` --- .pytest.ini | 2 -- pyproject.toml | 5 ++++- 2 files changed, 4 insertions(+), 3 deletions(-) delete mode 100644 .pytest.ini diff --git a/.pytest.ini b/.pytest.ini deleted file mode 100644 index 1f9cf2a8..00000000 --- a/.pytest.ini +++ /dev/null @@ -1,2 +0,0 @@ -[pytest] -addopts = --ignore=./tests/data diff --git a/pyproject.toml b/pyproject.toml index 9125c751..f2d74437 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,7 +13,7 @@ packages = [ ] [tool.poetry.scripts] -generate-safeds-stubs = "safeds_stubgen.main:main" +safe-ds-stubgen = "safeds_stubgen.main:main" [tool.poetry.dependencies] python = "^3.11" @@ -34,5 +34,8 @@ mkdocs-material = "^9.4.7" requires = ["poetry-core>=1.0.0"] build-backend = "poetry.core.masonry.api" +[tool.pytest.ini_options] +addopts = "--ignore=./tests/data" + [tool.black] line-length = 120 From cb9d9d9e1f2182b22ce14ce04089d22d331eca6b Mon Sep 17 00:00:00 2001 From: Arsam Date: Mon, 4 Dec 2023 13:34:43 +0100 Subject: [PATCH 091/109] [Refactoring] Renamed Variance class to TypeParameter and removed from_string method from NamedType Class --- src/safeds_stubgen/api_analyzer/__init__.py | 4 +- src/safeds_stubgen/api_analyzer/_api.py | 12 +++--- .../api_analyzer/_ast_visitor.py | 16 ++++---- .../api_analyzer/_mypy_helpers.py | 10 ++--- src/safeds_stubgen/api_analyzer/_types.py | 4 -- .../stubs_generator/_generate_stubs.py | 16 ++++---- .../__snapshots__/test_main.ambr | 12 +++--- .../__snapshots__/test__get_api.ambr | 38 +++++++++---------- 8 files changed, 54 insertions(+), 58 deletions(-) diff --git a/src/safeds_stubgen/api_analyzer/__init__.py b/src/safeds_stubgen/api_analyzer/__init__.py index 05414a9f..575a2556 100644 --- a/src/safeds_stubgen/api_analyzer/__init__.py +++ b/src/safeds_stubgen/api_analyzer/__init__.py @@ -13,7 +13,7 @@ ParameterAssignment, QualifiedImport, Result, - VarianceType, + VarianceKind, WildcardImport, ) from ._get_api import get_api @@ -64,6 +64,6 @@ "SetType", "TupleType", "UnionType", - "VarianceType", + "VarianceKind", "WildcardImport", ] diff --git a/src/safeds_stubgen/api_analyzer/_api.py b/src/safeds_stubgen/api_analyzer/_api.py index 8e68840f..b1b87d79 100644 --- a/src/safeds_stubgen/api_analyzer/_api.py +++ b/src/safeds_stubgen/api_analyzer/_api.py @@ -175,7 +175,7 @@ class Class: attributes: list[Attribute] = field(default_factory=list) methods: list[Function] = field(default_factory=list) classes: list[Class] = field(default_factory=list) - variances: list[Variance] = field(default_factory=list) + type_parameters: list[TypeParameter] = field(default_factory=list) def to_dict(self) -> dict[str, Any]: return { @@ -189,7 +189,7 @@ def to_dict(self) -> dict[str, Any]: "attributes": [attribute.id for attribute in self.attributes], "methods": [method.id for method in self.methods], "classes": [class_.id for class_ in self.classes], - "variances": [variance.to_dict() for variance in self.variances], + "type_parameters": [type_parameter.to_dict() for type_parameter in self.type_parameters], } def add_method(self, method: Function) -> None: @@ -310,16 +310,16 @@ class ParameterAssignment(PythonEnum): @dataclass(frozen=True) -class Variance: +class TypeParameter: name: str type: AbstractType - variance_type: VarianceType + variance: VarianceKind def to_dict(self) -> dict[str, Any]: - return {"name": self.name, "type": self.type.to_dict(), "variance_type": self.variance_type.name} + return {"name": self.name, "type": self.type.to_dict(), "variance_type": self.variance.name} -class VarianceType(PythonEnum): +class VarianceKind(PythonEnum): CONTRAVARIANT = "CONTRAVARIANT" COVARIANT = "COVARIANT" INVARIANT = "INVARIANT" diff --git a/src/safeds_stubgen/api_analyzer/_ast_visitor.py b/src/safeds_stubgen/api_analyzer/_ast_visitor.py index a0b6a11a..2343a378 100644 --- a/src/safeds_stubgen/api_analyzer/_ast_visitor.py +++ b/src/safeds_stubgen/api_analyzer/_ast_visitor.py @@ -19,8 +19,8 @@ Parameter, QualifiedImport, Result, - Variance, - VarianceType, + TypeParameter, + VarianceKind, WildcardImport, ) from ._mypy_helpers import ( @@ -134,7 +134,7 @@ def enter_classdef(self, node: mp_nodes.ClassDef) -> None: if base_name == "Generic": generic_exprs.append(removed_base_type_expr) - variances = [] + type_parameters = [] if generic_exprs: # Can only be one, since a class can inherit "Generic" only one time generic_expr = getattr(generic_exprs[0], "index", None) @@ -149,18 +149,18 @@ def enter_classdef(self, node: mp_nodes.ClassDef) -> None: for generic_type in generic_types: variance_type = mypy_variance_parser(generic_type.variance) variance_values: sds_types.AbstractType - if variance_type == VarianceType.INVARIANT: + if variance_type == VarianceKind.INVARIANT: variance_values = sds_types.UnionType([ mypy_type_to_abstract_type(value) for value in generic_type.values ]) else: variance_values = mypy_type_to_abstract_type(generic_type.upper_bound) - variances.append( - Variance( + type_parameters.append( + TypeParameter( name=generic_type.name, type=variance_values, - variance_type=variance_type, + variance=variance_type, ), ) @@ -190,7 +190,7 @@ def enter_classdef(self, node: mp_nodes.ClassDef) -> None: docstring=docstring, reexported_by=reexported_by, constructor_fulldocstring=constructor_fulldocstring, - variances=variances, + type_parameters=type_parameters, ) self.__declaration_stack.append(class_) diff --git a/src/safeds_stubgen/api_analyzer/_mypy_helpers.py b/src/safeds_stubgen/api_analyzer/_mypy_helpers.py index 5d02b61a..9b3ab1fd 100644 --- a/src/safeds_stubgen/api_analyzer/_mypy_helpers.py +++ b/src/safeds_stubgen/api_analyzer/_mypy_helpers.py @@ -9,7 +9,7 @@ import safeds_stubgen.api_analyzer._types as sds_types -from ._api import ParameterAssignment, VarianceType +from ._api import ParameterAssignment, VarianceKind if TYPE_CHECKING: from mypy.nodes import ClassDef, FuncDef, MypyFile @@ -163,14 +163,14 @@ def find_return_stmts_recursive(stmts: list[mp_nodes.Statement] | list[mp_nodes. return return_stmts -def mypy_variance_parser(mypy_variance_type: Literal[0, 1, 2]) -> VarianceType: +def mypy_variance_parser(mypy_variance_type: Literal[0, 1, 2]) -> VarianceKind: match mypy_variance_type: case 0: - return VarianceType.INVARIANT + return VarianceKind.INVARIANT case 1: - return VarianceType.COVARIANT + return VarianceKind.COVARIANT case 2: - return VarianceType.CONTRAVARIANT + return VarianceKind.CONTRAVARIANT case _: # pragma: no cover raise ValueError("Mypy variance parser received an illegal parameter value.") diff --git a/src/safeds_stubgen/api_analyzer/_types.py b/src/safeds_stubgen/api_analyzer/_types.py index 744a3954..43406c1a 100644 --- a/src/safeds_stubgen/api_analyzer/_types.py +++ b/src/safeds_stubgen/api_analyzer/_types.py @@ -52,10 +52,6 @@ class NamedType(AbstractType): def from_dict(cls, d: dict[str, Any]) -> NamedType: return NamedType(d["name"], d["qname"]) - @classmethod - def from_string(cls, name: str, qname: str = "") -> NamedType: - return NamedType(name, qname) - def to_dict(self) -> dict[str, str]: return {"kind": self.__class__.__name__, "name": self.name, "qname": self.qname} diff --git a/src/safeds_stubgen/stubs_generator/_generate_stubs.py b/src/safeds_stubgen/stubs_generator/_generate_stubs.py index 9ad00dd4..77326aa0 100644 --- a/src/safeds_stubgen/stubs_generator/_generate_stubs.py +++ b/src/safeds_stubgen/stubs_generator/_generate_stubs.py @@ -15,7 +15,7 @@ QualifiedImport, Result, UnionType, - VarianceType, + VarianceKind, WildcardImport, ) @@ -150,22 +150,22 @@ def _create_class_string(self, class_: Class, class_indentation: str = "") -> st # Variance & Constrains constraints_info = "" variance_info = "" - if class_.variances: + if class_.type_parameters: constraints = [] variances = [] - for variance in class_.variances: - match variance.variance_type.name: - case VarianceType.INVARIANT.name: + for variance in class_.type_parameters: + match variance.variance.name: + case VarianceKind.INVARIANT.name: variance_inheritance = "" variance_direction = "" - case VarianceType.COVARIANT.name: + case VarianceKind.COVARIANT.name: variance_inheritance = "sub" variance_direction = "out " - case VarianceType.CONTRAVARIANT.name: + case VarianceKind.CONTRAVARIANT.name: variance_inheritance = "super" variance_direction = "in " case _: # pragma: no cover - raise ValueError(f"Expected variance kind, got {variance.variance_type.name}.") + raise ValueError(f"Expected variance kind, got {variance.variance.name}.") # Convert name to camelCase and check for keywords variance_name_camel_case = self._convert_snake_to_camel_case(variance.name) diff --git a/tests/safeds_stubgen/__snapshots__/test_main.ambr b/tests/safeds_stubgen/__snapshots__/test_main.ambr index 90fcc10f..dfa35057 100644 --- a/tests/safeds_stubgen/__snapshots__/test_main.ambr +++ b/tests/safeds_stubgen/__snapshots__/test_main.ambr @@ -125,7 +125,7 @@ ]), 'superclasses': list([ ]), - 'variances': list([ + 'type_parameters': list([ ]), }), dict({ @@ -188,7 +188,7 @@ 'superclasses': list([ 'tests.data.main_package.main_module.AcDoubleAlias', ]), - 'variances': list([ + 'type_parameters': list([ ]), }), dict({ @@ -212,7 +212,7 @@ 'superclasses': list([ 'tests.data.main_package.another_path.another_module.AnotherClass', ]), - 'variances': list([ + 'type_parameters': list([ ]), }), dict({ @@ -256,7 +256,7 @@ ]), 'superclasses': list([ ]), - 'variances': list([ + 'type_parameters': list([ ]), }), dict({ @@ -281,7 +281,7 @@ ]), 'superclasses': list([ ]), - 'variances': list([ + 'type_parameters': list([ ]), }), dict({ @@ -303,7 +303,7 @@ ]), 'superclasses': list([ ]), - 'variances': list([ + 'type_parameters': list([ ]), }), ]), diff --git a/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr b/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr index 789225bd..ca94f21e 100644 --- a/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr +++ b/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr @@ -1726,7 +1726,7 @@ 'superclasses': list([ 'abc.ABC', ]), - 'variances': list([ + 'type_parameters': list([ ]), }) # --- @@ -1750,7 +1750,7 @@ ]), 'superclasses': list([ ]), - 'variances': list([ + 'type_parameters': list([ ]), }) # --- @@ -1796,7 +1796,7 @@ 'superclasses': list([ 'tests.data.various_modules_package.class_module.ClassModuleEmptyClassA', ]), - 'variances': list([ + 'type_parameters': list([ ]), }) # --- @@ -1825,7 +1825,7 @@ 'tests.data.various_modules_package.class_module.ClassModuleEmptyClassA', 'tests.data.various_modules_package.class_module.ClassModuleClassB', ]), - 'variances': list([ + 'type_parameters': list([ ]), }) # --- @@ -1850,7 +1850,7 @@ ]), 'superclasses': list([ ]), - 'variances': list([ + 'type_parameters': list([ ]), }) # --- @@ -1874,7 +1874,7 @@ ]), 'superclasses': list([ ]), - 'variances': list([ + 'type_parameters': list([ ]), }) # --- @@ -1902,7 +1902,7 @@ ]), 'superclasses': list([ ]), - 'variances': list([ + 'type_parameters': list([ ]), }) # --- @@ -1954,7 +1954,7 @@ ]), 'superclasses': list([ ]), - 'variances': list([ + 'type_parameters': list([ ]), }) # --- @@ -1979,7 +1979,7 @@ ]), 'superclasses': list([ ]), - 'variances': list([ + 'type_parameters': list([ ]), }) # --- @@ -2038,7 +2038,7 @@ ]), 'superclasses': list([ ]), - 'variances': list([ + 'type_parameters': list([ ]), }) # --- @@ -2089,7 +2089,7 @@ ]), 'superclasses': list([ ]), - 'variances': list([ + 'type_parameters': list([ ]), }) # --- @@ -2152,7 +2152,7 @@ ]), 'superclasses': list([ ]), - 'variances': list([ + 'type_parameters': list([ ]), }) # --- @@ -2178,7 +2178,7 @@ ]), 'superclasses': list([ ]), - 'variances': list([ + 'type_parameters': list([ ]), }) # --- @@ -2230,7 +2230,7 @@ ]), 'superclasses': list([ ]), - 'variances': list([ + 'type_parameters': list([ ]), }) # --- @@ -2254,7 +2254,7 @@ ]), 'superclasses': list([ ]), - 'variances': list([ + 'type_parameters': list([ dict({ 'name': '_T_co', 'type': dict({ @@ -2323,7 +2323,7 @@ ]), 'superclasses': list([ ]), - 'variances': list([ + 'type_parameters': list([ dict({ 'name': '_T_in', 'type': dict({ @@ -2376,7 +2376,7 @@ ]), 'superclasses': list([ ]), - 'variances': list([ + 'type_parameters': list([ ]), }) # --- @@ -2401,7 +2401,7 @@ ]), 'superclasses': list([ ]), - 'variances': list([ + 'type_parameters': list([ ]), }) # --- @@ -2426,7 +2426,7 @@ ]), 'superclasses': list([ ]), - 'variances': list([ + 'type_parameters': list([ ]), }) # --- From 09c258690793250b2743dc484151353eaf306a2c Mon Sep 17 00:00:00 2001 From: Arsam Date: Mon, 4 Dec 2023 14:21:40 +0100 Subject: [PATCH 092/109] [Refactoring] Removed the is_abstract constructor field from the Class "Class" in _api.py and added the property method is_abstract. Fixed a test. --- src/safeds_stubgen/api_analyzer/_api.py | 5 ++++- src/safeds_stubgen/api_analyzer/_ast_visitor.py | 2 -- tests/safeds_stubgen/api_analyzer/test_types.py | 1 - 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/safeds_stubgen/api_analyzer/_api.py b/src/safeds_stubgen/api_analyzer/_api.py index b1b87d79..fb74f06f 100644 --- a/src/safeds_stubgen/api_analyzer/_api.py +++ b/src/safeds_stubgen/api_analyzer/_api.py @@ -168,7 +168,6 @@ class Class: superclasses: list[str] is_public: bool docstring: ClassDocstring - is_abstract: bool = False constructor: Function | None = None constructor_fulldocstring: str = "" reexported_by: list[Module] = field(default_factory=list) @@ -192,6 +191,10 @@ def to_dict(self) -> dict[str, Any]: "type_parameters": [type_parameter.to_dict() for type_parameter in self.type_parameters], } + @property + def is_abstract(self) -> bool: + return "abc.ABC" in self.superclasses + def add_method(self, method: Function) -> None: self.methods.append(method) diff --git a/src/safeds_stubgen/api_analyzer/_ast_visitor.py b/src/safeds_stubgen/api_analyzer/_ast_visitor.py index 2343a378..2acdc759 100644 --- a/src/safeds_stubgen/api_analyzer/_ast_visitor.py +++ b/src/safeds_stubgen/api_analyzer/_ast_visitor.py @@ -167,7 +167,6 @@ def enter_classdef(self, node: mp_nodes.ClassDef) -> None: # superclasses # Todo Aliasing: Werden noch nicht aufgelöst superclasses = [superclass.fullname for superclass in node.base_type_exprs if hasattr(superclass, "fullname")] - is_abstract_class = "abc.ABC" in superclasses # Get reexported data reexported_by = self._get_reexported_by(name) @@ -186,7 +185,6 @@ def enter_classdef(self, node: mp_nodes.ClassDef) -> None: name=name, superclasses=superclasses, is_public=self._is_public(node.name, name), - is_abstract=is_abstract_class, docstring=docstring, reexported_by=reexported_by, constructor_fulldocstring=constructor_fulldocstring, diff --git a/tests/safeds_stubgen/api_analyzer/test_types.py b/tests/safeds_stubgen/api_analyzer/test_types.py index e2601f05..8cb2806b 100644 --- a/tests/safeds_stubgen/api_analyzer/test_types.py +++ b/tests/safeds_stubgen/api_analyzer/test_types.py @@ -73,7 +73,6 @@ def test_named_type() -> None: assert AbstractType.from_dict(named_type_dict) == named_type assert NamedType.from_dict(named_type_dict) == named_type - assert NamedType.from_string(name) == named_type assert named_type.to_dict() == named_type_dict From 077f192c792f466974eada6b6fb3f2e7cf2eede5 Mon Sep 17 00:00:00 2001 From: Arsam Date: Mon, 4 Dec 2023 15:05:55 +0100 Subject: [PATCH 093/109] [Refactoring] Removed the default_is_none constructor field from the Class "Parameter" in _api.py --- src/safeds_stubgen/api_analyzer/_api.py | 1 - src/safeds_stubgen/api_analyzer/_ast_visitor.py | 1 - src/safeds_stubgen/stubs_generator/_generate_stubs.py | 2 +- tests/safeds_stubgen/api_analyzer/test_types.py | 1 - 4 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/safeds_stubgen/api_analyzer/_api.py b/src/safeds_stubgen/api_analyzer/_api.py index fb74f06f..d93e7909 100644 --- a/src/safeds_stubgen/api_analyzer/_api.py +++ b/src/safeds_stubgen/api_analyzer/_api.py @@ -264,7 +264,6 @@ class Parameter: name: str is_optional: bool default_value: str | bool | int | float | None - default_is_none: bool assigned_by: ParameterAssignment docstring: ParameterDocstring type: AbstractType | None diff --git a/src/safeds_stubgen/api_analyzer/_ast_visitor.py b/src/safeds_stubgen/api_analyzer/_ast_visitor.py index 2acdc759..63906be9 100644 --- a/src/safeds_stubgen/api_analyzer/_ast_visitor.py +++ b/src/safeds_stubgen/api_analyzer/_ast_visitor.py @@ -754,7 +754,6 @@ def _parse_parameter_data(self, node: mp_nodes.FuncDef, function_id: str) -> lis name=arg_name, is_optional=default_value is not None or default_is_none, default_value=default_value, - default_is_none=default_is_none, assigned_by=arg_kind, docstring=docstring, type=arg_type, diff --git a/src/safeds_stubgen/stubs_generator/_generate_stubs.py b/src/safeds_stubgen/stubs_generator/_generate_stubs.py index 77326aa0..9f9791c0 100644 --- a/src/safeds_stubgen/stubs_generator/_generate_stubs.py +++ b/src/safeds_stubgen/stubs_generator/_generate_stubs.py @@ -401,7 +401,7 @@ def _create_parameter_string( else: default_value = f"{param_default_value}" param_value = f" = {default_value}" - elif parameter.default_is_none: + elif parameter.is_optional and parameter.default_value is None: param_value = " = null" # Mypy assignes *args parameters the tuple type, which is not supported in Safe-DS. Therefor we diff --git a/tests/safeds_stubgen/api_analyzer/test_types.py b/tests/safeds_stubgen/api_analyzer/test_types.py index 8cb2806b..192e1517 100644 --- a/tests/safeds_stubgen/api_analyzer/test_types.py +++ b/tests/safeds_stubgen/api_analyzer/test_types.py @@ -27,7 +27,6 @@ def test_correct_hash() -> None: name="test_parameter_for_hashing", is_optional=True, default_value="test_str", - default_is_none=False, assigned_by=ParameterAssignment.POSITION_OR_NAME, docstring=ParameterDocstring("'hashvalue'", "r", "r"), type=NamedType("str"), From d058b8345f6f0036b9024d43f4504cbd314d2f59 Mon Sep 17 00:00:00 2001 From: Arsam Date: Mon, 4 Dec 2023 15:10:05 +0100 Subject: [PATCH 094/109] [Refactoring] Fixed typos --- src/safeds_stubgen/api_analyzer/_ast_visitor.py | 4 ++-- src/safeds_stubgen/api_analyzer/_ast_walker.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/safeds_stubgen/api_analyzer/_ast_visitor.py b/src/safeds_stubgen/api_analyzer/_ast_visitor.py index 63906be9..80f580fb 100644 --- a/src/safeds_stubgen/api_analyzer/_ast_visitor.py +++ b/src/safeds_stubgen/api_analyzer/_ast_visitor.py @@ -398,7 +398,7 @@ def _parse_results(self, node: mp_nodes.FuncDef, function_id: str) -> list[Resul result_docstring = self.docstring_parser.get_result_documentation(node) if is_type_inferred and isinstance(ret_type, sds_types.TupleType): - return self._create_infered_results(ret_type, result_docstring, function_id) + return self._create_inferred_results(ret_type, result_docstring, function_id) # If we got a TupleType, we can iterate it for the results, but if we got a NamedType, we have just one result return_results = ret_type.types if isinstance(ret_type, sds_types.TupleType) else [ret_type] @@ -437,7 +437,7 @@ def _infer_type_from_return_stmts(func_node: mp_nodes.FuncDef) -> sds_types.Name return None @staticmethod - def _create_infered_results( + def _create_inferred_results( results: sds_types.TupleType, result_docstring: ResultDocstring, function_id: str, diff --git a/src/safeds_stubgen/api_analyzer/_ast_walker.py b/src/safeds_stubgen/api_analyzer/_ast_walker.py index 42c1803e..61caf165 100644 --- a/src/safeds_stubgen/api_analyzer/_ast_walker.py +++ b/src/safeds_stubgen/api_analyzer/_ast_walker.py @@ -30,7 +30,7 @@ def walk(self, tree: MypyFile) -> None: self.__walk(tree, set()) def __walk(self, node: MypyFile | ClassDef | Decorator | FuncDef | AssignmentStmt, visited_nodes: set) -> None: - # We ignore decorators and just take theire inner functions, since we can get decorator information from the + # We ignore decorators and just take their inner functions, since we can get decorator information from the # function node too if isinstance(node, Decorator): node = node.func From 1afef9fcae76866ea3ad1319771bf6e49f22dc40 Mon Sep 17 00:00:00 2001 From: Arsam Date: Mon, 4 Dec 2023 16:34:50 +0100 Subject: [PATCH 095/109] [Refactoring] Changed call argument from -ci to -nc --- src/safeds_stubgen/api_analyzer/cli/_cli.py | 8 ++++---- tests/safeds_stubgen/test_main.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/safeds_stubgen/api_analyzer/cli/_cli.py b/src/safeds_stubgen/api_analyzer/cli/_cli.py index e411188e..e4734fdf 100644 --- a/src/safeds_stubgen/api_analyzer/cli/_cli.py +++ b/src/safeds_stubgen/api_analyzer/cli/_cli.py @@ -61,11 +61,11 @@ def _get_args() -> argparse.Namespace: action="store_true", ) parser.add_argument( - "-ci", - "--convert_identifiers", + "-nc", + "--naming_convert", help=( - "Set this flag if the identifiers should be converted to Safe-DS standard (UpperCamelCase for classes and " - "camelCase for everything else)." + "Set this flag if the name identifiers should be converted to Safe-DS standard (UpperCamelCase for classes " + "and camelCase for everything else)." ), required=False, action="store_true", diff --git a/tests/safeds_stubgen/test_main.py b/tests/safeds_stubgen/test_main.py index 0016547d..bd25f416 100644 --- a/tests/safeds_stubgen/test_main.py +++ b/tests/safeds_stubgen/test_main.py @@ -28,7 +28,7 @@ def test_main(snapshot: SnapshotAssertion) -> None: "-tr", "--docstyle", "plaintext", - "-ci", + "-nc", ] main() From 01864b8039bfa25ceed6e18b9c54cae585c47886 Mon Sep 17 00:00:00 2001 From: Arsam Date: Mon, 4 Dec 2023 17:15:40 +0100 Subject: [PATCH 096/109] [Refactoring] --- src/safeds_stubgen/docstring_parsing/_numpydoc_parser.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/safeds_stubgen/docstring_parsing/_numpydoc_parser.py b/src/safeds_stubgen/docstring_parsing/_numpydoc_parser.py index ef4910e5..6d014a9d 100644 --- a/src/safeds_stubgen/docstring_parsing/_numpydoc_parser.py +++ b/src/safeds_stubgen/docstring_parsing/_numpydoc_parser.py @@ -83,7 +83,8 @@ def get_parameter_documentation( ] if len(matching_parameters_numpydoc) == 0: - # If we have a constructor we have to check both, the class and then the constructor (see issue #10) + # If we have a constructor we have to check both, the class and then the constructor (see issue + # https://github.com/Safe-DS/Library-Analyzer/issues/10) if function_node.name == "__init__": docstring_constructor = get_full_docstring(function_node) # Find matching parameter docstrings @@ -122,7 +123,8 @@ def get_attribute_documentation( if it.args[0] == "attribute" and _is_matching_attribute_numpydoc(it, attribute_name) ] - # If the class has a constructor we have to check both the class and then the constructor (see issue #10) + # If the class has a constructor we have to check both the class and then the constructor + # (see issue https://github.com/Safe-DS/Library-Analyzer/issues/10) if len(matching_attributes_numpydoc) == 0: # Find matching attribute docstrings function_numpydoc = parse_docstring( From 566e9298882373d01d1c7625b8f259b1a29c07f3 Mon Sep 17 00:00:00 2001 From: Arsam Date: Mon, 4 Dec 2023 17:24:22 +0100 Subject: [PATCH 097/109] Refactoring and bug fixing --- src/safeds_stubgen/stubs_generator/_generate_stubs.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/safeds_stubgen/stubs_generator/_generate_stubs.py b/src/safeds_stubgen/stubs_generator/_generate_stubs.py index 9f9791c0..d86e1626 100644 --- a/src/safeds_stubgen/stubs_generator/_generate_stubs.py +++ b/src/safeds_stubgen/stubs_generator/_generate_stubs.py @@ -147,7 +147,7 @@ def _create_class_string(self, class_: Class, class_indentation: str = "") -> st if len(superclasses) > 1: self._current_todo_msgs.add("multiple_inheritance") - # Variance & Constrains + # Type parameters constraints_info = "" variance_info = "" if class_.type_parameters: @@ -389,7 +389,7 @@ def _create_parameter_string( parameter_type_data = parameter.type.to_dict() # Default value - if param_default_value is not None: + if parameter.is_optional: if isinstance(param_default_value, str): if parameter_type_data["kind"] == "NamedType" and parameter_type_data["name"] != "str": default_value = f"{param_default_value}" @@ -398,10 +398,12 @@ def _create_parameter_string( elif isinstance(param_default_value, bool): # Bool values have to be written in lower case default_value = "true" if param_default_value else "false" + elif param_default_value is None: + default_value = "null" else: default_value = f"{param_default_value}" param_value = f" = {default_value}" - elif parameter.is_optional and parameter.default_value is None: + elif parameter.is_optional and param_default_value is None: param_value = " = null" # Mypy assignes *args parameters the tuple type, which is not supported in Safe-DS. Therefor we From d7ff69173ca0806bacad718672594b4513254d35 Mon Sep 17 00:00:00 2001 From: Arsam Date: Mon, 4 Dec 2023 17:30:20 +0100 Subject: [PATCH 098/109] bug fix --- src/safeds_stubgen/api_analyzer/cli/_cli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/safeds_stubgen/api_analyzer/cli/_cli.py b/src/safeds_stubgen/api_analyzer/cli/_cli.py index e4734fdf..c20c3833 100644 --- a/src/safeds_stubgen/api_analyzer/cli/_cli.py +++ b/src/safeds_stubgen/api_analyzer/cli/_cli.py @@ -17,7 +17,7 @@ def cli() -> None: if args.verbose: logging.basicConfig(level=logging.INFO) - _run_api_command(args.package, args.src, args.out, args.docstyle, args.testrun, args.convert_identifiers) + _run_api_command(args.package, args.src, args.out, args.docstyle, args.testrun, args.naming_convert) def _get_args() -> argparse.Namespace: From 032027c5673a0a3316f4f964ca4f102e371a5b7f Mon Sep 17 00:00:00 2001 From: Arsam Date: Tue, 5 Dec 2023 15:40:41 +0100 Subject: [PATCH 099/109] Removed unused is_type_inferred information --- src/safeds_stubgen/api_analyzer/_api.py | 6 - .../api_analyzer/_ast_visitor.py | 22 +-- .../__snapshots__/test_main.ambr | 21 --- .../__snapshots__/test__get_api.ambr | 163 ------------------ .../safeds_stubgen/api_analyzer/test_types.py | 4 +- 5 files changed, 6 insertions(+), 210 deletions(-) diff --git a/src/safeds_stubgen/api_analyzer/_api.py b/src/safeds_stubgen/api_analyzer/_api.py index d93e7909..9b7cac80 100644 --- a/src/safeds_stubgen/api_analyzer/_api.py +++ b/src/safeds_stubgen/api_analyzer/_api.py @@ -216,7 +216,6 @@ class Attribute: is_static: bool type: AbstractType | None docstring: AttributeDocstring - is_type_inferred: bool def to_dict(self) -> dict[str, Any]: return { @@ -226,7 +225,6 @@ def to_dict(self) -> dict[str, Any]: "is_public": self.is_public, "is_static": self.is_static, "type": self.type.to_dict() if self.type is not None else None, - "is_type_inferred": self.is_type_inferred, } @@ -267,7 +265,6 @@ class Parameter: assigned_by: ParameterAssignment docstring: ParameterDocstring type: AbstractType | None - is_type_inferred: bool @property def is_required(self) -> bool: @@ -289,7 +286,6 @@ def to_dict(self) -> dict[str, Any]: "default_value": self.default_value, "assigned_by": self.assigned_by.name, "type": self.type.to_dict() if self.type is not None else None, - "is_type_inferred": self.is_type_inferred, } @@ -332,7 +328,6 @@ class Result: id: str name: str type: AbstractType | None - is_type_inferred: bool docstring: ResultDocstring def to_dict(self) -> dict[str, Any]: @@ -341,7 +336,6 @@ def to_dict(self) -> dict[str, Any]: "name": self.name, "docstring": self.docstring.to_dict(), "type": self.type.to_dict() if self.type is not None else None, - "is_type_inferred": self.is_type_inferred, } diff --git a/src/safeds_stubgen/api_analyzer/_ast_visitor.py b/src/safeds_stubgen/api_analyzer/_ast_visitor.py index 80f580fb..333447e5 100644 --- a/src/safeds_stubgen/api_analyzer/_ast_visitor.py +++ b/src/safeds_stubgen/api_analyzer/_ast_visitor.py @@ -369,7 +369,7 @@ def _parse_results(self, node: mp_nodes.FuncDef, function_id: str) -> list[Resul # Get type ret_type: sds_types.AbstractType | None = None - is_type_inferred = False + type_is_inferred = False if hasattr(node, "type"): node_type = node.type if node_type is not None and hasattr(node_type, "ret_type"): @@ -382,7 +382,7 @@ def _parse_results(self, node: mp_nodes.FuncDef, function_id: str) -> list[Resul # In this case, the "Any" type was given because it was not explicitly annotated. # Therefor we have to try to infer the type. ret_type = self._infer_type_from_return_stmts(node) - is_type_inferred = ret_type is not None + type_is_inferred = ret_type is not None else: # Otherwise, we can parse the type normally unanalyzed_ret_type = getattr(node.unanalyzed_type, "ret_type", None) @@ -390,14 +390,14 @@ def _parse_results(self, node: mp_nodes.FuncDef, function_id: str) -> list[Resul else: # Infer type ret_type = self._infer_type_from_return_stmts(node) - is_type_inferred = ret_type is not None + type_is_inferred = ret_type is not None if ret_type is None: return [] result_docstring = self.docstring_parser.get_result_documentation(node) - if is_type_inferred and isinstance(ret_type, sds_types.TupleType): + if type_is_inferred and isinstance(ret_type, sds_types.TupleType): return self._create_inferred_results(ret_type, result_docstring, function_id) # If we got a TupleType, we can iterate it for the results, but if we got a NamedType, we have just one result @@ -406,7 +406,6 @@ def _parse_results(self, node: mp_nodes.FuncDef, function_id: str) -> list[Resul Result( id=f"{function_id}/result_{i + 1}", type=type_, - is_type_inferred=is_type_inferred, name=f"result_{i + 1}", docstring=result_docstring, ) @@ -492,7 +491,6 @@ def _create_inferred_results( Result( id=f"{function_id}/{name}", type=result_type, - is_type_inferred=True, name=name, docstring=result_docstring, ), @@ -572,7 +570,6 @@ def _create_attribute( qname = node.fullname attribute_type = None - is_type_inferred = False # MemberExpr are constructor (__init__) attributes if isinstance(attribute, mp_nodes.MemberExpr): @@ -580,15 +577,10 @@ def _create_attribute( if isinstance(attribute_type, mp_types.AnyType) and not has_correct_type_of_any(attribute_type.type_of_any): attribute_type = None - # Sometimes the is_inferred value is True even thoght has_explicit_value is False, thus we HAVE to check - # has_explicit_value, too. - is_type_inferred = node.is_inferred and node.has_explicit_value - # NameExpr are class attributes elif isinstance(attribute, mp_nodes.NameExpr): if not node.explicit_self_type: attribute_type = node.type - is_type_inferred = node.is_inferred # We need to get the unanalyzed_type for lists, since mypy is not able to check type hint information # regarding list item types @@ -597,7 +589,7 @@ def _create_attribute( and hasattr(attribute_type, "type") and hasattr(attribute_type, "args") and attribute_type.type.fullname == "builtins.list" - and not is_type_inferred + and not node.is_inferred ): if unanalyzed_type is not None and hasattr(unanalyzed_type, "args"): attribute_type.args = unanalyzed_type.args @@ -629,7 +621,6 @@ def _create_attribute( id=id_, name=name, type=type_, - is_type_inferred=is_type_inferred, is_public=self._is_public(name, qname), is_static=is_static, docstring=docstring, @@ -694,7 +685,6 @@ def _parse_parameter_data(self, node: mp_nodes.FuncDef, function_id: str) -> lis for argument in node.arguments: arg_name = argument.variable.name mypy_type = argument.variable.type - is_type_inferred = False arg_kind = get_argument_kind(argument) type_annotation = argument.type_annotation arg_type = None @@ -733,7 +723,6 @@ def _parse_parameter_data(self, node: mp_nodes.FuncDef, function_id: str) -> lis if infer_arg_type: arg_type = inferred_arg_type - is_type_inferred = True # Create parameter docstring parent = self.__declaration_stack[-1] @@ -757,7 +746,6 @@ def _parse_parameter_data(self, node: mp_nodes.FuncDef, function_id: str) -> lis assigned_by=arg_kind, docstring=docstring, type=arg_type, - is_type_inferred=is_type_inferred, ), ) diff --git a/tests/safeds_stubgen/__snapshots__/test_main.ambr b/tests/safeds_stubgen/__snapshots__/test_main.ambr index dfa35057..57dfbf97 100644 --- a/tests/safeds_stubgen/__snapshots__/test_main.ambr +++ b/tests/safeds_stubgen/__snapshots__/test_main.ambr @@ -11,7 +11,6 @@ 'id': 'main_package/main_module/ModuleClass/_init_attr_private', 'is_public': False, 'is_static': False, - 'is_type_inferred': False, 'name': '_init_attr_private', 'type': dict({ 'kind': 'NamedType', @@ -28,7 +27,6 @@ 'id': 'main_package/main_module/ModuleClass/attr_1', 'is_public': True, 'is_static': True, - 'is_type_inferred': False, 'name': 'attr_1', 'type': dict({ 'kind': 'NamedType', @@ -45,7 +43,6 @@ 'id': 'main_package/main_module/ModuleClass/init_attr', 'is_public': True, 'is_static': False, - 'is_type_inferred': False, 'name': 'init_attr', 'type': dict({ 'kind': 'NamedType', @@ -62,7 +59,6 @@ 'id': 'main_package/main_module/_PrivateClass/NestedPrivateClass/nested_class_attr', 'is_public': False, 'is_static': True, - 'is_type_inferred': True, 'name': 'nested_class_attr', 'type': dict({ 'kind': 'NamedType', @@ -79,7 +75,6 @@ 'id': 'main_package/main_module/_PrivateClass/public_attr_in_private_class', 'is_public': False, 'is_static': True, - 'is_type_inferred': True, 'name': 'public_attr_in_private_class', 'type': dict({ 'kind': 'NamedType', @@ -96,7 +91,6 @@ 'id': 'main_package/main_module/_PrivateClass/public_init_attr_in_private_class', 'is_public': False, 'is_static': False, - 'is_type_inferred': False, 'name': 'public_init_attr_in_private_class', 'type': dict({ 'kind': 'NamedType', @@ -570,7 +564,6 @@ }), 'id': 'main_package/main_module/ModuleClass/NestedClass/nested_class_function/param_1', 'is_optional': False, - 'is_type_inferred': False, 'name': 'param_1', 'type': dict({ 'kind': 'NamedType', @@ -588,7 +581,6 @@ }), 'id': 'main_package/main_module/ModuleClass/NestedClass/nested_class_function/self', 'is_optional': False, - 'is_type_inferred': False, 'name': 'self', 'type': None, }), @@ -602,7 +594,6 @@ }), 'id': 'main_package/main_module/ModuleClass/__init__/init_param_1', 'is_optional': False, - 'is_type_inferred': False, 'name': 'init_param_1', 'type': None, }), @@ -616,7 +607,6 @@ }), 'id': 'main_package/main_module/ModuleClass/__init__/self', 'is_optional': False, - 'is_type_inferred': False, 'name': 'self', 'type': None, }), @@ -630,7 +620,6 @@ }), 'id': 'main_package/main_module/ModuleClass/_some_function/param_1', 'is_optional': False, - 'is_type_inferred': False, 'name': 'param_1', 'type': dict({ 'kind': 'NamedType', @@ -648,7 +637,6 @@ }), 'id': 'main_package/main_module/ModuleClass/_some_function/param_2', 'is_optional': True, - 'is_type_inferred': False, 'name': 'param_2', 'type': dict({ 'kind': 'NamedType', @@ -666,7 +654,6 @@ }), 'id': 'main_package/main_module/ModuleClass/_some_function/self', 'is_optional': False, - 'is_type_inferred': False, 'name': 'self', 'type': None, }), @@ -680,7 +667,6 @@ }), 'id': 'main_package/main_module/_PrivateClass/__init__/self', 'is_optional': False, - 'is_type_inferred': False, 'name': 'self', 'type': None, }), @@ -694,7 +680,6 @@ }), 'id': 'main_package/main_module/_PrivateClass/public_func_in_private_class/self', 'is_optional': False, - 'is_type_inferred': False, 'name': 'self', 'type': None, }), @@ -708,7 +693,6 @@ }), 'id': 'main_package/main_module/global_func/main_test_param_1', 'is_optional': True, - 'is_type_inferred': False, 'name': 'main_test_param_1', 'type': dict({ 'kind': 'NamedType', @@ -726,7 +710,6 @@ }), 'id': 'main_package/main_module/global_func/main_test_param_2', 'is_optional': True, - 'is_type_inferred': False, 'name': 'main_test_param_2', 'type': dict({ 'kind': 'UnionType', @@ -752,7 +735,6 @@ 'type': '', }), 'id': 'main_package/main_module/ModuleClass/NestedClass/nested_class_function/result_1', - 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ 'kind': 'SetType', @@ -781,7 +763,6 @@ 'type': '', }), 'id': 'main_package/main_module/ModuleClass/_some_function/result_1', - 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ 'kind': 'NamedType', @@ -795,7 +776,6 @@ 'type': '', }), 'id': 'main_package/main_module/_private_global_func/result_1', - 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ 'kind': 'UnionType', @@ -824,7 +804,6 @@ 'type': '', }), 'id': 'main_package/main_module/global_func/result_1', - 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ 'kind': 'NamedType', diff --git a/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr b/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr index ca94f21e..03e57551 100644 --- a/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr +++ b/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr @@ -10,7 +10,6 @@ 'id': 'various_modules_package/attribute_module/AttributesClassB/_ignore_me', 'is_public': False, 'is_static': True, - 'is_type_inferred': True, 'name': '_ignore_me', 'type': dict({ 'kind': 'NamedType', @@ -27,7 +26,6 @@ 'id': 'various_modules_package/attribute_module/AttributesClassB/_multi_attr_2_private', 'is_public': False, 'is_static': True, - 'is_type_inferred': True, 'name': '_multi_attr_2_private', 'type': dict({ 'kind': 'NamedType', @@ -44,7 +42,6 @@ 'id': 'various_modules_package/attribute_module/AttributesClassB/_multi_attr_4_private', 'is_public': False, 'is_static': True, - 'is_type_inferred': True, 'name': '_multi_attr_4_private', 'type': dict({ 'kind': 'ListType', @@ -66,7 +63,6 @@ 'id': 'various_modules_package/attribute_module/AttributesClassB/_no_type_hint_private', 'is_public': False, 'is_static': True, - 'is_type_inferred': True, 'name': '_no_type_hint_private', 'type': dict({ 'kind': 'NamedType', @@ -83,7 +79,6 @@ 'id': 'various_modules_package/attribute_module/AttributesClassB/_type_hint_private', 'is_public': False, 'is_static': True, - 'is_type_inferred': False, 'name': '_type_hint_private', 'type': dict({ 'kind': 'NamedType', @@ -100,7 +95,6 @@ 'id': 'various_modules_package/attribute_module/AttributesClassB/bool_attr', 'is_public': True, 'is_static': True, - 'is_type_inferred': False, 'name': 'bool_attr', 'type': dict({ 'kind': 'NamedType', @@ -117,7 +111,6 @@ 'id': 'various_modules_package/attribute_module/AttributesClassB/callexpr_attr_class', 'is_public': True, 'is_static': True, - 'is_type_inferred': False, 'name': 'callexpr_attr_class', 'type': None, }), @@ -130,7 +123,6 @@ 'id': 'various_modules_package/attribute_module/AttributesClassB/callexpr_attr_function', 'is_public': True, 'is_static': True, - 'is_type_inferred': False, 'name': 'callexpr_attr_function', 'type': None, }), @@ -143,7 +135,6 @@ 'id': 'various_modules_package/attribute_module/AttributesClassB/defined_three_times', 'is_public': True, 'is_static': True, - 'is_type_inferred': False, 'name': 'defined_three_times', 'type': dict({ 'kind': 'NamedType', @@ -160,7 +151,6 @@ 'id': 'various_modules_package/attribute_module/AttributesClassB/dict_attr_1', 'is_public': True, 'is_static': True, - 'is_type_inferred': False, 'name': 'dict_attr_1', 'type': dict({ 'key_type': dict({ @@ -185,7 +175,6 @@ 'id': 'various_modules_package/attribute_module/AttributesClassB/dict_attr_2', 'is_public': True, 'is_static': True, - 'is_type_inferred': False, 'name': 'dict_attr_2', 'type': dict({ 'key_type': dict({ @@ -210,7 +199,6 @@ 'id': 'various_modules_package/attribute_module/AttributesClassB/dict_attr_3', 'is_public': True, 'is_static': True, - 'is_type_inferred': False, 'name': 'dict_attr_3', 'type': dict({ 'key_type': dict({ @@ -255,7 +243,6 @@ 'id': 'various_modules_package/attribute_module/AttributesClassB/final', 'is_public': True, 'is_static': True, - 'is_type_inferred': False, 'name': 'final', 'type': dict({ 'kind': 'FinalType', @@ -275,7 +262,6 @@ 'id': 'various_modules_package/attribute_module/AttributesClassB/final_union', 'is_public': True, 'is_static': True, - 'is_type_inferred': False, 'name': 'final_union', 'type': dict({ 'kind': 'FinalType', @@ -305,7 +291,6 @@ 'id': 'various_modules_package/attribute_module/AttributesClassB/finals', 'is_public': True, 'is_static': True, - 'is_type_inferred': False, 'name': 'finals', 'type': dict({ 'kind': 'FinalType', @@ -335,7 +320,6 @@ 'id': 'various_modules_package/attribute_module/AttributesClassB/flaot_attr', 'is_public': True, 'is_static': True, - 'is_type_inferred': False, 'name': 'flaot_attr', 'type': dict({ 'kind': 'NamedType', @@ -352,7 +336,6 @@ 'id': 'various_modules_package/attribute_module/AttributesClassB/init_attr', 'is_public': True, 'is_static': False, - 'is_type_inferred': False, 'name': 'init_attr', 'type': dict({ 'kind': 'NamedType', @@ -369,7 +352,6 @@ 'id': 'various_modules_package/attribute_module/AttributesClassB/int_or_bool_attr', 'is_public': True, 'is_static': True, - 'is_type_inferred': False, 'name': 'int_or_bool_attr', 'type': dict({ 'kind': 'UnionType', @@ -396,7 +378,6 @@ 'id': 'various_modules_package/attribute_module/AttributesClassB/list_attr_1', 'is_public': True, 'is_static': True, - 'is_type_inferred': False, 'name': 'list_attr_1', 'type': dict({ 'kind': 'ListType', @@ -413,7 +394,6 @@ 'id': 'various_modules_package/attribute_module/AttributesClassB/list_attr_2', 'is_public': True, 'is_static': True, - 'is_type_inferred': False, 'name': 'list_attr_2', 'type': dict({ 'kind': 'ListType', @@ -445,7 +425,6 @@ 'id': 'various_modules_package/attribute_module/AttributesClassB/list_attr_3', 'is_public': True, 'is_static': True, - 'is_type_inferred': False, 'name': 'list_attr_3', 'type': dict({ 'kind': 'ListType', @@ -472,7 +451,6 @@ 'id': 'various_modules_package/attribute_module/AttributesClassB/list_attr_4', 'is_public': True, 'is_static': True, - 'is_type_inferred': False, 'name': 'list_attr_4', 'type': dict({ 'kind': 'ListType', @@ -509,7 +487,6 @@ 'id': 'various_modules_package/attribute_module/AttributesClassB/literal', 'is_public': True, 'is_static': True, - 'is_type_inferred': False, 'name': 'literal', 'type': dict({ 'kind': 'LiteralType', @@ -525,7 +502,6 @@ 'id': 'various_modules_package/attribute_module/AttributesClassB/multi_attr_1', 'is_public': True, 'is_static': True, - 'is_type_inferred': True, 'name': 'multi_attr_1', 'type': dict({ 'kind': 'NamedType', @@ -542,7 +518,6 @@ 'id': 'various_modules_package/attribute_module/AttributesClassB/multi_attr_3', 'is_public': True, 'is_static': True, - 'is_type_inferred': True, 'name': 'multi_attr_3', 'type': dict({ 'kind': 'ListType', @@ -564,7 +539,6 @@ 'id': 'various_modules_package/attribute_module/AttributesClassB/multi_attr_5', 'is_public': True, 'is_static': True, - 'is_type_inferred': True, 'name': 'multi_attr_5', 'type': dict({ 'kind': 'NamedType', @@ -581,7 +555,6 @@ 'id': 'various_modules_package/attribute_module/AttributesClassB/multi_attr_6', 'is_public': True, 'is_static': True, - 'is_type_inferred': True, 'name': 'multi_attr_6', 'type': dict({ 'kind': 'NamedType', @@ -598,7 +571,6 @@ 'id': 'various_modules_package/attribute_module/AttributesClassB/multi_attr_7', 'is_public': True, 'is_static': True, - 'is_type_inferred': True, 'name': 'multi_attr_7', 'type': dict({ 'kind': 'NamedType', @@ -615,7 +587,6 @@ 'id': 'various_modules_package/attribute_module/AttributesClassB/multi_attr_8', 'is_public': True, 'is_static': True, - 'is_type_inferred': True, 'name': 'multi_attr_8', 'type': dict({ 'kind': 'NamedType', @@ -632,7 +603,6 @@ 'id': 'various_modules_package/attribute_module/AttributesClassB/no_type_hint_public', 'is_public': True, 'is_static': True, - 'is_type_inferred': True, 'name': 'no_type_hint_public', 'type': dict({ 'kind': 'NamedType', @@ -649,7 +619,6 @@ 'id': 'various_modules_package/attribute_module/AttributesClassB/none_attr', 'is_public': True, 'is_static': True, - 'is_type_inferred': False, 'name': 'none_attr', 'type': dict({ 'kind': 'NamedType', @@ -666,7 +635,6 @@ 'id': 'various_modules_package/attribute_module/AttributesClassB/object_attr', 'is_public': True, 'is_static': True, - 'is_type_inferred': False, 'name': 'object_attr', 'type': dict({ 'kind': 'NamedType', @@ -683,7 +651,6 @@ 'id': 'various_modules_package/attribute_module/AttributesClassB/optional', 'is_public': True, 'is_static': True, - 'is_type_inferred': False, 'name': 'optional', 'type': dict({ 'kind': 'UnionType', @@ -710,7 +677,6 @@ 'id': 'various_modules_package/attribute_module/AttributesClassB/set_attr_1', 'is_public': True, 'is_static': True, - 'is_type_inferred': False, 'name': 'set_attr_1', 'type': dict({ 'kind': 'SetType', @@ -732,7 +698,6 @@ 'id': 'various_modules_package/attribute_module/AttributesClassB/set_attr_2', 'is_public': True, 'is_static': True, - 'is_type_inferred': False, 'name': 'set_attr_2', 'type': dict({ 'kind': 'SetType', @@ -764,7 +729,6 @@ 'id': 'various_modules_package/attribute_module/AttributesClassB/set_attr_3', 'is_public': True, 'is_static': True, - 'is_type_inferred': False, 'name': 'set_attr_3', 'type': dict({ 'kind': 'SetType', @@ -791,7 +755,6 @@ 'id': 'various_modules_package/attribute_module/AttributesClassB/set_attr_4', 'is_public': True, 'is_static': True, - 'is_type_inferred': False, 'name': 'set_attr_4', 'type': dict({ 'kind': 'SetType', @@ -828,7 +791,6 @@ 'id': 'various_modules_package/attribute_module/AttributesClassB/str_attr_with_none_value', 'is_public': True, 'is_static': True, - 'is_type_inferred': False, 'name': 'str_attr_with_none_value', 'type': dict({ 'kind': 'NamedType', @@ -845,7 +807,6 @@ 'id': 'various_modules_package/attribute_module/AttributesClassB/tuple_attr_1', 'is_public': True, 'is_static': True, - 'is_type_inferred': False, 'name': 'tuple_attr_1', 'type': dict({ 'kind': 'TupleType', @@ -867,7 +828,6 @@ 'id': 'various_modules_package/attribute_module/AttributesClassB/tuple_attr_2', 'is_public': True, 'is_static': True, - 'is_type_inferred': False, 'name': 'tuple_attr_2', 'type': dict({ 'kind': 'TupleType', @@ -899,7 +859,6 @@ 'id': 'various_modules_package/attribute_module/AttributesClassB/tuple_attr_3', 'is_public': True, 'is_static': True, - 'is_type_inferred': False, 'name': 'tuple_attr_3', 'type': dict({ 'kind': 'TupleType', @@ -926,7 +885,6 @@ 'id': 'various_modules_package/attribute_module/AttributesClassB/type_hint_public', 'is_public': True, 'is_static': True, - 'is_type_inferred': False, 'name': 'type_hint_public', 'type': dict({ 'kind': 'NamedType', @@ -947,7 +905,6 @@ 'id': 'various_modules_package/class_module/ClassModuleClassD/ClassModuleNestedClassE/_nested_attr_2', 'is_public': False, 'is_static': True, - 'is_type_inferred': False, 'name': '_nested_attr_2', 'type': dict({ 'kind': 'NamedType', @@ -964,7 +921,6 @@ 'id': 'various_modules_package/class_module/ClassModuleClassD/ClassModuleNestedClassE/nested_attr_1', 'is_public': True, 'is_static': True, - 'is_type_inferred': False, 'name': 'nested_attr_1', 'type': dict({ 'kind': 'NamedType', @@ -985,7 +941,6 @@ 'id': 'various_modules_package/docstring_module/GoogleDocstringClass/attr_1', 'is_public': True, 'is_static': True, - 'is_type_inferred': False, 'name': 'attr_1', 'type': dict({ 'kind': 'NamedType', @@ -1006,7 +961,6 @@ 'id': 'various_modules_package/docstring_module/NumpyDocstringClass/attr_1', 'is_public': True, 'is_static': True, - 'is_type_inferred': False, 'name': 'attr_1', 'type': dict({ 'kind': 'NamedType', @@ -1027,7 +981,6 @@ 'id': 'various_modules_package/docstring_module/RestDocstringClass/attr_1', 'is_public': True, 'is_static': True, - 'is_type_inferred': False, 'name': 'attr_1', 'type': dict({ 'kind': 'NamedType', @@ -1048,7 +1001,6 @@ 'id': 'various_modules_package/class_module/_ClassModulePrivateClassG/_attr_1', 'is_public': False, 'is_static': True, - 'is_type_inferred': False, 'name': '_attr_1', 'type': dict({ 'kind': 'NamedType', @@ -1065,7 +1017,6 @@ 'id': 'various_modules_package/class_module/_ClassModulePrivateClassG/_attr_2', 'is_public': False, 'is_static': True, - 'is_type_inferred': False, 'name': '_attr_2', 'type': dict({ 'kind': 'NamedType', @@ -2561,7 +2512,6 @@ }), 'id': 'various_modules_package/function_module/FunctionModuleClassB/__init__/init_param', 'is_optional': False, - 'is_type_inferred': False, 'name': 'init_param', 'type': None, }), @@ -2575,7 +2525,6 @@ }), 'id': 'various_modules_package/function_module/FunctionModuleClassB/__init__/self', 'is_optional': False, - 'is_type_inferred': False, 'name': 'self', 'type': None, }), @@ -2593,7 +2542,6 @@ }), 'id': 'various_modules_package/function_module/_private/a', 'is_optional': False, - 'is_type_inferred': False, 'name': 'a', 'type': None, }), @@ -2611,7 +2559,6 @@ }), 'id': 'various_modules_package/abstract_module/AbstractModuleClass/abstract_method_params/param_1', 'is_optional': False, - 'is_type_inferred': False, 'name': 'param_1', 'type': dict({ 'kind': 'NamedType', @@ -2629,7 +2576,6 @@ }), 'id': 'various_modules_package/abstract_module/AbstractModuleClass/abstract_method_params/param_2', 'is_optional': True, - 'is_type_inferred': True, 'name': 'param_2', 'type': dict({ 'kind': 'NamedType', @@ -2647,7 +2593,6 @@ }), 'id': 'various_modules_package/abstract_module/AbstractModuleClass/abstract_method_params/param_3', 'is_optional': True, - 'is_type_inferred': True, 'name': 'param_3', 'type': dict({ 'kind': 'NamedType', @@ -2665,7 +2610,6 @@ }), 'id': 'various_modules_package/abstract_module/AbstractModuleClass/abstract_method_params/self', 'is_optional': False, - 'is_type_inferred': False, 'name': 'self', 'type': None, }), @@ -2683,7 +2627,6 @@ }), 'id': 'various_modules_package/abstract_module/AbstractModuleClass/abstract_property_method/self', 'is_optional': False, - 'is_type_inferred': False, 'name': 'self', 'type': None, }), @@ -2701,7 +2644,6 @@ }), 'id': 'various_modules_package/abstract_module/AbstractModuleClass/abstract_static_method_params/param', 'is_optional': False, - 'is_type_inferred': False, 'name': 'param', 'type': dict({ 'kind': 'NamedType', @@ -2723,7 +2665,6 @@ }), 'id': 'various_modules_package/function_module/arg/args', 'is_optional': False, - 'is_type_inferred': False, 'name': 'args', 'type': None, }), @@ -2737,7 +2678,6 @@ }), 'id': 'various_modules_package/function_module/arg/kwargs', 'is_optional': False, - 'is_type_inferred': False, 'name': 'kwargs', 'type': None, }), @@ -2755,7 +2695,6 @@ }), 'id': 'various_modules_package/function_module/args_type/args', 'is_optional': False, - 'is_type_inferred': False, 'name': 'args', 'type': dict({ 'kind': 'TupleType', @@ -2778,7 +2717,6 @@ }), 'id': 'various_modules_package/function_module/args_type/kwargs', 'is_optional': False, - 'is_type_inferred': False, 'name': 'kwargs', 'type': dict({ 'key_type': dict({ @@ -2808,7 +2746,6 @@ }), 'id': 'various_modules_package/function_module/callable_type/param', 'is_optional': False, - 'is_type_inferred': False, 'name': 'param', 'type': dict({ 'kind': 'CallableType', @@ -2850,7 +2787,6 @@ }), 'id': 'various_modules_package/function_module/FunctionModuleClassB/class_method/cls', 'is_optional': False, - 'is_type_inferred': False, 'name': 'cls', 'type': None, }), @@ -2868,7 +2804,6 @@ }), 'id': 'various_modules_package/function_module/FunctionModuleClassB/class_method_params/cls', 'is_optional': False, - 'is_type_inferred': False, 'name': 'cls', 'type': None, }), @@ -2882,7 +2817,6 @@ }), 'id': 'various_modules_package/function_module/FunctionModuleClassB/class_method_params/param_1', 'is_optional': False, - 'is_type_inferred': False, 'name': 'param_1', 'type': dict({ 'kind': 'NamedType', @@ -2904,7 +2838,6 @@ }), 'id': 'various_modules_package/docstring_module/EpydocDocstringClass/__init__/param_1', 'is_optional': False, - 'is_type_inferred': False, 'name': 'param_1', 'type': dict({ 'kind': 'NamedType', @@ -2922,7 +2855,6 @@ }), 'id': 'various_modules_package/docstring_module/EpydocDocstringClass/__init__/self', 'is_optional': False, - 'is_type_inferred': False, 'name': 'self', 'type': None, }), @@ -2940,7 +2872,6 @@ }), 'id': 'various_modules_package/docstring_module/EpydocDocstringClass/epydoc_docstring_func/self', 'is_optional': False, - 'is_type_inferred': False, 'name': 'self', 'type': None, }), @@ -2954,7 +2885,6 @@ }), 'id': 'various_modules_package/docstring_module/EpydocDocstringClass/epydoc_docstring_func/x', 'is_optional': False, - 'is_type_inferred': False, 'name': 'x', 'type': dict({ 'kind': 'NamedType', @@ -2972,7 +2902,6 @@ }), 'id': 'various_modules_package/docstring_module/EpydocDocstringClass/epydoc_docstring_func/y', 'is_optional': False, - 'is_type_inferred': False, 'name': 'y', 'type': dict({ 'kind': 'NamedType', @@ -2994,7 +2923,6 @@ }), 'id': 'various_modules_package/docstring_module/GoogleDocstringClass/__init__/param_1', 'is_optional': False, - 'is_type_inferred': False, 'name': 'param_1', 'type': dict({ 'kind': 'NamedType', @@ -3012,7 +2940,6 @@ }), 'id': 'various_modules_package/docstring_module/GoogleDocstringClass/__init__/self', 'is_optional': False, - 'is_type_inferred': False, 'name': 'self', 'type': None, }), @@ -3030,7 +2957,6 @@ }), 'id': 'various_modules_package/docstring_module/GoogleDocstringClass/google_docstring_func/self', 'is_optional': False, - 'is_type_inferred': False, 'name': 'self', 'type': None, }), @@ -3044,7 +2970,6 @@ }), 'id': 'various_modules_package/docstring_module/GoogleDocstringClass/google_docstring_func/x', 'is_optional': False, - 'is_type_inferred': False, 'name': 'x', 'type': dict({ 'kind': 'NamedType', @@ -3062,7 +2987,6 @@ }), 'id': 'various_modules_package/docstring_module/GoogleDocstringClass/google_docstring_func/y', 'is_optional': False, - 'is_type_inferred': False, 'name': 'y', 'type': dict({ 'kind': 'NamedType', @@ -3084,7 +3008,6 @@ }), 'id': 'various_modules_package/function_module/illegal_params/_', 'is_optional': True, - 'is_type_inferred': False, 'name': '_', 'type': dict({ 'kind': 'NamedType', @@ -3102,7 +3025,6 @@ }), 'id': 'various_modules_package/function_module/illegal_params/lst', 'is_optional': False, - 'is_type_inferred': False, 'name': 'lst', 'type': dict({ 'kind': 'ListType', @@ -3130,7 +3052,6 @@ }), 'id': 'various_modules_package/function_module/illegal_params/lst_2', 'is_optional': False, - 'is_type_inferred': False, 'name': 'lst_2', 'type': dict({ 'kind': 'ListType', @@ -3163,7 +3084,6 @@ }), 'id': 'various_modules_package/function_module/illegal_params/tpl', 'is_optional': False, - 'is_type_inferred': False, 'name': 'tpl', 'type': dict({ 'kind': 'TupleType', @@ -3205,7 +3125,6 @@ }), 'id': 'various_modules_package/function_module/FunctionModuleClassB/FunctionModuleClassC/nested_class_function/param1', 'is_optional': False, - 'is_type_inferred': False, 'name': 'param1', 'type': dict({ 'kind': 'NamedType', @@ -3223,7 +3142,6 @@ }), 'id': 'various_modules_package/function_module/FunctionModuleClassB/FunctionModuleClassC/nested_class_function/self', 'is_optional': False, - 'is_type_inferred': False, 'name': 'self', 'type': None, }), @@ -3241,7 +3159,6 @@ }), 'id': 'various_modules_package/docstring_module/NumpyDocstringClass/__init__/param_1', 'is_optional': False, - 'is_type_inferred': False, 'name': 'param_1', 'type': dict({ 'kind': 'NamedType', @@ -3259,7 +3176,6 @@ }), 'id': 'various_modules_package/docstring_module/NumpyDocstringClass/__init__/self', 'is_optional': False, - 'is_type_inferred': False, 'name': 'self', 'type': None, }), @@ -3277,7 +3193,6 @@ }), 'id': 'various_modules_package/docstring_module/NumpyDocstringClass/numpy_docstring_func/self', 'is_optional': False, - 'is_type_inferred': False, 'name': 'self', 'type': None, }), @@ -3291,7 +3206,6 @@ }), 'id': 'various_modules_package/docstring_module/NumpyDocstringClass/numpy_docstring_func/x', 'is_optional': False, - 'is_type_inferred': False, 'name': 'x', 'type': dict({ 'kind': 'NamedType', @@ -3309,7 +3223,6 @@ }), 'id': 'various_modules_package/docstring_module/NumpyDocstringClass/numpy_docstring_func/y', 'is_optional': False, - 'is_type_inferred': False, 'name': 'y', 'type': dict({ 'kind': 'NamedType', @@ -3331,7 +3244,6 @@ }), 'id': 'various_modules_package/function_module/opt_pos_only/optional', 'is_optional': True, - 'is_type_inferred': True, 'name': 'optional', 'type': dict({ 'kind': 'NamedType', @@ -3349,7 +3261,6 @@ }), 'id': 'various_modules_package/function_module/opt_pos_only/required', 'is_optional': False, - 'is_type_inferred': False, 'name': 'required', 'type': None, }), @@ -3367,7 +3278,6 @@ }), 'id': 'various_modules_package/function_module/param_position/a', 'is_optional': False, - 'is_type_inferred': False, 'name': 'a', 'type': None, }), @@ -3381,7 +3291,6 @@ }), 'id': 'various_modules_package/function_module/param_position/b', 'is_optional': False, - 'is_type_inferred': False, 'name': 'b', 'type': dict({ 'kind': 'NamedType', @@ -3399,7 +3308,6 @@ }), 'id': 'various_modules_package/function_module/param_position/c', 'is_optional': True, - 'is_type_inferred': True, 'name': 'c', 'type': dict({ 'kind': 'NamedType', @@ -3417,7 +3325,6 @@ }), 'id': 'various_modules_package/function_module/param_position/d', 'is_optional': False, - 'is_type_inferred': True, 'name': 'd', 'type': None, }), @@ -3431,7 +3338,6 @@ }), 'id': 'various_modules_package/function_module/param_position/e', 'is_optional': True, - 'is_type_inferred': False, 'name': 'e', 'type': dict({ 'kind': 'NamedType', @@ -3449,7 +3355,6 @@ }), 'id': 'various_modules_package/function_module/param_position/self', 'is_optional': False, - 'is_type_inferred': False, 'name': 'self', 'type': None, }), @@ -3467,7 +3372,6 @@ }), 'id': 'various_modules_package/function_module/params/any_', 'is_optional': False, - 'is_type_inferred': False, 'name': 'any_', 'type': dict({ 'kind': 'NamedType', @@ -3485,7 +3389,6 @@ }), 'id': 'various_modules_package/function_module/params/boolean', 'is_optional': False, - 'is_type_inferred': False, 'name': 'boolean', 'type': dict({ 'kind': 'NamedType', @@ -3503,7 +3406,6 @@ }), 'id': 'various_modules_package/function_module/params/callexpr', 'is_optional': False, - 'is_type_inferred': False, 'name': 'callexpr', 'type': None, }), @@ -3517,7 +3419,6 @@ }), 'id': 'various_modules_package/function_module/params/dictionary', 'is_optional': False, - 'is_type_inferred': False, 'name': 'dictionary', 'type': dict({ 'key_type': dict({ @@ -3553,7 +3454,6 @@ }), 'id': 'various_modules_package/function_module/params/float_', 'is_optional': False, - 'is_type_inferred': False, 'name': 'float_', 'type': dict({ 'kind': 'NamedType', @@ -3571,7 +3471,6 @@ }), 'id': 'various_modules_package/function_module/params/integer', 'is_optional': False, - 'is_type_inferred': False, 'name': 'integer', 'type': dict({ 'kind': 'NamedType', @@ -3589,7 +3488,6 @@ }), 'id': 'various_modules_package/function_module/params/list_', 'is_optional': False, - 'is_type_inferred': False, 'name': 'list_', 'type': dict({ 'kind': 'ListType', @@ -3612,7 +3510,6 @@ }), 'id': 'various_modules_package/function_module/params/literal', 'is_optional': False, - 'is_type_inferred': False, 'name': 'literal', 'type': dict({ 'kind': 'LiteralType', @@ -3629,7 +3526,6 @@ }), 'id': 'various_modules_package/function_module/params/none', 'is_optional': False, - 'is_type_inferred': False, 'name': 'none', 'type': dict({ 'kind': 'NamedType', @@ -3647,7 +3543,6 @@ }), 'id': 'various_modules_package/function_module/params/obj', 'is_optional': False, - 'is_type_inferred': False, 'name': 'obj', 'type': dict({ 'kind': 'NamedType', @@ -3665,7 +3560,6 @@ }), 'id': 'various_modules_package/function_module/params/optional', 'is_optional': False, - 'is_type_inferred': False, 'name': 'optional', 'type': dict({ 'kind': 'UnionType', @@ -3693,7 +3587,6 @@ }), 'id': 'various_modules_package/function_module/params/set_', 'is_optional': False, - 'is_type_inferred': False, 'name': 'set_', 'type': dict({ 'kind': 'SetType', @@ -3716,7 +3609,6 @@ }), 'id': 'various_modules_package/function_module/params/string', 'is_optional': False, - 'is_type_inferred': False, 'name': 'string', 'type': dict({ 'kind': 'NamedType', @@ -3734,7 +3626,6 @@ }), 'id': 'various_modules_package/function_module/params/tuple_', 'is_optional': False, - 'is_type_inferred': False, 'name': 'tuple_', 'type': dict({ 'kind': 'TupleType', @@ -3767,7 +3658,6 @@ }), 'id': 'various_modules_package/function_module/params/union', 'is_optional': False, - 'is_type_inferred': False, 'name': 'union', 'type': dict({ 'kind': 'UnionType', @@ -3795,7 +3685,6 @@ }), 'id': 'various_modules_package/function_module/params/union_with_none_1', 'is_optional': False, - 'is_type_inferred': False, 'name': 'union_with_none_1', 'type': dict({ 'kind': 'UnionType', @@ -3823,7 +3712,6 @@ }), 'id': 'various_modules_package/function_module/params/union_with_none_2', 'is_optional': False, - 'is_type_inferred': False, 'name': 'union_with_none_2', 'type': dict({ 'kind': 'UnionType', @@ -3859,7 +3747,6 @@ }), 'id': 'various_modules_package/function_module/req_name_only/optional', 'is_optional': True, - 'is_type_inferred': True, 'name': 'optional', 'type': dict({ 'kind': 'NamedType', @@ -3877,7 +3764,6 @@ }), 'id': 'various_modules_package/function_module/req_name_only/required', 'is_optional': False, - 'is_type_inferred': False, 'name': 'required', 'type': None, }), @@ -3895,7 +3781,6 @@ }), 'id': 'various_modules_package/docstring_module/RestDocstringClass/__init__/param_1', 'is_optional': False, - 'is_type_inferred': False, 'name': 'param_1', 'type': dict({ 'kind': 'NamedType', @@ -3913,7 +3798,6 @@ }), 'id': 'various_modules_package/docstring_module/RestDocstringClass/__init__/self', 'is_optional': False, - 'is_type_inferred': False, 'name': 'self', 'type': None, }), @@ -3931,7 +3815,6 @@ }), 'id': 'various_modules_package/docstring_module/RestDocstringClass/rest_docstring_func/self', 'is_optional': False, - 'is_type_inferred': False, 'name': 'self', 'type': None, }), @@ -3945,7 +3828,6 @@ }), 'id': 'various_modules_package/docstring_module/RestDocstringClass/rest_docstring_func/x', 'is_optional': False, - 'is_type_inferred': False, 'name': 'x', 'type': dict({ 'kind': 'NamedType', @@ -3963,7 +3845,6 @@ }), 'id': 'various_modules_package/docstring_module/RestDocstringClass/rest_docstring_func/y', 'is_optional': False, - 'is_type_inferred': False, 'name': 'y', 'type': dict({ 'kind': 'NamedType', @@ -3985,7 +3866,6 @@ }), 'id': 'various_modules_package/function_module/special_params/bool_none_union', 'is_optional': False, - 'is_type_inferred': False, 'name': 'bool_none_union', 'type': dict({ 'kind': 'UnionType', @@ -4013,7 +3893,6 @@ }), 'id': 'various_modules_package/function_module/special_params/none', 'is_optional': False, - 'is_type_inferred': False, 'name': 'none', 'type': dict({ 'kind': 'NamedType', @@ -4031,7 +3910,6 @@ }), 'id': 'various_modules_package/function_module/special_params/none_bool_int_union', 'is_optional': False, - 'is_type_inferred': False, 'name': 'none_bool_int_union', 'type': dict({ 'kind': 'UnionType', @@ -4064,7 +3942,6 @@ }), 'id': 'various_modules_package/function_module/special_params/none_bool_none_union', 'is_optional': False, - 'is_type_inferred': False, 'name': 'none_bool_none_union', 'type': dict({ 'kind': 'UnionType', @@ -4097,7 +3974,6 @@ }), 'id': 'various_modules_package/function_module/special_params/none_bool_union', 'is_optional': False, - 'is_type_inferred': False, 'name': 'none_bool_union', 'type': dict({ 'kind': 'UnionType', @@ -4125,7 +4001,6 @@ }), 'id': 'various_modules_package/function_module/special_params/none_list_union_none_none', 'is_optional': False, - 'is_type_inferred': False, 'name': 'none_list_union_none_none', 'type': dict({ 'kind': 'UnionType', @@ -4173,7 +4048,6 @@ }), 'id': 'various_modules_package/function_module/special_params/none_none_bool_none_union', 'is_optional': False, - 'is_type_inferred': False, 'name': 'none_none_bool_none_union', 'type': dict({ 'kind': 'UnionType', @@ -4211,7 +4085,6 @@ }), 'id': 'various_modules_package/function_module/special_params/none_union', 'is_optional': False, - 'is_type_inferred': False, 'name': 'none_union', 'type': dict({ 'kind': 'UnionType', @@ -4243,7 +4116,6 @@ }), 'id': 'various_modules_package/function_module/FunctionModuleClassB/static_method_params/param_1', 'is_optional': False, - 'is_type_inferred': False, 'name': 'param_1', 'type': dict({ 'kind': 'NamedType', @@ -4261,7 +4133,6 @@ 'type': '', }), 'id': 'various_modules_package/abstract_module/AbstractModuleClass/abstract_method_params/result_1', - 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ 'kind': 'ListType', @@ -4289,7 +4160,6 @@ 'type': '', }), 'id': 'various_modules_package/abstract_module/AbstractModuleClass/abstract_property_method/result_1', - 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ 'kind': 'NamedType', @@ -4303,7 +4173,6 @@ 'type': '', }), 'id': 'various_modules_package/abstract_module/AbstractModuleClass/abstract_property_method/result_2', - 'is_type_inferred': False, 'name': 'result_2', 'type': dict({ 'kind': 'NamedType', @@ -4321,7 +4190,6 @@ 'type': '', }), 'id': 'various_modules_package/abstract_module/AbstractModuleClass/abstract_static_method_params/result_1', - 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ 'kind': 'NamedType', @@ -4339,7 +4207,6 @@ 'type': '', }), 'id': 'various_modules_package/function_module/any_results/result_1', - 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ 'kind': 'NamedType', @@ -4357,7 +4224,6 @@ 'type': '', }), 'id': 'various_modules_package/function_module/callable_type/result_1', - 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ 'kind': 'CallableType', @@ -4398,7 +4264,6 @@ 'type': '', }), 'id': 'various_modules_package/function_module/FunctionModuleClassB/class_method_params/result_1', - 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ 'kind': 'NamedType', @@ -4416,7 +4281,6 @@ 'type': '', }), 'id': 'various_modules_package/function_module/dictionary_results/result_1', - 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ 'key_type': dict({ @@ -4442,7 +4306,6 @@ 'type': '', }), 'id': 'various_modules_package/function_module/dictionary_results_no_key_no_value/result_1', - 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ 'key_type': dict({ @@ -4468,7 +4331,6 @@ 'type': 'bool', }), 'id': 'various_modules_package/docstring_module/EpydocDocstringClass/epydoc_docstring_func/result_1', - 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ 'kind': 'NamedType', @@ -4486,7 +4348,6 @@ 'type': '', }), 'id': 'various_modules_package/function_module/float_result/result_1', - 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ 'kind': 'NamedType', @@ -4507,7 +4368,6 @@ 'type': 'bool', }), 'id': 'various_modules_package/docstring_module/GoogleDocstringClass/google_docstring_func/result_1', - 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ 'kind': 'NamedType', @@ -4525,7 +4385,6 @@ 'type': '', }), 'id': 'various_modules_package/function_module/illegal_dictionary_results/result_1', - 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ 'key_type': dict({ @@ -4551,7 +4410,6 @@ 'type': '', }), 'id': 'various_modules_package/function_module/illegal_list_results/result_1', - 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ 'kind': 'ListType', @@ -4579,7 +4437,6 @@ 'type': '', }), 'id': 'various_modules_package/function_module/illegal_set_results/result_1', - 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ 'kind': 'SetType', @@ -4607,7 +4464,6 @@ 'type': '', }), 'id': 'various_modules_package/infer_types_module/InferMyTypes/infer_function/result_1', - 'is_type_inferred': True, 'name': 'result_1', 'type': dict({ 'kind': 'UnionType', @@ -4671,7 +4527,6 @@ 'type': '', }), 'id': 'various_modules_package/infer_types_module/InferMyTypes/infer_function/result_2', - 'is_type_inferred': True, 'name': 'result_2', 'type': dict({ 'kind': 'UnionType', @@ -4695,7 +4550,6 @@ 'type': '', }), 'id': 'various_modules_package/infer_types_module/InferMyTypes/infer_function/result_3', - 'is_type_inferred': True, 'name': 'result_3', 'type': dict({ 'kind': 'NamedType', @@ -4713,7 +4567,6 @@ 'type': '', }), 'id': 'various_modules_package/function_module/FunctionModuleClassB/instance_method/result_1', - 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ 'kind': 'NamedType', @@ -4731,7 +4584,6 @@ 'type': '', }), 'id': 'various_modules_package/function_module/int_result/result_1', - 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ 'kind': 'NamedType', @@ -4749,7 +4601,6 @@ 'type': '', }), 'id': 'various_modules_package/function_module/list_results/result_1', - 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ 'kind': 'ListType', @@ -4772,7 +4623,6 @@ 'type': '', }), 'id': 'various_modules_package/function_module/literal_results/result_1', - 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ 'kind': 'LiteralType', @@ -4789,7 +4639,6 @@ 'type': '', }), 'id': 'various_modules_package/function_module/FunctionModuleClassB/FunctionModuleClassC/nested_class_function/result_1', - 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ 'kind': 'NamedType', @@ -4811,7 +4660,6 @@ 'type': 'bool', }), 'id': 'various_modules_package/docstring_module/NumpyDocstringClass/numpy_docstring_func/result_1', - 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ 'kind': 'NamedType', @@ -4829,7 +4677,6 @@ 'type': '', }), 'id': 'various_modules_package/function_module/obj_result/result_1', - 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ 'kind': 'NamedType', @@ -4847,7 +4694,6 @@ 'type': '', }), 'id': 'various_modules_package/function_module/optional_results/result_1', - 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ 'kind': 'UnionType', @@ -4879,7 +4725,6 @@ 'type': '', }), 'id': 'various_modules_package/function_module/FunctionModulePropertiesClass/property_function_infer/result_1', - 'is_type_inferred': True, 'name': 'result_1', 'type': dict({ 'kind': 'NamedType', @@ -4897,7 +4742,6 @@ 'type': '', }), 'id': 'various_modules_package/function_module/FunctionModulePropertiesClass/property_function_params/result_1', - 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ 'kind': 'NamedType', @@ -4915,7 +4759,6 @@ 'type': 'bool', }), 'id': 'various_modules_package/docstring_module/RestDocstringClass/rest_docstring_func/result_1', - 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ 'kind': 'NamedType', @@ -4933,7 +4776,6 @@ 'type': '', }), 'id': 'various_modules_package/function_module/set_results/result_1', - 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ 'kind': 'SetType', @@ -4960,7 +4802,6 @@ 'type': '', }), 'id': 'various_modules_package/function_module/str_result/result_1', - 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ 'kind': 'NamedType', @@ -4978,7 +4819,6 @@ 'type': '', }), 'id': 'various_modules_package/function_module/tuple_results/result_1', - 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ 'kind': 'NamedType', @@ -4992,7 +4832,6 @@ 'type': '', }), 'id': 'various_modules_package/function_module/tuple_results/result_2', - 'is_type_inferred': False, 'name': 'result_2', 'type': dict({ 'kind': 'NamedType', @@ -5010,7 +4849,6 @@ 'type': '', }), 'id': 'various_modules_package/function_module/union_dictionary_results/result_1', - 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ 'key_type': dict({ @@ -5056,7 +4894,6 @@ 'type': '', }), 'id': 'various_modules_package/function_module/union_results/result_1', - 'is_type_inferred': False, 'name': 'result_1', 'type': dict({ 'kind': 'UnionType', diff --git a/tests/safeds_stubgen/api_analyzer/test_types.py b/tests/safeds_stubgen/api_analyzer/test_types.py index 192e1517..761041f4 100644 --- a/tests/safeds_stubgen/api_analyzer/test_types.py +++ b/tests/safeds_stubgen/api_analyzer/test_types.py @@ -29,8 +29,7 @@ def test_correct_hash() -> None: default_value="test_str", assigned_by=ParameterAssignment.POSITION_OR_NAME, docstring=ParameterDocstring("'hashvalue'", "r", "r"), - type=NamedType("str"), - is_type_inferred=False, + type=NamedType(name="str"), ) assert hash(parameter) == hash(deepcopy(parameter)) enum_values = frozenset({"a", "b", "c"}) @@ -55,7 +54,6 @@ def test_correct_hash() -> None: min_inclusive=True, max_inclusive=True, ), - is_type_inferred=False, is_public=True, is_static=True, docstring=AttributeDocstring(), From 77c4be891eb793474fb89e978f37aa8e5483d8a5 Mon Sep 17 00:00:00 2001 From: Arsam Date: Tue, 5 Dec 2023 16:36:43 +0100 Subject: [PATCH 100/109] LiteralTypes are joined for stubs if a union has multiple literal types. --- .../api_analyzer/_mypy_helpers.py | 2 +- src/safeds_stubgen/api_analyzer/_types.py | 8 +- .../stubs_generator/_generate_stubs.py | 39 +++++- .../attribute_module.py | 2 + .../__snapshots__/test__get_api.ambr | 118 ++++++++++++++++-- .../safeds_stubgen/api_analyzer/test_types.py | 12 +- .../__snapshots__/test_generate_stubs.ambr | 4 + 7 files changed, 161 insertions(+), 24 deletions(-) diff --git a/src/safeds_stubgen/api_analyzer/_mypy_helpers.py b/src/safeds_stubgen/api_analyzer/_mypy_helpers.py index 9b3ab1fd..9889f1c1 100644 --- a/src/safeds_stubgen/api_analyzer/_mypy_helpers.py +++ b/src/safeds_stubgen/api_analyzer/_mypy_helpers.py @@ -76,7 +76,7 @@ def mypy_type_to_abstract_type( elif isinstance(mypy_type, mp_types.NoneType): return sds_types.NamedType(name="None", qname="builtins.None") elif isinstance(mypy_type, mp_types.LiteralType): - return sds_types.LiteralType(literal=mypy_type.value) + return sds_types.LiteralType(literals=[mypy_type.value]) elif isinstance(mypy_type, mp_types.UnboundType): if mypy_type.name in {"list", "set"}: return { diff --git a/src/safeds_stubgen/api_analyzer/_types.py b/src/safeds_stubgen/api_analyzer/_types.py index 43406c1a..0d19770f 100644 --- a/src/safeds_stubgen/api_analyzer/_types.py +++ b/src/safeds_stubgen/api_analyzer/_types.py @@ -337,17 +337,17 @@ def __hash__(self) -> int: @dataclass(frozen=True) class LiteralType(AbstractType): - literal: str | int | float | bool + literals: list[str | int | float | bool] @classmethod def from_dict(cls, d: dict[str, Any]) -> LiteralType: - return LiteralType(d["literal"]) + return LiteralType(d["literals"]) def to_dict(self) -> dict[str, Any]: - return {"kind": self.__class__.__name__, "literal": self.literal} + return {"kind": self.__class__.__name__, "literals": [literal for literal in self.literals]} def __hash__(self) -> int: - return hash(frozenset([self.literal])) + return hash(frozenset(self.literals)) @dataclass(frozen=True) diff --git a/src/safeds_stubgen/stubs_generator/_generate_stubs.py b/src/safeds_stubgen/stubs_generator/_generate_stubs.py index d86e1626..39eca0a9 100644 --- a/src/safeds_stubgen/stubs_generator/_generate_stubs.py +++ b/src/safeds_stubgen/stubs_generator/_generate_stubs.py @@ -569,8 +569,32 @@ def _create_type_string(self, type_data: dict | None) -> str: return f"{name}<{', '.join(types)}>" return f"{name}" elif kind == "UnionType": - # Union items have to be unique. 'types' has to be a sorted list, since otherwise the snapshot tests would - # fail b/c element order in sets is non-deterministic. + # In Mypy LiteralTypes are getting seperated into unions of LiteralTypes, + # and we have to join them for the stubs. + literal_data = [] + other_type_data = [] + for type_information in type_data["types"]: + if type_information["kind"] == "LiteralType": + literal_data.append(type_information) + else: + other_type_data.append(type_information) + + if len(literal_data) >= 2: + all_literals = [ + literal_type + for literal in literal_data + for literal_type in literal["literals"] + ] + + # We overwrite the old types of the union with the joined literal types + type_data["types"] = other_type_data + type_data["types"].append({ + "kind": "LiteralType", + "literals": all_literals, + }) + + # Union items have to be unique, therefore we use sets. But the types set has to be a sorted list, since + # otherwise the snapshot tests would fail b/c element order in sets is non-deterministic. types = list({self._create_type_string(type_) for type_ in type_data["types"]}) types.sort() @@ -596,10 +620,13 @@ def _create_type_string(self, type_data: dict | None) -> str: value_data = self._create_type_string(type_data["value_type"]) return f"Map<{key_data}, {value_data}>" elif kind == "LiteralType": - literal_type = type_data["literal"] - if isinstance(literal_type, str): - literal_type = f'"{literal_type}"' - return f"literal<{literal_type}>" + types = [] + for literal_type in type_data["literals"]: + if isinstance(literal_type, str): + types.append(f'"{literal_type}"') + else: + types.append(f'{literal_type}') + return f"literal<{', '.join(types)}>" raise ValueError(f"Unexpected type: {kind}") # pragma: no cover diff --git a/tests/data/various_modules_package/attribute_module.py b/tests/data/various_modules_package/attribute_module.py index b6d38769..a2bd7c34 100644 --- a/tests/data/various_modules_package/attribute_module.py +++ b/tests/data/various_modules_package/attribute_module.py @@ -54,6 +54,8 @@ def some_func() -> bool: finals: Final[str, int] = "Value" final_union: Final[str | int] = "Value" literal: Literal["Some String"] + multiple_literals: Literal["Literal_1", "Literal_2", 3, True] + mixed_literal_union: Literal["L1", 2] | int | Literal[4, False] | str multi_attr_1, _multi_attr_2_private = (123456, "I am a String") multi_attr_3 = _multi_attr_4_private = ["I am some", "kind of list"] diff --git a/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr b/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr index 03e57551..37a0dd6c 100644 --- a/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr +++ b/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr @@ -490,7 +490,59 @@ 'name': 'literal', 'type': dict({ 'kind': 'LiteralType', - 'literal': 'Some String', + 'literals': list([ + 'Some String', + ]), + }), + }), + dict({ + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'various_modules_package/attribute_module/AttributesClassB/mixed_literal_union', + 'is_public': True, + 'is_static': True, + 'name': 'mixed_literal_union', + 'type': dict({ + 'kind': 'UnionType', + 'types': list([ + dict({ + 'kind': 'LiteralType', + 'literals': list([ + 'L1', + ]), + }), + dict({ + 'kind': 'LiteralType', + 'literals': list([ + 2, + ]), + }), + dict({ + 'kind': 'NamedType', + 'name': 'int', + 'qname': 'builtins.int', + }), + dict({ + 'kind': 'LiteralType', + 'literals': list([ + 4, + ]), + }), + dict({ + 'kind': 'LiteralType', + 'literals': list([ + False, + ]), + }), + dict({ + 'kind': 'NamedType', + 'name': 'str', + 'qname': 'builtins.str', + }), + ]), }), }), dict({ @@ -594,6 +646,46 @@ 'qname': 'builtins.str', }), }), + dict({ + 'docstring': dict({ + 'default_value': '', + 'description': '', + 'type': '', + }), + 'id': 'various_modules_package/attribute_module/AttributesClassB/multiple_literals', + 'is_public': True, + 'is_static': True, + 'name': 'multiple_literals', + 'type': dict({ + 'kind': 'UnionType', + 'types': list([ + dict({ + 'kind': 'LiteralType', + 'literals': list([ + 'Literal_1', + ]), + }), + dict({ + 'kind': 'LiteralType', + 'literals': list([ + 'Literal_2', + ]), + }), + dict({ + 'kind': 'LiteralType', + 'literals': list([ + 3, + ]), + }), + dict({ + 'kind': 'LiteralType', + 'literals': list([ + True, + ]), + }), + ]), + }), + }), dict({ 'docstring': dict({ 'default_value': '', @@ -2239,11 +2331,15 @@ 'types': list([ dict({ 'kind': 'LiteralType', - 'literal': 1, + 'literals': list([ + 1, + ]), }), dict({ 'kind': 'LiteralType', - 'literal': 2, + 'literals': list([ + 2, + ]), }), ]), }), @@ -2290,11 +2386,15 @@ 'types': list([ dict({ 'kind': 'LiteralType', - 'literal': 1, + 'literals': list([ + 1, + ]), }), dict({ 'kind': 'LiteralType', - 'literal': 2, + 'literals': list([ + 2, + ]), }), ]), }), @@ -3513,7 +3613,9 @@ 'name': 'literal', 'type': dict({ 'kind': 'LiteralType', - 'literal': 'Some String', + 'literals': list([ + 'Some String', + ]), }), }), dict({ @@ -4626,7 +4728,9 @@ 'name': 'result_1', 'type': dict({ 'kind': 'LiteralType', - 'literal': 'Some String', + 'literals': list([ + 'Some String', + ]), }), }), ]) diff --git a/tests/safeds_stubgen/api_analyzer/test_types.py b/tests/safeds_stubgen/api_analyzer/test_types.py index 761041f4..f0ec2524 100644 --- a/tests/safeds_stubgen/api_analyzer/test_types.py +++ b/tests/safeds_stubgen/api_analyzer/test_types.py @@ -221,20 +221,20 @@ def test_set_type() -> None: def test_literal_type() -> None: - type_ = LiteralType("Literal_1") + type_ = LiteralType(["Literal_1", 2]) type_dict = { "kind": "LiteralType", - "literal": "Literal_1", + "literals": ["Literal_1", 2], } assert AbstractType.from_dict(type_dict) == type_ assert LiteralType.from_dict(type_dict) == type_ assert type_.to_dict() == type_dict - assert LiteralType("a") == LiteralType("a") - assert hash(LiteralType("a")) == hash(LiteralType("a")) - assert LiteralType("a") != LiteralType("b") - assert hash(LiteralType("a")) != hash(LiteralType("b")) + assert LiteralType(["a"]) == LiteralType(["a"]) + assert hash(LiteralType(["a"])) == hash(LiteralType(["a"])) + assert LiteralType(["a"]) != LiteralType(["b"]) + assert hash(LiteralType(["a"])) != hash(LiteralType(["b"])) def test_final_type() -> None: diff --git a/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr b/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr index 99ccf0c2..c1decd1c 100644 --- a/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr +++ b/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr @@ -115,6 +115,10 @@ @PythonName("final_union") static attr finalUnion: union static attr `literal`: literal<"Some String"> + @PythonName("multiple_literals") + static attr multipleLiterals: literal<"Literal_1", "Literal_2", 3, True> + @PythonName("mixed_literal_union") + static attr mixedLiteralUnion: union> @PythonName("multi_attr_1") static attr multiAttr1: Int @PythonName("multi_attr_3") From 2fe4bb84dc9b8d8f3f6ee193d73b32f6d1d8285d Mon Sep 17 00:00:00 2001 From: Arsam Date: Tue, 5 Dec 2023 17:01:27 +0100 Subject: [PATCH 101/109] Added test data for codecov --- .../infer_types_module.py | 8 +++++++ .../__snapshots__/test__get_api.ambr | 21 +++++++++++++++++++ .../__snapshots__/test_generate_stubs.ambr | 6 ++++++ 3 files changed, 35 insertions(+) diff --git a/tests/data/various_modules_package/infer_types_module.py b/tests/data/various_modules_package/infer_types_module.py index ff0fe707..7e991a95 100644 --- a/tests/data/various_modules_package/infer_types_module.py +++ b/tests/data/various_modules_package/infer_types_module.py @@ -60,3 +60,11 @@ def infer_function(infer_param=1, infer_param_2: int = "Something"): return InferMe3 return int + + @staticmethod + def infer_function_2(i=2): + """Test for results withour """ + if i: + return "a" + else: + return False diff --git a/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr b/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr index 37a0dd6c..2adf675e 100644 --- a/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr +++ b/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr @@ -1590,6 +1590,26 @@ 'various_modules_package/infer_types_module/InferMyTypes/infer_function/result_3', ]), }), + dict({ + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'various_modules_package/infer_types_module/InferMyTypes/infer_function_2', + 'is_class_method': False, + 'is_property': False, + 'is_public': True, + 'is_static': True, + 'name': 'infer_function_2', + 'parameters': list([ + 'various_modules_package/infer_types_module/InferMyTypes/infer_function_2/i', + ]), + 'reexported_by': list([ + ]), + 'results': list([ + 'various_modules_package/infer_types_module/InferMyTypes/infer_function_2/result_1', + ]), + }), ]) # --- # name: test_class_methods[NumpyDocstringClass] @@ -2126,6 +2146,7 @@ 'is_public': True, 'methods': list([ 'various_modules_package/infer_types_module/InferMyTypes/infer_function', + 'various_modules_package/infer_types_module/InferMyTypes/infer_function_2', ]), 'name': 'InferMyTypes', 'reexported_by': list([ diff --git a/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr b/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr index c1decd1c..692d87c1 100644 --- a/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr +++ b/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr @@ -534,6 +534,12 @@ @PythonName("infer_param") inferParam: Int = 1, @PythonName("infer_param_2") inferParam2: Int = Something ) -> (result1: union, result2: union, result3: Float) + + @Pure + @PythonName("infer_function_2") + static fun inferFunction2( + i: Int = 2 + ) -> result1: union } ''' From 8dcb2e2363a98641cdf59e57b5f6f834c7986880 Mon Sep 17 00:00:00 2001 From: Arsam Date: Tue, 5 Dec 2023 17:02:16 +0100 Subject: [PATCH 102/109] refactoring --- src/safeds_stubgen/api_analyzer/_types.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/safeds_stubgen/api_analyzer/_types.py b/src/safeds_stubgen/api_analyzer/_types.py index 0d19770f..cc908413 100644 --- a/src/safeds_stubgen/api_analyzer/_types.py +++ b/src/safeds_stubgen/api_analyzer/_types.py @@ -344,7 +344,7 @@ def from_dict(cls, d: dict[str, Any]) -> LiteralType: return LiteralType(d["literals"]) def to_dict(self) -> dict[str, Any]: - return {"kind": self.__class__.__name__, "literals": [literal for literal in self.literals]} + return {"kind": self.__class__.__name__, "literals": self.literals} def __hash__(self) -> int: return hash(frozenset(self.literals)) From 779e87c935bb4c29cfd1d1c03980ceb73ebe7a68 Mon Sep 17 00:00:00 2001 From: megalinter-bot <129584137+megalinter-bot@users.noreply.github.com> Date: Tue, 5 Dec 2023 16:03:56 +0000 Subject: [PATCH 103/109] style: apply automated linter fixes --- src/safeds_stubgen/stubs_generator/_generate_stubs.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/safeds_stubgen/stubs_generator/_generate_stubs.py b/src/safeds_stubgen/stubs_generator/_generate_stubs.py index 39eca0a9..9acfaf0c 100644 --- a/src/safeds_stubgen/stubs_generator/_generate_stubs.py +++ b/src/safeds_stubgen/stubs_generator/_generate_stubs.py @@ -580,11 +580,7 @@ def _create_type_string(self, type_data: dict | None) -> str: other_type_data.append(type_information) if len(literal_data) >= 2: - all_literals = [ - literal_type - for literal in literal_data - for literal_type in literal["literals"] - ] + all_literals = [literal_type for literal in literal_data for literal_type in literal["literals"]] # We overwrite the old types of the union with the joined literal types type_data["types"] = other_type_data @@ -625,7 +621,7 @@ def _create_type_string(self, type_data: dict | None) -> str: if isinstance(literal_type, str): types.append(f'"{literal_type}"') else: - types.append(f'{literal_type}') + types.append(f"{literal_type}") return f"literal<{', '.join(types)}>" raise ValueError(f"Unexpected type: {kind}") # pragma: no cover From 09fb9cddd0dbfcfa6f47d0b9c5b882df84e50532 Mon Sep 17 00:00:00 2001 From: Arsam Date: Tue, 5 Dec 2023 17:05:29 +0100 Subject: [PATCH 104/109] Fixing tests --- tests/data/various_modules_package/infer_types_module.py | 2 +- .../api_analyzer/__snapshots__/test__get_api.ambr | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/data/various_modules_package/infer_types_module.py b/tests/data/various_modules_package/infer_types_module.py index 7e991a95..cfb5bf49 100644 --- a/tests/data/various_modules_package/infer_types_module.py +++ b/tests/data/various_modules_package/infer_types_module.py @@ -63,7 +63,7 @@ def infer_function(infer_param=1, infer_param_2: int = "Something"): @staticmethod def infer_function_2(i=2): - """Test for results withour """ + """Test for inferring results with just one possible result, and not a tuple of results.""" if i: return "a" else: diff --git a/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr b/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr index 2adf675e..6d599baf 100644 --- a/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr +++ b/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr @@ -1592,8 +1592,8 @@ }), dict({ 'docstring': dict({ - 'description': '', - 'full_docstring': '', + 'description': 'Test for inferring results with just one possible result, and not a tuple of results.', + 'full_docstring': 'Test for inferring results with just one possible result, and not a tuple of results.', }), 'id': 'various_modules_package/infer_types_module/InferMyTypes/infer_function_2', 'is_class_method': False, From 2df50936050dc280c4e509a320cd0c5ba8920894 Mon Sep 17 00:00:00 2001 From: Arsam Date: Wed, 6 Dec 2023 14:34:31 +0100 Subject: [PATCH 105/109] fixing a bug where None default values would not correctly be parsed, refactoring and adding more test cases --- .../api_analyzer/_ast_visitor.py | 80 +++++-------------- .../api_analyzer/_mypy_helpers.py | 67 +++++++++++++++- .../stubs_generator/_generate_stubs.py | 6 +- .../function_module.py | 21 +++++ .../infer_types_module.py | 14 ++++ .../__snapshots__/test__get_api.ambr | 64 +++++++++++++++ .../__snapshots__/test_generate_stubs.ambr | 42 ++++++++++ 7 files changed, 228 insertions(+), 66 deletions(-) diff --git a/src/safeds_stubgen/api_analyzer/_ast_visitor.py b/src/safeds_stubgen/api_analyzer/_ast_visitor.py index 333447e5..415a1998 100644 --- a/src/safeds_stubgen/api_analyzer/_ast_visitor.py +++ b/src/safeds_stubgen/api_analyzer/_ast_visitor.py @@ -31,6 +31,7 @@ get_mypyfile_definitions, has_correct_type_of_any, mypy_expression_to_sds_type, + mypy_expression_to_python_value, mypy_type_to_abstract_type, mypy_variance_parser, ) @@ -418,6 +419,7 @@ def _infer_type_from_return_stmts(func_node: mp_nodes.FuncDef) -> sds_types.Name func_defn = get_funcdef_definitions(func_node) return_stmts = find_return_stmts_recursive(func_defn) if return_stmts: + # In this case the items of the types set can only be of the class "NamedType" or "TupleType" types = { mypy_expression_to_sds_type(return_stmt.expr) for return_stmt in return_stmts @@ -628,57 +630,6 @@ def _create_attribute( # #### Parameter utilities - def _get_default_parameter_value_and_type( - self, - initializer: mp_nodes.Expression, - infer_arg_type: bool = False, - ) -> tuple[None | str | float | int | bool | type, None | sds_types.NamedType]: - # Get default value information - default_value: None | str | float | int | bool | type = None - arg_type = None - - value: Any - if hasattr(initializer, "value"): - value = initializer.value - elif isinstance(initializer, mp_nodes.NameExpr): - if initializer.name == "None": - value = None - elif initializer.name == "True": - value = True - elif initializer.name == "False": - value = False - else: - # Check if callee path is in our package and create type information - if self._check_if_qname_in_package(initializer.fullname): - default_value = initializer.name - if infer_arg_type: - arg_type = sds_types.NamedType(name=initializer.name, qname=initializer.fullname) - - return default_value, arg_type - - elif isinstance(initializer, mp_nodes.CallExpr): - # We do not support call expressions as types - return default_value, arg_type - - else: # pragma: no cover - raise ValueError("No value found for parameter") - - if type(value) in {str, bool, int, float, NoneType}: - default_value = NoneType if value is None else value - - # Infer the type, if no type hint was found - if infer_arg_type: - value_type_name = { - str: "str", - bool: "bool", - int: "int", - float: "float", - NoneType: "None", - }[type(value)] - arg_type = sds_types.NamedType(name=value_type_name, qname=f"builtins.{value_type_name}") - - return default_value, arg_type - def _parse_parameter_data(self, node: mp_nodes.FuncDef, function_id: str) -> list[Parameter]: arguments: list[Parameter] = [] @@ -712,17 +663,26 @@ def _parse_parameter_data(self, node: mp_nodes.FuncDef, function_id: str) -> lis default_is_none = False if initializer is not None: infer_arg_type = arg_type is None - default_value, inferred_arg_type = self._get_default_parameter_value_and_type( - initializer=initializer, - infer_arg_type=infer_arg_type, - ) - if default_value == NoneType: - default_is_none = True - default_value = None + if (isinstance(initializer, mp_nodes.NameExpr) and + initializer.name not in {"None", "True", "False"} and + not self._check_if_qname_in_package(initializer.fullname)): + # Ignore this case, b/c Safe-DS does not support types that aren't core classes or classes definied + # in the package we analyze with Safe-DS. + pass + elif isinstance(initializer, mp_nodes.CallExpr): + # Safe-DS does not support call expressions as types + pass + elif not isinstance( + initializer, + (mp_nodes.DictExpr, mp_nodes.TupleExpr, mp_nodes.SetExpr, mp_nodes.ListExpr) + ): + # See https://github.com/Safe-DS/Stub-Generator/issues/34#issuecomment-1819643719 + default_value = mypy_expression_to_python_value(initializer) + default_is_none = default_value is None - if infer_arg_type: - arg_type = inferred_arg_type + if infer_arg_type: + arg_type = mypy_expression_to_sds_type(initializer) # Create parameter docstring parent = self.__declaration_stack[-1] diff --git a/src/safeds_stubgen/api_analyzer/_mypy_helpers.py b/src/safeds_stubgen/api_analyzer/_mypy_helpers.py index 9889f1c1..5bc00088 100644 --- a/src/safeds_stubgen/api_analyzer/_mypy_helpers.py +++ b/src/safeds_stubgen/api_analyzer/_mypy_helpers.py @@ -184,7 +184,10 @@ def has_correct_type_of_any(type_of_any: int) -> bool: } -def mypy_expression_to_sds_type(expr: mp_nodes.Expression) -> sds_types.NamedType | sds_types.TupleType: +def mypy_expression_to_sds_type( + expr: mp_nodes.NameExpr | mp_nodes.IntExpr | mp_nodes.FloatExpr | mp_nodes.StrExpr | mp_nodes.ListExpr | + mp_nodes.SetExpr | mp_nodes.TupleExpr | mp_nodes.DictExpr +) -> sds_types.AbstractType: if isinstance(expr, mp_nodes.NameExpr): if expr.name in {"False", "True"}: return sds_types.NamedType(name="bool", qname="builtins.bool") @@ -196,7 +199,65 @@ def mypy_expression_to_sds_type(expr: mp_nodes.Expression) -> sds_types.NamedTyp return sds_types.NamedType(name="float", qname="builtins.float") elif isinstance(expr, mp_nodes.StrExpr): return sds_types.NamedType(name="str", qname="builtins.str") + elif isinstance(expr, (mp_nodes.ListExpr, mp_nodes.SetExpr)): + unsorted_types = {mypy_expression_to_sds_type(item) for item in expr.items} + types = list(unsorted_types) + types.sort() + if isinstance(expr, mp_nodes.ListExpr): + return sds_types.ListType(types=types) + elif isinstance(expr, mp_nodes.SetExpr): + return sds_types.SetType(types=types) elif isinstance(expr, mp_nodes.TupleExpr): return sds_types.TupleType(types=[mypy_expression_to_sds_type(item) for item in expr.items]) - else: # pragma: no cover - raise TypeError("Unexpected expression type for return type.") + elif isinstance(expr, mp_nodes.DictExpr): + key_items = expr.items[0] + value_items = expr.items[1] + + key_types = [mypy_expression_to_sds_type(key_item) for key_item in key_items] + value_types = [mypy_expression_to_sds_type(value_item) for value_item in value_items] + + key_type = sds_types.UnionType(types=key_types) if len(key_types) >= 2 else key_types[0] + value_type = sds_types.UnionType(types=value_types) if len(value_types) >= 2 else value_types[0] + + return sds_types.DictType(key_type=key_type, value_type=value_type) + raise TypeError("Unexpected expression type.") # pragma: no cover + + +def mypy_expression_to_python_value( + expr: mp_nodes.NameExpr | mp_nodes.IntExpr | mp_nodes.FloatExpr | mp_nodes.StrExpr | mp_nodes.ListExpr | + mp_nodes.SetExpr | mp_nodes.TupleExpr | mp_nodes.DictExpr +) -> str | None | int | float | list | set | dict | tuple: + if isinstance(expr, mp_nodes.NameExpr): + match expr.name: + case "None": + return None + case "True": + return True + case "False": + return False + case _: + return expr.name + elif isinstance(expr, (mp_nodes.IntExpr, mp_nodes.FloatExpr, mp_nodes.StrExpr)): + return expr.value + elif isinstance(expr, mp_nodes.ListExpr): + return [ + mypy_expression_to_python_value(item) + for item in expr.items + ] + elif isinstance(expr, mp_nodes.SetExpr): + return { + mypy_expression_to_python_value(item) + for item in expr.items + } + elif isinstance(expr, mp_nodes.TupleExpr): + return tuple( + mypy_expression_to_python_value(item) + for item in expr.items + ) + elif isinstance(expr, mp_nodes.DictExpr): + return { + mypy_expression_to_python_value(item[0]): mypy_expression_to_python_value(item[1]) + for item in expr.items + } + + raise TypeError("Unexpected expression type.") # pragma: no cover diff --git a/src/safeds_stubgen/stubs_generator/_generate_stubs.py b/src/safeds_stubgen/stubs_generator/_generate_stubs.py index 9acfaf0c..e856cdb3 100644 --- a/src/safeds_stubgen/stubs_generator/_generate_stubs.py +++ b/src/safeds_stubgen/stubs_generator/_generate_stubs.py @@ -389,7 +389,9 @@ def _create_parameter_string( parameter_type_data = parameter.type.to_dict() # Default value - if parameter.is_optional: + if parameter.is_optional and param_default_value is None: + param_value = " = null" + elif parameter.is_optional: if isinstance(param_default_value, str): if parameter_type_data["kind"] == "NamedType" and parameter_type_data["name"] != "str": default_value = f"{param_default_value}" @@ -403,8 +405,6 @@ def _create_parameter_string( else: default_value = f"{param_default_value}" param_value = f" = {default_value}" - elif parameter.is_optional and param_default_value is None: - param_value = " = null" # Mypy assignes *args parameters the tuple type, which is not supported in Safe-DS. Therefor we # overwrite it and set the type to a list. diff --git a/tests/data/various_modules_package/function_module.py b/tests/data/various_modules_package/function_module.py index 361e2734..0a1df3c7 100644 --- a/tests/data/various_modules_package/function_module.py +++ b/tests/data/various_modules_package/function_module.py @@ -57,6 +57,27 @@ def params( ): ... +def params_with_default_value( + integer: int = 3, + boolean: bool = True, + float_: float = 1.2, + none: None = None, + string: str = "Some String", + obj: FunctionModuleClassA = FunctionModuleClassA(), + callexpr: FunctionModuleClassA() = FunctionModuleClassA(), + union: int | bool = 2, + union_with_none_1: int | None = 2, + union_with_none_2: None | int = 3, + list_: list[int] = [1, 2, 3], + dictionary: dict[str, int | float] = {"key": 1, "key2": 1.2}, + set_: set[str] = {"a", "b"}, + optional: Optional[int] = None, + tuple_: tuple[int, str, bool] = (1, "2", True), + literal: Literal["Some String"] = "Some String", + any_: Any = False +): ... + + def illegal_params( lst: list[int, str], lst_2: list[int, str, int], diff --git a/tests/data/various_modules_package/infer_types_module.py b/tests/data/various_modules_package/infer_types_module.py index cfb5bf49..c6a34d96 100644 --- a/tests/data/various_modules_package/infer_types_module.py +++ b/tests/data/various_modules_package/infer_types_module.py @@ -21,6 +21,20 @@ class InferMyTypes: def __init__(self, init_param=1): self.init_infer = 3 + @staticmethod + def infer_param_types( + integer=3, + boolean=True, + float_=1.2, + none=None, + string="Some String", + callexpr=InferMe(), + int_list=[1, 2, 3], + dictionary={"key": 1, "key2": 1.2}, + string_set={"a", "b"}, + tuple_=(1, "2", True) + ): ... + @staticmethod def infer_function(infer_param=1, infer_param_2: int = "Something"): if infer_param_2: diff --git a/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr b/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr index 6d599baf..79aefcae 100644 --- a/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr +++ b/tests/safeds_stubgen/api_analyzer/__snapshots__/test__get_api.ambr @@ -1610,6 +1610,34 @@ 'various_modules_package/infer_types_module/InferMyTypes/infer_function_2/result_1', ]), }), + dict({ + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'various_modules_package/infer_types_module/InferMyTypes/infer_param_types', + 'is_class_method': False, + 'is_property': False, + 'is_public': True, + 'is_static': True, + 'name': 'infer_param_types', + 'parameters': list([ + 'various_modules_package/infer_types_module/InferMyTypes/infer_param_types/integer', + 'various_modules_package/infer_types_module/InferMyTypes/infer_param_types/boolean', + 'various_modules_package/infer_types_module/InferMyTypes/infer_param_types/float_', + 'various_modules_package/infer_types_module/InferMyTypes/infer_param_types/none', + 'various_modules_package/infer_types_module/InferMyTypes/infer_param_types/string', + 'various_modules_package/infer_types_module/InferMyTypes/infer_param_types/callexpr', + 'various_modules_package/infer_types_module/InferMyTypes/infer_param_types/int_list', + 'various_modules_package/infer_types_module/InferMyTypes/infer_param_types/dictionary', + 'various_modules_package/infer_types_module/InferMyTypes/infer_param_types/string_set', + 'various_modules_package/infer_types_module/InferMyTypes/infer_param_types/tuple_', + ]), + 'reexported_by': list([ + ]), + 'results': list([ + ]), + }), ]) # --- # name: test_class_methods[NumpyDocstringClass] @@ -2145,6 +2173,7 @@ 'id': 'various_modules_package/infer_types_module/InferMyTypes', 'is_public': True, 'methods': list([ + 'various_modules_package/infer_types_module/InferMyTypes/infer_param_types', 'various_modules_package/infer_types_module/InferMyTypes/infer_function', 'various_modules_package/infer_types_module/InferMyTypes/infer_function_2', ]), @@ -5630,6 +5659,41 @@ 'results': list([ ]), }), + dict({ + 'docstring': dict({ + 'description': '', + 'full_docstring': '', + }), + 'id': 'various_modules_package/function_module/params_with_default_value', + 'is_class_method': False, + 'is_property': False, + 'is_public': True, + 'is_static': False, + 'name': 'params_with_default_value', + 'parameters': list([ + 'various_modules_package/function_module/params_with_default_value/integer', + 'various_modules_package/function_module/params_with_default_value/boolean', + 'various_modules_package/function_module/params_with_default_value/float_', + 'various_modules_package/function_module/params_with_default_value/none', + 'various_modules_package/function_module/params_with_default_value/string', + 'various_modules_package/function_module/params_with_default_value/obj', + 'various_modules_package/function_module/params_with_default_value/callexpr', + 'various_modules_package/function_module/params_with_default_value/union', + 'various_modules_package/function_module/params_with_default_value/union_with_none_1', + 'various_modules_package/function_module/params_with_default_value/union_with_none_2', + 'various_modules_package/function_module/params_with_default_value/list_', + 'various_modules_package/function_module/params_with_default_value/dictionary', + 'various_modules_package/function_module/params_with_default_value/set_', + 'various_modules_package/function_module/params_with_default_value/optional', + 'various_modules_package/function_module/params_with_default_value/tuple_', + 'various_modules_package/function_module/params_with_default_value/literal', + 'various_modules_package/function_module/params_with_default_value/any_', + ]), + 'reexported_by': list([ + ]), + 'results': list([ + ]), + }), dict({ 'docstring': dict({ 'description': '', diff --git a/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr b/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr index 692d87c1..4bd5b29e 100644 --- a/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr +++ b/tests/safeds_stubgen/stubs_generator/__snapshots__/test_generate_stubs.ambr @@ -258,6 +258,31 @@ @PythonName("any_") any: Any ) + // TODO Result type information missing. + // TODO Safe-DS does not support tuple types. + // TODO Some parameter have no type information. + @Pure + @PythonName("params_with_default_value") + fun paramsWithDefaultValue( + integer: Int = 3, + boolean: Boolean = true, + @PythonName("float_") float: Float = 1.2, + none: Nothing? = null, + string: String = "Some String", + obj: FunctionModuleClassA, + callexpr, + `union`: union = 2, + @PythonName("union_with_none_1") unionWithNone1: Int? = 2, + @PythonName("union_with_none_2") unionWithNone2: Int? = 3, + @PythonName("list_") list: List, + dictionary: Map>, + @PythonName("set_") set: Set, + optional: Int? = null, + @PythonName("tuple_") tuple: Tuple, + `literal`: literal<"Some String"> = "Some String", + @PythonName("any_") any: Any = false + ) + // TODO List type has to many type arguments. // TODO Result type information missing. // TODO Safe-DS does not support tuple types. @@ -528,6 +553,23 @@ @PythonName("init_infer") attr initInfer + // TODO Result type information missing. + // TODO Some parameter have no type information. + @Pure + @PythonName("infer_param_types") + static fun inferParamTypes( + integer: Int = 3, + boolean: Boolean = true, + @PythonName("float_") float: Float = 1.2, + none: Nothing? = null, + string: String = "Some String", + callexpr, + @PythonName("int_list") intList, + dictionary, + @PythonName("string_set") stringSet, + @PythonName("tuple_") tuple + ) + @Pure @PythonName("infer_function") static fun inferFunction( From 63c7d03cf468841861124ca92983d6c6ca925b20 Mon Sep 17 00:00:00 2001 From: Arsam Date: Wed, 6 Dec 2023 14:52:10 +0100 Subject: [PATCH 106/109] codecov and linter fixes --- .../api_analyzer/_ast_visitor.py | 26 +++++--- .../api_analyzer/_mypy_helpers.py | 61 +++++++++---------- 2 files changed, 45 insertions(+), 42 deletions(-) diff --git a/src/safeds_stubgen/api_analyzer/_ast_visitor.py b/src/safeds_stubgen/api_analyzer/_ast_visitor.py index 415a1998..756cece4 100644 --- a/src/safeds_stubgen/api_analyzer/_ast_visitor.py +++ b/src/safeds_stubgen/api_analyzer/_ast_visitor.py @@ -419,12 +419,14 @@ def _infer_type_from_return_stmts(func_node: mp_nodes.FuncDef) -> sds_types.Name func_defn = get_funcdef_definitions(func_node) return_stmts = find_return_stmts_recursive(func_defn) if return_stmts: - # In this case the items of the types set can only be of the class "NamedType" or "TupleType" - types = { - mypy_expression_to_sds_type(return_stmt.expr) - for return_stmt in return_stmts - if return_stmt.expr is not None - } + # In this case the items of the types set can only be of the class "NamedType" or "TupleType" but we have to + # make a typecheck anyway for the mypy linter. + types = set() + for return_stmt in return_stmts: + if return_stmt.expr is not None: + type_ = mypy_expression_to_sds_type(return_stmt.expr) + if isinstance(type_, sds_types.NamedType | sds_types.TupleType): + types.add(type_) # We have to sort the list for the snapshot tests return_stmt_types = list(types) @@ -673,12 +675,16 @@ def _parse_parameter_data(self, node: mp_nodes.FuncDef, function_id: str) -> lis elif isinstance(initializer, mp_nodes.CallExpr): # Safe-DS does not support call expressions as types pass - elif not isinstance( - initializer, - (mp_nodes.DictExpr, mp_nodes.TupleExpr, mp_nodes.SetExpr, mp_nodes.ListExpr) + elif isinstance( + initializer, mp_nodes.IntExpr | mp_nodes.FloatExpr | mp_nodes.StrExpr | mp_nodes.NameExpr ): # See https://github.com/Safe-DS/Stub-Generator/issues/34#issuecomment-1819643719 - default_value = mypy_expression_to_python_value(initializer) + inferred_default_value = mypy_expression_to_python_value(initializer) + if isinstance(inferred_default_value, str | bool | int | float | NoneType): + default_value = inferred_default_value + else: # pragma: no cover + raise TypeError("Default value got an unsupported value.") + default_is_none = default_value is None if infer_arg_type: diff --git a/src/safeds_stubgen/api_analyzer/_mypy_helpers.py b/src/safeds_stubgen/api_analyzer/_mypy_helpers.py index 5bc00088..c1aec402 100644 --- a/src/safeds_stubgen/api_analyzer/_mypy_helpers.py +++ b/src/safeds_stubgen/api_analyzer/_mypy_helpers.py @@ -184,10 +184,7 @@ def has_correct_type_of_any(type_of_any: int) -> bool: } -def mypy_expression_to_sds_type( - expr: mp_nodes.NameExpr | mp_nodes.IntExpr | mp_nodes.FloatExpr | mp_nodes.StrExpr | mp_nodes.ListExpr | - mp_nodes.SetExpr | mp_nodes.TupleExpr | mp_nodes.DictExpr -) -> sds_types.AbstractType: +def mypy_expression_to_sds_type(expr: mp_nodes.Expression) -> sds_types.AbstractType: if isinstance(expr, mp_nodes.NameExpr): if expr.name in {"False", "True"}: return sds_types.NamedType(name="bool", qname="builtins.bool") @@ -199,7 +196,7 @@ def mypy_expression_to_sds_type( return sds_types.NamedType(name="float", qname="builtins.float") elif isinstance(expr, mp_nodes.StrExpr): return sds_types.NamedType(name="str", qname="builtins.str") - elif isinstance(expr, (mp_nodes.ListExpr, mp_nodes.SetExpr)): + elif isinstance(expr, mp_nodes.ListExpr | mp_nodes.SetExpr): unsorted_types = {mypy_expression_to_sds_type(item) for item in expr.items} types = list(unsorted_types) types.sort() @@ -213,8 +210,9 @@ def mypy_expression_to_sds_type( key_items = expr.items[0] value_items = expr.items[1] - key_types = [mypy_expression_to_sds_type(key_item) for key_item in key_items] - value_types = [mypy_expression_to_sds_type(value_item) for value_item in value_items] + key_types = [ + mypy_expression_to_sds_type(key_item) for key_item in key_items if key_item is not None] + value_types = [mypy_expression_to_sds_type(value_item) for value_item in value_items if value_item is not None] key_type = sds_types.UnionType(types=key_types) if len(key_types) >= 2 else key_types[0] value_type = sds_types.UnionType(types=value_types) if len(value_types) >= 2 else value_types[0] @@ -223,10 +221,7 @@ def mypy_expression_to_sds_type( raise TypeError("Unexpected expression type.") # pragma: no cover -def mypy_expression_to_python_value( - expr: mp_nodes.NameExpr | mp_nodes.IntExpr | mp_nodes.FloatExpr | mp_nodes.StrExpr | mp_nodes.ListExpr | - mp_nodes.SetExpr | mp_nodes.TupleExpr | mp_nodes.DictExpr -) -> str | None | int | float | list | set | dict | tuple: +def mypy_expression_to_python_value(expr: mp_nodes.Expression) -> str | None | int | float | list | set | dict | tuple: if isinstance(expr, mp_nodes.NameExpr): match expr.name: case "None": @@ -237,27 +232,29 @@ def mypy_expression_to_python_value( return False case _: return expr.name - elif isinstance(expr, (mp_nodes.IntExpr, mp_nodes.FloatExpr, mp_nodes.StrExpr)): + elif isinstance(expr, mp_nodes.IntExpr | mp_nodes.FloatExpr | mp_nodes.StrExpr): return expr.value - elif isinstance(expr, mp_nodes.ListExpr): - return [ - mypy_expression_to_python_value(item) - for item in expr.items - ] - elif isinstance(expr, mp_nodes.SetExpr): - return { - mypy_expression_to_python_value(item) - for item in expr.items - } - elif isinstance(expr, mp_nodes.TupleExpr): - return tuple( - mypy_expression_to_python_value(item) - for item in expr.items - ) - elif isinstance(expr, mp_nodes.DictExpr): - return { - mypy_expression_to_python_value(item[0]): mypy_expression_to_python_value(item[1]) - for item in expr.items - } + # # This is currently not used since Safe-DS does not support these default value types + # elif isinstance(expr, mp_nodes.ListExpr): + # return [ + # mypy_expression_to_python_value(item) + # for item in expr.items + # ] + # elif isinstance(expr, mp_nodes.SetExpr): + # return { + # mypy_expression_to_python_value(item) + # for item in expr.items + # } + # elif isinstance(expr, mp_nodes.TupleExpr): + # return tuple( + # mypy_expression_to_python_value(item) + # for item in expr.items + # ) + # elif isinstance(expr, mp_nodes.DictExpr): + # return { + # mypy_expression_to_python_value(item[0]): mypy_expression_to_python_value(item[1]) + # for item in expr.items + # if item[0] is not None and item[1] is not None + # } raise TypeError("Unexpected expression type.") # pragma: no cover From 64ad07f85d5e93029946b189cad9a0bb70ba0ce0 Mon Sep 17 00:00:00 2001 From: megalinter-bot <129584137+megalinter-bot@users.noreply.github.com> Date: Wed, 6 Dec 2023 13:53:46 +0000 Subject: [PATCH 107/109] style: apply automated linter fixes --- src/safeds_stubgen/api_analyzer/_ast_visitor.py | 14 ++++++++------ src/safeds_stubgen/api_analyzer/_mypy_helpers.py | 3 +-- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/safeds_stubgen/api_analyzer/_ast_visitor.py b/src/safeds_stubgen/api_analyzer/_ast_visitor.py index 756cece4..98ebc4cd 100644 --- a/src/safeds_stubgen/api_analyzer/_ast_visitor.py +++ b/src/safeds_stubgen/api_analyzer/_ast_visitor.py @@ -1,7 +1,7 @@ from __future__ import annotations from types import NoneType -from typing import TYPE_CHECKING, Any +from typing import TYPE_CHECKING import mypy.types as mp_types from mypy import nodes as mp_nodes @@ -30,8 +30,8 @@ get_funcdef_definitions, get_mypyfile_definitions, has_correct_type_of_any, - mypy_expression_to_sds_type, mypy_expression_to_python_value, + mypy_expression_to_sds_type, mypy_type_to_abstract_type, mypy_variance_parser, ) @@ -666,9 +666,11 @@ def _parse_parameter_data(self, node: mp_nodes.FuncDef, function_id: str) -> lis if initializer is not None: infer_arg_type = arg_type is None - if (isinstance(initializer, mp_nodes.NameExpr) and - initializer.name not in {"None", "True", "False"} and - not self._check_if_qname_in_package(initializer.fullname)): + if ( + isinstance(initializer, mp_nodes.NameExpr) + and initializer.name not in {"None", "True", "False"} + and not self._check_if_qname_in_package(initializer.fullname) + ): # Ignore this case, b/c Safe-DS does not support types that aren't core classes or classes definied # in the package we analyze with Safe-DS. pass @@ -676,7 +678,7 @@ def _parse_parameter_data(self, node: mp_nodes.FuncDef, function_id: str) -> lis # Safe-DS does not support call expressions as types pass elif isinstance( - initializer, mp_nodes.IntExpr | mp_nodes.FloatExpr | mp_nodes.StrExpr | mp_nodes.NameExpr + initializer, mp_nodes.IntExpr | mp_nodes.FloatExpr | mp_nodes.StrExpr | mp_nodes.NameExpr, ): # See https://github.com/Safe-DS/Stub-Generator/issues/34#issuecomment-1819643719 inferred_default_value = mypy_expression_to_python_value(initializer) diff --git a/src/safeds_stubgen/api_analyzer/_mypy_helpers.py b/src/safeds_stubgen/api_analyzer/_mypy_helpers.py index c1aec402..556a3092 100644 --- a/src/safeds_stubgen/api_analyzer/_mypy_helpers.py +++ b/src/safeds_stubgen/api_analyzer/_mypy_helpers.py @@ -210,8 +210,7 @@ def mypy_expression_to_sds_type(expr: mp_nodes.Expression) -> sds_types.Abstract key_items = expr.items[0] value_items = expr.items[1] - key_types = [ - mypy_expression_to_sds_type(key_item) for key_item in key_items if key_item is not None] + key_types = [mypy_expression_to_sds_type(key_item) for key_item in key_items if key_item is not None] value_types = [mypy_expression_to_sds_type(value_item) for value_item in value_items if value_item is not None] key_type = sds_types.UnionType(types=key_types) if len(key_types) >= 2 else key_types[0] From a08450de578090b97eb42cde31346d03044cbcb9 Mon Sep 17 00:00:00 2001 From: megalinter-bot <129584137+megalinter-bot@users.noreply.github.com> Date: Wed, 6 Dec 2023 13:55:23 +0000 Subject: [PATCH 108/109] style: apply automated linter fixes --- src/safeds_stubgen/api_analyzer/_ast_visitor.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/safeds_stubgen/api_analyzer/_ast_visitor.py b/src/safeds_stubgen/api_analyzer/_ast_visitor.py index 98ebc4cd..ba308cd6 100644 --- a/src/safeds_stubgen/api_analyzer/_ast_visitor.py +++ b/src/safeds_stubgen/api_analyzer/_ast_visitor.py @@ -678,7 +678,8 @@ def _parse_parameter_data(self, node: mp_nodes.FuncDef, function_id: str) -> lis # Safe-DS does not support call expressions as types pass elif isinstance( - initializer, mp_nodes.IntExpr | mp_nodes.FloatExpr | mp_nodes.StrExpr | mp_nodes.NameExpr, + initializer, + mp_nodes.IntExpr | mp_nodes.FloatExpr | mp_nodes.StrExpr | mp_nodes.NameExpr, ): # See https://github.com/Safe-DS/Stub-Generator/issues/34#issuecomment-1819643719 inferred_default_value = mypy_expression_to_python_value(initializer) From 0c26c801e58ad25ce6eeed2aa957c19d025fbfa0 Mon Sep 17 00:00:00 2001 From: Arsam Date: Wed, 6 Dec 2023 15:05:15 +0100 Subject: [PATCH 109/109] codecov --- .../api_analyzer/_mypy_helpers.py | 43 ++++++++++--------- .../stubs_generator/_generate_stubs.py | 4 +- 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/src/safeds_stubgen/api_analyzer/_mypy_helpers.py b/src/safeds_stubgen/api_analyzer/_mypy_helpers.py index c1aec402..99e3b4ba 100644 --- a/src/safeds_stubgen/api_analyzer/_mypy_helpers.py +++ b/src/safeds_stubgen/api_analyzer/_mypy_helpers.py @@ -196,28 +196,31 @@ def mypy_expression_to_sds_type(expr: mp_nodes.Expression) -> sds_types.Abstract return sds_types.NamedType(name="float", qname="builtins.float") elif isinstance(expr, mp_nodes.StrExpr): return sds_types.NamedType(name="str", qname="builtins.str") - elif isinstance(expr, mp_nodes.ListExpr | mp_nodes.SetExpr): - unsorted_types = {mypy_expression_to_sds_type(item) for item in expr.items} - types = list(unsorted_types) - types.sort() - if isinstance(expr, mp_nodes.ListExpr): - return sds_types.ListType(types=types) - elif isinstance(expr, mp_nodes.SetExpr): - return sds_types.SetType(types=types) elif isinstance(expr, mp_nodes.TupleExpr): return sds_types.TupleType(types=[mypy_expression_to_sds_type(item) for item in expr.items]) - elif isinstance(expr, mp_nodes.DictExpr): - key_items = expr.items[0] - value_items = expr.items[1] - - key_types = [ - mypy_expression_to_sds_type(key_item) for key_item in key_items if key_item is not None] - value_types = [mypy_expression_to_sds_type(value_item) for value_item in value_items if value_item is not None] - - key_type = sds_types.UnionType(types=key_types) if len(key_types) >= 2 else key_types[0] - value_type = sds_types.UnionType(types=value_types) if len(value_types) >= 2 else value_types[0] - - return sds_types.DictType(key_type=key_type, value_type=value_type) + # # This is currently not used since Safe-DS does not support these default value types + # elif isinstance(expr, mp_nodes.ListExpr | mp_nodes.SetExpr): + # unsorted_types = {mypy_expression_to_sds_type(item) for item in expr.items} + # types = list(unsorted_types) + # types.sort() + # if isinstance(expr, mp_nodes.ListExpr): + # return sds_types.ListType(types=types) + # elif isinstance(expr, mp_nodes.SetExpr): + # return sds_types.SetType(types=types) + # elif isinstance(expr, mp_nodes.DictExpr): + # key_items = expr.items[0] + # value_items = expr.items[1] + # + # key_types = [ + # mypy_expression_to_sds_type(key_item) for key_item in key_items if key_item is not None] + # value_types = [ + # mypy_expression_to_sds_type(value_item) for value_item in value_items if value_item is not None + # ] + # + # key_type = sds_types.UnionType(types=key_types) if len(key_types) >= 2 else key_types[0] + # value_type = sds_types.UnionType(types=value_types) if len(value_types) >= 2 else value_types[0] + # + # return sds_types.DictType(key_type=key_type, value_type=value_type) raise TypeError("Unexpected expression type.") # pragma: no cover diff --git a/src/safeds_stubgen/stubs_generator/_generate_stubs.py b/src/safeds_stubgen/stubs_generator/_generate_stubs.py index e856cdb3..cbf9e159 100644 --- a/src/safeds_stubgen/stubs_generator/_generate_stubs.py +++ b/src/safeds_stubgen/stubs_generator/_generate_stubs.py @@ -389,9 +389,7 @@ def _create_parameter_string( parameter_type_data = parameter.type.to_dict() # Default value - if parameter.is_optional and param_default_value is None: - param_value = " = null" - elif parameter.is_optional: + if parameter.is_optional: if isinstance(param_default_value, str): if parameter_type_data["kind"] == "NamedType" and parameter_type_data["name"] != "str": default_value = f"{param_default_value}"