cogant.static
The cogant.static package runs static analysis on the ingested sources: AST parse, symbol extraction, type inference, import resolution, call-graph construction, and dataflow hints.
Package
cogant.static
COGANT static analysis pipeline: Python AST parsing and symbol extraction.
Provides tools for parsing Python source code, extracting symbols, resolving imports, building call graphs, inferring types, and analyzing data flow.
AssignmentDef
dataclass
Variable assignment from AST.
Source code in py/cogant/static/parser.py
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
annotation = None
class-attribute
instance-attribute
Type annotation if present.
line_num
instance-attribute
Line number of assignment.
metadata = field(default_factory=dict)
class-attribute
instance-attribute
Additional metadata.
parent_scope = None
class-attribute
instance-attribute
Scope containing assignment (module or function).
target_name
instance-attribute
Variable name being assigned.
value = None
class-attribute
instance-attribute
String representation of assigned value.
CallEdge
dataclass
A function/method call relationship.
Source code in py/cogant/static/calls.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | |
args = field(default_factory=list)
class-attribute
instance-attribute
Argument values as strings.
callee_id = None
class-attribute
instance-attribute
Symbol ID of called function (if resolved).
callee_name
instance-attribute
Name of called function/method.
caller_id
instance-attribute
Symbol ID of the calling function.
caller_name
instance-attribute
Name of calling function/method.
id
instance-attribute
Unique edge identifier.
is_method_call = False
class-attribute
instance-attribute
Whether this is a method call.
line_num = 0
class-attribute
instance-attribute
Line number of call.
metadata = field(default_factory=dict)
class-attribute
instance-attribute
Additional metadata.
receiver = None
class-attribute
instance-attribute
Object/module the method is called on.
source_file
instance-attribute
File containing the call.
CallGraphBuilder
Extract function and method calls from Python source.
Source code in py/cogant/static/calls.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | |
__init__(repo_root=None)
Initialize call graph builder.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repo_root
|
Path | None
|
Root path of repository. |
None
|
Source code in py/cogant/static/calls.py
57 58 59 60 61 62 63 64 65 | |
extract_calls_from_file(file_path)
Extract all function/method calls from a Python file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
Path
|
Path to Python file. |
required |
Returns:
| Type | Description |
|---|---|
list[CallEdge]
|
List of CallEdge for all calls found. |
Source code in py/cogant/static/calls.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | |
extract_calls_from_source(source, file_path)
Extract function/method calls from Python source code.
Module-level functions are reported first, then class methods, each
in source order. Every def and async def is visited once with
its own visitor, so same-named defs (a property getter and setter,
@overload variants) each contribute their own calls exactly once.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
str
|
Python source code. |
required |
file_path
|
Path
|
Path for reference. |
required |
Returns:
| Type | Description |
|---|---|
list[CallEdge]
|
List of CallEdge for all calls found. |
Source code in py/cogant/static/calls.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | |
ClassDef
dataclass
Class definition from AST.
Source code in py/cogant/static/parser.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | |
attributes = field(default_factory=list)
class-attribute
instance-attribute
Class attributes.
bases = field(default_factory=list)
class-attribute
instance-attribute
Base class names.
decorators = field(default_factory=list)
class-attribute
instance-attribute
List of decorator names.
docstring = None
class-attribute
instance-attribute
Class docstring.
line_end
instance-attribute
Ending line number.
line_start
instance-attribute
Starting line number.
metadata = field(default_factory=dict)
class-attribute
instance-attribute
Additional metadata.
methods = field(default_factory=list)
class-attribute
instance-attribute
Methods defined in class.
name
instance-attribute
Class name.
DataFlowAnalyzer
Analyze data flow: track variable reads, writes, and mutations.
Source code in py/cogant/static/dataflow.py
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 | |
__init__(repo_root=None)
Initialize data flow analyzer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repo_root
|
Path | None
|
Root path of repository. |
None
|
Source code in py/cogant/static/dataflow.py
170 171 172 173 174 175 176 177 | |
analyze_file(file_path)
Analyze data flow in a Python file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
Path
|
Path to Python file. |
required |
Returns:
| Type | Description |
|---|---|
list[DataFlowEdge]
|
List of DataFlowEdge for data flow relationships. |
Source code in py/cogant/static/dataflow.py
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | |
analyze_source(source, file_path)
Analyze data flow in Python source code.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
str
|
Python source code. |
required |
file_path
|
Path
|
Path for reference. |
required |
Returns:
| Type | Description |
|---|---|
list[DataFlowEdge]
|
List of DataFlowEdge for data flow relationships. |
Source code in py/cogant/static/dataflow.py
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 | |
build_flow_graph(file_path)
Build a data flow graph from a Python file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
Path
|
Path to Python file. |
required |
Returns:
| Type | Description |
|---|---|
DataFlowGraph
|
DataFlowGraph instance. |
Source code in py/cogant/static/dataflow.py
256 257 258 259 260 261 262 263 264 265 266 267 268 269 | |
build_flow_graph_from_source(source, file_path)
Build a data flow graph from source code.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
str
|
Python source code. |
required |
file_path
|
Path
|
Path for reference. |
required |
Returns:
| Type | Description |
|---|---|
DataFlowGraph
|
DataFlowGraph instance. |
Source code in py/cogant/static/dataflow.py
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 | |
DataFlowEdge
dataclass
A data flow relationship between symbols.
Source code in py/cogant/static/dataflow.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | |
context = 'module'
class-attribute
instance-attribute
Context (module, function name, class.method).
edge_type
instance-attribute
Edge type: reads, writes, mutates, depends_on.
file_path
instance-attribute
Source file path.
id
instance-attribute
Unique edge identifier.
line_num
instance-attribute
Line number where flow occurs.
metadata = field(default_factory=dict)
class-attribute
instance-attribute
Additional metadata.
source_symbol
instance-attribute
Source symbol ID or name.
target_symbol
instance-attribute
Target symbol ID or name.
FunctionDef
dataclass
Function definition from AST.
Source code in py/cogant/static/parser.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | |
args = field(default_factory=list)
class-attribute
instance-attribute
Parameter names.
decorators = field(default_factory=list)
class-attribute
instance-attribute
List of decorator names.
docstring = None
class-attribute
instance-attribute
Function docstring.
is_async = False
class-attribute
instance-attribute
Whether function is async.
line_end
instance-attribute
Ending line number.
line_start
instance-attribute
Starting line number.
metadata = field(default_factory=dict)
class-attribute
instance-attribute
Additional metadata.
name
instance-attribute
Function name.
parent = None
class-attribute
instance-attribute
Parent class name if method.
return_annotation = None
class-attribute
instance-attribute
Return type annotation if present.
ImportAnalyzer
Analyze and resolve import statements.
Source code in py/cogant/static/imports.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 | |
__init__(repo_root=None)
Initialize import analyzer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repo_root
|
Path | None
|
Root path of repository for local import resolution.
Absolute imports ( |
None
|
Source code in py/cogant/static/imports.py
59 60 61 62 63 64 65 66 67 68 69 70 71 | |
analyze_file(file_path)
Analyze imports in a Python file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
Path
|
Path to Python file. |
required |
Returns:
| Type | Description |
|---|---|
list[ImportEdge]
|
List of ImportEdge for all imports found. |
Source code in py/cogant/static/imports.py
73 74 75 76 77 78 79 80 81 82 83 | |
analyze_source(source, file_path)
Analyze imports in Python source code.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
str
|
Python source code. |
required |
file_path
|
Path
|
Path for reference. |
required |
Returns:
| Type | Description |
|---|---|
list[ImportEdge]
|
List of ImportEdge for all imports found. |
Source code in py/cogant/static/imports.py
85 86 87 88 89 90 91 92 93 94 95 96 | |
ImportDef
dataclass
Import statement from AST.
Source code in py/cogant/static/parser.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | |
is_relative
instance-attribute
Whether import is relative.
line_num = 0
class-attribute
instance-attribute
Line number of import.
metadata = field(default_factory=dict)
class-attribute
instance-attribute
Additional metadata.
module_name
instance-attribute
Module being imported.
names = field(default_factory=list)
class-attribute
instance-attribute
Specific names imported (for 'from X import Y').
ImportEdge
dataclass
An import relationship between modules.
Source code in py/cogant/static/imports.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | |
id
instance-attribute
Unique edge identifier.
imported_names = field(default_factory=list)
class-attribute
instance-attribute
Specific names imported (for 'from X import Y').
is_local
instance-attribute
Whether module is local to repository.
is_relative
instance-attribute
Whether import is relative.
is_stdlib
instance-attribute
Whether module is from Python standard library.
is_third_party
instance-attribute
Whether module is from third-party package.
line_num = 0
class-attribute
instance-attribute
Line number of import statement.
metadata = field(default_factory=dict)
class-attribute
instance-attribute
Additional metadata.
module_name
instance-attribute
Module being imported.
resolved_file = None
class-attribute
instance-attribute
Resolved file path if found.
resolved_module = None
class-attribute
instance-attribute
Resolved module name.
source_file
instance-attribute
File containing the import.
PythonASTParser
Parse Python source files and extract AST information.
Source code in py/cogant/static/parser.py
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 | |
parse_file(file_path)
Parse a Python source file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
Path
|
Path to Python file. |
required |
Returns:
| Type | Description |
|---|---|
PythonModule
|
PythonModule with extracted AST information. |
Source code in py/cogant/static/parser.py
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 | |
parse_string(source, file_path=None)
Parse Python source from string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
str
|
Python source code as string. |
required |
file_path
|
Path | None
|
Optional file path for reference. |
None
|
Returns:
| Type | Description |
|---|---|
PythonModule
|
PythonModule with extracted AST information. |
Source code in py/cogant/static/parser.py
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 | |
PythonModule
dataclass
Complete parsed Python module.
Source code in py/cogant/static/parser.py
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | |
assignments = field(default_factory=list)
class-attribute
instance-attribute
Module-level assignments.
classes = field(default_factory=list)
class-attribute
instance-attribute
Module-level classes.
docstring = None
class-attribute
instance-attribute
Module docstring.
errors = field(default_factory=list)
class-attribute
instance-attribute
Parse errors encountered.
file_path
instance-attribute
Source file path.
functions = field(default_factory=list)
class-attribute
instance-attribute
Module-level functions.
imports = field(default_factory=list)
class-attribute
instance-attribute
Import statements.
SymbolExtractor
Extract symbols from parsed Python modules.
Source code in py/cogant/static/symbols.py
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 | |
__init__(repo_root=None)
Initialize symbol extractor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repo_root
|
Path | None
|
Optional repository root for qualified name generation. |
None
|
Source code in py/cogant/static/symbols.py
125 126 127 128 129 130 131 132 | |
extract_from_file(file_path)
Extract symbols from a Python file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
Path
|
Path to Python file. |
required |
Returns:
| Type | Description |
|---|---|
SymbolTable
|
SymbolTable with extracted symbols. |
Source code in py/cogant/static/symbols.py
134 135 136 137 138 139 140 141 142 143 144 145 146 147 | |
extract_from_source(source, file_path)
Extract symbols from Python source code.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
str
|
Python source code. |
required |
file_path
|
Path
|
Path for reference and qualified names. |
required |
Returns:
| Type | Description |
|---|---|
SymbolTable
|
SymbolTable with extracted symbols. |
Source code in py/cogant/static/symbols.py
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | |
SymbolInfo
dataclass
Information about a code symbol.
Source code in py/cogant/static/symbols.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | |
decorators = field(default_factory=list)
class-attribute
instance-attribute
List of decorators.
doc = None
class-attribute
instance-attribute
Docstring if available.
file_path
instance-attribute
Source file path.
id
instance-attribute
Unique stable identifier.
kind
instance-attribute
Symbol kind (function, class, method, variable).
line_end
instance-attribute
Ending line number.
line_start
instance-attribute
Starting line number.
metadata = field(default_factory=dict)
class-attribute
instance-attribute
Language-specific metadata.
name
instance-attribute
Short name (e.g., 'foo').
parent_id = None
class-attribute
instance-attribute
ID of parent symbol if nested.
qualified_name
instance-attribute
Fully qualified name (e.g., 'module.Class.method').
scope
instance-attribute
Scope context (module, class_name, function_name).
SymbolTable
dataclass
Collection of extracted symbols.
Source code in py/cogant/static/symbols.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
errors = field(default_factory=list)
class-attribute
instance-attribute
Errors encountered during extraction.
file_path
instance-attribute
Source file path.
symbols = field(default_factory=list)
class-attribute
instance-attribute
Extracted symbols.
get_entry_points()
Get symbols callable from outside (public functions and public methods).
Returns:
| Type | Description |
|---|---|
list[SymbolInfo]
|
List of public functions and methods. |
Source code in py/cogant/static/symbols.py
79 80 81 82 83 84 85 86 87 88 89 | |
get_public_api()
Get all public (non-underscore) symbols.
Returns:
| Type | Description |
|---|---|
list[SymbolInfo]
|
List of public symbols. |
Source code in py/cogant/static/symbols.py
71 72 73 74 75 76 77 | |
to_json()
Serialize symbol table to JSON.
Returns:
| Type | Description |
|---|---|
str
|
JSON string representation. |
Source code in py/cogant/static/symbols.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
TypeInferencer
Infer and extract type information from Python code.
Source code in py/cogant/static/types.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 | |
__init__(repo_root=None)
Initialize type inferencer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repo_root
|
Path | None
|
Root path of repository. |
None
|
Source code in py/cogant/static/types.py
59 60 61 62 63 64 65 66 67 | |
infer_types_from_file(file_path)
Infer types for all symbols in a Python file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
Path
|
Path to Python file. |
required |
Returns:
| Type | Description |
|---|---|
list[TypeInfo]
|
List of TypeInfo for symbols with inferred types. |
Source code in py/cogant/static/types.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | |
infer_types_from_source(source, file_path)
Infer types from Python source code.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
str
|
Python source code. |
required |
file_path
|
Path
|
Path for reference. |
required |
Returns:
| Type | Description |
|---|---|
list[TypeInfo]
|
List of TypeInfo for symbols with inferred types. |
Source code in py/cogant/static/types.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | |
TypeInfo
dataclass
Type information for a symbol.
Source code in py/cogant/static/types.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | |
annotation = None
class-attribute
instance-attribute
Explicit type annotation.
confidence = 0.0
class-attribute
instance-attribute
Confidence score (0.0 to 1.0).
inferred_type = None
class-attribute
instance-attribute
Inferred type.
is_mutable = True
class-attribute
instance-attribute
Whether the symbol is mutable.
metadata = field(default_factory=dict)
class-attribute
instance-attribute
Additional type metadata.
symbol_id
instance-attribute
Symbol ID.
symbol_kind
instance-attribute
Symbol kind (function, variable, parameter, attribute).
symbol_name
instance-attribute
Symbol name.
Parser
cogant.static.parser
Python AST parsing for extracting code structure.
AssignmentDef
dataclass
Variable assignment from AST.
Source code in py/cogant/static/parser.py
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
annotation = None
class-attribute
instance-attribute
Type annotation if present.
line_num
instance-attribute
Line number of assignment.
metadata = field(default_factory=dict)
class-attribute
instance-attribute
Additional metadata.
parent_scope = None
class-attribute
instance-attribute
Scope containing assignment (module or function).
target_name
instance-attribute
Variable name being assigned.
value = None
class-attribute
instance-attribute
String representation of assigned value.
ClassDef
dataclass
Class definition from AST.
Source code in py/cogant/static/parser.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | |
attributes = field(default_factory=list)
class-attribute
instance-attribute
Class attributes.
bases = field(default_factory=list)
class-attribute
instance-attribute
Base class names.
decorators = field(default_factory=list)
class-attribute
instance-attribute
List of decorator names.
docstring = None
class-attribute
instance-attribute
Class docstring.
line_end
instance-attribute
Ending line number.
line_start
instance-attribute
Starting line number.
metadata = field(default_factory=dict)
class-attribute
instance-attribute
Additional metadata.
methods = field(default_factory=list)
class-attribute
instance-attribute
Methods defined in class.
name
instance-attribute
Class name.
FunctionDef
dataclass
Function definition from AST.
Source code in py/cogant/static/parser.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | |
args = field(default_factory=list)
class-attribute
instance-attribute
Parameter names.
decorators = field(default_factory=list)
class-attribute
instance-attribute
List of decorator names.
docstring = None
class-attribute
instance-attribute
Function docstring.
is_async = False
class-attribute
instance-attribute
Whether function is async.
line_end
instance-attribute
Ending line number.
line_start
instance-attribute
Starting line number.
metadata = field(default_factory=dict)
class-attribute
instance-attribute
Additional metadata.
name
instance-attribute
Function name.
parent = None
class-attribute
instance-attribute
Parent class name if method.
return_annotation = None
class-attribute
instance-attribute
Return type annotation if present.
ImportDef
dataclass
Import statement from AST.
Source code in py/cogant/static/parser.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | |
is_relative
instance-attribute
Whether import is relative.
line_num = 0
class-attribute
instance-attribute
Line number of import.
metadata = field(default_factory=dict)
class-attribute
instance-attribute
Additional metadata.
module_name
instance-attribute
Module being imported.
names = field(default_factory=list)
class-attribute
instance-attribute
Specific names imported (for 'from X import Y').
PythonASTParser
Parse Python source files and extract AST information.
Source code in py/cogant/static/parser.py
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 | |
parse_file(file_path)
Parse a Python source file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
Path
|
Path to Python file. |
required |
Returns:
| Type | Description |
|---|---|
PythonModule
|
PythonModule with extracted AST information. |
Source code in py/cogant/static/parser.py
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 | |
parse_string(source, file_path=None)
Parse Python source from string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
str
|
Python source code as string. |
required |
file_path
|
Path | None
|
Optional file path for reference. |
None
|
Returns:
| Type | Description |
|---|---|
PythonModule
|
PythonModule with extracted AST information. |
Source code in py/cogant/static/parser.py
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 | |
PythonModule
dataclass
Complete parsed Python module.
Source code in py/cogant/static/parser.py
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | |
assignments = field(default_factory=list)
class-attribute
instance-attribute
Module-level assignments.
classes = field(default_factory=list)
class-attribute
instance-attribute
Module-level classes.
docstring = None
class-attribute
instance-attribute
Module docstring.
errors = field(default_factory=list)
class-attribute
instance-attribute
Parse errors encountered.
file_path
instance-attribute
Source file path.
functions = field(default_factory=list)
class-attribute
instance-attribute
Module-level functions.
imports = field(default_factory=list)
class-attribute
instance-attribute
Import statements.
Symbols
cogant.static.symbols
Symbol extraction: build symbol table with qualified names, types, and scopes.
SymbolExtractor
Extract symbols from parsed Python modules.
Source code in py/cogant/static/symbols.py
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 | |
__init__(repo_root=None)
Initialize symbol extractor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repo_root
|
Path | None
|
Optional repository root for qualified name generation. |
None
|
Source code in py/cogant/static/symbols.py
125 126 127 128 129 130 131 132 | |
extract_from_file(file_path)
Extract symbols from a Python file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
Path
|
Path to Python file. |
required |
Returns:
| Type | Description |
|---|---|
SymbolTable
|
SymbolTable with extracted symbols. |
Source code in py/cogant/static/symbols.py
134 135 136 137 138 139 140 141 142 143 144 145 146 147 | |
extract_from_source(source, file_path)
Extract symbols from Python source code.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
str
|
Python source code. |
required |
file_path
|
Path
|
Path for reference and qualified names. |
required |
Returns:
| Type | Description |
|---|---|
SymbolTable
|
SymbolTable with extracted symbols. |
Source code in py/cogant/static/symbols.py
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | |
SymbolInfo
dataclass
Information about a code symbol.
Source code in py/cogant/static/symbols.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | |
decorators = field(default_factory=list)
class-attribute
instance-attribute
List of decorators.
doc = None
class-attribute
instance-attribute
Docstring if available.
file_path
instance-attribute
Source file path.
id
instance-attribute
Unique stable identifier.
kind
instance-attribute
Symbol kind (function, class, method, variable).
line_end
instance-attribute
Ending line number.
line_start
instance-attribute
Starting line number.
metadata = field(default_factory=dict)
class-attribute
instance-attribute
Language-specific metadata.
name
instance-attribute
Short name (e.g., 'foo').
parent_id = None
class-attribute
instance-attribute
ID of parent symbol if nested.
qualified_name
instance-attribute
Fully qualified name (e.g., 'module.Class.method').
scope
instance-attribute
Scope context (module, class_name, function_name).
SymbolTable
dataclass
Collection of extracted symbols.
Source code in py/cogant/static/symbols.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
errors = field(default_factory=list)
class-attribute
instance-attribute
Errors encountered during extraction.
file_path
instance-attribute
Source file path.
symbols = field(default_factory=list)
class-attribute
instance-attribute
Extracted symbols.
get_entry_points()
Get symbols callable from outside (public functions and public methods).
Returns:
| Type | Description |
|---|---|
list[SymbolInfo]
|
List of public functions and methods. |
Source code in py/cogant/static/symbols.py
79 80 81 82 83 84 85 86 87 88 89 | |
get_public_api()
Get all public (non-underscore) symbols.
Returns:
| Type | Description |
|---|---|
list[SymbolInfo]
|
List of public symbols. |
Source code in py/cogant/static/symbols.py
71 72 73 74 75 76 77 | |
to_json()
Serialize symbol table to JSON.
Returns:
| Type | Description |
|---|---|
str
|
JSON string representation. |
Source code in py/cogant/static/symbols.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
Types
cogant.static.types
Type inference: extract type annotations and infer basic types.
This module walks Python source with the raw ast library (rather than
only the pre-parsed :class:~cogant.static.parser.PythonModule) so that it
can see argument annotations, class attribute annotations, and assignments
inside __init__. It produces :class:TypeInfo records suitable for
attaching to graph nodes.
The inferencer is intentionally conservative: explicit annotations get
confidence 1.0, literal-based heuristics get 0.7, and the simple
@property fallback gets 0.6. When no information is available the
symbol is skipped rather than being given a guessed type.
TypeInferencer
Infer and extract type information from Python code.
Source code in py/cogant/static/types.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 | |
__init__(repo_root=None)
Initialize type inferencer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repo_root
|
Path | None
|
Root path of repository. |
None
|
Source code in py/cogant/static/types.py
59 60 61 62 63 64 65 66 67 | |
infer_types_from_file(file_path)
Infer types for all symbols in a Python file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
Path
|
Path to Python file. |
required |
Returns:
| Type | Description |
|---|---|
list[TypeInfo]
|
List of TypeInfo for symbols with inferred types. |
Source code in py/cogant/static/types.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | |
infer_types_from_source(source, file_path)
Infer types from Python source code.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
str
|
Python source code. |
required |
file_path
|
Path
|
Path for reference. |
required |
Returns:
| Type | Description |
|---|---|
list[TypeInfo]
|
List of TypeInfo for symbols with inferred types. |
Source code in py/cogant/static/types.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | |
TypeInfo
dataclass
Type information for a symbol.
Source code in py/cogant/static/types.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | |
annotation = None
class-attribute
instance-attribute
Explicit type annotation.
confidence = 0.0
class-attribute
instance-attribute
Confidence score (0.0 to 1.0).
inferred_type = None
class-attribute
instance-attribute
Inferred type.
is_mutable = True
class-attribute
instance-attribute
Whether the symbol is mutable.
metadata = field(default_factory=dict)
class-attribute
instance-attribute
Additional type metadata.
symbol_id
instance-attribute
Symbol ID.
symbol_kind
instance-attribute
Symbol kind (function, variable, parameter, attribute).
symbol_name
instance-attribute
Symbol name.
Imports
cogant.static.imports
Import resolution and analysis: classify imports and build import graph.
ImportAnalyzer
Analyze and resolve import statements.
Source code in py/cogant/static/imports.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 | |
__init__(repo_root=None)
Initialize import analyzer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repo_root
|
Path | None
|
Root path of repository for local import resolution.
Absolute imports ( |
None
|
Source code in py/cogant/static/imports.py
59 60 61 62 63 64 65 66 67 68 69 70 71 | |
analyze_file(file_path)
Analyze imports in a Python file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
Path
|
Path to Python file. |
required |
Returns:
| Type | Description |
|---|---|
list[ImportEdge]
|
List of ImportEdge for all imports found. |
Source code in py/cogant/static/imports.py
73 74 75 76 77 78 79 80 81 82 83 | |
analyze_source(source, file_path)
Analyze imports in Python source code.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
str
|
Python source code. |
required |
file_path
|
Path
|
Path for reference. |
required |
Returns:
| Type | Description |
|---|---|
list[ImportEdge]
|
List of ImportEdge for all imports found. |
Source code in py/cogant/static/imports.py
85 86 87 88 89 90 91 92 93 94 95 96 | |
ImportEdge
dataclass
An import relationship between modules.
Source code in py/cogant/static/imports.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | |
id
instance-attribute
Unique edge identifier.
imported_names = field(default_factory=list)
class-attribute
instance-attribute
Specific names imported (for 'from X import Y').
is_local
instance-attribute
Whether module is local to repository.
is_relative
instance-attribute
Whether import is relative.
is_stdlib
instance-attribute
Whether module is from Python standard library.
is_third_party
instance-attribute
Whether module is from third-party package.
line_num = 0
class-attribute
instance-attribute
Line number of import statement.
metadata = field(default_factory=dict)
class-attribute
instance-attribute
Additional metadata.
module_name
instance-attribute
Module being imported.
resolved_file = None
class-attribute
instance-attribute
Resolved file path if found.
resolved_module = None
class-attribute
instance-attribute
Resolved module name.
source_file
instance-attribute
File containing the import.
Calls
cogant.static.calls
Call graph extraction: find function/method calls and build call relationships.
CallEdge
dataclass
A function/method call relationship.
Source code in py/cogant/static/calls.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | |
args = field(default_factory=list)
class-attribute
instance-attribute
Argument values as strings.
callee_id = None
class-attribute
instance-attribute
Symbol ID of called function (if resolved).
callee_name
instance-attribute
Name of called function/method.
caller_id
instance-attribute
Symbol ID of the calling function.
caller_name
instance-attribute
Name of calling function/method.
id
instance-attribute
Unique edge identifier.
is_method_call = False
class-attribute
instance-attribute
Whether this is a method call.
line_num = 0
class-attribute
instance-attribute
Line number of call.
metadata = field(default_factory=dict)
class-attribute
instance-attribute
Additional metadata.
receiver = None
class-attribute
instance-attribute
Object/module the method is called on.
source_file
instance-attribute
File containing the call.
CallExtractorVisitor
Bases: NodeVisitor
AST visitor to extract function/method calls.
Source code in py/cogant/static/calls.py
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 | |
__init__(file_path, function_name, scope, symbol_table)
Initialize call extractor visitor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
Path
|
Source file path. |
required |
function_name
|
str
|
Name of the function being analyzed. |
required |
scope
|
str
|
Scope context (module or class name). |
required |
symbol_table
|
Any
|
SymbolTable for callee resolution. |
required |
Source code in py/cogant/static/calls.py
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 | |
visit_Call(node)
Visit function call node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
Call
|
AST Call node. |
required |
Source code in py/cogant/static/calls.py
159 160 161 162 163 164 165 166 167 168 169 | |
CallGraphBuilder
Extract function and method calls from Python source.
Source code in py/cogant/static/calls.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | |
__init__(repo_root=None)
Initialize call graph builder.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repo_root
|
Path | None
|
Root path of repository. |
None
|
Source code in py/cogant/static/calls.py
57 58 59 60 61 62 63 64 65 | |
extract_calls_from_file(file_path)
Extract all function/method calls from a Python file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
Path
|
Path to Python file. |
required |
Returns:
| Type | Description |
|---|---|
list[CallEdge]
|
List of CallEdge for all calls found. |
Source code in py/cogant/static/calls.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | |
extract_calls_from_source(source, file_path)
Extract function/method calls from Python source code.
Module-level functions are reported first, then class methods, each
in source order. Every def and async def is visited once with
its own visitor, so same-named defs (a property getter and setter,
@overload variants) each contribute their own calls exactly once.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
str
|
Python source code. |
required |
file_path
|
Path
|
Path for reference. |
required |
Returns:
| Type | Description |
|---|---|
list[CallEdge]
|
List of CallEdge for all calls found. |
Source code in py/cogant/static/calls.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | |
Dataflow
cogant.static.dataflow
Data flow analysis: track variable reads/writes and build data flow edges.
This module extracts READ, WRITE, MUTATE, and DEPENDS_ON relationships from Python source. It drives several translation rules that need to know which symbols a function modifies or observes.
The analyzer works at two levels:
DataFlowAnalyzer— top-level orchestrator. Walks a parsed module and launches aDataFlowVisitorfor module-level code, every function body, and every method body.DataFlowVisitor— an :class:ast.NodeVisitorthat records reads/writes inside a single scope. It understands simple assignments, annotated assignments, augmented assignments, attribute writes, attribute reads, freeNameloads, function calls, and return statements.
All operations are resilient: malformed source or unexpected AST shapes are logged at debug level and skipped rather than aborting extraction.
DataFlowAnalyzer
Analyze data flow: track variable reads, writes, and mutations.
Source code in py/cogant/static/dataflow.py
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 | |
__init__(repo_root=None)
Initialize data flow analyzer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repo_root
|
Path | None
|
Root path of repository. |
None
|
Source code in py/cogant/static/dataflow.py
170 171 172 173 174 175 176 177 | |
analyze_file(file_path)
Analyze data flow in a Python file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
Path
|
Path to Python file. |
required |
Returns:
| Type | Description |
|---|---|
list[DataFlowEdge]
|
List of DataFlowEdge for data flow relationships. |
Source code in py/cogant/static/dataflow.py
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | |
analyze_source(source, file_path)
Analyze data flow in Python source code.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
str
|
Python source code. |
required |
file_path
|
Path
|
Path for reference. |
required |
Returns:
| Type | Description |
|---|---|
list[DataFlowEdge]
|
List of DataFlowEdge for data flow relationships. |
Source code in py/cogant/static/dataflow.py
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 | |
build_flow_graph(file_path)
Build a data flow graph from a Python file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
Path
|
Path to Python file. |
required |
Returns:
| Type | Description |
|---|---|
DataFlowGraph
|
DataFlowGraph instance. |
Source code in py/cogant/static/dataflow.py
256 257 258 259 260 261 262 263 264 265 266 267 268 269 | |
build_flow_graph_from_source(source, file_path)
Build a data flow graph from source code.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
str
|
Python source code. |
required |
file_path
|
Path
|
Path for reference. |
required |
Returns:
| Type | Description |
|---|---|
DataFlowGraph
|
DataFlowGraph instance. |
Source code in py/cogant/static/dataflow.py
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 | |
DataFlowEdge
dataclass
A data flow relationship between symbols.
Source code in py/cogant/static/dataflow.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | |
context = 'module'
class-attribute
instance-attribute
Context (module, function name, class.method).
edge_type
instance-attribute
Edge type: reads, writes, mutates, depends_on.
file_path
instance-attribute
Source file path.
id
instance-attribute
Unique edge identifier.
line_num
instance-attribute
Line number where flow occurs.
metadata = field(default_factory=dict)
class-attribute
instance-attribute
Additional metadata.
source_symbol
instance-attribute
Source symbol ID or name.
target_symbol
instance-attribute
Target symbol ID or name.
DataFlowGraph
dataclass
Directed graph of data flow relationships.
Source code in py/cogant/static/dataflow.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | |
edges = field(default_factory=list)
class-attribute
instance-attribute
List of data flow edges.
nodes = field(default_factory=set)
class-attribute
instance-attribute
Set of all node names.
add_edge(edge)
Add an edge to the graph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
edge
|
DataFlowEdge
|
DataFlowEdge to add. |
required |
Source code in py/cogant/static/dataflow.py
72 73 74 75 76 77 78 79 80 | |
find_sinks()
Find nodes with no outgoing data flow (final consumers).
Returns:
| Type | Description |
|---|---|
list[str]
|
List of sink node names. |
Source code in py/cogant/static/dataflow.py
91 92 93 94 95 96 97 98 | |
find_sources()
Find nodes with no incoming data flow (entry points).
Returns:
| Type | Description |
|---|---|
list[str]
|
List of source node names. |
Source code in py/cogant/static/dataflow.py
82 83 84 85 86 87 88 89 | |
get_taint_paths(source, sink)
Find all paths from source to sink node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
str
|
Source node name. |
required |
sink
|
str
|
Sink node name. |
required |
Returns:
| Type | Description |
|---|---|
list[list[str]]
|
List of paths (each path is a list of node names). |
Source code in py/cogant/static/dataflow.py
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 | |
to_dict()
Serialize graph to dictionary.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary representation of the graph. |
Source code in py/cogant/static/dataflow.py
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | |
DataFlowVisitor
Bases: NodeVisitor
AST visitor to extract data flow edges from one scope.
A visitor is scoped to one function, method, class body, or the module
body. It tracks which names have been written (assigned) and which have
been read, and emits DataFlowEdge instances describing each flow.
Handled node kinds:
ast.Assign— plain assignment; targets are WRITES, sources are READS from each RHS name.ast.AugAssign— augmented assignment (x += 1); target is both READ and MUTATED.ast.AnnAssign— annotated assignment (x: int = 5); target is a WRITE, RHS names are READS. Handlesx: intwithout a value too.ast.Attributein Store context — attribute writes (self.x = 1) produce a WRITE edge to the dotted name.ast.Attributein Load context — attribute reads produce a READ edge.ast.Namein Load context — a free-standing name read (e.g. a loop condition) produces a READ edge.ast.Call— argument names are READ; method calls onselfadditionally emit a MUTATES edge toself.<attr>if the callee is on an attribute (potential mutation).ast.Return— return value names are READ against the synthetic<return>target.
Source code in py/cogant/static/dataflow.py
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 | |
__init__(file_path, context, body)
Initialize data flow visitor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
Path
|
Source file path. |
required |
context
|
str
|
Context (function/method name or |
required |
body
|
list[stmt]
|
AST body nodes to analyze. |
required |
Source code in py/cogant/static/dataflow.py
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 | |
visit_AnnAssign(node)
Handle an annotated assignment (x: int = 5 or x: int).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
AnnAssign
|
AST AnnAssign node. |
required |
Source code in py/cogant/static/dataflow.py
382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 | |
visit_Assign(node)
Handle a plain assignment statement.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
Assign
|
AST Assign node. |
required |
Source code in py/cogant/static/dataflow.py
346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 | |
visit_Attribute(node)
Handle an Attribute access.
Stores (e.g., self.x = 1) are handled by :meth:visit_Assign;
this covers loads (return self.x).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
Attribute
|
AST Attribute node. |
required |
Source code in py/cogant/static/dataflow.py
549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 | |
visit_AugAssign(node)
Handle an augmented assignment (x += 1).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
AugAssign
|
AST AugAssign node. |
required |
Source code in py/cogant/static/dataflow.py
417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 | |
visit_Call(node)
Handle a function or method call.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
Call
|
AST Call node. |
required |
Source code in py/cogant/static/dataflow.py
481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 | |
visit_Name(node)
Handle a bare Name load (e.g., if x:).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
Name
|
AST Name node. |
required |
Source code in py/cogant/static/dataflow.py
532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 | |
visit_Return(node)
Handle a return statement.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
Return
|
AST Return node. |
required |
Source code in py/cogant/static/dataflow.py
463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 | |
Examples
The static parser, symbol extractor, type / import resolver, call-graph builder, and dataflow helpers are exercised by:
- Zoo:
examples/zoo/01_simple_state/— single-file target with one class and three methods (smallest static run). - Zoo:
examples/zoo/06_hierarchical/— multi-class hierarchy that exercises symbol resolution and call-graph edges. - Zoo:
examples/zoo/11_sensor_fusion/— multi-module imports + dataflow patterns. - Cookbook: Recipe 1: Scan your first Python project — runs the static stage end-to-end from the CLI.
- Cookbook: Recipe: Analyze a Flask app — six-module real-world target for symbol / import / call-graph stages.
- Tutorial: Tutorial 3: Flask walkthrough — narrative on the 98-node static output of the Flask fixture.