Skip to content
This repository has been archived by the owner on Nov 23, 2024. It is now read-only.

Commit

Permalink
feat: resolve references (#153)
Browse files Browse the repository at this point in the history
Closes #90 

### Summary of Changes

This feature contains many additions to the collection of data when
parsing python code (former scope detection).
We now collect: the scope, the classes, the functions, all global
variables, all value and target nodes, the parameters as well as all
function calls when traversing the AST.
During this traversal, we also determine the symbols for all name nodes.
We distinguish between `GlobalVariables, LocalVariables, ClassVariables,
InstanceVariables, Parameters` and `Builtins`.

Furthermore, this feature resolves the references for all name nodes
(target and value nodes).
For each name node we determine its scope, as mentioned above, and a
list of all referenced symbols and return a `ReferenceNode`.
<!-- Please provide a summary of changes in this pull request, ensuring
all changes are explained. -->

---------

Co-authored-by: megalinter-bot <129584137+megalinter-bot@users.noreply.github.com>
  • Loading branch information
lukarade and megalinter-bot authored Oct 2, 2023
1 parent 45b1329 commit bfcd292
Show file tree
Hide file tree
Showing 17 changed files with 4,761 additions and 823 deletions.
2 changes: 2 additions & 0 deletions .github/linters/.ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ ignore = [
"RET508",
# private-member-access (we cannot always avoid it if we want a clean API)
"SLF001",
# collapsible-if (sometimes it's more readable)
"SIM102",
# if-else-block-instead-of-if-exp (an if-else block can be more readable)
"SIM108",
# compare-to-empty-string (sometimes it's better to be explicit)
Expand Down
2 changes: 2 additions & 0 deletions src/library_analyzer/cli/_run_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,5 @@ def _run_api_command(
api_dependencies = get_dependencies(api)
out_file_api_dependencies = out_dir_path.joinpath(f"{package}__api_dependencies.json")
api_dependencies.to_json_file(out_file_api_dependencies)

# TODO: call resolve_references here
37 changes: 0 additions & 37 deletions src/library_analyzer/processing/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,52 +22,19 @@
from ._get_api import get_api
from ._get_instance_attributes import get_instance_attributes
from ._get_parameter_list import get_parameter_list
from ._infer_purity import (
DefinitelyImpure,
DefinitelyPure,
ImpurityIndicator,
MaybeImpure,
OpenMode,
PurityInformation,
PurityResult,
calc_function_id,
determine_open_mode,
determine_purity,
extract_impurity_reasons,
generate_purity_information,
get_function_defs,
get_purity_result_str,
infer_purity,
)
from ._package_metadata import (
distribution,
distribution_version,
package_files,
package_root,
)
from ._resolve_references import ClassScopeNode, MemberAccess, ScopeNode, get_scope

__all__ = [
"DefinitelyImpure",
"DefinitelyPure",
"ImpurityIndicator",
"MaybeImpure",
"OpenMode",
"PurityInformation",
"PurityResult",
"calc_function_id",
"determine_open_mode",
"determine_purity",
"distribution",
"distribution_version",
"extract_impurity_reasons",
"generate_purity_information",
"get_api",
"get_function_defs",
"get_instance_attributes",
"get_parameter_list",
"get_purity_result_str",
"infer_purity",
"package_files",
"package_root",
"extract_param_dependencies",
Expand All @@ -82,10 +49,6 @@
"ParameterIsIllegal",
"ParameterHasType",
"ParametersInRelation",
"ScopeNode",
"MemberAccess",
"get_scope",
"ClassScopeNode",
"extract_called_after_functions",
"CalledAfterValues",
"extract_boundary",
Expand Down
225 changes: 0 additions & 225 deletions src/library_analyzer/processing/api/_resolve_references.py

This file was deleted.

38 changes: 0 additions & 38 deletions src/library_analyzer/processing/api/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,6 @@
ParameterDocstring,
ResultDocstring,
)
from ._purity import (
AttributeAccess,
BuiltInFunction,
Call,
ConcreteImpurityIndicator,
Expression,
FileRead,
FileWrite,
GlobalAccess,
ImpurityCertainty,
ImpurityIndicator,
InstanceAccess,
ParameterAccess,
Reference,
StringLiteral,
SystemInteraction,
UnknownCallTarget,
VariableRead,
VariableWrite,
)
from ._types import (
AbstractType,
BoundaryType,
Expand All @@ -55,41 +35,23 @@
"API_SCHEMA_VERSION",
"AbstractType",
"Attribute",
"AttributeAccess",
"AttributeAssignment",
"AttributeDocstring",
"BoundaryType",
"BuiltInFunction",
"Call",
"Class",
"ClassDocstring",
"ConcreteImpurityIndicator",
"EnumType",
"Expression",
"FileRead",
"FileWrite",
"FromImport",
"Function",
"FunctionDocstring",
"GlobalAccess",
"Import",
"ImpurityCertainty",
"ImpurityIndicator",
"InstanceAccess",
"Module",
"NamedType",
"Parameter",
"ParameterAccess",
"ParameterAssignment",
"ParameterDocstring",
"Reference",
"Result",
"ResultDocstring",
"StringLiteral",
"SystemInteraction",
"UnknownCallTarget",
"UnionType",
"VariableRead",
"VariableWrite",
"create_type",
]
Loading

0 comments on commit bfcd292

Please sign in to comment.