cpg2py 1.2.2__tar.gz → 1.2.3__tar.gz

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.
Files changed (38) hide show
  1. cpg2py-1.2.3/PKG-INFO +120 -0
  2. cpg2py-1.2.3/README.md +95 -0
  3. cpg2py-1.2.3/pyproject.toml +96 -0
  4. cpg2py-1.2.3/pyproject.toml.orig +73 -0
  5. cpg2py-1.2.3/src/cpg2py/__init__.py +29 -0
  6. {cpg2py-1.2.2 → cpg2py-1.2.3/src}/cpg2py/_abc/__init__.py +2 -0
  7. {cpg2py-1.2.2 → cpg2py-1.2.3/src}/cpg2py/_abc/edge.py +31 -26
  8. {cpg2py-1.2.2 → cpg2py-1.2.3/src}/cpg2py/_abc/graph.py +53 -54
  9. {cpg2py-1.2.2 → cpg2py-1.2.3/src}/cpg2py/_abc/node.py +25 -19
  10. {cpg2py-1.2.2 → cpg2py-1.2.3/src}/cpg2py/_abc/storage.py +79 -77
  11. {cpg2py-1.2.2 → cpg2py-1.2.3/src}/cpg2py/_cpg/__init__.py +2 -0
  12. cpg2py-1.2.3/src/cpg2py/_cpg/edge.py +44 -0
  13. {cpg2py-1.2.2 → cpg2py-1.2.3/src}/cpg2py/_cpg/graph.py +41 -36
  14. cpg2py-1.2.3/src/cpg2py/_cpg/node.py +86 -0
  15. cpg2py-1.2.3/src/cpg2py/_exceptions.py +58 -0
  16. cpg2py-1.2.2/cpg2py/__init__.py → cpg2py-1.2.3/src/cpg2py/_loaders.py +40 -44
  17. {cpg2py-1.2.2 → cpg2py-1.2.3/src}/cpg2py/_logger.py +11 -12
  18. cpg2py-1.2.3/src/cpg2py/py.typed +0 -0
  19. cpg2py-1.2.2/MANIFEST.in +0 -3
  20. cpg2py-1.2.2/PKG-INFO +0 -179
  21. cpg2py-1.2.2/README.md +0 -124
  22. cpg2py-1.2.2/cpg2py/_cpg/edge.py +0 -31
  23. cpg2py-1.2.2/cpg2py/_cpg/node.py +0 -66
  24. cpg2py-1.2.2/cpg2py/_exceptions.py +0 -43
  25. cpg2py-1.2.2/cpg2py.egg-info/PKG-INFO +0 -179
  26. cpg2py-1.2.2/cpg2py.egg-info/SOURCES.txt +0 -27
  27. cpg2py-1.2.2/cpg2py.egg-info/dependency_links.txt +0 -1
  28. cpg2py-1.2.2/cpg2py.egg-info/requires.txt +0 -11
  29. cpg2py-1.2.2/cpg2py.egg-info/top_level.txt +0 -1
  30. cpg2py-1.2.2/pyproject.toml +0 -144
  31. cpg2py-1.2.2/setup.cfg +0 -4
  32. cpg2py-1.2.2/tests/test_edge.py +0 -203
  33. cpg2py-1.2.2/tests/test_exceptions.py +0 -157
  34. cpg2py-1.2.2/tests/test_generics.py +0 -188
  35. cpg2py-1.2.2/tests/test_graph.py +0 -647
  36. cpg2py-1.2.2/tests/test_node.py +0 -320
  37. cpg2py-1.2.2/tests/test_storage.py +0 -791
  38. {cpg2py-1.2.2 → cpg2py-1.2.3}/LICENSE +0 -0
cpg2py-1.2.3/PKG-INFO ADDED
@@ -0,0 +1,120 @@
1
+ Metadata-Version: 2.4
2
+ Name: cpg2py
3
+ Version: 1.2.3
4
+ Summary: A graph-based data structure designed for querying CSV files in Joern format in Python
5
+ Keywords: Joern,CPG,Graph,CSV
6
+ Author: samhsu-dev
7
+ Author-email: samhsu-dev <yxu166@jhu.edu>
8
+ License-Expression: MIT
9
+ License-File: LICENSE
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.8
14
+ Classifier: Programming Language :: Python :: 3.9
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
20
+ Requires-Python: >=3.8
21
+ Project-URL: Homepage, https://github.com/samhsu-dev/cpg2py
22
+ Project-URL: Repository, https://github.com/samhsu-dev/cpg2py
23
+ Project-URL: Documentation, https://github.com/samhsu-dev/cpg2py
24
+ Description-Content-Type: text/markdown
25
+
26
+ # cpg2py
27
+
28
+ [![PyPI](https://img.shields.io/pypi/v/cpg2py)](https://pypi.org/project/cpg2py/)
29
+ [![Python](https://img.shields.io/pypi/pyversions/cpg2py)](https://pypi.org/project/cpg2py/)
30
+ [![License](https://img.shields.io/github/license/samhsu-dev/cpg2py)](LICENSE)
31
+ [![Last commit](https://img.shields.io/github/last-commit/samhsu-dev/cpg2py)](https://github.com/samhsu-dev/cpg2py)
32
+ [![Repo size](https://img.shields.io/github/repo-size/samhsu-dev/cpg2py)](https://github.com/samhsu-dev/cpg2py)
33
+
34
+ > **cpg2py**: [code property graph](docs/glossary-graph.md#code-property-graph-cpg) (CPG) to Python.
35
+
36
+ Load [Joern](https://joern.io/) code property graph CSV exports into Python and query nodes, edges and traversals.
37
+
38
+ ## Install
39
+
40
+ Prerequisites: Python 3.8 or later, and either [uv](https://docs.astral.sh/uv/) or pip.
41
+
42
+ ```bash
43
+ uv add cpg2py
44
+ pip install cpg2py
45
+ ```
46
+
47
+ ## Usage
48
+
49
+ Tab-separated Joern export, `nodes.csv` and `rels.csv`. The edge file names its columns `start`, `end`, `type`, or `start:str`, `end:str`, `type:str`:
50
+
51
+ ```text
52
+ id:int name type flags:string_array lineno:int
53
+ 1 f.php File TOPLEVEL_FILE 1
54
+ 2 main AST_FUNC_DECL 3
55
+ 3 x AST_VAR 4
56
+ ```
57
+
58
+ ```text
59
+ start end type var
60
+ 1 2 PARENT_OF
61
+ 2 3 PARENT_OF
62
+ 3 2 FLOWS_TO x
63
+ ```
64
+
65
+ ```python
66
+ from pathlib import Path
67
+
68
+ from cpg2py import cpg_graph
69
+
70
+ graph = cpg_graph(Path("nodes.csv"), Path("rels.csv"))
71
+ func = graph.node("2")
72
+ print(func.name, func.line_num)
73
+ print([child.name for child in graph.children(func)])
74
+ print([node.id for node in graph.flow_to(graph.node("3"))])
75
+ print(graph.topfile_node("3").name)
76
+ ```
77
+
78
+ ```text
79
+ main 3
80
+ ['x']
81
+ ['2']
82
+ f.php
83
+ ```
84
+
85
+ ## API
86
+
87
+ All names are imported from `cpg2py`.
88
+
89
+ | Name | Signature or role |
90
+ |------|-------------------|
91
+ | `cpg_graph` | `cpg_graph(node_csv: Path, edge_csv: Path, verbose: bool = False) -> CpgGraph` — loads a Joern CSV export |
92
+ | `storage_from_json` | `storage_from_json(path: Path \| str) -> Storage` — loads a graph saved by `Storage.save_json` |
93
+ | `CpgGraph` | `CpgGraph(target: Storage)` — `node`, `edge`, `nodes`, `first_node`, `edges`, `succ`, `prev`, `children`, `parent`, `flow_to`, `flow_from`, `descendants`, `ancestors`, `topfile_node` |
94
+ | `CpgNode` | node view — `id`, `code`, `label`, `flags`, `line_num`, `children_num`, `func_id`, `class_name`, `namespace`, `name`, `end_num`, `comment`, `type` |
95
+ | `CpgEdge` | edge view — `id`, `start`, `end`, `type`, `var`, `from_nid`, `to_nid`, `edge_type` |
96
+ | `Storage` | `Storage()` — in-memory directed multigraph with node and edge properties; `save_json`, `load_json` |
97
+ | `AbcGraphQuerier`, `AbcNodeQuerier`, `AbcEdgeQuerier` | base classes for queriers of other graph schemas |
98
+ | `CPGError` | base exception; `NodeNotFoundError`, `EdgeNotFoundError`, `TopFileNotFoundError` extend it |
99
+
100
+ Full API: [docs/design-cpg.md](docs/design-cpg.md), [docs/design-storage.md](docs/design-storage.md), [docs/design-querier.md](docs/design-querier.md).
101
+
102
+ ## Contributing
103
+
104
+ Development setup and checks: [docs/impl.md](docs/impl.md).
105
+
106
+ ## Documentation
107
+
108
+ - [docs/concept.md](docs/concept.md) — problem, scope, core concepts and usage scenarios.
109
+ - [docs/model.md](docs/model.md) — graph invariants and the CSV and JSON file mappings.
110
+ - [docs/design-storage.md](docs/design-storage.md) — `Storage` and JSON persistence.
111
+ - [docs/design-querier.md](docs/design-querier.md) — querier base classes, traversal semantics and exceptions.
112
+ - [docs/design-cpg.md](docs/design-cpg.md) — `CpgGraph`, `CpgNode`, `CpgEdge` and the CSV loader.
113
+
114
+ ## For Agents
115
+
116
+ Agent-consumable documentation index at [`docs/llms.txt`](docs/llms.txt) (llmstxt.org format).
117
+
118
+ ## License
119
+
120
+ [MIT](LICENSE)
cpg2py-1.2.3/README.md ADDED
@@ -0,0 +1,95 @@
1
+ # cpg2py
2
+
3
+ [![PyPI](https://img.shields.io/pypi/v/cpg2py)](https://pypi.org/project/cpg2py/)
4
+ [![Python](https://img.shields.io/pypi/pyversions/cpg2py)](https://pypi.org/project/cpg2py/)
5
+ [![License](https://img.shields.io/github/license/samhsu-dev/cpg2py)](LICENSE)
6
+ [![Last commit](https://img.shields.io/github/last-commit/samhsu-dev/cpg2py)](https://github.com/samhsu-dev/cpg2py)
7
+ [![Repo size](https://img.shields.io/github/repo-size/samhsu-dev/cpg2py)](https://github.com/samhsu-dev/cpg2py)
8
+
9
+ > **cpg2py**: [code property graph](docs/glossary-graph.md#code-property-graph-cpg) (CPG) to Python.
10
+
11
+ Load [Joern](https://joern.io/) code property graph CSV exports into Python and query nodes, edges and traversals.
12
+
13
+ ## Install
14
+
15
+ Prerequisites: Python 3.8 or later, and either [uv](https://docs.astral.sh/uv/) or pip.
16
+
17
+ ```bash
18
+ uv add cpg2py
19
+ pip install cpg2py
20
+ ```
21
+
22
+ ## Usage
23
+
24
+ Tab-separated Joern export, `nodes.csv` and `rels.csv`. The edge file names its columns `start`, `end`, `type`, or `start:str`, `end:str`, `type:str`:
25
+
26
+ ```text
27
+ id:int name type flags:string_array lineno:int
28
+ 1 f.php File TOPLEVEL_FILE 1
29
+ 2 main AST_FUNC_DECL 3
30
+ 3 x AST_VAR 4
31
+ ```
32
+
33
+ ```text
34
+ start end type var
35
+ 1 2 PARENT_OF
36
+ 2 3 PARENT_OF
37
+ 3 2 FLOWS_TO x
38
+ ```
39
+
40
+ ```python
41
+ from pathlib import Path
42
+
43
+ from cpg2py import cpg_graph
44
+
45
+ graph = cpg_graph(Path("nodes.csv"), Path("rels.csv"))
46
+ func = graph.node("2")
47
+ print(func.name, func.line_num)
48
+ print([child.name for child in graph.children(func)])
49
+ print([node.id for node in graph.flow_to(graph.node("3"))])
50
+ print(graph.topfile_node("3").name)
51
+ ```
52
+
53
+ ```text
54
+ main 3
55
+ ['x']
56
+ ['2']
57
+ f.php
58
+ ```
59
+
60
+ ## API
61
+
62
+ All names are imported from `cpg2py`.
63
+
64
+ | Name | Signature or role |
65
+ |------|-------------------|
66
+ | `cpg_graph` | `cpg_graph(node_csv: Path, edge_csv: Path, verbose: bool = False) -> CpgGraph` — loads a Joern CSV export |
67
+ | `storage_from_json` | `storage_from_json(path: Path \| str) -> Storage` — loads a graph saved by `Storage.save_json` |
68
+ | `CpgGraph` | `CpgGraph(target: Storage)` — `node`, `edge`, `nodes`, `first_node`, `edges`, `succ`, `prev`, `children`, `parent`, `flow_to`, `flow_from`, `descendants`, `ancestors`, `topfile_node` |
69
+ | `CpgNode` | node view — `id`, `code`, `label`, `flags`, `line_num`, `children_num`, `func_id`, `class_name`, `namespace`, `name`, `end_num`, `comment`, `type` |
70
+ | `CpgEdge` | edge view — `id`, `start`, `end`, `type`, `var`, `from_nid`, `to_nid`, `edge_type` |
71
+ | `Storage` | `Storage()` — in-memory directed multigraph with node and edge properties; `save_json`, `load_json` |
72
+ | `AbcGraphQuerier`, `AbcNodeQuerier`, `AbcEdgeQuerier` | base classes for queriers of other graph schemas |
73
+ | `CPGError` | base exception; `NodeNotFoundError`, `EdgeNotFoundError`, `TopFileNotFoundError` extend it |
74
+
75
+ Full API: [docs/design-cpg.md](docs/design-cpg.md), [docs/design-storage.md](docs/design-storage.md), [docs/design-querier.md](docs/design-querier.md).
76
+
77
+ ## Contributing
78
+
79
+ Development setup and checks: [docs/impl.md](docs/impl.md).
80
+
81
+ ## Documentation
82
+
83
+ - [docs/concept.md](docs/concept.md) — problem, scope, core concepts and usage scenarios.
84
+ - [docs/model.md](docs/model.md) — graph invariants and the CSV and JSON file mappings.
85
+ - [docs/design-storage.md](docs/design-storage.md) — `Storage` and JSON persistence.
86
+ - [docs/design-querier.md](docs/design-querier.md) — querier base classes, traversal semantics and exceptions.
87
+ - [docs/design-cpg.md](docs/design-cpg.md) — `CpgGraph`, `CpgNode`, `CpgEdge` and the CSV loader.
88
+
89
+ ## For Agents
90
+
91
+ Agent-consumable documentation index at [`docs/llms.txt`](docs/llms.txt) (llmstxt.org format).
92
+
93
+ ## License
94
+
95
+ [MIT](LICENSE)
@@ -0,0 +1,96 @@
1
+ [build-system]
2
+ requires = ["uv_build>=0.9.0,<0.14"]
3
+ build-backend = "uv_build"
4
+
5
+ [project]
6
+ name = "cpg2py"
7
+ version = "1.2.3"
8
+ description = "A graph-based data structure designed for querying CSV files in Joern format in Python"
9
+ readme = "README.md"
10
+ license = "MIT"
11
+ license-files = ["LICENSE"]
12
+ keywords = [
13
+ "Joern",
14
+ "CPG",
15
+ "Graph",
16
+ "CSV",
17
+ ]
18
+ dependencies = []
19
+ requires-python = ">=3.8"
20
+ classifiers = [
21
+ "Development Status :: 4 - Beta",
22
+ "Intended Audience :: Developers",
23
+ "Programming Language :: Python :: 3",
24
+ "Programming Language :: Python :: 3.8",
25
+ "Programming Language :: Python :: 3.9",
26
+ "Programming Language :: Python :: 3.10",
27
+ "Programming Language :: Python :: 3.11",
28
+ "Programming Language :: Python :: 3.12",
29
+ "Programming Language :: Python :: 3.13",
30
+ "Topic :: Software Development :: Libraries :: Python Modules",
31
+ ]
32
+
33
+ [[project.authors]]
34
+ name = "samhsu-dev"
35
+ email = "yxu166@jhu.edu"
36
+
37
+ [project.urls]
38
+ Homepage = "https://github.com/samhsu-dev/cpg2py"
39
+ Repository = "https://github.com/samhsu-dev/cpg2py"
40
+ Documentation = "https://github.com/samhsu-dev/cpg2py"
41
+
42
+ [dependency-groups]
43
+ dev = [
44
+ "mypy>=1.14",
45
+ "pytest>=8.3",
46
+ "pytest-cov>=5.0",
47
+ "ruff>=0.15",
48
+ ]
49
+
50
+ [tool.pytest.ini_options]
51
+ testpaths = ["tests"]
52
+ addopts = [
53
+ "--import-mode=importlib",
54
+ "--strict-markers",
55
+ ]
56
+ filterwarnings = [
57
+ "error",
58
+ "ignore::DeprecationWarning",
59
+ ]
60
+
61
+ [tool.coverage.run]
62
+ branch = true
63
+ source_pkgs = ["cpg2py"]
64
+
65
+ [tool.coverage.report]
66
+ show_missing = true
67
+ fail_under = 90
68
+
69
+ [tool.mypy]
70
+ strict = true
71
+ files = ["src"]
72
+
73
+ [tool.ruff]
74
+ line-length = 88
75
+
76
+ [tool.ruff.lint]
77
+ select = [
78
+ "E",
79
+ "W",
80
+ "F",
81
+ "I",
82
+ "N",
83
+ "UP",
84
+ "B",
85
+ "C4",
86
+ "SIM",
87
+ "PLC2701",
88
+ ]
89
+ preview = true
90
+ explicit-preview-rules = true
91
+
92
+ [tool.ruff.lint.pycodestyle]
93
+ max-doc-length = 72
94
+
95
+ [tool.ruff.lint.per-file-ignores]
96
+ "**/tests/**" = ["PLC2701"]
@@ -0,0 +1,73 @@
1
+ [build-system]
2
+ requires = ["uv_build>=0.9.0,<0.14"]
3
+ build-backend = "uv_build"
4
+
5
+ [project]
6
+ name = "cpg2py"
7
+ version = "1.2.3"
8
+ description = "A graph-based data structure designed for querying CSV files in Joern format in Python"
9
+ readme = "README.md"
10
+ authors = [
11
+ { name = "samhsu-dev", email = "yxu166@jhu.edu" }
12
+ ]
13
+ license = "MIT"
14
+ license-files = ["LICENSE"]
15
+ keywords = ["Joern", "CPG", "Graph", "CSV"]
16
+ dependencies = []
17
+ requires-python = ">=3.8"
18
+ classifiers = [
19
+ "Development Status :: 4 - Beta",
20
+ "Intended Audience :: Developers",
21
+ "Programming Language :: Python :: 3",
22
+ "Programming Language :: Python :: 3.8",
23
+ "Programming Language :: Python :: 3.9",
24
+ "Programming Language :: Python :: 3.10",
25
+ "Programming Language :: Python :: 3.11",
26
+ "Programming Language :: Python :: 3.12",
27
+ "Programming Language :: Python :: 3.13",
28
+ "Topic :: Software Development :: Libraries :: Python Modules",
29
+ ]
30
+
31
+ [project.urls]
32
+ Homepage = "https://github.com/samhsu-dev/cpg2py"
33
+ Repository = "https://github.com/samhsu-dev/cpg2py"
34
+ Documentation = "https://github.com/samhsu-dev/cpg2py"
35
+
36
+ [dependency-groups]
37
+ dev = [
38
+ "mypy>=1.14",
39
+ "pytest>=8.3",
40
+ "pytest-cov>=5.0",
41
+ "ruff>=0.15",
42
+ ]
43
+
44
+ [tool.pytest.ini_options]
45
+ testpaths = ["tests"]
46
+ addopts = ["--import-mode=importlib", "--strict-markers"]
47
+ filterwarnings = ["error", "ignore::DeprecationWarning"]
48
+
49
+ [tool.coverage.run]
50
+ branch = true
51
+ source_pkgs = ["cpg2py"]
52
+
53
+ [tool.coverage.report]
54
+ show_missing = true
55
+ fail_under = 90
56
+
57
+ [tool.mypy]
58
+ strict = true
59
+ files = ["src"]
60
+
61
+ [tool.ruff]
62
+ line-length = 88
63
+
64
+ [tool.ruff.lint]
65
+ select = ["E", "W", "F", "I", "N", "UP", "B", "C4", "SIM", "PLC2701"]
66
+ preview = true
67
+ explicit-preview-rules = true
68
+
69
+ [tool.ruff.lint.pycodestyle]
70
+ max-doc-length = 72
71
+
72
+ [tool.ruff.lint.per-file-ignores]
73
+ "**/tests/**" = ["PLC2701"]
@@ -0,0 +1,29 @@
1
+ """Query code property graphs held in an in-memory multigraph."""
2
+
3
+ from __future__ import annotations
4
+
5
+ __all__ = [
6
+ "cpg_graph",
7
+ "storage_from_json",
8
+ "CpgGraph",
9
+ "CpgNode",
10
+ "CpgEdge",
11
+ "AbcGraphQuerier",
12
+ "AbcNodeQuerier",
13
+ "AbcEdgeQuerier",
14
+ "Storage",
15
+ "CPGError",
16
+ "NodeNotFoundError",
17
+ "EdgeNotFoundError",
18
+ "TopFileNotFoundError",
19
+ ]
20
+
21
+ from ._abc import AbcEdgeQuerier, AbcGraphQuerier, AbcNodeQuerier, Storage
22
+ from ._cpg import CpgEdge, CpgGraph, CpgNode
23
+ from ._exceptions import (
24
+ CPGError,
25
+ EdgeNotFoundError,
26
+ NodeNotFoundError,
27
+ TopFileNotFoundError,
28
+ )
29
+ from ._loaders import cpg_graph, storage_from_json
@@ -1,3 +1,5 @@
1
+ from __future__ import annotations
2
+
1
3
  from .edge import AbcEdgeQuerier
2
4
  from .graph import AbcGraphQuerier
3
5
  from .node import AbcNodeQuerier
@@ -1,20 +1,27 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  import abc
4
- from typing import Any, Dict, Optional, Tuple
4
+ from typing import Any
5
5
 
6
6
  from .._exceptions import EdgeNotFoundError
7
7
  from .storage import Storage
8
8
 
9
9
 
10
- class AbcEdgeQuerier(abc.ABC):
11
- """
12
- Abstract base class for edge property access, queries, and updates.
10
+ # B024: subclasses need not override any method, so none is abstract.
11
+ class AbcEdgeQuerier(abc.ABC): # noqa: B024
12
+ """Base class for edge property access, queries, and updates.
13
+
14
+ Attributes:
15
+ edge_id: Identifier (from_nid, to_nid, edge_type) of the edge;
16
+ the constructor checks that the storage contains it.
17
+ from_nid: Source node identifier.
18
+ to_nid: Target node identifier.
19
+ edge_type: Edge type string.
20
+ properties: Property dictionary of the edge, or None if absent.
13
21
  """
14
22
 
15
23
  def __init__(self, graph: Storage, f_nid: str, t_nid: str, e_type: str) -> None:
16
- """
17
- Initializes edge querier and validates edge existence.
24
+ """Initialize edge querier and validates edge existence.
18
25
 
19
26
  Args:
20
27
  graph: Storage instance containing the graph.
@@ -26,40 +33,37 @@ class AbcEdgeQuerier(abc.ABC):
26
33
  EdgeNotFoundError: If edge does not exist in the graph.
27
34
  """
28
35
  self.__graph: Storage = graph
29
- self.__edge_id: Tuple[str, str, str] = (str(f_nid), str(t_nid), str(e_type))
36
+ self.__edge_id: tuple[str, str, str] = (str(f_nid), str(t_nid), str(e_type))
30
37
  if not graph.contains_edge(self.__edge_id):
31
38
  raise EdgeNotFoundError(f_nid, t_nid, e_type)
32
39
 
33
40
  @property
34
- def edge_id(self) -> Tuple[str, str, str]:
35
- """
36
- Returns the edge identifier tuple (from_nid, to_nid, edge_type).
37
- """
41
+ def edge_id(self) -> tuple[str, str, str]:
42
+ """Return the edge identifier (from_nid, to_nid, edge_type)."""
38
43
  return self.__edge_id
39
44
 
40
45
  @property
41
46
  def from_nid(self) -> str:
42
- """Returns the source node identifier."""
47
+ """Return the source node identifier."""
43
48
  return self.__edge_id[0]
44
49
 
45
50
  @property
46
51
  def to_nid(self) -> str:
47
- """Returns the target node identifier."""
52
+ """Return the target node identifier."""
48
53
  return self.__edge_id[1]
49
54
 
50
55
  @property
51
56
  def edge_type(self) -> str:
52
- """Returns the edge type string."""
57
+ """Return the edge type string."""
53
58
  return self.__edge_id[2]
54
59
 
55
60
  @property
56
- def properties(self) -> Optional[Dict[str, Any]]:
57
- """Returns all edge properties dictionary, or None if not found."""
61
+ def properties(self) -> dict[str, Any] | None:
62
+ """Return the edge property dictionary, or None if absent."""
58
63
  return self.__graph.get_edge_props(self.__edge_id)
59
64
 
60
- def get_property(self, *prop_names: str) -> Optional[Any]:
61
- """
62
- Returns first found property value trying multiple name alternatives.
65
+ def get_property(self, *prop_names: str) -> Any | None:
66
+ """Return the first non-None value of the given property names.
63
67
 
64
68
  Args:
65
69
  prop_names: Property name alternatives to try.
@@ -67,12 +71,13 @@ class AbcEdgeQuerier(abc.ABC):
67
71
  Returns:
68
72
  First found value, or None if none found.
69
73
  """
70
- prop_values = (self.__graph.get_edge_prop(self.__edge_id, p_name) for p_name in prop_names)
74
+ prop_values = (
75
+ self.__graph.get_edge_prop(self.__edge_id, p_name) for p_name in prop_names
76
+ )
71
77
  return next((value for value in prop_values if value is not None), None)
72
78
 
73
79
  def set_property(self, key: str, value: Any) -> bool:
74
- """
75
- Sets single edge property value.
80
+ """Set single edge property value.
76
81
 
77
82
  Args:
78
83
  key: Property key.
@@ -83,14 +88,14 @@ class AbcEdgeQuerier(abc.ABC):
83
88
  """
84
89
  return self.__graph.set_edge_prop(self.__edge_id, key, value)
85
90
 
86
- def set_properties(self, props: Dict[str, Any]) -> bool:
87
- """
88
- Updates multiple edge properties at once.
91
+ def set_properties(self, props: dict[str, Any]) -> bool:
92
+ """Update multiple edge properties at once.
89
93
 
90
94
  Args:
91
95
  props: Dictionary of property key-value pairs.
92
96
 
93
97
  Returns:
94
- True if properties were updated, False if edge does not exist.
98
+ True if the properties were updated, False if the edge
99
+ does not exist.
95
100
  """
96
101
  return self.__graph.set_edge_props(self.__edge_id, props)