Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
253 commits
Select commit Hold shift + click to select a range
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
83dc721
updated deprecated griffe imports
Muellersen Sep 17, 2024
4baeef2
moved extractor of boundaries and enums from library analyzer to stub…
Muellersen Sep 19, 2024
407fa6d
style: apply code conventions of stubs generator project
Muellersen Sep 19, 2024
eb29f1a
feat: implement type_string, update tests
Muellersen Sep 21, 2024
f1548f1
test: parameterized test_main
Muellersen Sep 22, 2024
f2ca142
feat: added boundaries and valid_values
Muellersen Sep 30, 2024
c506f46
test: added new test main testcase
Muellersen Sep 30, 2024
a99a40f
feat: added valid values and boundaries to stub generator
Muellersen Oct 1, 2024
9346071
feat: added purity analyzer from library analyzer
Muellersen Oct 1, 2024
a2f8bfe
test: moved purity test from library analizer to stub generator
Muellersen Oct 3, 2024
b8567a3
feat: implemented correct syntax of boundary and enum for stub genera…
Muellersen Oct 3, 2024
9ba8221
Merge branch 'main' into various_fixes
Masara Oct 3, 2024
a6e640b
Big performance fix for the docstring parser by creating an indexer f…
Masara Oct 3, 2024
446fbcf
chore: save state
Muellersen Oct 6, 2024
a1e7156
feat: purity analysis runs now while generating stubs
Muellersen Oct 6, 2024
eb4fa7d
updated deprecated griffe imports
Muellersen Sep 17, 2024
8206cef
moved extractor of boundaries and enums from library analyzer to stub…
Muellersen Sep 19, 2024
95ff95b
style: apply code conventions of stubs generator project
Muellersen Sep 19, 2024
e58dd2d
feat: implement type_string, update tests
Muellersen Sep 21, 2024
6a8a04b
test: parameterized test_main
Muellersen Sep 22, 2024
ee4c77b
feat: added boundaries and valid_values
Muellersen Sep 30, 2024
878be93
test: added new test main testcase
Muellersen Sep 30, 2024
00883a2
feat: added valid values and boundaries to stub generator
Muellersen Oct 1, 2024
cf39785
feat: added purity analyzer from library analyzer
Muellersen Oct 1, 2024
4298e57
test: moved purity test from library analizer to stub generator
Muellersen Oct 3, 2024
7d974d2
feat: implemented correct syntax of boundary and enum for stub genera…
Muellersen Oct 3, 2024
ab7c40c
chore: save state
Muellersen Oct 6, 2024
0f877c1
feat: purity analysis runs now while generating stubs
Muellersen Oct 6, 2024
4fe4b77
feat: implemented @Impure and @Pure annotation
Muellersen Oct 7, 2024
08d224e
Merge branch 'ba-pm-extend-docstring-parser' of https://github.com/Sa…
Muellersen Oct 8, 2024
e997a6e
chore: save state
Muellersen Oct 8, 2024
2a1ba7a
fix: generate correct id from Function for astroid NodeID
Muellersen Oct 8, 2024
695aafa
feat: stub generator generates correct boolean values and null
Muellersen Oct 9, 2024
d9e0b71
fix: changed direction of < for boundaries
Muellersen Oct 12, 2024
d7ea3ef
chore: save state
Muellersen Oct 12, 2024
5724235
chore: save state
Muellersen Oct 13, 2024
003ca3a
chore: save state
Muellersen Oct 15, 2024
a7787bf
feat: implemented type extraction of call references receiver with mypy
Muellersen Oct 16, 2024
adc0a08
Trying to reduce the runtime for the "_add_to_imports" function in th…
Masara Oct 4, 2024
9c69b79
Merge remote-tracking branch 'origin/fix-docstring-runtime' into fix-…
Masara Oct 16, 2024
5a47d30
Runtime fix for the O(n^3) bug
Masara Oct 17, 2024
26577a1
Optimizing the _check_publicity_in_reexports function
Masara Oct 17, 2024
6f3e35d
chore: save state
Muellersen Oct 17, 2024
a78eafc
feat: implemented finding referenced functions by mypy type of receiver
Muellersen Oct 18, 2024
61fb727
test: added some end to end test for improved purity analysis
Muellersen Oct 19, 2024
c1800aa
chore: added comment
Muellersen Oct 19, 2024
d905e20
test: added more tests
Muellersen Oct 20, 2024
844aa95
fix: fixed finding of subclasses
Muellersen Oct 22, 2024
c7ad552
chore: save state
Muellersen Oct 22, 2024
54efba8
chore: save state, refactor and clean code
Muellersen Oct 22, 2024
9481043
test: fixed purity snapshot tests being inconsistent
Muellersen Oct 23, 2024
ae91891
fix: cleaned code and fixed finding call references
Muellersen Oct 23, 2024
bc831f9
chore: removed TODO comment
Muellersen Oct 23, 2024
21822dd
chore: save state
Muellersen Oct 23, 2024
6a1cc33
feat: updated call_reference extraction
Muellersen Oct 25, 2024
7ead1f1
chore: save state
Muellersen Oct 26, 2024
bd2e596
feat: improved finding call_references
Muellersen Oct 27, 2024
de965e3
chore: added docstrings
Muellersen Oct 28, 2024
6474563
chore: added more docstrings
Muellersen Oct 28, 2024
87a8004
feat: if method or attribute names ar not found, they will be looked …
Muellersen Oct 28, 2024
66ecbeb
chore: updated todo messages and added new commented out test cases
Muellersen Oct 28, 2024
7752de7
chore: added todo comments
Muellersen Oct 29, 2024
80ffcc5
chore: added comments
Muellersen Oct 29, 2024
2310286
feat: added boundary and enum extractor to attributes
Muellersen Oct 29, 2024
1e13da3
test: added tests for attributes
Muellersen Oct 29, 2024
a53a3bb
chore: Todo -> TODO
Muellersen Oct 29, 2024
8a3e499
feat: added parameter to body extraction
Muellersen Oct 29, 2024
86abc59
chore: save state
Muellersen Oct 30, 2024
2a65711
chore: refactored code, added comments and added tuple index handling…
Muellersen Oct 30, 2024
ee06dc2
Removed unused code
Masara Nov 10, 2024
7bf2ed1
Merge branch 'various_fixes' into fix-docstring-runtime
Masara Nov 10, 2024
9235d3d
Merge branch 'main' into various_fixes
Masara Nov 10, 2024
5655120
Merge branch 'various_fixes' into fix-docstring-runtime
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
436b87c
feat: added cli arg old, to run the old purity analysis, for evaluation
Muellersen Nov 19, 2024
ce0400f
chore: save state
Muellersen Nov 19, 2024
afa992b
feat: implemented union types for callreference extraction
Muellersen Nov 19, 2024
9463931
chore: updated comments
Muellersen Nov 19, 2024
11dc513
chore: added logging and evaluation code
Muellersen Nov 20, 2024
e00e973
feat: implemented extracting correct receiver class for deeply nested…
Muellersen Nov 22, 2024
843eed0
chore: save state
Muellersen Nov 26, 2024
09aacee
chore: added and updated TODOs for next steps
Muellersen Nov 29, 2024
2d582ad
chore: save state
Muellersen Nov 29, 2024
cf8faa5
feat: refactored _find_correct_type_by_path_to_call_reference but rec…
Muellersen Dec 8, 2024
02cf6b2
fix: added fix to refactored function
Muellersen Dec 9, 2024
ef80e84
Merge branch 'main' into ba-pm-extend-docstring-parser
Muellersen Dec 10, 2024
024f663
chore: update lockfile
Muellersen Dec 10, 2024
1eed27e
Merge branch 'various_fixes' into ba-pm-extend-docstring-parser
Muellersen Dec 10, 2024
d4047e6
Merge branch 'fix-docstring-runtime' into ba-pm-extend-docstring-parser
Muellersen Dec 10, 2024
9df798d
chore: removed comments
Muellersen Dec 10, 2024
0061a19
test: added new purity test for self
Muellersen Dec 10, 2024
da9a81a
chore: added comment
Muellersen Dec 10, 2024
c889016
chore: save state
Muellersen Dec 12, 2024
cb065ad
feat: added api evaluation code
Muellersen Dec 12, 2024
d548a1f
fix: fixed circular import error
Muellersen Dec 13, 2024
57059b9
feat: improved api evaluation
Muellersen Dec 14, 2024
edd4953
feat: improved api evaluation and added missing and conflicted types csv
Muellersen Dec 15, 2024
4869f60
chore: save state, evaluation
Muellersen Dec 17, 2024
af3055d
chore: save state
Muellersen Dec 18, 2024
ffd9a05
chore: save state, evaluated evaluation, started fixing errors, alrea…
Muellersen Dec 18, 2024
d4a1372
fix: fixed many bugs, updated snapshots, improved finding super() stuff
Muellersen Dec 20, 2024
cdf6692
chore: save state
Muellersen Dec 21, 2024
a37a03e
fix: fixed generator expressions, saved state
Muellersen Dec 29, 2024
5c1952d
fix: get_class_by_id fixes getting the correct class
Muellersen Dec 30, 2024
4b618aa
fix: fix finding receiver type when getting any, and handling None sh…
Muellersen Jan 1, 2025
489d0eb
fix: NamedSequenceType is also considered now, thus more types are found
Muellersen Jan 3, 2025
ce366bd
feat: implemented finding types when global functions are imported
Muellersen Jan 4, 2025
17bbfaa
feat: added closures to Function class, added finding global_function…
Muellersen Jan 6, 2025
4e80683
test: tested closures, added tests, updated snapshots
Muellersen Jan 6, 2025
b935234
fix: finding more call refs, added comments, updated snapshots
Muellersen Jan 6, 2025
46e08cf
test: added purity evaluation data of lukas, added finding receiver f…
Muellersen Jan 7, 2025
16bc8cb
fix: fixed counting purity results
Muellersen Jan 7, 2025
69d3d18
feat: added bool to track if type aware purity analysis found functio…
Muellersen Jan 8, 2025
1a48515
chore: update .gitignore
Muellersen Jan 10, 2025
5087c9e
chore: improved evaluation structure
Muellersen Jan 10, 2025
46a06cf
Merge branch 'ba-pm-extend-docstring-parser' of https://github.com/Sa…
Muellersen Jan 10, 2025
4a4fdff
chore: removed duplicate .gitignore entry
Muellersen Jan 10, 2025
bb552dd
fix: corrected out_dir for evaluation
Muellersen Jan 10, 2025
ff4549d
fix: evaluation fix, updated snapshots
Muellersen Jan 10, 2025
2f38b5e
chore: save state, started implementing call graph evaluation
Muellersen Jan 10, 2025
84f4e59
fix: call graph evaluation
Muellersen Jan 11, 2025
f2ef46b
feat: implemented call_graph_comparison
Muellersen Jan 12, 2025
4f11898
feat: call graphs are only analyzed if they are of a function which i…
Muellersen Jan 13, 2025
b5d77cd
chore: save state
Muellersen Jan 14, 2025
236298c
feat: implement memoized dfs
Muellersen Jan 14, 2025
724d023
chore: added other libraries and ran seaborn purity analysis
Muellersen Jan 15, 2025
9ebda9c
fix: fixed some infinite recursion
Muellersen Jan 17, 2025
7a3bfee
chore: save state
Muellersen Jan 17, 2025
05d06b5
fix: limited callgraph depth to 60
Muellersen Jan 17, 2025
b01f95c
chore: improved evaluation code
Muellersen Jan 18, 2025
788cad6
chore: save state
Muellersen Jan 19, 2025
0ff5b58
fix: fixed module imports like module.globalfunc() and finding call r…
Muellersen Jan 20, 2025
26eeafb
Merge branch 'ba-pm-extend-docstring-parser' of https://github.com/Sa…
Muellersen Jan 20, 2025
f5daab5
fix: fixed path to package for evaluation packages
Muellersen Jan 20, 2025
6fe84da
chore: finished pandas evaluation
Muellersen Jan 21, 2025
f4db45d
Merge branch 'ba-pm-extend-docstring-parser' of https://github.com/Sa…
Muellersen Jan 21, 2025
321f649
chore: save sklearn evaluation results
Muellersen Jan 21, 2025
534fe7b
Merge branch 'ba-pm-extend-docstring-parser' of https://github.com/Sa…
Muellersen Jan 21, 2025
0090d8d
feat: adjusted api evaluation to purity evaluation
Muellersen Jan 21, 2025
a938cd2
chore: adjusted printing of branching factor, adjusted runtime evalua…
Muellersen Jan 21, 2025
9f30eac
chore: save state and fix cli
Muellersen Jan 21, 2025
55250b5
chore: save state and start runtime eval code
Muellersen Jan 21, 2025
98ef2ab
feat: tested and implemented improved module handling, cleaned code, …
Muellersen Jan 23, 2025
cee2923
feat: implement runtime evaluation
Muellersen Feb 5, 2025
86f2edb
feat: improved runtime analysis
Muellersen Feb 8, 2025
e3464e2
tests: wrote tests for new features that the analysis should handle, …
Muellersen Feb 9, 2025
eac03be
feat: added attribute of call ref to track reasons why we havent foun…
Muellersen Feb 9, 2025
b91ba2d
tests: tested and implemented new testcases, updated snapshots
Muellersen Feb 10, 2025
3219fbb
chore: refactored and ran some tests
Muellersen Feb 10, 2025
0305ac6
chore. ran old purity on sklearn
Muellersen Feb 11, 2025
1e9266b
Merge branch 'ba-pm-extend-docstring-parser' of https://github.com/Sa…
Muellersen Feb 11, 2025
e7617b2
chore: save state ran some tests
Muellersen Feb 11, 2025
292c2e2
Merge branch 'ba-pm-extend-docstring-parser' of https://github.com/Sa…
Muellersen Feb 11, 2025
fb61a2b
chore: ran some evaluations
Muellersen Feb 13, 2025
d548705
chore: remove linebreaks in possible reason for no found function
Muellersen Feb 15, 2025
b2f9b6f
chore: refactored extracting classes, added fallback tracking, this s…
Muellersen Feb 16, 2025
bdfc412
chore: cleaned code
Muellersen Feb 16, 2025
8830667
Merge branch 'ba-pm-extend-docstring-parser' of https://github.com/Sa…
Muellersen Feb 16, 2025
825ae20
chore: removed most evaluation files, moved them to local storage, fo…
Muellersen Feb 19, 2025
2d9a12b
chore: ran evaluation of safeds and seaborn
Muellersen Feb 21, 2025
4ed9e20
fix: undo refactoring changes of purity analyzer that could have led …
Muellersen Feb 25, 2025
a33f10e
chore: refactor and typo
Muellersen Feb 25, 2025
32f6b56
Merge branch 'ba-pm-extend-docstring-parser' of https://github.com/Sa…
Muellersen Feb 25, 2025
dc445ef
fix: undo refactor
Muellersen Feb 25, 2025
fb82d65
fix: runtime fix, test files are ignored now
Muellersen Feb 26, 2025
9b3e304
Merge branch 'ba-pm-extend-docstring-parser' of https://github.com/Sa…
Muellersen Feb 26, 2025
d7c6559
chore: ran panda analysis
Muellersen Feb 26, 2025
0d9b67b
Merge branch 'ba-pm-extend-docstring-parser' of https://github.com/Sa…
Muellersen Feb 26, 2025
bd55fad
chore: finished runtime evaluation two times
Muellersen Feb 28, 2025
d6e4f54
chore: added result folders and files for better result evaluation
Muellersen Mar 1, 2025
233883c
fix: fixed getting weird results
Muellersen Mar 1, 2025
11142db
fix: removed is old check in evaluate call graph forest
Muellersen Mar 1, 2025
38bf7f0
Merge branch 'ba-pm-extend-docstring-parser' of https://github.com/Sa…
Muellersen Mar 1, 2025
f6d0aa2
chore: safe evaluation data
Muellersen Mar 1, 2025
f4f70b7
chore: save state, ran purity evaluation
Muellersen Mar 2, 2025
fd748dc
chore: removed evaluation tracking
Muellersen Mar 3, 2025
a016e65
chore: ran evaluations (pc)
Muellersen Mar 3, 2025
0c385e3
chore: ran runtime eval
Muellersen Mar 4, 2025
14771cb
Merge branch 'main' into fix-docstring-runtime
lars-reimann Mar 7, 2025
bcbc7d0
style: fix ruff errors
lars-reimann Mar 7, 2025
806b7e9
fix: mypy error
lars-reimann Mar 7, 2025
1940a4a
chore: results are sorted now for better comparison, updated snapshots
Muellersen Mar 8, 2025
a470c5b
chore: ran evaluations (pc)
Muellersen Mar 8, 2025
777b3c4
chore: ran evaluation (pc)
Muellersen Mar 11, 2025
5125da7
chore: ran evaluations (laptop)
Muellersen Mar 11, 2025
5724c0d
Merge branch 'ba-pm-extend-docstring-parser' of https://github.com/Sa…
Muellersen Mar 11, 2025
4f9be8a
chore: cleaned code
Muellersen Mar 11, 2025
a7db44c
Fix for the import generation
Masara Apr 3, 2025
2a3cb09
Added test for bytes types conversion to Safe-DS stubs from docstrings
Masara Apr 3, 2025
3e5962f
Merge branch 'main' into fix-docstring-runtime
Masara Apr 3, 2025
2190b10
chore: save state
Muellersen Apr 7, 2025
0c9fa82
chore: ran pandas evaluation
Muellersen Apr 7, 2025
cdade7c
chore: implemented start of type evaluation
Muellersen Apr 7, 2025
72475ca
feat: implement type evaluation
Muellersen Apr 8, 2025
f71571f
chore: ran seaborn(pc)
Muellersen Apr 8, 2025
cf827e6
chore: ran evaluations (laptop)
Muellersen Apr 9, 2025
0547766
chore: ran evaluations (pc)
Muellersen Apr 9, 2025
5204240
Merge branch 'ba-pm-extend-docstring-parser' of https://github.com/Sa…
Muellersen Apr 9, 2025
271a770
chore: cleaned code
Muellersen Apr 10, 2025
782ce02
chore: ran matplotlib
Muellersen Apr 11, 2025
9b61f65
fix: improved variable name
Muellersen Apr 11, 2025
3c6ac47
chore: added eval_tracking for panda sampling
Muellersen Apr 11, 2025
ef63126
chore: corrected unittests
Muellersen Apr 19, 2025
aec65f7
Merge branch 'ba-pm-extend-docstring-parser' of https://github.com/Sa…
Muellersen Apr 19, 2025
8d085b9
chore: clean code
Muellersen Apr 22, 2025
d8294bf
chore: disable evaluation test
Muellersen Apr 22, 2025
8ec00cd
Merge branch 'fix-docstring-runtime' into ba-pm-extend-docstring-parser
Muellersen Apr 22, 2025
531a30b
chore: start removing evaluation stuff
Muellersen Apr 22, 2025
a6d124e
chore: undo previous commit
Muellersen Apr 22, 2025
bc5003a
chore: remove evaluation code
Muellersen Apr 22, 2025
2d1a99b
chore: cleaned code and added more docstrings
Muellersen Apr 22, 2025
f604205
chore: linter fixes and implemented impurity reasons
Muellersen Apr 23, 2025
7819c53
chore: remove unused lines but kept them for later
Muellersen Apr 23, 2025
10706b5
chore: updated lock file
Muellersen Apr 23, 2025
1a28b45
chore: more linter fixes
Muellersen Apr 23, 2025
3f4d3a2
chore: more fixes
Muellersen Apr 23, 2025
c2e37af
style: apply automated linter fixes
megalinter-bot Apr 23, 2025
bba1472
chore: more fixes
Muellersen Apr 23, 2025
32a5207
Merge branch 'ba-pm-extend-docstring-parser' of https://github.com/Sa…
Muellersen Apr 23, 2025
9f10909
chore: further mypy fixes
Muellersen Apr 23, 2025
59ce5d8
chore: fix unused variable
Muellersen Apr 23, 2025
5a69eb5
chore: fix last errors
Muellersen Apr 23, 2025
7ddbf84
chore: last error fix
Muellersen Apr 23, 2025
eb9f4fd
chore: test pragma no cover, as these functions are tested through sn…
Muellersen Apr 24, 2025
f77b65f
chore: added rest of pragma no cover, as they are tested through snap…
Muellersen Apr 24, 2025
b97acff
chore: last pragma
Muellersen Apr 24, 2025
007b4b5
chore: added pragma no cover to code from lukas and nils
Muellersen Apr 24, 2025
6e7951f
chore: remove eval files
Muellersen Apr 24, 2025
ee0151f
updated lockfile
Muellersen Apr 30, 2025
fd791a4
revert change
Muellersen Apr 30, 2025
3f95bf4
chore: upgraded astroid to >3.0.0 and fixed breaking changes
Muellersen May 17, 2025
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
1,814 changes: 1,445 additions & 369 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ safe-ds-stubgen = "safeds_stubgen.main:main"
[tool.poetry.dependencies]
python = "^3.11"
mypy = "^1.6.1"
astroid = "^3.0.0"
griffe = ">=0.47.0,<0.49"
spacy = "^3.5.1"

[tool.poetry.group.dev.dependencies]
pytest = ">=7.4.3,<9.0.0"
Expand Down
6 changes: 6 additions & 0 deletions src/safeds_stubgen/api_analyzer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
VarianceKind,
WildcardImport,
)
from safeds_stubgen.api_analyzer._extract_boundary_values import extract_boundary
from safeds_stubgen.api_analyzer._extract_valid_values import extract_valid_literals
from ._ast_visitor import result_name_generator
from ._get_api import get_api
from ._mypy_helpers import get_classdef_definitions, get_funcdef_definitions, get_mypyfile_definitions
Expand All @@ -36,6 +38,7 @@
TypeVarType,
UnionType,
UnknownType,
EnumType
)

__all__ = [
Expand All @@ -46,6 +49,9 @@
"Class",
"DictType",
"Enum",
"EnumType",
"extract_boundary",
"extract_valid_literals",
"FinalType",
"Function",
"ListType",
Expand Down
61 changes: 59 additions & 2 deletions src/safeds_stubgen/api_analyzer/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from enum import Enum as PythonEnum
from typing import TYPE_CHECKING, Any

from safeds_stubgen.api_analyzer._types import NamedType

if TYPE_CHECKING:
from pathlib import Path

Expand Down Expand Up @@ -36,7 +38,7 @@ def ensure_file_exists(file: Path) -> None:


class API:
def __init__(self, distribution: str, package: str, version: str) -> None:
def __init__(self, distribution: str, package: str, version: str, path_to_package: str) -> None:
self.distribution: str = distribution
self.package: str = package
self.version: str = version
Expand All @@ -49,15 +51,30 @@ def __init__(self, distribution: str, package: str, version: str) -> None:
self.attributes_: dict[str, Attribute] = {}
self.parameters_: dict[str, Parameter] = {}
self.reexport_map: dict[str, set[Module]] = defaultdict(set)
self.path_to_package: str = path_to_package

def add_module(self, module: Module) -> None:
self.modules[module.id] = module

def add_class(self, class_: Class) -> None:
self.classes[class_.id] = class_

def create_astroid_module_path(self, path_str: str) -> str:
package_name = self.package
module_path_list = path_str.split(".")
index_to_split = module_path_list.index(package_name)
module_path = module_path_list[index_to_split:]
correct_module_path = ".".join(module_path)
return correct_module_path

def create_astroid_id(self, function: Function) -> str:
correct_module_path = self.create_astroid_module_path(function.module_id_which_contains_def)
full_id = function.id.split("/")
id = full_id[-1]
return f"{correct_module_path}.{id}.{function.line}.{function.column}"

def add_function(self, function: Function) -> None:
self.functions[function.id] = function
self.functions[self.create_astroid_id(function)] = function

def add_enum(self, enum: Enum) -> None:
self.enums[enum.id] = enum
Expand Down Expand Up @@ -168,6 +185,7 @@ class Class:
id: str
name: str
superclasses: list[str]
subclasses: list[str]
is_public: bool
docstring: ClassDocstring
constructor: Function | None = None
Expand Down Expand Up @@ -235,8 +253,12 @@ def to_dict(self) -> dict[str, Any]:
@dataclass
class Function:
id: str
module_id_which_contains_def: str
line: int
column: int
name: str
docstring: FunctionDocstring
body: Body
is_public: bool
is_static: bool
is_class_method: bool
Expand All @@ -246,6 +268,7 @@ class Function:
results: list[Result] = field(default_factory=list)
reexported_by: list[Module] = field(default_factory=list)
parameters: list[Parameter] = field(default_factory=list)
closures: dict[str, Function] = field(default_factory=dict)

def to_dict(self) -> dict[str, Any]:
return {
Expand All @@ -259,8 +282,42 @@ def to_dict(self) -> dict[str, Any]:
"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],
# "closures": [closure.to_dict for closure in self.closures],
}

@dataclass
class Body:
line: int
column: int
end_line: int | None
end_column: int | None
call_references: dict[str, CallReference] = field(default_factory=dict)

@dataclass
class CallReference:
receiver: CallReceiver
function_name: str
line: int
column: int
possibly_referenced_functions: list[Function] = field(default_factory=list)
isSuperCallRef: bool = False
reason_for_no_found_functions: str = ""
fallbackToSignatureCheck: bool = True

@dataclass
class CallReceiver:
type: Any | NamedType
full_name: str
path_to_call_reference: list[str]
found_classes: list[Class]
isFromParameter: bool = False
typeThroughTypeHint: bool = False
typeThroughDocString: bool = False
typeThroughInference: bool = False
typeOutsideOfPackage: bool = False
decrease: int = 0
increase: int = 0
missingTypesWhileFindingFunction: bool = False

class UnknownValue:
pass
Expand Down
Loading
Loading