Портируем на Python 3

  • View
    447

  • Download
    0

Embed Size (px)

DESCRIPTION

Почему стоит все чаще задумывать о поддержке Python 3 и с какими проблемами можно столкнуться при портировании. Рассмотрим на примерах из Sentry (https://github.com/getsentry/sentry) как добавить поддержку Python 3 с использованием 2to3 (http://docs.python.org/3.3/library/2to3.html), tox (http://tox.readthedocs.org/en/latest/) и six (http://pythonhosted.org/six/). Автор: Никита Гришко (Wargaming.net)

Text of Портируем на Python 3

  • 1. PYTHON 3 Nikita Grishko Wargaming.net

2. PYTHON 3? 3. PYTHON 3? 2010 2. 2. 4. PYTHON 3? Asynchronous IO Support (PEP-3156) yield from (PEP-0380) Function Annotations (PEP-3107) ... 5. ? 2.x 3.x, .. 2. 6. ? 7. ? 1. ! 8. ? 1. ! 2. ! 9. ? 1. ! 2. ! 3. : py26, py27, py32+, pypy? 10. 2TO3 (PEP-3000) 3. , 11. 2TO3 12. 2TO3 @@ -314,7 +314,7 @@ tags.append((k, v)) data['tags'] = tags +for k in data.keys(): for k in list(data.keys()): if k in RESERVED_FIELDS: continue 13. 2TO3 @@ -147,7 +147,7 @@ if worker not in default_servers: raise CommandError( 'Unsupported udp server type; expected one of %s, but got "%s".' % (', '.join(default_servers.keys()), worker)) + % (', '.join(list(default_servers.keys())), worker)) return default_servers[worker] 14. 2TO3 @@ -75,7 +75,7 @@+# Ensure values are unique, do not contain already present values, and # values specified in select_related values = set(filter(None, (getattr(o, column) for o in objects))) values = set([_f for _f in (getattr(o, column) for o in objects) if _f]) if values: qs = model.objects if database: 15. 2TO3 16. 2+3 M 2.x 3.. : django, virtualenv, requests, ... . 17. 2+3 18. 2+3 tox (http://tox.readthedocs.org/) 19. 2+3 tox (http://tox.readthedocs.org/) __future__ (http://docs.python.org/2/library/__future__.html) 20. 2+3 tox (http://tox.readthedocs.org/) __future__ (http://docs.python.org/2/library/__future__.html) six (http://pythonhosted.org/six/) 21. ? pull requests issues 22. http://www.slideshare.net/it-people/ekbpy2012-python-3 http://www.slideshare.net/it-people/python-3-16964834 23. ?NIKITA GRISHKO / HTTPS://GITHUB.COM/GR1N