Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit aba3ac7

Browse files
committed
Python: Modernise py/uninitialized-local-variable
1 parent 697a006 commit aba3ac7

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

python/ql/src/Variables/UninitializedLocal.ql

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,11 @@ predicate uninitialized_local(NameNode use) {
3030
predicate explicitly_guarded(NameNode u) {
3131
exists(Try t |
3232
t.getBody().contains(u.getNode()) and
33-
t.getAHandler().getType().refersTo(theNameErrorType())
33+
t.getAHandler().getType().pointsTo(ClassValue::nameError())
3434
)
3535
}
3636

3737

3838
from NameNode u
3939
where uninitialized_local(u) and not explicitly_guarded(u)
4040
select u.getNode(), "Local variable '" + u.getId() + "' may be used before it is initialized."
41-
42-

python/ql/src/semmle/python/objects/ObjectAPI.qll

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,4 +675,9 @@ module ClassValue {
675675
result = TBuiltinClassObject(Builtin::special("NoneType"))
676676
}
677677

678+
/** Get the `ClassValue` for the `NameError` class. */
679+
ClassValue nameError() {
680+
result = TBuiltinClassObject(Builtin::builtin("NameError"))
681+
}
682+
678683
}

0 commit comments

Comments
 (0)