-
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
Ruff rule to remove six #11091
Comments
There's some of this in the |
I'm open to adding some of these selectively under the |
I share the sentiment with @charliermarsh. If the primary target group is python 2 users, then we should not implement the rule according to our rule acceptance guidelines.
|
Hi @charliermarsh and @MichaReiser, thank you for the replies. The point here is not serve people upgrading from python 2, it is to drop the old compatibility layer many projects kept for a long time even now supporting most modern python versions only. Same thing with UP025 where you replace "u" prefix of strings which is leftover from years of legacy support. I have a repo with over 1M LOC of python and it took a while to remove everything, but then I noticed many dependencies still imported six even if they no longer supported python 2. This means having these rules could speed up projects from dropping this layer (again same purpose as many of the UP rules). If you feel this doesn't bring enough benefit, you may close the issue |
Related: |
If it's possible to reimplement via more generic rewriting methods that didn't exist at the time, I think that would be quite convenient as IMO the UP rules are mostly a matter for oneshot actions, and six isn't particularly special. I think the only real reason in the past for not covering these rules effectively boiled down to implementation complexity and no one available to do the work? |
What about just the first rule?
The only things that have to be checked are This would be a minimal amount of work to implement and maintain. It would also be high impact. I implemented this as a Pylint rule in my org. It was an enormous success. We were two years past a migration to Python 3 and had a bunch of |
For that case alone, if you can use TID251 and configure six on banned-api for pyproject.toml Sometimes I use TID253 if the ban is only on top level imports By the way, I now agree with the ruff team here as there are other ways to block six and there is low value in maintaining these rules. IMO this Issue can be closed |
Oh, that's great. Thanks! |
Proposal: creation of rules to remove usages of the six module, replacing with the Python 3 only equivalent. This would align with the UP rules, but I don't know if they would be allowed in there or simply into the RUF code. The idea is to have fixable rules for the most common features of six and help people migrate with more confidence. There should also exist a catch-all rule just checking if six was imported.
import six
-> "Usage of six is discouraged on applications not supporting Python 2"six.string_types
,six.text_type
,six.binary_type
,six.integer_types
) with corresponding Python 3 types.isinstance(foo, six.string_types)
->isintance(foo, (str,))
six.iter*
with the corresponding method.for k, v in six.iteritems(foo):
->for k, v in foo.items():
six.print_
withprint
.six.print_("hello")
->print("hello")
six.PY2, PY3, ... with direct checks
.if six.PY3:
->if sys.version_info[0] == 3:
The text was updated successfully, but these errors were encountered: