Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Stubs are created for referenced declarations in other packages #70

Merged
merged 30 commits into from
Mar 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
e4c9d07
now limited stubs are created for the imported classes from other pac…
Masara Feb 28, 2024
c0e13ea
Refactoring: Removed type hints from docs
Masara Feb 29, 2024
59de157
bug fixes and added tests
Masara Feb 29, 2024
e6bed74
Imports in stubs are camel case and checked for safeds keyword
Masara Feb 29, 2024
33ab05e
linter fix
Masara Feb 29, 2024
96f759c
linter fix
Masara Feb 29, 2024
b5b8d6c
style: apply automated linter fixes
megalinter-bot Feb 29, 2024
8078d0c
style: apply automated linter fixes
megalinter-bot Feb 29, 2024
9d53610
added test case
Masara Feb 29, 2024
6c21255
Merge remote-tracking branch 'origin/66-limited-stubs-for-referenced-…
Masara Feb 29, 2024
9cf0eb0
fixed tests
Masara Feb 29, 2024
0f289fc
Merge branch 'main' into 66-limited-stubs-for-referenced-declarations
Masara Mar 1, 2024
b6950d6
fixed a bug which occurred with the main merge
Masara Mar 1, 2024
39673db
Merge branch 'main' into 66-limited-stubs-for-referenced-declarations
Masara Mar 1, 2024
0e98955
Changed the way stub params are names (param1, param2, ...) and renam…
Masara Mar 2, 2024
6d1df60
linter fix
Masara Mar 2, 2024
bea75fe
style: apply automated linter fixes
megalinter-bot Mar 2, 2024
2fdd225
style: apply automated linter fixes
megalinter-bot Mar 2, 2024
98afcc2
split the stubs_generator function into three and refactored tests
Masara Mar 2, 2024
fc95c28
Merge remote-tracking branch 'origin/66-limited-stubs-for-referenced-…
Masara Mar 2, 2024
2f45e79
style: apply automated linter fixes
megalinter-bot Mar 2, 2024
37558c1
style: apply automated linter fixes
megalinter-bot Mar 2, 2024
e048738
test fix
Masara Mar 2, 2024
e91cb44
Merge remote-tracking branch 'origin/66-limited-stubs-for-referenced-…
Masara Mar 2, 2024
454d317
Changed logic of stubs generator tests, now every file is checked
Masara Mar 2, 2024
86201e1
typo
Masara Mar 2, 2024
a91bae3
linter fixes
Masara Mar 2, 2024
08151c9
style: apply automated linter fixes
megalinter-bot Mar 2, 2024
a920657
Refactoring the _convert_name_to_convention function and adding a Nam…
Masara Mar 2, 2024
b003965
style: apply automated linter fixes
megalinter-bot Mar 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
367 changes: 225 additions & 142 deletions src/safeds_stubgen/stubs_generator/_generate_stubs.py

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions tests/data/main_package/another_path/another_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@

class AnotherClass:
pass


class yetAnotherClass:
def another_function(self) -> str: ...
5 changes: 4 additions & 1 deletion tests/data/various_modules_package/class_module.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from tests.data.main_package.another_path.another_module import yetAnotherClass


class ClassModuleEmptyClassA:
...

Expand All @@ -8,7 +11,7 @@ def __init__(self, a: int, b: ClassModuleEmptyClassA | None): ...
def f(self): ...


class ClassModuleClassC(ClassModuleEmptyClassA, ClassModuleClassB):
class ClassModuleClassC(ClassModuleEmptyClassA, ClassModuleClassB, yetAnotherClass):
attr_1: int
attr_2: int

Expand Down
70 changes: 70 additions & 0 deletions tests/safeds_stubgen/__snapshots__/test_main.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,29 @@
'type_parameters': list([
]),
}),
dict({
'attributes': list([
]),
'classes': list([
]),
'constructor': None,
'docstring': dict({
'description': '',
'full_docstring': '',
}),
'id': 'main_package/another_path/another_module/yetAnotherClass',
'is_public': True,
'methods': list([
'main_package/another_path/another_module/yetAnotherClass/another_function',
]),
'name': 'yetAnotherClass',
'reexported_by': list([
]),
'superclasses': list([
]),
'type_parameters': list([
]),
}),
dict({
'attributes': list([
'main_package/main_module/ModuleClass/attr_1',
Expand Down Expand Up @@ -307,6 +330,26 @@
'enums': list([
]),
'functions': list([
dict({
'docstring': dict({
'description': '',
'full_docstring': '',
}),
'id': 'main_package/another_path/another_module/yetAnotherClass/another_function',
'is_class_method': False,
'is_property': False,
'is_public': True,
'is_static': False,
'name': 'another_function',
'parameters': list([
'main_package/another_path/another_module/yetAnotherClass/another_function/self',
]),
'reexported_by': list([
]),
'results': list([
'main_package/another_path/another_module/yetAnotherClass/another_function/result_1',
]),
}),
dict({
'docstring': dict({
'description': '',
Expand Down Expand Up @@ -495,6 +538,7 @@
dict({
'classes': list([
'main_package/another_path/another_module/AnotherClass',
'main_package/another_path/another_module/yetAnotherClass',
]),
'docstring': '''
Another Module Docstring.
Expand Down Expand Up @@ -554,6 +598,19 @@
]),
'package': 'main_package',
'parameters': list([
dict({
'assigned_by': 'IMPLICIT',
'default_value': None,
'docstring': dict({
'default_value': '',
'description': '',
'type': '',
}),
'id': 'main_package/another_path/another_module/yetAnotherClass/another_function/self',
'is_optional': False,
'name': 'self',
'type': None,
}),
dict({
'assigned_by': 'POSITION_OR_NAME',
'default_value': None,
Expand Down Expand Up @@ -729,6 +786,19 @@
}),
]),
'results': list([
dict({
'docstring': dict({
'description': '',
'type': '',
}),
'id': 'main_package/another_path/another_module/yetAnotherClass/another_function/result_1',
'name': 'result_1',
'type': dict({
'kind': 'NamedType',
'name': 'str',
'qname': 'builtins.str',
}),
}),
dict({
'docstring': dict({
'description': '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2035,6 +2035,7 @@
'superclasses': list([
'tests.data.various_modules_package.class_module.ClassModuleEmptyClassA',
'tests.data.various_modules_package.class_module.ClassModuleClassB',
'tests.data.main_package.another_path.another_module.yetAnotherClass',
]),
'type_parameters': list([
]),
Expand Down Expand Up @@ -6431,6 +6432,10 @@
'id': 'various_modules_package/class_module',
'name': 'class_module',
'qualified_imports': list([
dict({
'alias': None,
'qualified_name': 'tests.data.main_package.another_path.another_module.yetAnotherClass',
}),
]),
'wildcard_imports': list([
]),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@PythonModule("various_modules_package.file_creation._module_3")
package variousModulesPackage.fileCreation.Module3

class Reexported()
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@PythonModule("various_modules_package.file_creation._module_6")
package variousModulesPackage.fileCreation.Module6

// TODO Result type information missing.
@Pure
@PythonName("public_reexported")
fun publicReexported()
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@PythonModule("various_modules_package._reexport_module_1")
package variousModulesPackage.ReexportModule1

class ReexportClass()
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@PythonModule("various_modules_package._reexport_module_2")
package variousModulesPackage.ReexportModule2

// TODO Result type information missing.
@Pure
@PythonName("reexported_function_2")
fun reexportedFunction2()

class AnotherReexportClass()
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@PythonModule("various_modules_package._reexport_module_4")
package variousModulesPackage.ReexportModule4

class FourthReexportClass()
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@PythonModule("various_modules_package.another_path.another_module")
package variousModulesPackage.anotherPath.anotherModule

class AnotherClass()
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
@PythonModule("various_modules_package.attribute_module")
package variousModulesPackage.attributeModule

from tests.data.mainPackage.anotherPath.anotherModule import AnotherClass

class AttributesClassA()

class AttributesClassB() {
Expand Down Expand Up @@ -92,7 +94,7 @@ class AttributesClassB() {
@PythonName("attr_type_from_outside_package")
static attr attrTypeFromOutsidePackage: AnotherClass
@PythonName("attr_default_value_from_outside_package")
static attr attrDefaultValueFromOutsidePackage: () -> a: AnotherClass
static attr attrDefaultValueFromOutsidePackage: () -> param1: AnotherClass
@PythonName("init_attr")
attr initAttr: Boolean

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
@PythonModule("various_modules_package.class_module")
package variousModulesPackage.classModule

from tests.data.mainPackage.anotherPath.anotherModule import yetAnotherClass

class ClassModuleEmptyClassA()

class ClassModuleClassB(
Expand All @@ -13,7 +15,7 @@ class ClassModuleClassB(
}

// TODO Safe-DS does not support multiple inheritance.
class ClassModuleClassC() sub ClassModuleEmptyClassA, ClassModuleClassB {
class ClassModuleClassC() sub ClassModuleEmptyClassA, ClassModuleClassB, yetAnotherClass {
@PythonName("attr_1")
static attr attr1: Int
@PythonName("attr_2")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
@PythonModule("various_modules_package.docstring_module")
package variousModulesPackage.docstringModule

class EpydocDocstringClass(
@PythonName("param_1") param1: String
) {
@PythonName("attr_1")
static attr attr1: String

@Pure
@PythonName("epydoc_docstring_func")
fun epydocDocstringFunc(
x: Int,
y: Int
) -> result1: Boolean
}

class RestDocstringClass(
@PythonName("param_1") param1: String
) {
@PythonName("attr_1")
static attr attr1: String

@Pure
@PythonName("rest_docstring_func")
fun restDocstringFunc(
x: Int,
y: Int
) -> result1: Boolean
}

class NumpyDocstringClass(
@PythonName("param_1") param1: String
) {
@PythonName("attr_1")
static attr attr1: String

@Pure
@PythonName("numpy_docstring_func")
fun numpyDocstringFunc(
x: Int,
y: Int
) -> result1: Boolean
}

class GoogleDocstringClass(
@PythonName("param_1") param1: String
) {
@PythonName("attr_1")
static attr attr1: String

@Pure
@PythonName("google_docstring_func")
fun googleDocstringFunc(
x: Int,
y: Int
) -> result1: Boolean
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
@PythonModule("various_modules_package.function_module")
package variousModulesPackage.functionModule

from tests.data.mainPackage.anotherPath.anotherModule import AnotherClass

// TODO Result type information missing.
@Pure
@PythonName("public_no_params_no_result")
Expand Down Expand Up @@ -230,8 +232,8 @@ fun anyResults() -> result1: Any
@Pure
@PythonName("callable_type")
fun callableType(
param: (a: String) -> (b: Int, c: String)
) -> result1: (a: Int, b: Int) -> c: Int
param: (param1: String) -> (param2: Int, param3: String)
) -> result1: (param1: Int, param2: Int) -> param3: Int

// TODO Result type information missing.
// TODO Some parameter have no type information.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class InferMyTypes(
@PythonName("infer_none")
static attr inferNone: Nothing?
@PythonName("infer_obj")
static attr inferObj: () -> a: InferMe
static attr inferObj: () -> param1: InferMe
// TODO Attribute has no type information.
@PythonName("init_infer")
attr initInfer
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@PythonModule("various_modules_package.file_creation.module_1")
package variousModulesPackage.fileCreation.module1

class C()
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@PythonModule("various_modules_package.file_creation.package_1.module_5")
package variousModulesPackage.fileCreation.package1.module5

class C()
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@PythonModule("tests.data.main_package.another_path.another_module")
package tests.data.mainPackage.anotherPath.anotherModule

class AnotherClass

@PythonName("yetAnotherClass")
class YetAnotherClass
Loading