Skip to content

Python: Remove points-to from metrics library#21344

Open
tausbn wants to merge 3 commits intomainfrom
tausbn/python-remove-points-to-from-metrics-libraries
Open

Python: Remove points-to from metrics library#21344
tausbn wants to merge 3 commits intomainfrom
tausbn/python-remove-points-to-from-metrics-libraries

Conversation

@tausbn
Copy link
Contributor

@tausbn tausbn commented Feb 18, 2026

In the recent introduction of LegacyPointsTo many metrics queries ended up getting an import of that module, even though they did not depend on points-to.

This PR rectifies that situation by splitting the points-to-dependant functionality off (moving it into LegacyPointsTo), leaving behind a completely benign Metrics.qll (which is now imported by default).

@tausbn tausbn force-pushed the tausbn/python-remove-points-to-from-metrics-libraries branch 3 times, most recently from 00b60b1 to 01fe34f Compare February 19, 2026 12:10
Moves the classes/predicates that _actually_ depend on points-to to the
`LegacyPointsTo` module, leaving behind a module that contains all of
the metrics-related stuff (line counts, nesting depth, etc.) that don't
need points-to to be evaluated.

Consequently, `Metrics` is now no longer a private import in
`python.qll`.
The ones that no longer require points-to no longer import
`LegacyPointsTo`. The ones that do use the specific
`...MetricsWithPointsTo` classes that are applicable.
@tausbn tausbn force-pushed the tausbn/python-remove-points-to-from-metrics-libraries branch from 01fe34f to 07099f1 Compare February 19, 2026 12:32
@tausbn tausbn marked this pull request as ready for review February 19, 2026 15:07
@tausbn tausbn requested a review from a team as a code owner February 19, 2026 15:07
Copilot AI review requested due to automatic review settings February 19, 2026 15:07
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request removes points-to analysis dependencies from the Python metrics library by splitting functionality into two separate modules. The base Metrics.qll now only contains metrics that don't require points-to analysis, while new *MetricsWithPointsTo classes in LegacyPointsTo.qll provide the points-to-dependent functionality like cyclomatic complexity and coupling metrics.

Changes:

  • Moved points-to-dependent metrics (cyclomatic complexity, coupling, inheritance depth) from Metrics.qll to new *MetricsWithPointsTo classes in LegacyPointsTo.qll
  • Updated queries that use points-to-dependent metrics to use the new *MetricsWithPointsTo types
  • Removed unnecessary LegacyPointsTo imports from queries that only use basic metrics
  • Made Metrics module publicly available in python.qll since it no longer requires points-to

Reviewed changes

Copilot reviewed 32 out of 32 changed files in this pull request and generated no comments.

Show a summary per file
File Description
python/ql/lib/semmle/python/Metrics.qll Removed all points-to-dependent functionality (cyclomatic complexity, coupling, inheritance depth methods)
python/ql/lib/LegacyPointsTo.qll Added FunctionMetricsWithPointsTo, ClassMetricsWithPointsTo, and ModuleMetricsWithPointsTo classes with moved functionality
python/ql/lib/python.qll Changed Metrics import from private to public since it no longer depends on points-to
python/ql/src/Metrics/CyclomaticComplexity.ql Updated to use FunctionMetricsWithPointsTo instead of FunctionMetrics
python/ql/src/Metrics/ClassAfferentCoupling.ql Updated to use ClassMetricsWithPointsTo instead of ClassMetrics
python/ql/src/Metrics/ClassEfferentCoupling.ql Updated to use ClassMetricsWithPointsTo instead of ClassMetrics
python/ql/src/Metrics/ModuleAfferentCoupling.ql Updated to use ModuleMetricsWithPointsTo instead of ModuleMetrics
python/ql/src/Metrics/ModuleEfferentCoupling.ql Updated to use ModuleMetricsWithPointsTo instead of ModuleMetrics
python/ql/src/Functions/OverlyComplexDelMethod.ql Updated to use FunctionMetricsWithPointsTo instead of FunctionMetrics
python/ql/test/library-tests/ControlFlow/general/Cyclo.ql Updated to use FunctionMetricsWithPointsTo instead of FunctionMetrics
python/ql/src/Summary/LinesOfCode.ql Removed unnecessary LegacyPointsTo import
python/ql/src/Summary/LinesOfUserCode.ql Removed unnecessary LegacyPointsTo import
python/ql/src/Metrics/*.ql (13 files) Removed unnecessary LegacyPointsTo imports from queries using only basic metrics
python/ql/lib/change-notes/2026-02-18-remove-points-to-from-metrics.md Added change note documenting the API changes
Comments suppressed due to low confidence (1)

python/ql/lib/change-notes/2026-02-18-remove-points-to-from-metrics.md:5

  • The phrase "must now remember to import" is awkward. It would be clearer to say "must import" instead.
- The `Metrics` library no longer contains code that depends on the points-to analysis. The removed functionality has instead been moved to the `LegacyPointsTo` module, to classes like `ModuleMetricsWithPointsTo` etc. If you depend on any of these classes, you must now remember to import `LegacyPointsTo`, and use the appropriate types in order to use the points-to-based functionality.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments