Class UsesImport

java.lang.Object
org.openrewrite.Recipe
org.openrewrite.python.search.UsesImport
All Implemented Interfaces:
Cloneable

public class UsesImport extends org.openrewrite.Recipe
Match Python source files that import a given module, by the as-written import syntax rather than by type attribution.

This is the host-evaluable counterpart of the Python uses_import(...) precondition helper. It exists because HasType (the uses_type gate) cannot reliably gate import-migration recipes on Python: the type checker canonicalizes aliases (so from typing import List resolves to list and never to typing.List), removed symbols (e.g. from base64 import encodestring) get no attribution at all, and Python imports never reach TypesInUse in the first place. Reading the import path off Py.MultiImport sidesteps all of that.

The match is a deliberate superset (module, submodule, or parent module), which is what a precondition wants: over-matching merely runs the gated visitor, while under-matching would skip a file the recipe should change.

  • Nested Class Summary

    Nested classes/interfaces inherited from class org.openrewrite.Recipe

    org.openrewrite.Recipe.Builder, org.openrewrite.Recipe.DelegatingRecipe
  • Field Summary

    Fields inherited from class org.openrewrite.Recipe

    contributors, examples, PANIC
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
     
    org.openrewrite.TreeVisitor<?,org.openrewrite.ExecutionContext>
     

    Methods inherited from class org.openrewrite.Recipe

    addDataTable, aggregateDataTableDescriptors, builder, buildRecipeList, causesAnotherCycle, clone, createRecipeDescriptor, equals, getContributors, getDataTableDescriptors, getDescription, getDescriptor, getDisplayName, getEstimatedEffortPerOccurrence, getExamples, getInstanceName, getJacksonPolymorphicTypeTag, getMaintainers, getName, getRecipeList, getTags, hashCode, maxCycles, noop, onComplete, run, run, run, setContributors, setExamples, validate, validate, validateAll, validateAll, withOptions

    Methods inherited from class java.lang.Object

    finalize, getClass, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • UsesImport

      public UsesImport()
  • Method Details

    • getInstanceNameSuffix

      public String getInstanceNameSuffix()
      Overrides:
      getInstanceNameSuffix in class org.openrewrite.Recipe
    • getVisitor

      public org.openrewrite.TreeVisitor<?,org.openrewrite.ExecutionContext> getVisitor()
      Overrides:
      getVisitor in class org.openrewrite.Recipe