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

fix: Stub generation testing and fixing of miscellaneous bugs #76

Merged
merged 84 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
3250351
Added tests for generating stubs for public methods from inherited in…
Masara Feb 28, 2024
90f2d93
Added stubs generation for public methods of inherited intern classes
Masara Feb 28, 2024
f2ddff8
style: apply automated linter fixes
megalinter-bot Feb 28, 2024
efd55c6
style: apply automated linter fixes
megalinter-bot Feb 28, 2024
0156096
Merge branch 'main' into 64-stubs-for-public-methods
Masara Mar 1, 2024
c97c653
Merge branch 'main' into 64-stubs-for-public-methods
Masara Mar 1, 2024
1520720
Refactoring
Masara Mar 2, 2024
dfab52a
Merge branch 'main' into 64-stubs-for-public-methods
Masara Mar 3, 2024
dd4bc25
Test snapshot update after merge with main
Masara Mar 3, 2024
52c6288
Added an is_internal function, refactoring how internal superclasses …
Masara Mar 3, 2024
bc9309c
Internal superclasses are now also searched transitively for methods
Masara Mar 3, 2024
a4f61e8
Changed and fixed how mypy finds the python files of the package we w…
Masara Mar 3, 2024
b4db31c
Changed how imports are found in modules, previously, imports couldn'…
Masara Mar 3, 2024
48b13da
upped the code coverage
Masara Mar 3, 2024
54b7076
Added generated stub files from the "Library" project
Masara Mar 3, 2024
3c85366
Changed the way "package" information and imports are generated for s…
Masara Mar 4, 2024
29f7c99
Removed a redundant directory creation
Masara Mar 4, 2024
9498723
Updated Library-Stubs data
Masara Mar 4, 2024
217ef56
Updated Library-Stubs data - Added too much data by mistake in the la…
Masara Mar 4, 2024
97e05b7
fixed file creation test
Masara Mar 4, 2024
9f4405c
changed the get_api test for the modules, it now checks all existing …
Masara Mar 4, 2024
9d428e0
test fix for Python3.11
Masara Mar 4, 2024
83ebdcf
small change which could fix ubuntu tests (?)
Masara Mar 4, 2024
637450b
linter fixes
Masara Mar 4, 2024
71a311a
linter fixes
Masara Mar 4, 2024
8f2c6ac
style: apply automated linter fixes
megalinter-bot Mar 4, 2024
646a110
style: apply automated linter fixes
megalinter-bot Mar 4, 2024
4f0adce
Fixing a bug where stubs with "Nothing??" as type would be generated
Masara Mar 4, 2024
b943748
Merge remote-tracking branch 'origin/stubs-testing-and-fixing' into s…
Masara Mar 4, 2024
5d16778
Library-Stubs update
Masara Mar 4, 2024
547952c
added test data for code coverage
Masara Mar 4, 2024
24052c3
changed test data for code coverage
Masara Mar 4, 2024
ccf5a12
Intern classes won't be displayed as superclasses in stub files
Masara Mar 4, 2024
083dce7
style: apply automated linter fixes
megalinter-bot Mar 4, 2024
2c626eb
style: apply automated linter fixes
megalinter-bot Mar 4, 2024
1fa3b5f
Merge branch '64-stubs-for-public-methods' into stubs-testing-and-fixing
Masara Mar 4, 2024
0e80f83
Merge branch 'main' into stubs-testing-and-fixing
Masara Mar 4, 2024
8e4eec6
removed Boolean, Nothing and String from the sds keyword function; No…
Masara Mar 5, 2024
6086367
Removed superclasses for stubs if the superclasses inherit directly o…
Masara Mar 5, 2024
9f29421
style: apply automated linter fixes
megalinter-bot Mar 5, 2024
35ad11c
updated Library Stub files
Masara Mar 5, 2024
ba6a7ce
style: apply automated linter fixes
megalinter-bot Mar 5, 2024
78bc870
(WIP) creating stubs for reexported modules was bugged until now, now…
Masara Mar 5, 2024
7a0aa19
Merge remote-tracking branch 'origin/stubs-testing-and-fixing' into s…
Masara Mar 5, 2024
d81c548
refactoring and linter fixes
Masara Mar 5, 2024
a47091c
style: apply automated linter fixes
megalinter-bot Mar 5, 2024
b4c4ff1
style: apply automated linter fixes
megalinter-bot Mar 5, 2024
a83dcff
Added more test cases for reexporting classes and functions
Masara Mar 5, 2024
9f4a9c0
Merge remote-tracking branch 'origin/stubs-testing-and-fixing' into s…
Masara Mar 5, 2024
73fe169
Added more test cases for reexporting classes and functions
Masara Mar 5, 2024
fa21477
Omit classes in Safe-DS that import directly or transitively from Exc…
Masara Mar 6, 2024
df007b0
Added test cases for Mapping
Masara Mar 6, 2024
6a3d430
Mapping, Sequence and Collection types for classes can now be correct…
Masara Mar 6, 2024
30d16a5
Refactoring
Masara Mar 6, 2024
28da90b
Further expanding the "reexported" checks and adding test cases
Masara Mar 7, 2024
2aec8fb
style: apply automated linter fixes
megalinter-bot Mar 7, 2024
249d42d
Refactoring
Masara Mar 7, 2024
15a63c5
Merge remote-tracking branch 'origin/stubs-testing-and-fixing' into s…
Masara Mar 7, 2024
9cef7c6
style: apply automated linter fixes
megalinter-bot Mar 7, 2024
021e84e
Refactoring
Masara Mar 7, 2024
c91bd73
Reexports from other packages are now recognized as well for the stub…
Masara Mar 7, 2024
7ef3e1e
Refactoring
Masara Mar 7, 2024
b4986e1
linter fix
Masara Mar 7, 2024
ca53f19
style: apply automated linter fixes
megalinter-bot Mar 7, 2024
b119ef5
removed todos
Masara Mar 7, 2024
a28f1e1
Fixed package names: Now the shortest public "reexport" is being used…
Masara Mar 7, 2024
28569c2
style: apply automated linter fixes
megalinter-bot Mar 7, 2024
e5e8355
Fixed a bug with in the ast walker and updated Library-Stub files
Masara Mar 7, 2024
d150697
style: apply automated linter fixes
megalinter-bot Mar 7, 2024
0b66c06
code cov fix
Masara Mar 7, 2024
562a2f4
Merge remote-tracking branch 'origin/stubs-testing-and-fixing' into s…
Masara Mar 7, 2024
88911c0
Fixed a bug where the is_public check for classes, attr and functions…
Masara Mar 7, 2024
9ca0282
style: apply automated linter fixes
megalinter-bot Mar 7, 2024
ce2108a
Added test data for code cov
Masara Mar 8, 2024
3728c01
Merge remote-tracking branch 'origin/stubs-testing-and-fixing' into s…
Masara Mar 8, 2024
815b228
Fixed package names (part 2): Now the shortest public "reexport" is b…
Masara Mar 11, 2024
da9f97f
style: apply automated linter fixes
megalinter-bot Mar 11, 2024
d934d35
Refactoring and adding test data
Masara Mar 11, 2024
779a8f3
Merge remote-tracking branch 'origin/stubs-testing-and-fixing' into s…
Masara Mar 11, 2024
ae73a21
Inferring types (attributes): Callable classes are removed
Masara Mar 11, 2024
f123596
style: apply automated linter fixes
megalinter-bot Mar 11, 2024
5397183
Fixed package names (part 3): fixed paths, which where missing elemen…
Masara Mar 12, 2024
32a2d16
Merge remote-tracking branch 'origin/stubs-testing-and-fixing' into s…
Masara Mar 12, 2024
faadddd
chore: remove library stubs
lars-reimann Mar 12, 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
77 changes: 53 additions & 24 deletions src/safeds_stubgen/stubs_generator/_generate_stubs.py
Original file line number Diff line number Diff line change
Expand Up @@ -871,36 +871,65 @@

def _get_shortest_public_reexport(self) -> str:
module_qname = self.module.id.replace("/", ".")

module_name = self.module.name
reexports = self.api.reexport_map
if self.module.name in reexports:
reexport_sources = reexports[self.module.name]
elif module_qname in reexports:
reexport_sources = reexports[module_qname]
else:
return module_qname

same_package_modules = []
other_package_modules = []
for reexport_source in reexport_sources:
if self.module.id.startswith(reexport_source.id):
same_package_modules.append(reexport_source)
else:
other_package_modules.append(reexport_source)
def _module_name_check(name: str, string: str) -> bool:
return (
string == name or
(f".{name}" in string and (string.endswith(f".{name}") or f"{name}." in string)) or
(f"{name}." in string and (string.startswith(f"{name}.") or f".{name}" in string))
)

keys = [reexport_key for reexport_key in reexports if _module_name_check(module_name, reexport_key)]

module_ids = set()
for key in keys:
for module in reexports[key]:
added_module_id = False

for qualified_import in module.qualified_imports:
if _module_name_check(module_name, qualified_import.qualified_name):
module_ids.add(module.id)
added_module_id = True
break

modules_to_check = same_package_modules if same_package_modules else other_package_modules
if added_module_id:
continue

for wildcard_import in module.wildcard_imports:
if _module_name_check(module_name, wildcard_import.module_name):
module_ids.add(module.id)
break

# Adjust all ids
package = self.api.package
fixed_module_ids_parts = [
[package, *module_id.split(f"{package}/", maxsplit=1)[-1].split("/")]
if not module_id.endswith(package) else [package]
for module_id in module_ids
]

shortest_id = None
for fixed_module_id_parts in fixed_module_ids_parts:
if shortest_id is None or len(fixed_module_id_parts) < len(shortest_id):
internal_part = False
for part in fixed_module_id_parts:
if is_internal(part):
internal_part = True
break

Check warning on line 920 in src/safeds_stubgen/stubs_generator/_generate_stubs.py

View check run for this annotation

Codecov / codecov/patch

src/safeds_stubgen/stubs_generator/_generate_stubs.py#L919-L920

Added lines #L919 - L920 were not covered by tests

shortest_module_path: Module | None = None
for source_module in modules_to_check:
if shortest_module_path is None or len(shortest_module_path.id.split("/")) > len(
source_module.id.split("/"),
):
shortest_module_path = source_module
if internal_part:
continue

Check warning on line 923 in src/safeds_stubgen/stubs_generator/_generate_stubs.py

View check run for this annotation

Codecov / codecov/patch

src/safeds_stubgen/stubs_generator/_generate_stubs.py#L923

Added line #L923 was not covered by tests

shortest_id = fixed_module_id_parts

if shortest_module_path is None: # pragma: no cover
raise ValueError
if len(shortest_id) == 1:
break

return shortest_module_path.id.replace("/", ".")
if shortest_id is None:
return module_qname
return ".".join(shortest_id)


def _callable_type_name_generator() -> Generator:
Expand Down
2 changes: 2 additions & 0 deletions tests/data/various_modules_package/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from ._reexport_module_4 import _two_times_reexported
from ._reexport_module_4 import _two_times_reexported as two_times_reexported
from .enum_module import _ReexportedEmptyEnum
from file_creation._module_3 import Reexported

__all__ = [
"reex_1",
Expand All @@ -20,4 +21,5 @@
"two_times_reexported",
"FourthReexportClass",
"_ReexportedEmptyEnum",
"Reexported",
]
Original file line number Diff line number Diff line change
Expand Up @@ -6512,6 +6512,10 @@
'alias': None,
'qualified_name': 'enum_module._ReexportedEmptyEnum',
}),
dict({
'alias': None,
'qualified_name': 'file_creation._module_3.Reexported',
}),
])
# ---
# name: test_imports[__init__ (wildcard_imports)]
Expand Down Expand Up @@ -6621,6 +6625,10 @@
'alias': None,
'qualified_name': 'enum_module._ReexportedEmptyEnum',
}),
dict({
'alias': None,
'qualified_name': 'file_creation._module_3.Reexported',
}),
]),
'wildcard_imports': list([
dict({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@PythonModule("tests.data.various_modules_package.file_creation._module_3")
package tests.data.variousModulesPackage.fileCreation.Module3
@PythonModule("various_modules_package")
package variousModulesPackage

Masara marked this conversation as resolved.
Show resolved Hide resolved
class Reexported()
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@PythonModule("tests.data.various_modules_package.file_creation._module_6")
package tests.data.variousModulesPackage.fileCreation.Module6
@PythonModule("various_modules_package.file_creation")
package variousModulesPackage.fileCreation

// TODO Result type information missing.
@Pure
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@PythonModule("tests.data.various_modules_package")
package tests.data.variousModulesPackage
@PythonModule("various_modules_package")
package variousModulesPackage

// TODO Result type information missing.
@Pure
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@PythonModule("tests.data.various_modules_package._reexport_module_2")
package tests.data.variousModulesPackage.ReexportModule2
@PythonModule("various_modules_package")
package variousModulesPackage

// TODO Result type information missing.
@Pure
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@PythonModule("tests.data.various_modules_package")
package tests.data.variousModulesPackage
@PythonModule("various_modules_package")
package variousModulesPackage

// TODO Result type information missing.
@Pure
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@PythonModule("tests.data.various_modules_package._reexport_module_4")
package tests.data.variousModulesPackage.ReexportModule4
@PythonModule("various_modules_package")
package variousModulesPackage

// TODO Result type information missing.
@Pure
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@PythonModule("tests.data.various_modules_package.file_creation")
package tests.data.variousModulesPackage.fileCreation
@PythonModule("various_modules_package.file_creation")
package variousModulesPackage.fileCreation

@Pure
@PythonName("reexported_in_another_package_function")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@PythonModule("tests.data.various_modules_package.another_path._reexported_from_another_package_2")
package tests.data.variousModulesPackage.anotherPath.ReexportedFromAnotherPackage2
@PythonModule("various_modules_package.file_creation")
package variousModulesPackage.fileCreation

@Pure
@PythonName("reexported_in_another_package_function2")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@PythonModule("tests.data.various_modules_package.file_creation")
package tests.data.variousModulesPackage.fileCreation
@PythonModule("various_modules_package.file_creation")
package variousModulesPackage.fileCreation

@Pure
@PythonName("reexported_in_another_package_function3")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@PythonModule("tests.data.various_modules_package.enum_module")
package tests.data.variousModulesPackage.enumModule
@PythonModule("various_modules_package")
package variousModulesPackage

enum _ReexportedEmptyEnum

Expand Down