Skip to content
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

tomllib is not considered as in standard library in Format imports #465

Closed
Tracked by #480
GuillaumeLeGoc opened this issue May 16, 2024 · 3 comments
Closed
Tracked by #480

Comments

@GuillaumeLeGoc
Copy link

Hi,
I'm using vscode on a project with a conda environment using python 3.12. The conda environment is selected in vscode. When running Ruff: Format imports from the command palette, tomllib is moved with non-standard imports.

Before Ruff: Format imports :

import os
import tomllib

import numpy as np

After Ruff: Format imports :

import os

import numpy as np
import tomllib

The issue was raised here astral-sh/ruff#2343, and supposedly fixed here astral-sh/ruff#2345.

System information :

  • Windows 10
  • vscode 1.89.1
  • Ruff vscode extension v2024.20.0

Do I have to take further action to fix the problem (configuration, ...) ?

Cheers !

@dhruvmanila
Copy link
Member

I think this will only work if the required Python version is 3.11 or greater as tomllib was added in that Python version. Can you share your pyproject.toml? You could also run ruff from the command-line with the --verbose flag which will provide which category an import is in:

[2024-05-20][11:53:16][ruff_linter::rules::isort::categorize][DEBUG] Categorized 'tomllib' as Known(StandardLibrary) (KnownStandardLibrary)

@charliermarsh
Copy link
Member

👍 You can add something like:

[project]
...
requires-python = ">=3.11"

...to your pyproject.toml, to indicate that your project only supports Python 3.11 and later. Alternatively, you can tell Ruff to treat 3.11 as your minimum supported version with:

[tool.ruff]
target-version = "py311"

@charliermarsh
Copy link
Member

Closing for now, let me know if you're continuing to see this after applying the above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants