2024-07-06 16:22:30 +01:00

45 lines
2.0 KiB
Plaintext

= Python 3 Port =
This page provides more detailed information on porting to Python 3 started in ticket #1328.
The current consensus is that the core and common files should be prepared for a future Twisted release with full Python 3 support and UI's worked on at a later date.
== References ==
It is best to read these other documents on Python 3 porting
[https://docs.djangoproject.com/en/dev/topics/python3/ Django]
[https://wiki.ubuntu.com/Python/3]
[https://twistedmatrix.com/trac/wiki/Plan/Python3]
== Twisted ==
Deluge relies on all dependant packages supporting Python 3 with Twisted being the most crucial and support is just about complete: [https://twistedmatrix.com/trac/wiki/Plan/Python3 Twisted Python 3 Plan].
Another option for Twisted is to remove the use of it in favour of Python 3's [https://docs.python.org/dev/library/asyncio.html asyncio]. This would, of course, remove backwards compatibility with Python 2 and require a lot of work to port to asyncio, but could be worthwhile in the end.
== 2to3 ==
Using [http://python-future.org/ python-future] is the best option to convert the code.
== Required changes ==
* Magic Method `__cmp__` in `common.py` replaced with `__lt__`
* `iteritems()` where needed replace with try/except: http://python3porting.com/differences.html#dictionary-methods
== Future Imports ==
`from __future__ import unicode_literals`::
Likely to be applied to all files to ensure byte, Unicode string separation
`from __future__ import division` ''and'' `from __future__ import print_function`::
Added to files where required
`from __future__ import absolute_import`::
Should not be required if the imports are properly set up. See: http://python3porting.com/differences.html#imports
== Compatibility Module ==
It will be easier and simpler to use either `future` or `six` (see [http://python-future.org/faq.html#what-is-the-relationship-between-future-and-six py-future] docs) to write compatible code.