I'm attempting to convert a library from Py 2.7.x to Py 3.7.x using 2to3 on Win10. Following reference from here.
I've seen that to convert some parts of Python you need to explicitly add Fixers, specifically:
idioms
This optional fixer performs several transformations that make Python code more idiomatic. Type comparisons like type(x) is SomeClass and type(x) == SomeClass are converted to isinstance(x, SomeClass). while 1 becomes while True. This fixer also tries to make use of sorted() in appropriate places. For example, this block
L = list(some_iterable) L.sort() is changed to
L = sorted(some_iterable)
So I add it to my commandline:
2to3 --output-dir=C:\my\py3\module -f all -f buffer -f idioms -f set_literal -f ws_comma -W -n C:\my\py2\module
2to3 will generate the correct files in the C:\my\py3\module folder but list.sort() has not been resolved to sorted(list)
What am I missing here?
Product of trying to convert a lib off github at 3am. The real issue is the changes between the return value of dictionary .keys() between Py2 and Py3.
Snippet from lib I was running through 2to3:
keys = timeSamples.keys()
keys.sort()
Which I changed to:
keys = sorted(timeSamples.keys())
If I'd actually read the error message would have seen was trying to call .sort() on dict_keys type not list in Py3.