-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
[pylint
] Also emit PLR0206
for properties with variadic parameters
#11200
Conversation
|
code | total | + violation | - violation | + fix | - fix |
---|---|---|---|---|---|
PLR0206 | 6 | 6 | 0 | 0 | 0 |
Linter (preview)
ℹ️ ecosystem check detected linter changes. (+6 -0 violations, +0 -0 fixes in 1 projects; 43 projects unchanged)
milvus-io/pymilvus (+6 -0 violations, +0 -0 fixes)
ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview
+ pymilvus/orm/collection.py:1114:9: PLR0206 Cannot have defined parameters for properties + pymilvus/orm/collection.py:1255:9: PLR0206 Cannot have defined parameters for properties + pymilvus/orm/collection.py:237:9: PLR0206 Cannot have defined parameters for properties + pymilvus/orm/collection.py:259:9: PLR0206 Cannot have defined parameters for properties + pymilvus/orm/collection.py:266:9: PLR0206 Cannot have defined parameters for properties + pymilvus/orm/partition.py:112:9: PLR0206 Cannot have defined parameters for properties
Changes by rule (1 rules affected)
code | total | + violation | - violation | + fix | - fix |
---|---|---|---|---|---|
PLR0206 | 6 | 6 | 0 | 0 | 0 |
These all look like true positives to me. The affected project defines a bunch of properties with |
I think these changes are correct but it would be useful to get a second opinion. I'd also look at why Pylint doesn't trigger on them. Is there an issue in Pylint which might give us an insight here? (Edit: Pyright -> Pylint) |
Yeah, I'll do some digging and check to see if there's a reason why pylint only checks for the number of positional-or-keyword parameters. |
The results of digging:
I confirmed locally that running pylint on the original motivating example for the pylint check given in pylint-dev/pylint#3006 (comment) does not actually trigger a violation of the pylint rule (because the example has variadic non- |
@carljm, could you possibly take a look? |
Thanks for the details. It's good to go from my side 👍 |
I opened a pylint issue here to let them know about the bug on their side: pylint-dev/pylint#9584 |
The pylint maintainers have added labels to pylint-dev/pylint#9584 which indicate that they agree there's a bug on their side, so I'll merge this now 👍 Thanks for the review @dhruvmanila! |
Summary
Currently this rule checks the number of nonvariadic parameters a property has, but doesn't check how many variadic parameters the property has. That makes little sense to me: if a property has variadic non-self parameters, that seems just as invalid as if a property has nonvariadic non-self parameters.
This PR changes the rule so that it checks the total number of parameters the property has, rather than just the number of nonvariadic parameters. Following the new APIs added in 87929ad, this has the nice side effect of also simplifying the code slightly.
This means that we diverge from pylint's behaviour a little more in how we implement this rule, but we were already doing something slightly different. It looks like pylint for some reason only checks the number of positional-or-keyword nonvariadic parameters in a property function, and ignores the number of positional-only or keyword-only nonvariadic parameters: https://github.com/pylint-dev/pylint/blob/524f2561eda21b5593ab1c69963442031817883d/pylint/checkers/classes/class_checker.py#L1414. I don't understand why they would do that; I think that's buggy behaviour from pylint there.
Test Plan
cargo test
. I added some new fixtures.