From a385e872733be4a0a6969abede237cca7b349e3e Mon Sep 17 00:00:00 2001 From: Taus Date: Mon, 21 Nov 2022 14:29:39 +0000 Subject: [PATCH 1/3] Python: Add change note for module resolution Also adapts the version-specific tests to support results specific to Python 2 (though at the moment there are no such tests). --- .../2022-11-21-module-resolution-rewrite.md | 5 +++++ .../import-resolution/importflow.ql | 17 ++++++++++------- 2 files changed, 15 insertions(+), 7 deletions(-) create mode 100644 python/ql/lib/change-notes/2022-11-21-module-resolution-rewrite.md diff --git a/python/ql/lib/change-notes/2022-11-21-module-resolution-rewrite.md b/python/ql/lib/change-notes/2022-11-21-module-resolution-rewrite.md new file mode 100644 index 00000000000..32484ffed56 --- /dev/null +++ b/python/ql/lib/change-notes/2022-11-21-module-resolution-rewrite.md @@ -0,0 +1,5 @@ +--- + category: minorAnalysis +--- + * The data-flow library has been rewritten to no longer rely on the points-to analysis in order to + resolve references to modules. This should result in more results for data-flow queries. diff --git a/python/ql/test/experimental/import-resolution/importflow.ql b/python/ql/test/experimental/import-resolution/importflow.ql index 6160560a3ee..875fb947901 100644 --- a/python/ql/test/experimental/import-resolution/importflow.ql +++ b/python/ql/test/experimental/import-resolution/importflow.ql @@ -93,26 +93,29 @@ class ResolutionTest extends InlineExpectationsTest { } } -class ResolutionTest3 extends InlineExpectationsTest { - ResolutionTest3() { this = "ResolutionTest3" } +class VersionSpecificResolutionTest extends InlineExpectationsTest { + VersionSpecificResolutionTest() { this = "VersionSpecificResolutionTest" } - override string getARelevantTag() { result = "prints3" and major_version() = 3 } + override string getARelevantTag() { result = getTagForVersion(_) } + + private string getTagForVersion(int version) { + result = "prints" + version and + version = major_version() + } override predicate hasActualResult(Location location, string element, string tag, string value) { ( exists(DataFlow::PathNode source, DataFlow::PathNode sink, ImportConfiguration config | config.hasFlowPath(source, sink) and - sink.getNode().(VersionGuardedNode).getVersion() = 3 and - tag = "prints3" and + tag = getTagForVersion(sink.getNode().(VersionGuardedNode).getVersion()) and location = sink.getNode().getLocation() and value = source.getNode().(SourceString).getContents() and element = sink.getNode().toString() ) or exists(ModuleRef ref | - ref.(VersionGuardedNode).getVersion() = 3 and ref instanceof CheckArgument and - tag = "prints3" and + tag = getTagForVersion(ref.(VersionGuardedNode).getVersion()) and location = ref.getLocation() and value = "\"\"" and element = ref.toString() From f12e15b46b0679fae1465620788d5fa3797933f2 Mon Sep 17 00:00:00 2001 From: Taus Date: Mon, 21 Nov 2022 15:23:13 +0000 Subject: [PATCH 2/3] Python: Fix implicit `this` warnings --- .../test/experimental/import-resolution/importflow.ql | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/python/ql/test/experimental/import-resolution/importflow.ql b/python/ql/test/experimental/import-resolution/importflow.ql index 875fb947901..e6e51afa963 100644 --- a/python/ql/test/experimental/import-resolution/importflow.ql +++ b/python/ql/test/experimental/import-resolution/importflow.ql @@ -93,16 +93,16 @@ class ResolutionTest extends InlineExpectationsTest { } } +private string getTagForVersion(int version) { + result = "prints" + version and + version = major_version() +} + class VersionSpecificResolutionTest extends InlineExpectationsTest { VersionSpecificResolutionTest() { this = "VersionSpecificResolutionTest" } override string getARelevantTag() { result = getTagForVersion(_) } - private string getTagForVersion(int version) { - result = "prints" + version and - version = major_version() - } - override predicate hasActualResult(Location location, string element, string tag, string value) { ( exists(DataFlow::PathNode source, DataFlow::PathNode sink, ImportConfiguration config | From 18be30d1774ab7a84452da1306f69941f2ea3b6b Mon Sep 17 00:00:00 2001 From: Taus Date: Tue, 22 Nov 2022 13:46:45 +0100 Subject: [PATCH 3/3] Python: Apply suggestion from review Co-authored-by: Rasmus Wriedt Larsen --- .../ql/lib/change-notes/2022-11-21-module-resolution-rewrite.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/ql/lib/change-notes/2022-11-21-module-resolution-rewrite.md b/python/ql/lib/change-notes/2022-11-21-module-resolution-rewrite.md index 32484ffed56..fa04c07e9d5 100644 --- a/python/ql/lib/change-notes/2022-11-21-module-resolution-rewrite.md +++ b/python/ql/lib/change-notes/2022-11-21-module-resolution-rewrite.md @@ -2,4 +2,4 @@ category: minorAnalysis --- * The data-flow library has been rewritten to no longer rely on the points-to analysis in order to - resolve references to modules. This should result in more results for data-flow queries. + resolve references to modules. Improvements in the module resolution can lead to more results.