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: Fixing various bugs which appear with different libraries #168

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
159f5a2
Various fixes, new tests and replacements of raises with logger warnings
Masara Aug 16, 2024
56c0a39
Fixing several bugs where return variables cant be parsed correctly
Masara Aug 17, 2024
f53d93b
Removed unused EnumType and BoundaryType; Added short Docstring descr…
Masara Aug 18, 2024
84c7237
Fixing a few bugs and replacing some raises with warnings
Masara Aug 18, 2024
091868b
added analysis of "not" statements as bool type
Masara Aug 21, 2024
32036c7
fixed a bug where, if stub files already existed, content that was al…
Masara Aug 21, 2024
16a589c
fixed a bug where some functions would not have "None" types even tho…
Masara Aug 23, 2024
702344f
Added TypeAliasType parsing for parameters
Masara Aug 25, 2024
b384f99
fixed a bug for type parsing where subclasses of aliases couldn't be …
Masara Aug 25, 2024
fe3ef13
fixed a bug where some class attributes defined in the __init__ funct…
Masara Aug 25, 2024
3921da7
fixed a bug where some class attributes would wrongly be labeled as T…
Masara Aug 25, 2024
fc46724
Added handling for results with operations (boolean results) and fixe…
Masara Aug 25, 2024
2fd3e5d
fixed a bug where type names would not be checked for naming conventi…
Masara Aug 26, 2024
54ae851
fixed the way reexported paths are searched and found; multiple text …
Masara Aug 27, 2024
881a1b6
reversed the change concerning None from commit #16a589c1
Masara Aug 27, 2024
ad2a11e
fixed a bug for parsing parameter types; replacing some logging.warni…
Masara Aug 27, 2024
9ba8221
Merge branch 'main' into various_fixes
Masara Oct 3, 2024
ee06dc2
Removed unused code
Masara Nov 10, 2024
f37d7de
style: apply automated linter fixes
megalinter-bot Nov 10, 2024
61af573
build(deps-dev): bump semantic-release from 24.1.2 to 24.2.0 (#184)
dependabot[bot] Nov 1, 2024
3afb84e
build(deps-dev): bump pytest-cov from 5.0.0 to 6.0.0 (#183)
dependabot[bot] Nov 1, 2024
e6e8c6f
build(deps-dev): bump mkdocs-material from 9.5.39 to 9.5.43 (#182)
dependabot[bot] Nov 1, 2024
c973b8c
build(deps-dev): bump syrupy from 4.7.1 to 4.7.2 (#179)
dependabot[bot] Nov 1, 2024
736c0dd
build(deps): bump mypy from 1.11.2 to 1.13.0 (#181)
dependabot[bot] Nov 1, 2024
fbe2a20
Merge branch 'main' into various_fixes
Masara Nov 10, 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
65 changes: 65 additions & 0 deletions src/safeds_stubgen/_helpers.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,67 @@
from __future__ import annotations

from typing import TYPE_CHECKING

if TYPE_CHECKING:
from safeds_stubgen.api_analyzer import Module


def is_internal(name: str) -> bool:
"""Check if a function / method / class name indicate if it's internal."""
return name.startswith("_")


def get_reexported_by(qname: str, reexport_map: dict[str, set[Module]]) -> list[Module]:
"""Get all __init__ modules where a given function / class / enum was reexported."""
path = qname.split(".")

# Check if there is a reexport entry for each item in the path to the current module
reexported_by = set()
for i in range(len(path)):
reexport_name_forward = ".".join(path[: i + 1])
# We ignore i = 0, b/c some inner package could import the whole upper package
if i != 0 and reexport_name_forward in reexport_map:
for module in reexport_map[reexport_name_forward]:

# Check if the module or the class/function itself are beeing reexported. If not, it means a
# subpackage is beeing reexported.
last_forward_part = reexport_name_forward.split(".")[-1]
part_index = path.index(last_forward_part) + 1
if len(path) - part_index > 1:
continue

reexported_by.add(module)

reexport_name_backward = ".".join(path[-i - 1 :])
if reexport_name_backward in reexport_map:
for module in reexport_map[reexport_name_backward]:

# Check if the module or the class/function itself are beeing reexported. If not, it means a
# subpackage is beeing reexported.
if module.name == "__init__" and i < len(path) - 1:
zipped = list(zip(module.id.split("/"), path, strict=False))
# Check if there is a part of the paths that differs
if not all(m == p for m, p in zipped):
continue

reexported_by.add(module)

reexport_name_backward_whitelist = f"{'.'.join(path[-2 - i:-1])}.*"
if reexport_name_backward_whitelist in reexport_map:
for module in reexport_map[reexport_name_backward_whitelist]:

if len(path) > i + 2:
# Check if the found module actually references our object. E.g.: It could be the case that the
# file at `path/to/__init__.py` has `from .api import *` and we find this entry, even though we
# are searching for reexports of a class/function in the `path\from\api.py` file.
is_wrong_module_path = False
for j, module_part in enumerate(module.id.split("/")):
if module_part != path[j]:
is_wrong_module_path = True
break
if is_wrong_module_path:
continue

reexported_by.add(module)

return list(reexported_by)
4 changes: 0 additions & 4 deletions src/safeds_stubgen/api_analyzer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@
from ._type_source_enums import TypeSourcePreference, TypeSourceWarning
from ._types import (
AbstractType,
BoundaryType,
CallableType,
DictType,
EnumType,
FinalType,
ListType,
LiteralType,
Expand All @@ -44,14 +42,12 @@
"AbstractType",
"API",
"Attribute",
"BoundaryType",
"CallableType",
"Class",
"DictType",
"distribution",
"distribution_version",
"Enum",
"EnumType",
"FinalType",
"Function",
"get_api",
Expand Down
Loading