# How to configure VS Code for type checking in a uv project


Pylance's type-checking mode defaults to `off`, but a project's [Pyright](https://pydevtools.com/handbook/reference/pyright.md) configuration can override it. To enable its bundled checker, follow [Pylance's diagnostics setup](#choose-pylances-diagnostics-backend); no separate checker dependency is needed. For a [uv](https://pydevtools.com/handbook/reference/uv.md)-managed project using another checker, this guide also covers [ty](https://pydevtools.com/handbook/reference/ty.md) with the official ty extension, and [mypy](https://pydevtools.com/handbook/reference/mypy.md) with Microsoft's Mypy Type Checker extension.

{{< callout type="warning" >}}
This guide assumes a uv-managed project with a `.venv` directory. If you haven't set one up yet, see [create your first Python project](https://pydevtools.com/handbook/tutorial/create-your-first-python-project.md).
{{< /callout >}}

## Pick the right extension

|  | ty extension | mypy extension |
|--|--|--|
| Extension ID | `astral-sh.ty` | `ms-python.mypy-type-checker` |
| Replaces Pylance | Yes (by default) | No |
| Completions source | ty | Pylance |
| Config in `pyproject.toml` | `[tool.ty]` | `[tool.mypy]` |
| Best for | New projects on the Astral toolchain | Projects already on mypy |

If your project already runs mypy in CI, start with the mypy extension so the editor matches the pipeline. If you're adding type checking for the first time, the ty extension gives you a type checker and language server in one install.

## Set up the ty extension

Add ty as a dev dependency:

```bash
uv add --dev ty
```

Install the [ty extension](https://marketplace.visualstudio.com/items?itemName=astral-sh.ty) (`astral-sh.ty`) from the VS Code Marketplace. Its default `importStrategy` is `fromEnvironment`, so it finds the ty binary in `.venv` automatically after `uv sync`.

### Keep Pylance or let ty replace it

Pylance (bundled with the Python extension) and ty are both language servers: each provides completions, go-to-definition, hover documentation, and type-error diagnostics. Running both produces duplicate diagnostics.

The ty extension resolves this by disabling Pylance when it activates, setting `python.languageServer` to `None`. Keep this default when you want ty to own every language-server feature.

To keep Pylance's IntelliSense alongside ty's type checking, switch ty into type-checking-only mode:

```json {filename=".vscode/settings.json"}
{
  "python.languageServer": "Pylance",
  "ty.disableLanguageServices": true
}
```

With `ty.disableLanguageServices` set to `true`, ty reports type errors as diagnostics but leaves completions and hover to Pylance. Use this when adopting ty incrementally.

### Check the whole workspace

By default, ty reports diagnostics only for open files (`ty.diagnosticMode` is `openFilesOnly`). To see type errors across the whole project, set it to `workspace`:

```json {filename=".vscode/settings.json"}
{
  "ty.diagnosticMode": "workspace"
}
```

### Point ty at the venv interpreter

ty discovers `.venv/` without extra configuration. If the environment lives in a non-standard location, or imports stay unresolved after `uv sync`, set `ty.interpreter` (a list whose first entry is used):

```json {filename=".vscode/settings.json"}
{
  "ty.interpreter": [".venv/bin/python"]
}
```
```json {filename=".vscode/settings.json"}
{
  "ty.interpreter": [".venv\\Scripts\\python.exe"]
}
```
> [!NOTE]
> ty is in beta as of 2026. If Pylance provides a feature ty doesn't yet support, run them together in type-checking-only mode rather than letting ty disable Pylance.

## Set up the mypy extension

[mypy](https://pydevtools.com/handbook/reference/mypy.md) uses the [Mypy Type Checker extension](https://marketplace.visualstudio.com/items?itemName=ms-python.mypy-type-checker) (`ms-python.mypy-type-checker`). It only reports diagnostics, so Pylance keeps handling IntelliSense and no language-server conflict arises.

Add mypy as a dev dependency:

```bash
uv add --dev mypy
```

Then install the extension from the Marketplace and configure it:

```json {filename=".vscode/settings.json"}
{
  "mypy-type-checker.importStrategy": "fromEnvironment",
  "mypy-type-checker.reportingScope": "workspace"
}
```

### Use the venv mypy, not the bundled copy

The extension defaults `importStrategy` to `useBundled`, shipping its own mypy. For a uv project that causes two problems: the bundled mypy can differ from the version pinned in `pyproject.toml`, and it can't see third-party type stubs installed with `uv add --dev`. Setting `importStrategy` to `fromEnvironment` makes the extension use the mypy in the active environment, which is the `.venv` uv creates. Run `uv sync` before opening VS Code so mypy is present.

`reportingScope: "workspace"` reports errors across the whole project instead of only open files (the default is `file`).

### Keep daemon mode enabled {#daemon-mode-is-already-on}

The extension defaults `preferDaemon` to `true`, keeping a `dmypy` process alive between saves so incremental checks are fast. No extra configuration is needed. If the daemon gets into a bad state after a dependency change, stop it and let VS Code restart it on the next check:

```bash
uv run dmypy stop
```

### Set the working directory in a monorepo

The extension runs mypy with `${workspaceFolder}` as the working directory, matching the project root where `pyproject.toml` lives. When the mypy configuration lives in a subdirectory, point `cwd` at it:

```json {filename=".vscode/settings.json"}
{
  "mypy-type-checker.cwd": "${workspaceFolder}/backend"
}
```

`cwd` also accepts `${fileDirname}` (run from the checked file's directory) and `${nearestConfig}` (run from the nearest ancestor directory containing a mypy configuration file).

## Resolve imports across a uv workspace

In a [uv workspace](https://pydevtools.com/handbook/how-to/how-to-configure-vs-code-for-a-uv-project.md), packages that import from sibling members can trip false "unresolved import" warnings. When Pylance handles completions (the mypy route, or ty in type-checking-only mode), add the source roots:

```json {filename=".vscode/settings.json"}
{
  "python.analysis.extraPaths": ["packages/pkg-a/src", "packages/pkg-b/src"]
}
```

For mypy's own resolution, add the same roots to `pyproject.toml`:

```toml {filename="pyproject.toml"}
[tool.mypy]
mypy_path = "packages/pkg-a/src"
```

For multiple paths, separate them with colons on macOS/Linux or semicolons on Windows.

## Choose Pylance's diagnostics backend

Pylance uses Pyright by default. Enable its built-in type checking without a separate project dependency:

```json {filename=".vscode/settings.json"}
{
  "python.analysis.typeCheckingMode": "standard"
}
```

The modes are `off` (default), `basic`, `standard`, and `strict`. `standard` checks annotated code and infers types for most patterns; `strict` enables additional diagnostics, matching [Pyright](https://pydevtools.com/handbook/reference/pyright.md) configured with `typeCheckingMode = "strict"`. Pyright has no `--strict` command-line flag.

Pylance reads `[tool.pyright]` in `pyproject.toml`, as well as `pyrightconfig.json` and `python.analysis.*` editor settings. `pyrightconfig.json` takes precedence over `[tool.pyright]`; either project configuration overrides the editor's type-checking mode. It does not read `[tool.mypy]` or `[tool.ty]`.

Pylance also supports [Pyrefly](https://pydevtools.com/handbook/reference/pyrefly.md) through the Type Server Protocol. Select **Pylance + Pyrefly** in the Diagnostics Source setting to keep Pylance's editor features and use Pyrefly's type analysis. Pylance locates or downloads Pyrefly; project checking then follows Pyrefly's configuration rather than `[tool.pyright]`. See [Microsoft's setup instructions](https://devblogs.microsoft.com/python/announcing-tsp/) and [Pyrefly's integration guide](https://pyrefly.org/blog/pyrefly-pylance/).

Use the same checker version and project environment in CI. For a Pyrefly project, initialize `[tool.pyrefly]` or `pyrefly.toml`; its unconfigured `basic` preset suppresses many type errors.

## Restart the language server after switching setups

After changing the interpreter or switching extensions, the language server can hold stale state. Reset it from the Command Palette:

- ty: **ty: Restart server**
- mypy: **Mypy: Restart Server**
