ruff-pycharm-plugin icon indicating copy to clipboard operation
ruff-pycharm-plugin copied to clipboard

Automatic import organisation inconsistent between type hints and action on save

Open KarimAED opened this issue 1 year ago • 2 comments

Describe the bug Ruff runs as an action on save, even if I don't tell it to. I literally have all boxes in the Ruff settings page unchecked. Worst of all, however, the context action for organizing imports, and the action on save disagree on the correct import formatting for the snippet:

from pathlib import Path
from typing import Any

import click
import matplotlib.pyplot as plt
import numpy as np

from my_package.utils import MyObject

With one suggesting a line between numpy and my_package imports while the other keeps removing the line. This only happens when I use top-level imports from my_package, i.e. the issue is resolved with from .utils import.

To Reproduce Steps to reproduce the behavior:

  1. Install ruff plugin
  2. Deactivate all actions in the Settings>Tools>Ruff pane
  3. Still get Ruff actions on save
  4. Create a project structure where you import files from a top-level package
  5. Actions on save and code annotations disagree

Expected behavior When I turn off Run ruff on save and Run ruff when reformat code, Ruff should never run automatically to fix my code. Also, the action on save is incorrect in this case, I believe, in suggesting removing the line between imports from my_package and third party software. This should be fixed.

Screenshots

This is my ruff tool pane:

image

This is what the action on save formats it to (Ruff thinks this is wrong):

image

This is what it should look like:

image

Environments (please complete the following information):

  • IDE: PyCharm Professional 2024.1.1
  • OS: Debian Bookworm 12.5
  • Ruff Version: 0.4.4
  • Plugin version: 0.0.33

Additional context Add any other context about the problem here.

KarimAED avatar May 17 '24 10:05 KarimAED

@KarimAED @koxudaxi this might be a duplicate of https://github.com/koxudaxi/ruff-pycharm-plugin/issues/422

hexvolt avatar Jul 25 '24 15:07 hexvolt

@hexvolt not sure if we are encountering the exact same behaviour, but it might be a very similar issue.

KarimAED avatar Jul 29 '24 16:07 KarimAED