Skip to content

Commit ea30598

Browse files
committed
Python: Split dotted names more efficiently
1 parent c59b5c9 commit ea30598

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

python/ql/src/semmle/python/ApiGraphs.qll

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -319,12 +319,11 @@ module API {
319319
* For instance, `prefix_member("foo.bar", "baz", "foo.bar.baz")` would hold.
320320
*/
321321
private predicate prefix_member(TApiNode base, string member, TApiNode sub) {
322-
exists(string base_str, string sub_str |
323-
base = MkModuleImport(base_str) and
322+
exists(string sub_str, string regexp |
323+
regexp = "(.+)[.]([^.]+)" and
324+
base = MkModuleImport(sub_str.regexpCapture(regexp, 1)) and
325+
member = sub_str.regexpCapture(regexp, 2) and
324326
sub = MkModuleImport(sub_str)
325-
|
326-
base_str + "." + member = sub_str and
327-
not member.matches("%.%")
328327
)
329328
}
330329

0 commit comments

Comments
 (0)