Skip to content

Update refactoring-python-code.md #8385

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 26, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 0 additions & 23 deletions docs/python/refactoring-python-code.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,29 +44,6 @@ Visual Studio provides several commands for automatically transforming and clean
:::image type="content" source="media/vs-2022/code-refactor-rename-1.png" alt-text="Screenshot of Rename prompt for new identifer name.":::
::: moniker-end

## Extract method

::: moniker range="<=vs-2019"

1. Select the lines of code or the expression to extract into a separate method.
1. Select the **Edit** > **Refactor** > **Extract method** menu command or press **Ctrl**+**R** > **M**.
1. In the dialog that appears, enter a new method name, indicate where to extract it to, and select any closure variables. Variables not selected for closure are turned into method arguments:
:::image type="content" source="media/code-refactor-extract-method-1.png" alt-text="Screenshot of Extract method dialog.":::

1. Select **OK**, and the code is modified.
:::image type="content" source="media/code-refactor-extract-method-2.png" alt-text="Screenshot showing the effect of extracting a method.":::
::: moniker-end
::: moniker range=">=vs-2022"

1. Select the lines of code or the expression to extract into a separate method.
1. When you place the caret on code sample, Visual Studio provides a smart tag (the wrench icon to the left of the code).
1. In the dialog that appears, select **Extract** for closure to be turned into method arguments:
:::image type="content" source="media/vs-2022/code-refactor-extract-method-1.png" alt-text="Screenshot of Extract method dialog.":::

1. Select **OK** and the code is modified.
:::image type="content" source="media/vs-2022/code-refactor-extract-method-2.png" alt-text="Screenshot of Effects of extracting a method.":::
::: moniker-end

## Add import

When you place the caret on an identifier that lacks type information, Visual Studio provides a smart tag (the light bulb icon to the left of the code) whose commands add the necessary `import` or `from ... import` statement.
Expand Down