-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
feat: add ARG001 rule #8045
feat: add ARG001 rule #8045
Conversation
035f8f2
to
d6a4c1a
Compare
Honestly, I don't like this. The amount of false positives that we have to silence is just too high for my taste. I am all for doing some cleaning, but to keep this rule enabled in the long run, not really. |
Maybe a good compromise would be to activate this rule only for the package code, but not for the tests? |
For me, tests are an integral part of code, so treating them differently would be weird imho. Disclaimer: I won't block this PR if others think it's a good change. Just sounding out my concerns. |
I may have missed an obvious thing, but I didn't find a way to disable rules on entire folders on ruff 🤔 |
That was actually my first thought as well.
Sounds good to me. |
Would also be ok for me.
Did you try file patterns with |
Silly me.. it's actually possible to disable the check on the entire
We now have a total of 2 additional |
pyproject.toml
Outdated
@@ -102,6 +102,7 @@ unfixable = [ | |||
target-version = "py38" | |||
line-length = 88 | |||
extend-select = [ | |||
"ARG001", # flake8-unused-arguments - Rules other than ARG001 result in false positives only |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not seeing any false positives when I enable ARG
, only true positives.
Did you report a bug to ruff
for any false positives that you see?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I might have explained myself incorrectly. They are true positives but provide meaningless action (like a #noqa pragma), so I don't see value in keeping them enabled.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then I'd prefer - if the consensus is that checking for unused arguments is useful at all - to turn them all on and # noqa
the ones that are deliberate (usually because the method must comply with some base class or protocol).
There aren't very many such examples, certainly if you're limiting yourself to src
.
The point of enabling rules is not only to do a one-time clean-up of the codebase, it's to prevent future mistakes. Seems inconsistent to say "we don't want unused arguments in functions, but we're ok with them in methods, class methods, static methods, lambdas".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also I think the warnings can mostly be suppressed by using an _
for [the first character of] the unused parameter name, which hardly clutters the code at all - makes it clearer, if anything.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is kind of the opposite of #8045 (comment) though. Hard to find consensus 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
personally I find _operation
as a convention meaning "operation
, but not used" to be more than acceptable - it preserves enough of the original to be not confusing, it acknowledges that the value is not used and it makes clear that someone has thought about it and had some reason to leave the unused parameter there anyway.
The exact means by which warnings for intentional unused parameters are suppressed is secondary though: my main point is that if we think this is a valuable warning, then it is strange to think that it is only valuable in certain types of function. For me, it should be all of ARG
, or none.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
personally I find
_operation
as a convention meaning "operation
, but not used" to be more than acceptable
I don't think so. The parameter name is part of the interface (except for positional-only parameters). Changing the name in an overridden method changes the interface and thereby hurts the Liskov substitution principle.
my main point is that if we think this is a valuable warning, then it is strange to think that it is only valuable in certain types of function.
On first thought: yes. However, Liskov is not relevant for functions. That's why there will be less "false positives" than for methods and so on. IMO, it's perfectly valid to say ARG001
is the only one that does not do more damage than good. As already mentioned before I'm also fine with just merging the improvements and not enabling the check at all.
I enabled all ARG rules on the main codebase while keeping them disabled on tests. I'm more in favour of radoering's comment on preserving names to keep the Liskov principle valid rather than modifying variable names with If this version doesn't find consensus yet, then I'll probably revert enabling ARG rules everywhere and just propose the improvements. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO the current version is fine. We have only 9 # noqa: ARG...
now. If we find that the rules are too annoying, we can still disable them in the future.
I'd just revert some changes in the tests that don't make sense anymore (formatting and _
/ __
arguments).
@@ -19,7 +17,10 @@ def tester(command_tester_factory: CommandTesterFactory) -> CommandTester: | |||
|
|||
|
|||
def test_cache_list( | |||
tester: CommandTester, mock_caches: None, repository_one: str, repository_two: str |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change can be reverted.
@@ -22,7 +22,7 @@ def build_venv(path: Path | str, **_: Any) -> None: | |||
def check_output_wrapper( | |||
version: Version = VERSION_3_7_1, | |||
) -> Callable[[list[str], Any, Any], str]: | |||
def check_output(cmd: list[str], *args: Any, **kwargs: Any) -> str: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I'd revert that, too
io: IO | None = None, | ||
disable_cache: bool = False, | ||
) -> RepositoryPool: | ||
def _create_pool(*_: Any, **__: Any) -> RepositoryPool: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we have *args: Any, **kwargs: Any
here, too?
@@ -40,7 +40,9 @@ def with_add_command_plugin(mocker: MockerFixture) -> None: | |||
mock_metadata_entry_points(mocker, AddCommandPlugin) | |||
|
|||
|
|||
def test_application_with_plugins(with_add_command_plugin: None) -> None: | |||
def test_application_with_plugins( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be reverted.
@@ -50,7 +52,9 @@ def test_application_with_plugins(with_add_command_plugin: None) -> None: | |||
assert tester.status_code == 0 | |||
|
|||
|
|||
def test_application_with_plugins_disabled(with_add_command_plugin: None) -> None: | |||
def test_application_with_plugins_disabled( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be reverted.
@@ -37,7 +37,7 @@ | |||
|
|||
|
|||
class MockEnv(BaseMockEnv): | |||
def run(self, bin: str, *args: str, **kwargs: Any) -> str: | |||
def run(self, *_: str, **__: Any) -> str: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revert or *args: str, **kwargs: Any
@@ -34,7 +35,7 @@ def _get_page(self, name: NormalizedName) -> SimpleRepositoryPage: | |||
with fixture.open(encoding="utf-8") as f: | |||
return SimpleRepositoryPage(self._url, f.read()) | |||
|
|||
def _download(self, url: str, dest: Path) -> None: | |||
def _download(self, *_: Any, **__: Any) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revert or *args: Any, **kwargs: Any
@@ -190,7 +190,7 @@ def build_venv(path: Path | str, **__: Any) -> None: | |||
def check_output_wrapper( | |||
version: Version = VERSION_3_7_1, | |||
) -> Callable[[list[str], Any, Any], str]: | |||
def check_output(cmd: list[str], *args: Any, **kwargs: Any) -> str: | |||
def check_output(cmd: list[str], *_: Any, **__: Any) -> str: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revert
@@ -936,7 +916,7 @@ def test_remove_keeps_dir_if_not_deleteable( | |||
side_effect=check_output_wrapper(Version.parse("3.6.6")), | |||
) | |||
|
|||
def err_on_rm_venv_only(path: Path, *args: Any, **kwargs: Any) -> None: | |||
def err_on_rm_venv_only(path: Path, *_: Any, **__: Any) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revert
@@ -1626,7 +1586,7 @@ def test_create_venv_accepts_fallback_version_w_nonzero_patchlevel( | |||
|
|||
poetry.package.python_versions = "~3.5.1" | |||
|
|||
def mock_check_output(cmd: str, *args: Any, **kwargs: Any) -> str: | |||
def mock_check_output(cmd: str, *_: Any, **__: Any) -> str: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revert
@ralbertazzi are you still interested in this? If not, please close. |
@ralbertazzi thank you for taking the time to work on this, propose this, and worth through feedback. However, at this point I do not think we would want this change unfortunately. In a code base like Poetry, the the noise a rule like this produces is quite high. Things might change in the future, but considering how most of this code base is written, I would not encourage this rule being activated. For now closing. Once again, we really appreciate your time and effort. |
No worries, thank you for your steady contributions :) |
As this affects the whole codebase it would be great to have a quick feedback cycle to avoid lots of painful rebases 🙏
This kind of rules doesn't obviously play well with pytest fixtures, that's why many inline ignores. On the other side, it helped detecting lots of unneeded fixtures.