Porting/updating `six` and older python 3.x code to latest standard python modules🤔

Hi,

In the past have been developed for example nose2pytest module which provides possibility to filter existing nose test suites based code and more or less automatically port it to use with pytest.

Someone maybe saw some similar tools which provided filtering existing six code and more or less automatically port it to use with with latest standard modules? :thinking:

There are as well some changes for example between python 3.8.x and >= 3.9.
Someone have been thinking and/or maybe developed some tools make easier to at least encircle fragments which could be rewritten to latest pythons versions? :thinking:

kloczek

do you mean something like pyupgrade?

2 Likes

You might also want to consider Ruff, which implements all the Pyupgrade autofixers as well as hundreds of others, while running much faster due to being written in Rust. Additionally, I’m currently working on infrastructure that will allow exposing a substantial substantial amount of information on additions, changes, deprecations and removals to the language in programmatic form, which such tools could then consume to even more comprehensively identify, and in some safer automatically resolve, changes between Python versions.

4 Likes

Can you show some examples how to use ruff? :thinking:

Try the tutorial?

1 Like

do you mean something like pyupgrade?

Just tested pyupgrade and looks like it does not provide upgrade python code which uses six.

I don’t see anything in ruff about upgrade code which uses six.
It is yet another issue with ruff. I cannot build it because final linking fails with thousandths missing symbols (many rust code is COMPLETLY USELESS when LTO is used).

You don’t need to build it, you can just install it with pip.

Did this not work? Did you confirm pyupgrade ran at all?

Oh, looks like they later removed it, since it was only useful as a one-time conversion on legacy codebases rather than an ongoing linter/fixer.

Bug is always bug.
As I’m working on my own OS distribution I’m not interested to use and test anything taken from pypi.

Sorry I had wrong impression that pyupgrade does not work at all (in context of six).
It does not work in some few cases:

  • cannot replace six.StringIO by io.StringIO (and add import io)
  • sometimes it leaves no longer used from six import <foo>

Someone knows how can I replace use of six.MAXSIZE? :thinking:

Ruff should be available in the package managers of many mainstream distros (though not Debian stable, it seems), and is built and tested with LTO by default in release mode. If you run into issues building it, you might want to search or ask about your issue on the various Ruff communication channels (issue tracker, forums, etc). At least from what I’ve seen, Charlie Marsh and the other Rust maintainers are quite active, friendly and helpful on this Discourse and elsewhere responding to issue reports, particularly if the issue is with Ruff and not your bespoke config.

Per six’s own documentation, six.MAXSIZE is equivalent to sys.maxsize all the way back to Python 2.6 through present-day Python 3; the constant in six is only necessary for compat with Python 2.5, which hasn’t been relevant for well over a decade by now.