mirror of
https://github.com/github/codeql.git
synced 2025-12-19 02:13:17 +01:00
Python: Modernise py/uninitialized-local-variable
This commit is contained in:
@@ -30,7 +30,7 @@ predicate uninitialized_local(NameNode use) {
|
||||
predicate explicitly_guarded(NameNode u) {
|
||||
exists(Try t |
|
||||
t.getBody().contains(u.getNode()) and
|
||||
t.getAHandler().getType().refersTo(theNameErrorType())
|
||||
t.getAHandler().getType().pointsTo(ClassValue::nameError())
|
||||
)
|
||||
}
|
||||
|
||||
@@ -38,5 +38,3 @@ predicate explicitly_guarded(NameNode u) {
|
||||
from NameNode u
|
||||
where uninitialized_local(u) and not explicitly_guarded(u)
|
||||
select u.getNode(), "Local variable '" + u.getId() + "' may be used before it is initialized."
|
||||
|
||||
|
||||
|
||||
@@ -675,4 +675,9 @@ module ClassValue {
|
||||
result = TBuiltinClassObject(Builtin::special("NoneType"))
|
||||
}
|
||||
|
||||
/** Get the `ClassValue` for the `NameError` class. */
|
||||
ClassValue nameError() {
|
||||
result = TBuiltinClassObject(Builtin::builtin("NameError"))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user