No more Refactor > Move to File in Python?

Describe the Bug

Since moving to Anysphere Python, I’m unable to right click class or function names and “Refactor” > “Move to File” or “Move to New File”.

This is a very useful command for moving around classes and functions between files and having all the imports automatically updated, a task that is not great for LLMs.

Steps to Reproduce

Install Anysphere Python. Right click a function name. Click “Refactor”. It now says “No refactorings available”

Expected Behavior

It should provide two refactor options:

  1. Move to new file (creates a new file with all the appropriate imports)
  2. Move to file (just moves to an existing file)

Operating System

MacOS

Current Cursor Version (Menu → About Cursor → Copy)

Version: 1.1.3
VSCode Version: 1.96.2
Commit: 979ba33804ac150108481c14e0b5cb970bda3260
Date: 2025-06-15T06:35:49.230Z (17 hrs ago)
Electron: 34.5.1
Chromium: 132.0.6834.210
Node.js: 20.19.0
V8: 13.2.152.41-electron.0
OS: Darwin arm64 23.6.0

Does this stop you from using Cursor

No - Cursor works, but with this issue

7 Likes

Hi! Can you double check that a python interpreter is selected for your workspace, and that the python language server setter is none?

If you had settings configured in pylance, you’ll want to import them – there’s a pop-up when first installing the extension, and it’s also available in the command palette.

Could you also try reloading the window?

Hi @ravirahman

Thanks for looking into this. I followed your suggestions, but no luck.

  • Python interpreter selected (3.12.8, using the extension Python Envy by teticio to swap between python venvs managed by uv in my multi-project monorepo)
  • “python.languageServer”: “None” (in my defaultSettings.json. I don’t have this key in my user settings or workspace settings)
  • Cursor Pyright: Import Pylance Settings
  • Reload window

Still seeing “No refactorings available” when I right click on a classname and select “Refactor”.

I have the following python-related extensions installed:

  1. Python by Anysphere
  2. Ruff by charliermarsh
  3. Python by ms-python (required by Ruff)
  4. Python by teticio (I use this for managing multiple python environments in one workspace)

I’ve tried disabling each of them and still had the same problem. Is this an MS Pylance feature that is missing from Cursor Pyright?

In case this helps, here are all of my settings files with any mention of Python I can find:

.vscode/settings.json

{
    // Python settings
    "[python]": {
        "editor.formatOnSave": true,
        "editor.defaultFormatter": "charliermarsh.ruff",
        "editor.codeActionsOnSave": {
            "source.fixAll": "explicit",
            "source.organizeImports": "explicit"
        },
        "python.analysis.extraPaths": [
            "${workspaceFolder}/lib/src",
            "${workspaceFolder}/frontend/src",
            "${workspaceFolder}/backend/app"
        ],
    },

    // Let VS Code discover the Poetry environments
    "python.analysis.autoImportCompletions": true,
    "python.analysis.indexing": true,
    "python.analysis.typeCheckingMode": "basic",
    
    "yaml.schemas": {
        "./data/questions/v4/schema-questionnaire-v4.json": ["data/questions/v4/**/*.{yaml,yml}"],
        "./data/questions/v1/schema-questionnaire-v1.json": ["data/questions/v1/**/*.{yaml,yml}"]
    },
    "python.REPL.enableREPLSmartSend": false,
    "cursorpyright.analysis.autoImportCompletions": true,
    "cursorpyright.analysis.typeCheckingMode": "basic",
}

Cursor/User/settings.json

...
    "[python]": {
        
        "diffEditor.ignoreTrimWhitespace": false,
        "editor.defaultColorDecorators": "never",
        "gitlens.codeLens.symbolScopes": [
            "!Module"
        ],
        "editor.formatOnType": true,
        "editor.wordBasedSuggestions": "off"
    },
...

defaultSettings.json

...
	// Path to the State Tool executable for ActiveState runtimes (version 0.36+).
	"python.activeStateToolPath": "state",

	// List of paths to libraries and the like that need to be imported by auto complete engine. E.g. when using Google App SDK, the paths are not in system path, hence need to be added into this list.
	"python.autoComplete.extraPaths": [],

	// Path to the conda executable to use for activation (version 4.4+).
	"python.condaPath": "",

	// Show or hide Create Environment button in the editor for `requirements.txt` or other dependency files.
	"python.createEnvironment.contentButton": "hide",

	// Detect if environment creation is required for the current project
	"python.createEnvironment.trigger": "prompt",

	// Path to default Python to use when extension loads up for the first time, no longer used once an interpreter is selected for the workspace. See [here](https://aka.ms/AAfekmf) to understand when this is used
	"python.defaultInterpreterPath": "python",

	// Absolute path to a file containing environment variable definitions.
	"python.envFile": "${workspaceFolder}/.env",

	// Enables A/B tests experiments in the Python extension. If enabled, you may get included in proposed enhancements and/or features.
	"python.experiments.enabled": true,

	// List of experiments to opt into. If empty, user is assigned the default experiment groups. See [here](https://github.com/microsoft/vscode-python/wiki/AB-Experiments) for more details.
	"python.experiments.optInto": [],

	// List of experiments to opt out of. If empty, user is assigned the default experiment groups. See [here](https://github.com/microsoft/vscode-python/wiki/AB-Experiments) for more details.
	"python.experiments.optOutFrom": [],

	// Whether to install Python modules globally when not using an environment.
	"python.globalModuleInstallation": false,

	// Controls when to display information of selected interpreter in the status bar.
	//  - never: Never display information.
	//  - onPythonRelated: Only display information if Python-related files are opened.
	//  - always: Always display information.
	"python.interpreter.infoVisibility": "onPythonRelated",

	// Defines type of the language server.
	//  - Default: Automatically select a language server: Pylance if installed and available, otherwise fallback to Jedi.
	//  - Jedi: Use Jedi behind the Language Server Protocol (LSP) as a language server.
	//  - Pylance: Use Pylance as a language server.
	//  - None: Disable language server capabilities.
	"python.languageServer": "None",

	// [Experimental] Select implementation of environment locators. This is an experimental setting while we test native environment location.
	"python.locator": "js",

	// This setting is deprecated. Please use command `Developer: Set Log Level...` to set logging level.
	// The logging level the extension logs at, defaults to 'error'
	"python.logging.level": "error",

	// Set severity of missing packages in requirements.txt or pyproject.toml
	"python.missingPackage.severity": "Hint",

	// Path to the pipenv executable to use for activation.
	"python.pipenvPath": "pipenv",

	// Path to the pixi executable.
	"python.pixiToolPath": "pixi",

	// Path to the poetry executable.
	"python.poetryPath": "poetry",

	// Toggle Smart Send for the Python REPL. Smart Send enables sending the smallest runnable block of code to the REPL on Shift+Enter and moves the cursor accordingly.
	"python.REPL.enableREPLSmartSend": true,

	// Toggle to provide variables for the REPL variable view for the native REPL.
	"python.REPL.provideVariables": true,

	// Toggle to send code to Python REPL instead of the terminal on execution. Turning this on will change the behavior for both Smart Send and Run Selection/Line in the Context Menu.
	"python.REPL.sendToNativeREPL": false,

	// Activate Python Environment in the current Terminal on load of the Extension.
	"python.terminal.activateEnvInCurrentTerminal": false,

	// Activate Python Environment in all Terminals created.
	"python.terminal.activateEnvironment": true,

	// When executing a file in the terminal, whether to use execute in the file's directory, instead of the current open folder.
	"python.terminal.executeInFileDir": false,

	// When launching a python terminal, whether to focus the cursor on the terminal.
	"python.terminal.focusAfterLaunch": false,

	// Python launch arguments to use when executing a file in the terminal.
	"python.terminal.launchArgs": [],

	// Enable [shell integration](https://code.visualstudio.com/docs/terminal/shell-integration) for the terminals running python. Shell integration enhances the terminal experience by enabling command decorations, run recent command, improving accessibility among other things.
	"python.terminal.shellIntegration.enabled": false,

	// Enable auto run test discovery when saving a test file.
	"python.testing.autoTestDiscoverOnSaveEnabled": true,

	// Glob pattern used to determine which files are used by autoTestDiscoverOnSaveEnabled.
	"python.testing.autoTestDiscoverOnSavePattern": "**/*.py",

	// Optional working directory for tests.
	"python.testing.cwd": null,

	// Port number used for debugging of tests.
	"python.testing.debugPort": 3000,

	// Prompt to configure a test framework if potential tests directories are discovered.
	"python.testing.promptToConfigure": true,

	// Arguments passed in. Each argument is a separate item in the array.
	"python.testing.pytestArgs": [],

	// Enable testing using pytest.
	"python.testing.pytestEnabled": false,

	// Path to pytest. You can use a custom version of pytest by modifying this setting to include the full path.
	"python.testing.pytestPath": "pytest",

	// Arguments passed in. Each argument is a separate item in the array.
	"python.testing.unittestArgs": [
		"-v",
		"-s",
		".",
		"-p",
		"*test*.py"
	],

	// Enable testing using unittest.
	"python.testing.unittestEnabled": false,

	// Folders in your home directory to look into for virtual environments (supports pyenv, direnv and virtualenvwrapper by default).
	"python.venvFolders": [],
...

Hi @not-an-llm – it looks like the “import settings” feautre missed the “python.analysis.extraPaths” inside the “[python]” section. Could you manually copy those entries so your file looks something like (see the extra section at the end):

{
    // Python settings
    "[python]": {
        "editor.formatOnSave": true,
        "editor.defaultFormatter": "charliermarsh.ruff",
        "editor.codeActionsOnSave": {
            "source.fixAll": "explicit",
            "source.organizeImports": "explicit"
        },
        "python.analysis.extraPaths": [
            "${workspaceFolder}/lib/src",
            "${workspaceFolder}/frontend/src",
            "${workspaceFolder}/backend/app"
        ],
    },

    // Let VS Code discover the Poetry environments
    "python.analysis.autoImportCompletions": true,
    "python.analysis.indexing": true,
    "python.analysis.typeCheckingMode": "basic",


    "yaml.schemas": {
        "./data/questions/v4/schema-questionnaire-v4.json": ["data/questions/v4/**/*.{yaml,yml}"],
        "./data/questions/v1/schema-questionnaire-v1.json": ["data/questions/v1/**/*.{yaml,yml}"]
    },
    "python.REPL.enableREPLSmartSend": false,
    "cursorpyright.analysis.autoImportCompletions": true,
    "cursorpyright.analysis.typeCheckingMode": "basic",
    "cursorpyright.analysis.extraPaths": [
        "${workspaceFolder}/lib/src",
        "${workspaceFolder}/frontend/src",
        "${workspaceFolder}/backend/app"
    ],
}

Hi @ravirahman, thanks for the suggestion. I just appended the extraPaths to my settings.json and restarted cursor, but the issue persists.

{
    // Python settings
    "[python]": {
        "editor.formatOnSave": true,
        "editor.defaultFormatter": "charliermarsh.ruff",
        "editor.codeActionsOnSave": {
            "source.fixAll": "explicit",
            "source.organizeImports": "explicit"
        },
        "python.analysis.extraPaths": [
            "${workspaceFolder}/lib/src",
            "${workspaceFolder}/frontend/src",
            "${workspaceFolder}/backend/app"
        ],
    },

    // Let VS Code discover the Poetry environments
    "python.analysis.autoImportCompletions": true,
    "python.analysis.indexing": true,
    "python.analysis.typeCheckingMode": "basic",
    
    "yaml.schemas": {
        "./data/questions/v4/schema-questionnaire-v4.json": ["data/questions/v4/**/*.{yaml,yml}"],
        "./data/questions/v1/schema-questionnaire-v1.json": ["data/questions/v1/**/*.{yaml,yml}"]
    },
    "python.REPL.enableREPLSmartSend": false,
    "cursorpyright.analysis.autoImportCompletions": true,
    "cursorpyright.analysis.typeCheckingMode": "basic",
    "cursorpyright.analysis.extraPaths": [
        "${workspaceFolder}/lib/src",
        "${workspaceFolder}/frontend/src",
        "${workspaceFolder}/backend/app"
    ],
}

Could you share the logs for the “Cursor - Pyright” and “basedpyright” output consoles?

This is also an issue for me:

[Info  - 23:13:47.120] [pylance import] Already imported settings globally
[Info  - 23:13:47.120] [pylance import] Already imported settings for remote dev-container://aethis_backend
[Info  - 23:13:47.120] [pylance import] Already imported settings for workspace tda-server [Container aethis_backend (8f7f24bf9c2d)]
[Info  - 23:13:47.120] [pylance import] Already imported settings for workspace folder /workspaces/tda-server
[Info  - 23:13:47.149] failed to find pyright executable, falling back to bundled:
/workspaces/tda-server/.venv/bin/basedpyright-langserver
[Info  - 23:13:47.149] using bundled pyright
[Info  - 23:13:47.149] running node with args: --max-old-space-size=16384
[Info  - 23:13:47.149] using default node executable

Version: 1.2.1 (user setup)
VSCode Version: 1.99.3
Commit: 031e7e0ff1e2eda9c1a0f5df67d44053b059c5d0
Date: 2025-07-03T06:16:02.610Z
Electron: 34.5.1
Chromium: 132.0.6834.210
Node.js: 20.19.0
V8: 13.2.152.41-electron.0
OS: Windows_NT x64 10.0.22631

..either in win11 or running within a devcontainer

Having the same issue!

@ravirahman

Here are my output consoles:

Cursor - Pyright

[Info  - 17:53:30.22] [pylance import] Already imported settings globally
[Info  - 17:53:30.22] [pylance import] No remote authority found, skipping remote settings migration
[Info  - 17:53:30.22] [pylance import] Already imported settings for workspace clearly
[Info  - 17:53:30.22] [pylance import] Already imported settings for workspace folder /Users/joe/workplace/clearly
[Info  - 17:53:30.71] failed to find pyright executable, falling back to bundled:
/Users/joe/workplace/clearly/lib/.venv/bin/basedpyright-langserver
[Info  - 17:53:30.71] using bundled pyright
[Info  - 17:53:30.71] running node with args: --max-old-space-size=16384
[Info  - 17:53:30.71] using default node executable

basedpyright

[Info  - 10:53:30 AM] basedpyright language server 1.29.4 starting
[Info  - 10:53:30 AM] Server root directory: file:///Users/joe/.cursor/extensions/anysphere.cursorpyright-1.0.5/dist
[Info  - 10:53:30 AM] Starting service instance "clearly"
Received pythonPath from Python extension: /Users/joe/workplace/clearly/lib/.venv/bin/python
[Info  - 10:53:30 AM] Setting pythonPath for service "clearly": "/Users/joe/workplace/clearly/lib/.venv/bin/python"
[Info  - 10:53:30 AM] No include entries specified; assuming /Users/joe/workplace/clearly
[Info  - 10:53:30 AM] Auto-excluding **/node_modules
[Info  - 10:53:30 AM] Auto-excluding **/__pycache__
[Info  - 10:53:30 AM] Auto-excluding **/.*
[Info  - 10:53:30 AM] Assuming Python version 3.12.8.final.0
[Info  - 10:53:30 AM] Found 243 source files
[Info  - 10:53:30 AM] BG: Background analysis(1) root directory: file:///Users/joe/.cursor/extensions/anysphere.cursorpyright-1.0.5/dist
[Info  - 10:53:30 AM] BG: Background analysis(1) started

I also updated cursor today (no effect on this issue, still happens), so here’s my current About Cursor:

Version: 1.2.2
VSCode Version: 1.99.3
Commit: faa03b17cce93e8a80b7d62d57f5eda6bb6ab9f0
Date: 2025-07-07T06:08:52.104Z (1 day ago)
Electron: 34.5.1
Chromium: 132.0.6834.210
Node.js: 20.19.0
V8: 13.2.152.41-electron.0
OS: Darwin arm64 23.6.0

Hi @Paul_Simpson, @heyyyjoo, and @not-an-llm – I have looked into this more, and unfortunately our Python extension does not support refactoring like this. I would recommend asking the Agent to perform refactors, such as “Move to File”.

@ravirahman
Thanks for getting back. Are there no plans to support it? I would very much prefer a deterministic refactor than using Agent for this use case. Agent might miss something. Pretty unfortunate that the update resulted in a regression imo.

1 Like

Thanks for looking into this @ravirahman. Can you please bring this up to your team?

This feature is one that is unique to desktop IDEs, like Cursor, over CLI tools like Claude Code.

Agents are a poor substitute because:

  1. a single refactor operation can touch import statements in hundreds of files, requiring a huge quantity of tool calls / diffs.
  2. import statements are the most frequent source of code hallucinations (anecdotally).

Depending on the number of imports, I’d rather just open VSCode, do the refactor there, and then switch back to Cursor.

Could you create an issue in the DetachHead/basedpyright GitHub? Our extension is based on this, so we’ll port over any features/improvements they add.

I dont understand.
Cursor IDE will not support python language features like Refactor?
this is so basic functionality for python developers. AI is not replacement for this action.
Am i wrong?

2 Likes

Hi, @ravirahman

Thanks for the response. Using an LLM to refactor code is not good practice. This is a 100% show-stopper for me (and I’d imagine any other professional developers) - as projects are typically too large to trust an LLM to refactor.

This functionality is core to a modern coding editor. I hope you will reconsider this functionality ASAP.

I’ve created an issue here:

..please add support for it everyone!

1 Like

Forking Python + BasedPyright feels like i mistake… There are a lot of Python+Pylance features that are missing from cursor, and until a few weeks ago, the side-loaded python+pylance extensions worked fine :frowning:

1 Like

@ravirahman is there a chance we can bump the priority of this? This is a super basic functionality that can’t get broken and advised to file an issue in a different repo. Is there any other workaround? We won’t follow the advice of asking agent to work on it – it just doesn’t work on a project of our size, plus I wouldn’t want to waste tokens on it. That’s a big blocker to continue using Cursor. Thank you.

5 Likes

Hi @Omar_Shykhkerimov, thanks for the ask. I would recommend trying the pyrefly extension inside Cursor; it is on their roadmap to add refactoring support.

+1 to this feature request. the expected deterministic javascript refactorings from vscode work as expected, while those in python are not available. Asking the agent to do it with python is hitting a tac with a sledgehammer.

1 Like