Personal tools

PEP 3002

要約

This PEP describes the procedure for changes to Python that are backwards-incompatible between the Python 2.X series and Python 3000. All such changes must be documented by an appropriate Python 3000 PEP and must be accompanied by code that can identify when pieces of Python 2.X code may be problematic in Python 3000.

この PEP は Python 2.x と Python 3000 の間で後方互換性を崩す変更を決めるための 手続きについて記述しています。後方互換性を崩す変更は, Python 3000 の適切な PEP に記述されるべきです。PEP には,Python 3000 で問題を起こす Python 2.x のコードを添えておくべきです。

論拠

Python 3000 will introduce a number of backwards-incompatible changes to Python, mainly to streamline the language and to remove some previous design mistakes. But Python 3000 is not intended to be a new and completely different language from the Python 2.X series, and it is expected that much of the Python user community will make the transition to Python 3000 when it becomes available.

Python 3000 では後方互換性を崩す沢山の変更が行われる予定です。その種の変更は 言語の実装とデザイン上の誤りを修正するために行われます。 とはいえ, Python 3000 Python 2.x とまったくべつの言語を作ることを 目指してはいません。Python 3000 がリリースされたら,コミュニティのユーザの多くが 移行してくれることを期待しています。

To encourage this transition, it is crucial to provide a clear and complete guide on how to upgrade Python 2.X code to Python 3000 code. Thus, for any backwards-incompatible change, two things are required:

移行を進めるためには, Python 2.x から Python 3000 に移行するための完全な ガイドが必須でしょう。後方互換性を崩す変更については,2つのことが必要です。

  • An official Python Enhancement Proposal (PEP)
  • Code that can identify pieces of Python 2.X code that may be problematic in Python 3000
  • 公式なPEP
  • Python 3000 で問題となる Python 2.x のコード集

PEPについて

Every backwards-incompatible change must be accompanied by a PEP. This PEP should follow the usual PEP guidelines and explain the purpose and reasoning behind the backwards incompatible change. In addition to the usual PEP sections, all PEPs proposing backwards-incompatible changes must include an additional section: Compatibility Issues. This section should describe what is backwards incompatible about the proposed change to Python, and the major sorts of breakage to be expected.

後方互換性を崩す個々の変更には,かならず PEP が必要です。 この PEP は通常の PEP ガイドラインに従い,目的について解説し,後方互換性を崩す変更 がなぜ必要なのかについての説明を記述すべきです。 通常の PEP が持つ章に加え,後方互換性を崩す変更は以下の追加の記述を設けるべきです。 互換性に関する記述 - この記述には,後方互換性を崩す変更が Python をどのように 変えるのかについて記述する必要があります。また,どのような非互換性が発生するのか についても記述すべきです。

While PEPs must still be evaluated on a case-by-case basis, a PEP may be inappropriate for Python 3000 if its Compatibility Issues section implies any of the following:

PEP は状況に従って評価されますが,Python 3000 の後方互換性二関する PEP が以下に 記述するどれかに当てはまる場合は不適切と判断されるかも知れません。

  • Most or all instances of a Python 2.X construct are incorrect in Python 3000, and most or all instances of the Python 3000 construct are incorrect in Python 2.X.

  • 多くの,または全ての Pyton 2.x インスタンス生成が正しく行われないような変更。多くの,または全ての Python 3000 インスタンス生成が Python 2.x で正しく行われない場合。

    So for example, changing the meaning of the for-loop else-clause from "executed when the loop was not broken out of" to "executed when the loop had zero iterations" would mean that all Python 2.X for-loop else-clauses would be broken, and there would be no way to use a for-loop else-clause in a Python-3000-appropriate manner. Thus a PEP for such an idea would likely be rejected.

    例えば, for ループの else 節の意味を「breakで抜けなかった場合に実行する」という 意味から「ループのイテレーションが行われなかった場合に実行する」というように変える ような変更は,全ての Python 2.x と Python 3000 の for ループの else 節の 互換性を壊します。従って,このような PEP は拒否されるでしょう。

  • Many instances of a Python 2.X construct are incorrect in Python 3000 and the PEP fails to demonstrate real-world use-cases for the changes.

  • Python 2.x で生成するインスタンスの多くが Python 3000 で正しく動かない 場合は,PEP は現実的に受け入れることが出来ません。

    Backwards incompatible changes are allowed in Python 3000, but not to excess. A PEP that proposes backwards-incompatible changes should provide good examples of code that visibly benefits from the changes.

    後方互換性を崩す変更は Python 3000 で許されていますが,過度な変更は許されません。 後方互換性に関する PEP は変更から受けられる利点を明確に示す例とコードを伴っている 必要があります。

PEP-writing is time-consuming, so when a number of backwards-incompatible changes are closely related, they should be proposed in the same PEP. Such PEPs will likely have longer Compatibility Issues sections however, since they must now describe the sorts of breakage expected from all the proposed changes.

PEP を書くには時間がかかります。そのため,似通った多くの後方互換性がある場合, 同じ PEP に記述しても良いものとします。そのような PEP は,互換性に関するより長い 記述を含んでいるかも知れませんが,非互換性に関する記述はまとめて書くことが出来ます。

問題となるコードの発見

In addition to the PEP requirement, backwards incompatible changes to Python must also be accompanied by code to issue warnings for pieces of Python 2.X code that will behave differently in Python 3000. Such warnings will be enabled in Python 2.X using a new command-line switch: --python3. All backwards incompatible changes should be accompanied by a patch for Python 2.X that, when --python3 is specified, issues warnings for each construct that is being changed.

PEP を要求することに加え,Python に後方互換性を崩す変更は Python 3000 で異なった挙動を示す Python 2.x のコードに警告を表示する仕組みが必要です。 そのような警告は「--python3」のような新しいコマンドラインオプションを追加する ことで有効になるでしょう。

For example, if dict.keys() returns an iterator in Python 3000, the patch to the Python 2.X branch should do something like:

例えば,もし dict.keys() が Python 3000 でイテレータを返すとすると, Python 2.x へのパッチは以下のように動作するでしょう。

If --python3 was specified, change dict.keys() to return a subclass of list that issues warnings whenever you use any methods other than __iter__().

もし「--python3」がオブションに追加された場合, dict.keys() を利用 する時に __iter__() を使わないと,警告が発せられます。

Such a patch would mean that warnings are only issued when features that will not be present in Python 3000 are used, and almost all existing code should continue to work. (Code that relies on dict.keys() always returning a list and not a subclass should be pretty much non-existent.)

Such a patch would mean that warnings are only issued when features that will not be present in Python 3000 are used, and almost all existing code should continue to work. (Code that relies on dict.keys() always returning a list and not a subclass should be pretty much non-existent.)

Pythonな求人
r = urlopen("http://www.webcore.co.jp/recruit")
About this blog
■Author
atsこと柴田淳です。Atsushiはガイジンにうまく発音して頂けないので,これからはJunというペンネームで行こうと思っていましたがあんまり使ってません。
Webcore株式会社 代表取締役
■TRIVIAL TECHNOLOGIES 2.0
トリビアル・テクノロジー 2.0,「トリテク 2.0」と呼んでください。
Blog(ブログ)サイトです。Plone上で動く,オープンソースのBlog Product - COREBlog2を使っています。
 
最近書いた本,Mook
みんなのPython Webアプリ編
Pythonの基礎から,Webアプリやフレームワークの仕組みまで,つまることなく一気に学べる書籍です。「みんなのPython」と一緒に読んでください:-)。
みんなのPython
Pythonの入門書です。基本的なことから分かりやすく解説するよう勤めました。Pythonをはじめたいと思っている人,JavaやC++,PerlやRubyを学ぼうと思って躓いてしまった人はぜひ読んで下さい。
 

Powered by Plone, the Open Source Content Management System