Commit a0b94ff
committed
fix(pycg): canonicalize the builtins module spelling on PyCG edges (#132)
PyCG spells the builtins module `<builtin>`; Jedi spells it `builtins`.
Nothing normalized the two, so `_home_external_symbols` minted a separate
`can://.../@external/<module>/<name>` home per spelling and one builtin ended
up with two identities. Measured on the `requests` fixture at -a 2: 29 ids
under `<builtin>/` against 14 under `builtins/`, with 12 names present under
both (len, isinstance, getattr, sorted, ...).
Two things follow from that. A consumer asking "who calls len" gets two
disjoint answers, neither complete. And provenance can never merge for a
builtin: `merge_edges` coalesces on (src, dst), so differing dst ids keep the
two backends' edges apart -- in the same run 198 non-builtin edges do carry
`prov: ["jedi", "pycg"]`, while builtins are structurally excluded from it.
Canonicalization happens at `build_call_graph_edges`' single exit, so every
shard strategy is covered, and before `merge_edges` runs in core.py -- doing it
at id-minting time would leave two already-merged edges with identical
endpoints and split provenance, moving the symptom rather than removing it.
Endpoints that collide once rewritten are coalesced with summed weight and
unioned provenance, matching merge_edges' semantics. That coalescing is done
locally rather than through `_coalesce_edges`, which raises on its duplicate
branch (#133).
PyCG only ever emits the bare `<builtin>` module, so an exact-match alias
suffices; the dotted forms (`builtins.str`, `builtins.dict`) are Jedi's and are
already canonical.1 parent 6f02581 commit a0b94ff
2 files changed
Lines changed: 95 additions & 0 deletions
File tree
- codeanalyzer/semantic_analysis/pycg
- test
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
88 | 88 | | |
89 | 89 | | |
90 | 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 | + | |
91 | 129 | | |
92 | 130 | | |
93 | 131 | | |
| |||
1110 | 1148 | | |
1111 | 1149 | | |
1112 | 1150 | | |
| 1151 | + | |
1113 | 1152 | | |
1114 | 1153 | | |
1115 | 1154 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 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 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
0 commit comments