Skip to content

Commit 96d5703

Browse files
committed
Python: Remove use of deprecated methods
1 parent e6425bb commit 96d5703

File tree

22 files changed

+41
-45
lines changed

22 files changed

+41
-45
lines changed

python/ql/src/Statements/ModificationOfLocals.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Object aFunctionLocalsObject() {
2525

2626

2727
predicate modification_of_locals(ControlFlowNode f) {
28-
f.(SubscriptNode).getValue().refersTo(aFunctionLocalsObject()) and (f.isStore() or f.isDelete())
28+
f.(SubscriptNode).getObject().refersTo(aFunctionLocalsObject()) and (f.isStore() or f.isDelete())
2929
or
3030
exists(string mname, AttrNode attr |
3131
attr = f.(CallNode).getFunction() and

python/ql/src/Statements/RedundantAssignment.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ predicate same_attribute(Attribute a1, Attribute a2) {
6565

6666
int pyflakes_commented_line(File file) {
6767
exists(Comment c | c.getText().toLowerCase().matches("%pyflakes%") |
68-
c.getLocation().hasLocationInfo(file.getName(), result, _, _, _)
68+
c.getLocation().hasLocationInfo(file.getAbsolutePath(), result, _, _, _)
6969
)
7070
}
7171

python/ql/src/Variables/UndefinedExport.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ predicate mutates_globals(ModuleValue m) {
3030
|
3131
exists(AttrNode attr | attr.getObject() = globals)
3232
or
33-
exists(SubscriptNode sub | sub.getValue() = globals and sub.isStore())
33+
exists(SubscriptNode sub | sub.getObject() = globals and sub.isStore())
3434
)
3535
or
3636
exists(Value enum_convert, ClassValue enum_class |

python/ql/src/analysis/Sanity.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,8 @@ predicate file_sanity(string clsname, string problem, string what) {
206206
exists(File file, Folder folder |
207207
clsname = file.getAQlClass() and
208208
problem = "has same name as a folder" and
209-
what = file.getName() and
210-
what = folder.getName()
209+
what = file.getAbsolutePath() and
210+
what = folder.getAbsolutePath()
211211
) or
212212
exists(Container f |
213213
clsname = f.getAQlClass() and

python/ql/src/external/DuplicateBlock.ql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ predicate sorted_by_location(DuplicateBlock x, DuplicateBlock y) {
2121
if x.sourceFile() = y.sourceFile() then
2222
x.sourceStartLine() < y.sourceStartLine()
2323
else
24-
x.sourceFile().getName() < y.sourceFile().getName()
24+
x.sourceFile().getAbsolutePath() < y.sourceFile().getAbsolutePath()
2525
}
2626

2727
from DuplicateBlock d, DuplicateBlock other
2828
where d.sourceLines() > 10 and
2929
other.getEquivalenceClass() = d.getEquivalenceClass() and
3030
sorted_by_location(other, d)
31-
select
32-
d,
31+
select
32+
d,
3333
"Duplicate code: " + d.sourceLines() + " lines are duplicated at " +
3434
other.sourceFile().getShortName() + ":" + other.sourceStartLine().toString()

python/ql/src/semmle/python/Files.qll

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ class File extends Container {
1010

1111
/** DEPRECATED: Use `getAbsolutePath` instead. */
1212
deprecated override string getName() {
13-
files(this, result, _, _, _)
13+
result = this.getAbsolutePath()
1414
}
1515

1616
/** DEPRECATED: Use `getAbsolutePath` instead. */
1717
deprecated string getFullName() {
18-
result = getName()
18+
result = this.getAbsolutePath()
1919
}
2020

2121
predicate hasLocationInfo(string filepath, int bl, int bc, int el, int ec) {
22-
this.getName() = filepath and bl = 0 and bc = 0 and el = 0 and ec = 0
22+
this.getAbsolutePath() = filepath and bl = 0 and bc = 0 and el = 0 and ec = 0
2323
}
2424

2525
/** Whether this file is a source code file. */
@@ -98,7 +98,7 @@ class Folder extends Container {
9898

9999
/** DEPRECATED: Use `getAbsolutePath` instead. */
100100
deprecated override string getName() {
101-
folders(this, result, _)
101+
result = this.getAbsolutePath()
102102
}
103103

104104
/** DEPRECATED: Use `getBaseName` instead. */
@@ -107,7 +107,7 @@ class Folder extends Container {
107107
}
108108

109109
predicate hasLocationInfo(string filepath, int bl, int bc, int el, int ec) {
110-
this.getName() = filepath and bl = 0 and bc = 0 and el = 0 and ec = 0
110+
this.getAbsolutePath() = filepath and bl = 0 and bc = 0 and el = 0 and ec = 0
111111
}
112112

113113
override string getAbsolutePath() {
@@ -427,11 +427,11 @@ class Location extends @location {
427427
}
428428

429429
string toString() {
430-
result = this.getPath().getName() + ":" + this.getStartLine().toString()
430+
result = this.getPath().getAbsolutePath() + ":" + this.getStartLine().toString()
431431
}
432432

433433
predicate hasLocationInfo(string filepath, int bl, int bc, int el, int ec) {
434-
exists(File f | f.getName() = filepath |
434+
exists(File f | f.getAbsolutePath() = filepath |
435435
locations_default(this, f, bl, bc, el, ec)
436436
or
437437
exists(Module m | m.getFile() = f |
@@ -445,7 +445,7 @@ class Location extends @location {
445445
class Line extends @py_line {
446446

447447
predicate hasLocationInfo(string filepath, int bl, int bc, int el, int ec) {
448-
exists(Module m | m.getFile().getName() = filepath and
448+
exists(Module m | m.getFile().getAbsolutePath() = filepath and
449449
el = bl and bc = 1 and
450450
py_line_lengths(this, m, bl, ec))
451451
}

python/ql/src/semmle/python/pointsto/PointsTo.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ cached module PointsToInternal {
612612
exists(ControlFlowNode sys_modules_flow, ControlFlowNode n, ControlFlowNode mod |
613613
/* Use previous points-to here to avoid slowing down the recursion too much */
614614
exists(SubscriptNode sub |
615-
sub.getValue() = sys_modules_flow and
615+
sub.getObject() = sys_modules_flow and
616616
pointsTo(sys_modules_flow, _, ObjectInternal::sysModules(), _) and
617617
sub.getIndex() = n and
618618
n.getNode().(StrConst).getText() = name and

python/ql/test/2/library-tests/PointsTo/import_time/Pruned.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ from ControlFlowNode f, Location l, Context c
77

88
where not PointsToInternal::reachableBlock(f.getBasicBlock(), c) and c.isImport() and
99
(f.getNode() instanceof FunctionExpr or f.getNode() instanceof ClassExpr) and
10-
l = f.getLocation() and l.getFile().getName().matches("%test.py")
11-
select l.getStartLine()
10+
l = f.getLocation() and l.getFile().getShortName() = "test.py"
11+
select l.getStartLine()

python/ql/test/2/library-tests/PointsTo/origin_uniqueness/Origin.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import python
22

33
string short_loc(Location l) {
4-
result = l.getFile().getShortName() + ":" + l.getStartLine()
4+
result = l.getFile().getShortName() + ":" + l.getStartLine()
55
}
66

77
from ControlFlowNode use, Object obj, ControlFlowNode orig, int line
88

99
where use.refersTo(obj, orig) and
10-
use.getLocation().getFile().getName().matches("%test.py") and
10+
use.getLocation().getFile().getShortName() = "test.py" and
1111
line = use.getLocation().getStartLine() and
1212
not line = 0
1313

python/ql/test/3/library-tests/PointsTo/import_time/Pruned.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ import python
33
import semmle.python.pointsto.PointsTo
44

55
from ControlFlowNode f, Location l
6-
where not PointsToInternal::reachableBlock(f.getBasicBlock(), _) and l = f.getLocation() and l.getFile().getName().matches("%test.py")
7-
select l.getStartLine()
6+
where not PointsToInternal::reachableBlock(f.getBasicBlock(), _) and l = f.getLocation() and l.getFile().getShortName() = "test.py"
7+
select l.getStartLine()

0 commit comments

Comments
 (0)