This commit is contained in:
Rasmus Wriedt Larsen 2020-01-27 15:53:28 +01:00
Родитель 816a8d1f9e
Коммит 647b9cdcb0
1 изменённых файлов: 18 добавлений и 15 удалений

Просмотреть файл

@ -10,22 +10,25 @@
* @precision medium
* @id py/import-of-mutable-attribute
*/
import python
import semmle.python.filters.Tests
from ImportMember im, ModuleObject m, AttrNode store_attr, string name
where im.getModule().(ImportExpr).getImportedModuleName() = m.getName() and
im.getName() = name and
/* Modification must be in a function, so it can occur during lifetime of the import value */
store_attr.getScope() instanceof Function and
/* variable resulting from import must have a long lifetime */
not im.getScope() instanceof Function and
store_attr.isStore() and
store_attr.getObject(name).refersTo(m) and
/* Import not in same module as modification. */
not im.getEnclosingModule() = store_attr.getScope().getEnclosingModule() and
/* Modification is not in a test */
not store_attr.getScope().getScope*() instanceof TestScope
select im, "Importing the value of '" + name + "' from $@ means that any change made to $@ will be not be observed locally.",
m, "module " + m.getName(), store_attr, m.getName() + "." + store_attr.getName()
where
im.getModule().(ImportExpr).getImportedModuleName() = m.getName() and
im.getName() = name and
/* Modification must be in a function, so it can occur during lifetime of the import value */
store_attr.getScope() instanceof Function and
/* variable resulting from import must have a long lifetime */
not im.getScope() instanceof Function and
store_attr.isStore() and
store_attr.getObject(name).refersTo(m) and
/* Import not in same module as modification. */
not im.getEnclosingModule() = store_attr.getScope().getEnclosingModule() and
/* Modification is not in a test */
not store_attr.getScope().getScope*() instanceof TestScope
select im,
"Importing the value of '" + name +
"' from $@ means that any change made to $@ will be not be observed locally.", m,
"module " + m.getName(), store_attr, m.getName() + "." + store_attr.getName()