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.
This commit is contained in:
Taus
2025-11-26 17:01:50 +00:00
parent cd1619b43e
commit c75329d7b7
5 changed files with 2 additions and 10 deletions

View File

@@ -34,6 +34,7 @@ import semmle.python.types.Exceptions
import semmle.python.types.Properties import semmle.python.types.Properties
import semmle.python.types.Descriptors import semmle.python.types.Descriptors
import semmle.python.SelfAttribute import semmle.python.SelfAttribute
import semmle.python.Metrics
/** /**
* An extension of `ControlFlowNode` that provides points-to predicates. * An extension of `ControlFlowNode` that provides points-to predicates.

View File

@@ -14,7 +14,7 @@ import semmle.python.Patterns
import semmle.python.Keywords import semmle.python.Keywords
import semmle.python.Comprehensions import semmle.python.Comprehensions
import semmle.python.Flow import semmle.python.Flow
import semmle.python.Metrics private import semmle.python.Metrics
import semmle.python.Constants import semmle.python.Constants
import semmle.python.Scope import semmle.python.Scope
import semmle.python.Comment import semmle.python.Comment

View File

@@ -147,9 +147,6 @@ class Class extends Class_, Scope, AstNode {
/** Gets a base of this class definition. */ /** Gets a base of this class definition. */
Expr getABase() { result = this.getParent().getABase() } Expr getABase() { result = this.getParent().getABase() }
/** Gets the metrics for this class */
ClassMetrics getMetrics() { result = this }
/** /**
* Gets the qualified name for this class. * Gets the qualified name for this class.
* Should return the same name as the `__qualname__` attribute on classes in Python 3. * Should return the same name as the `__qualname__` attribute on classes in Python 3.

View File

@@ -84,9 +84,6 @@ class Function extends Function_, Scope, AstNode {
/** Gets the name used to define this function */ /** Gets the name used to define this function */
override string getName() { result = Function_.super.getName() } 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. * 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. * Note that generator and async functions are not procedures as they return generators and coroutines respectively.

View File

@@ -86,9 +86,6 @@ class Module extends Module_, Scope, AstNode {
result = this.getName().regexpReplaceAll("\\.[^.]*$", "") result = this.getName().regexpReplaceAll("\\.[^.]*$", "")
} }
/** Gets the metrics for this module */
ModuleMetrics getMetrics() { result = this }
string getAnImportedModuleName() { string getAnImportedModuleName() {
exists(Import i | i.getEnclosingModule() = this | result = i.getAnImportedModuleName()) exists(Import i | i.getEnclosingModule() = this | result = i.getAnImportedModuleName())
or or