honestcode 0.2.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of honestcode might be problematic. Click here for more details.

@@ -0,0 +1,43 @@
1
+ """Relation types and shared data structures for structural code analysis."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from dataclasses import dataclass
6
+ from enum import Enum
7
+
8
+ __all__ = ["RelationType", "StructEdge", "ParseResult"]
9
+
10
+
11
+ class RelationType(Enum):
12
+ DEF_CALL = "def_call"
13
+ VAR_DEF_USE = "var_def_use"
14
+ AST_PARENT_CHILD = "ast_parent_child"
15
+ IMPORT = "import"
16
+ IMPORT_REF = "import_ref"
17
+ SAME_SCOPE = "same_scope"
18
+ CROSS_FILE_REF = "cross_file_ref" # def in file_a -> call in file_b
19
+
20
+
21
+ @dataclass(frozen=True)
22
+ class StructEdge:
23
+ src_start: int
24
+ src_end: int
25
+ tgt_start: int
26
+ tgt_end: int
27
+ relation_type: str
28
+ name: str | None = None
29
+ # For cross-file edges: which file the source/target belongs to
30
+ src_file: str | None = None
31
+ tgt_file: str | None = None
32
+
33
+
34
+ @dataclass
35
+ class ParseResult:
36
+ edges: list[StructEdge]
37
+ func_defs: dict[str, tuple[int, int]]
38
+ class_defs: dict[str, tuple[int, int]]
39
+ var_defs: dict[str, tuple[int, int]]
40
+ imports: set[str]
41
+ # Cross-file: symbols imported from / exported to other files
42
+ imported_symbols: dict[str, str] | None = None # name -> source_module
43
+ exported_symbols: set[str] | None = None # names defined here, usable by others
@@ -0,0 +1,31 @@
1
+ """Shared AST utilities for HonestCode."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import ast
6
+
7
+ __all__ = ["call_name", "call_base"]
8
+
9
+
10
+ def call_name(node: ast.expr) -> str | None:
11
+ """Return a dotted name for a call target (e.g. ``obj.method``).
12
+
13
+ Returns ``None`` for complex expressions (e.g. ``(a + b).foo()``).
14
+ """
15
+ if isinstance(node, ast.Name):
16
+ return node.id
17
+ if isinstance(node, ast.Attribute):
18
+ parts: list[str] = []
19
+ current: ast.expr = node
20
+ while isinstance(current, ast.Attribute):
21
+ parts.append(current.attr)
22
+ current = current.value
23
+ if isinstance(current, ast.Name):
24
+ parts.append(current.id)
25
+ return ".".join(reversed(parts))
26
+ return None
27
+
28
+
29
+ def call_base(name: str) -> str:
30
+ """Return the first component of a dotted name."""
31
+ return name.split(".")[0]