-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Require Python 3.6 for consider f-string check #5024
Require Python 3.6 for consider f-string check #5024
Conversation
Although @Pierre-Sassoulas did remove all tests with However, I think there might be a discussion to be had about making checkers backwards compatible. This checker was designed in 2.10 which only supports python > 3.6. Adding checks for unsupported Python versions does not seem logical and is not what (new) contributors will expect. |
Pull Request Test Coverage Report for Build 1246284932
💛 - Coveralls |
Please see the discussion in #5019. The added test is explicitly to be executed with Python 3.6+
I don't agree. Although we don't support running To underscore my point, consider the following: We add a check to suggest the use of the new
It might only seem that way at first. |
@@ -56,10 +57,15 @@ class RecommendationChecker(checkers.BaseChecker): | |||
"Formatting a regular string which could be a f-string", | |||
"consider-using-f-string", | |||
"Used when we detect a string that is being formatted with format() or % " | |||
"which could potentially be a f-string. The use of f-strings is preferred.", | |||
"which could potentially be a f-string. The use of f-strings is preferred. " | |||
"Requires Python 3.6", |
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 believe the check doesn't actually require Python 3.6, but that py-version
is set to >= that. In that sense, this is misleading.
Same problem exists in R6103 docs (and ChangeLog and whatsnew entry for it). Fixed also in a few related places below.
"Requires Python 3.6", | |
"Requires py-version >= 3.6", |
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 see what you mean and how it can be misleading. However, I don't think using py-version
would be better. Technically f-strings
do require Python 3.6. Most users shouldn't need to set py-version
as long as they run pylint
with the oldest version that their project supports.
Another argument, if a project still supports Python 3.5, it's also correct to state that 3.6 is required.
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.
Most users shouldn't need to set py-version as long as they run pylint with the oldest version that their project supports.
Yup. But is there any documentation that would hint or explicitly say this would be the recommended thing to do? How could users tell? Unless one is familiar with the tool internals, going with the latest Python would be arguably an equally good or even better choice on surface.
For the f-strings case the Python version vs py-version distinction is coincidentally not that relevant if pylint won't run with earlier than 3.6. But saying "Requires Python 3.8" for a feature that can be checked with pylint running with Python 3.6 perfectly well it wouldn't be so. I haven't actually checked if such a case exists currently (i.e. if one can get consider-using-assignment-expr checked and messages when running with 3.6), but talking based on a hunch that it could. For that case I don't think anything besides referring to "py-version >= 3.8" would be the right thing to do, and for the same reasons, ignoring the noted coincidence, I still think documenting in terms of py-version would be the better choice here as well.
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.
(Anyway, happy to see this went in, thanks a bunch for that! Doc matters such as the one being discussed here, while important, are a secondary concern.)
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.
Yup. But is there any documentation that would hint or explicitly say this would be the recommended thing to do?
Not that I know of. That is certainly an area that needs improvement. See #5038
How could users tell? Unless one is familiar with the tool internals, going with the latest Python would be arguably an equally good or even better choice on surface.
I generalized py-version
exactly for that use case. For pylint
and astroid
we have a pylint
pre-commit hook that uses the local pylint
install. I'm using Python 3.10 at the moment, so every time pre-commit would fail for things I couldn't fix as pylint
still supports Python 3.6.
But saying "Requires Python 3.8" for a feature that can be checked with pylint running with Python 3.6 perfectly well it wouldn't be so. I haven't actually checked if such a case exists currently (i.e. if one can get consider-using-assignment-expr checked and messages when running with 3.6), but talking based on a hunch that it could. For that case I don't think anything besides referring to "py-version >= 3.8" would be the right thing to do, and for the same reasons, ignoring the noted coincidence, I still think documenting in terms of py-version would be the better choice here as well.
consider-using-assignment-expr
could indeed be checked with pylint on 3.6
. However, I think of it differently. If a user uses Python 3.6
for pylint
, he/she most likely also still supports it for their project. (Otherwise they wouldn't be using 3.6 in the first place.) Thus by saying Requires Python 3.8
, even a beginner should now that he/she needs to update their Python install first.
In contrast, using py-version >= 3.8
might lead to a situation where they think they can just set and start using it without updating Python. Although (hopefully) not that common, I imaging that would be quite frustrating.
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.
Otherwise they wouldn't be using 3.6 in the first place.
That is a fair point. I don't quite agree with the rest of the argumentation though, I think it trades potential beginner friendliness for inaccuracy, and for project like pylint, to me the latter is vastly more important. But I'm happy to leave it for the pylint maintainers to decide, just wanted to raise the point and thought I'd say what I'd do if it was my call.
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.
Maybe we can be very specific ? It would probably prevent multiple stackoverflow question or pylint's issues. It's not like we have a limited number of characters available 😄 . "Requires a python interpreter >= 3.6 to work and the pylint option 'py-version' set to >= 3.6 to be 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.
Just a note, the former "to work" part in that wording would be ambiguous -- it's not clear from that alone whether it means the check would work, or f-strings would work. "f-strings require Python >= 3.6, and this check is enabled only if the pylint option py-version is set to >= 3.6" would be more accurate if you want to go that route.
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.
LGTM :)
I was afraid of the potential for unexpected compatibility work to do but maybe you're right. The tests matrix just got enormous though. Do we need to check functional tests with each py-version ? It seems like we should but this would add maybe 5mn per pipeline. |
I misunderstood the purpose of this option. It allows users which are on >= 3.6 to check if their code would be good on < 3.6 (or any other version), right? Then I do indeed think this is fine. Sorry for the confusion!
Perhaps we could make one functional test for |
Co-authored-by: Ville Skyttä <[email protected]>
Not quite. It's only intended to hide suggestions for new features that aren't available for all versions supported by a project.
That's what I've done here 🙂 One test to make sure these warnings aren't emitted if |
IMO this PR is ready. Left a comment on the last open question: #5024 (comment) |
Type of Changes
Description
Don't emit
consider-using-f-string
ifpy-version
is set to< 3.6
.Closes #5019
/CC: @DanielNoord