From c75329d7b740f7f6f46cf9c22f91b73d96550ca0 Mon Sep 17 00:00:00 2001 From: Taus Date: Wed, 26 Nov 2025 17:01:50 +0000 Subject: [PATCH] Python: Move metrics-related API to `LegacyPointsTo` module Gets rid of the `getMetrics` methods on the `Function`, `Class`, and `Module` classes. To access the metrics, one must first import the `LegacyPointsTo` module, and then either change the type to `{Function,Class,Module}Metrics` or cast to the appropriate type. --- python/ql/lib/LegacyPointsTo.qll | 1 + python/ql/lib/python.qll | 2 +- python/ql/lib/semmle/python/Class.qll | 3 --- python/ql/lib/semmle/python/Function.qll | 3 --- python/ql/lib/semmle/python/Module.qll | 3 --- 5 files changed, 2 insertions(+), 10 deletions(-) diff --git a/python/ql/lib/LegacyPointsTo.qll b/python/ql/lib/LegacyPointsTo.qll index 99b49a91986..c5821f3d009 100644 --- a/python/ql/lib/LegacyPointsTo.qll +++ b/python/ql/lib/LegacyPointsTo.qll @@ -34,6 +34,7 @@ import semmle.python.types.Exceptions import semmle.python.types.Properties import semmle.python.types.Descriptors import semmle.python.SelfAttribute +import semmle.python.Metrics /** * An extension of `ControlFlowNode` that provides points-to predicates. diff --git a/python/ql/lib/python.qll b/python/ql/lib/python.qll index d127e297dbb..54306408a33 100644 --- a/python/ql/lib/python.qll +++ b/python/ql/lib/python.qll @@ -14,7 +14,7 @@ import semmle.python.Patterns import semmle.python.Keywords import semmle.python.Comprehensions import semmle.python.Flow -import semmle.python.Metrics +private import semmle.python.Metrics import semmle.python.Constants import semmle.python.Scope import semmle.python.Comment diff --git a/python/ql/lib/semmle/python/Class.qll b/python/ql/lib/semmle/python/Class.qll index dd7da9ee041..19b81e86a12 100644 --- a/python/ql/lib/semmle/python/Class.qll +++ b/python/ql/lib/semmle/python/Class.qll @@ -147,9 +147,6 @@ class Class extends Class_, Scope, AstNode { /** Gets a base of this class definition. */ Expr getABase() { result = this.getParent().getABase() } - /** Gets the metrics for this class */ - ClassMetrics getMetrics() { result = this } - /** * Gets the qualified name for this class. * Should return the same name as the `__qualname__` attribute on classes in Python 3. diff --git a/python/ql/lib/semmle/python/Function.qll b/python/ql/lib/semmle/python/Function.qll index a5d122c3de7..e15d28d3a12 100644 --- a/python/ql/lib/semmle/python/Function.qll +++ b/python/ql/lib/semmle/python/Function.qll @@ -84,9 +84,6 @@ class Function extends Function_, Scope, AstNode { /** Gets the name used to define this function */ override string getName() { result = Function_.super.getName() } - /** Gets the metrics for this function */ - FunctionMetrics getMetrics() { result = this } - /** * Whether this function is a procedure, that is, it has no explicit return statement and always returns None. * Note that generator and async functions are not procedures as they return generators and coroutines respectively. diff --git a/python/ql/lib/semmle/python/Module.qll b/python/ql/lib/semmle/python/Module.qll index 666217874b7..f22f0d6fe39 100644 --- a/python/ql/lib/semmle/python/Module.qll +++ b/python/ql/lib/semmle/python/Module.qll @@ -86,9 +86,6 @@ class Module extends Module_, Scope, AstNode { result = this.getName().regexpReplaceAll("\\.[^.]*$", "") } - /** Gets the metrics for this module */ - ModuleMetrics getMetrics() { result = this } - string getAnImportedModuleName() { exists(Import i | i.getEnclosingModule() = this | result = i.getAnImportedModuleName()) or