Skip to main content
Moderne OnlyThis recipe is proprietary to Moderne and runs on the Moderne platform or CLI — it isn’t part of the open-source catalog. Available with a Moderne subscription.Contact Sales

Find Python types

Recipe IDorg.openrewrite.python.migrate.FindTypes
Artifactorg.openrewrite.recipe:rewrite-migrate-python

Find type references by name. Identifies classes matching a type pattern. In Python, all type definitions use the class keyword, covering regular classes, abstract base classes, protocols, enums, dataclasses, named tuples, typed dicts, and more.

Single recipePythonModerne Proprietary License
Try in PlatformTry this recipe in the Moderne platform. Not a user yet? You’ll get a no-setup demo environment, with nothing to install or configure.

Options

2 parameters
1 required1 optional
ParameterExampleTypeRequired
typeNameOrderedDictStringRequired
A type name used to find matching type references. Can be a simple class name (e.g., OrderedDict) or a module-qualified name (e.g., collections.OrderedDict). Simple names match against the class name only, while qualified names match against the full module path. Supports glob expressions. collections..* finds every type from every submodule of the collections module.
checkAssignabilityBooleanOptional
When enabled, find type references that are assignable to (i.e., subclasses of) the provided type.

Examples

python
ParameterValue
typeNameOrderedDict
checkAssignabilitynull
Before
from collections import OrderedDict
x = OrderedDict()
After
from collections import OrderedDict
x = /*~~>*/OrderedDict()

Usage

Run this recipe

In order to run Python recipes, you will need to use the Moderne CLI.

This recipe calls into other OpenRewrite packages as it runs, and the CLI needs every one of them in its marketplace. Once the CLI is installed, install all of the following:

RELEASE resolves to the newest release and LATEST to the newest build of any kind, including snapshots. Either one lets mod config recipes upgrade pull in later versions without editing this command; a pinned version stays where you put it.

Install the recipe packages
mod config recipes pip install openrewrite-migrate-python
mod config recipes jar install org.openrewrite.recipe:rewrite-migrate-python:RELEASE
mod config recipes jar install org.openrewrite:rewrite-python:RELEASE

Then, you can run the recipe via:

Run the recipe
mod run . --recipe org.openrewrite.python.migrate.FindTypes --recipe-option "typeName=OrderedDict"

Data tables

Type uses
org.openrewrite.java.table.TypeUses

The source code of matching type uses.

ColumnDescription
Source fileThe source file that the method call occurred in.
SourceThe source code of the type use.
Concrete typeThe concrete type in use, which may be a subtype of a searched type.
Source files that had results
org.openrewrite.table.SourcesFileResults

Source files that were modified by the recipe run.

ColumnDescription
Source path before the runThe source path of the file before the run. null when a source file was created during the run.
Source path after the runA recipe may modify the source path. This is the path after the run. null when a source file was deleted during the run.
Parent of the recipe that made changesIn a hierarchical recipe, the parent of the recipe that made a change. Empty if this is the root of a hierarchy or if the recipe is not hierarchical at all.
Recipe that made changesThe specific recipe that made a change.
Estimated time savingAn estimated effort that a developer to fix manually instead of using this recipe, in unit of seconds.
CycleThe recipe cycle in which the change was made.
Source files that had search results
org.openrewrite.table.SearchResults

Search results that were found during the recipe run.

ColumnDescription
Source path of search result before the runThe source path of the file with the search result markers present.
Source path of search result after run the runA recipe may modify the source path. This is the path after the run. null when a source file was deleted during the run.
ResultThe trimmed printed tree of the LST element that the marker is attached to.
DescriptionThe content of the description of the marker.
Recipe that added the search markerThe specific recipe that added the Search marker.
Source files that errored on a recipe
org.openrewrite.table.SourcesFileErrors

The details of all errors produced by a recipe run.

ColumnDescription
Source pathThe file that failed to parse.
Recipe that made changesThe specific recipe that made a change.
Stack traceThe stack trace of the failure.
Recipe performance
org.openrewrite.table.RecipeRunStats

Statistics used in analyzing the performance of recipes.

ColumnDescription
The recipeThe recipe whose stats are being measured both individually and cumulatively.
Source file countThe number of source files the recipe ran over.
Source file changed countThe number of source files which were changed in the recipe run. Includes files created, deleted, and edited.
Cumulative scanning time (ns)The total time spent across the scanning phase of this recipe.
Max scanning time (ns)The max time scanning any one source file.
Cumulative edit time (ns)The total time spent across the editing phase of this recipe.
Max edit time (ns)The max time editing any one source file.