[Python] Ruff ignore F401

Discussão em 'Python' iniciado por Stack, Dezembro 6, 2024.

  1. Stack

    Stack Membro Participativo

    I am working with VScode and python. I installed ruff because I really like it, but thee one thing I don't like is the F401 error, which basically automatically removes the unused libraries when I try to include them in my main files. For instance, if I try to go from this:

    from fastapi import FastAPI, Response, HTTPException
    from pydantic import BaseModel


    to this,

    from fastapi import FastAPI, Response, HTTPException, status
    from pydantic import BaseModel


    the status package gets automatically removed before I even scroll down to start using it on the code. This is counterintuitive and super cumbersome. The error I get is this:

    "status" is not accessedPylance
    `fastapi.status` imported but unusedRuff (F401)


    I included this line on my pyproject.toml file:

    [tool.ruff.lint]
    ignore = ["E501", "F401"]


    but it keeps happening all the same. It does not work.

    Can somebody give me any clues on how to get rid of this functionality? I would appreciate it a lot! Thanks in advance!

    extent:

    My folder structure is like this:

    MY-PROJ-FOLDER
    │
    ├── .git
    ├── .github
    ├── .pytest_cache
    ├── .venv
    ├── .vscode
    ├── dist
    ├── garbish_code
    ├── src
    ├── tests
    │ └── tests_main.py
    ├── .dockerignore
    ├── .gitignore
    ├── .python-version
    ├── compose.yml
    ├── Dockerfile
    ├── multistage.Dockerfile
    ├── pyproject.toml
    ├── README.md
    ├── ruff.toml
    ├── run_compose.sh
    └── run.sh


    and my settings are:

    {
    // Python settings
    "python.analysis.autoSearchPaths": true,
    "python.analysis.diagnosticSeverityOverrides": {
    "reportMissingImports": "none"
    },
    "python.analysis.extraPaths": [
    "${workspaceFolder}/src"
    ],
    "python.envFile": "${workspaceFolder}/.env",
    "python.terminal.activateEnvironment": true,
    "python.defaultInterpreterPath": "${workspaceFolder}/.venv/Scripts/python",
    // Test settings
    "python.testing.pytestEnabled": true,
    "python.testing.unittestEnabled": false,
    "python.testing.cwd": "${workspaceFolder}/tests",
    "python.testing.pytestPath": "${workspaceFolder}/.venv/Scripts/pytest",
    "python.testing.autoTestDiscoverOnSaveEnabled": true,
    }

    Continue reading...

Compartilhe esta Página