Porting to Python 3: Do’s and Don’ts

http://lucumr.pocoo.org/cogitations/2008/12/07/porting-to-python-3-dos-and-donts/ の翻訳です。原文のライセンスに従い、この翻訳は Creative Commons ライセンス (http://creativecommons.org/licenses/by-nc-sa/2.0/at/deed.ja) に従います。翻訳の誤りや改善案があればコメント欄で指摘してください。

Porting to Python 3: Do’s and Don’ts
==================================================

Python 3 への移植: すべきこととすべきでないこと

So. Python 3 is here and everybody is happy. Now the community expects everyone who wrote a library to port it over to Python 3. So here my experiences so far:

Python 3 が公開されてみんな喜んでいる。今、コミュニティはライブラリの作者が Python 3 へ移植することを期待している。そこで、これまでの私の経験によると:

Don’ts

                  • -

すべきでないこと

Let’s start with the things you should not do.

すべきでないことから始めよう。

  • Use py.test for your testsuite. The developers told me that they do not plan to adapt it to Python 3 in the near future. That however is a gib no-go for such a library because it automatically breaks all the libraries that use it for unittesting. So switch over to unittest or nose as soon as possible. I’m not exactly sure how compatible nose is with Python 3, but I will post a followup about that issue in the following days because nearly all the testsuites of my libraries are currently written in py.test and nose is the testsuite that comes the closest.

py.test をテストスイートに使うこと。(py.test の)開発者達は、近い将来に py.test を python 3 へ適応させるつもりがないことを教えてくれた。しかし、それはユニットテストに py.test を使用するすべてのライブラリを自動的に壊すので、そのような(=テストスイート)ライブラリにとっての gib (big?) 失策だ。したがって、できるだけ早く unittest か nose に移行したほうがいい。 nose が Python 3 とどのくらい互換性があるのか正確には知らないが、この件について数日中に followup をポストするつもりだ。なぜなら私のライブラリのほとんど全てが現在 py.test を使って書かれていて、 nose が最も近いテストスイートだからだ。

  • Forking your library for Python 3. Don’t do that. If you can’t create a version that comes out of 2to3 and passes your testsuite do not try to hand correct the code generated. Keep in mind that you will have to support both 2.x and 3.x for at least the next two years so hand correcting the 3.x version is nothing you want to do. If you have problems with 2to3 (because it does something wrong) write it to the python-porting mailinglist.

ライブラリを Python 3 用にフォークすること。そんなことするな。もし 2to3 でテストスイートを通るバージョンを作成できないなら、生成されたコードを手で修正してはいけない。あなたは 2.x と 3.x を少なくともあと 2 年はサポートしなければならず、手作業による 3.x バージョンの修正はあなたの望むことではないということを思い出そう。もし 2to3 を使って問題があれば (because it does something wrong) python-porting メーリングリストにそのことを伝えよう。

  • Drop 2.5 support. I know converting libraries is easier if you can just support 2.6 and 3.0 but until Linux distributions / OS X ship up to date Python versions it will take some time. You will only hurt your users with such a decision.

2.5 サポートを打ち切ること。2.6 と 3.0 だけをサポートするならライブラリを変換するのは簡単だということは分かっているが、多くの Linux ディストリビューションOS X が最新の Python を搭載するようになるまでしばらくかかるだろう。そんな決断をすればユーザを傷つけるだけだ。

Dos

                  • -

すべきこと

Now to what you should do

次はあなたがすべきことだ。

  • Report problems with 2to3 as soon as possible and suggest improvements. From what I saw so far 2to3 is a nice tool but it needs a lot of post-converting fixes which are unacceptable. Try to port your library and think of how you could give 2to3 hints what it should do. I guess we can expect more command line switches, custom fixes or even comments that give 2to3 an idea of what to do (similar to how pylint ignores warnings). Write that to the porting mailinglist as soon as possible or inform “gutworth” on irc.freenode.net/#python-dev who is maintaining the 2to3 tool.

2to3 の問題をできるだけ早く連絡して、改良を提案すること。私のこれまでに見たところ 2to3 は良いツールだが、容認できない多くの変換後の修正を必要としている。私は、何をすべきかに関する考えを 2to3 に与えるための、より多くのコマンドラインスイッチや、カスタム修正またはコメントさえ期待できると思う(pylint が警告を無視するのと同様)。それを、なるべく早く porting メーリングリストに書くか、あるいは 2to3 ツールを維持している "gutworth" に irc.freenode.net/#python-dev 上で知らせる。

That’s it for the moment. Concrete tips for porting specific idoms over will come once that is possible :)

さしあたりこのくらいだ。特定のイディオムを移植するための具体的な tips は、それが可能になれば、出てくるだろう。

posted by id:knzm