Python 3.16 で削除予定

  • インポートシステム:

    • モジュールの __spec__.loader を設定せずに __loader__ を設定することは非推奨です。 Python 3.16 では、インポートシステムや標準ライブラリは __loader__ を設定しなくなり、その値も参照しなくなります。

    • Setting __package__ on a module while failing to set __spec__.parent is deprecated. In Python 3.16, __package__ will cease to be taken into consideration by the import system or standard library. (gh-97879)

  • The bundled copy of libmpdec.

  • array:

    • 書式コード 'u' (wchar_t) は、Python 3.3 からドキュメントで非推奨とされ、Python 3.13 からは実行時にも非推奨とされています。 Unicode 文字には、代わりに書式コード 'w' (Py_UCS4) を使ってください。

  • asyncio:

    • asyncio.iscoroutinefunction() は非推奨となり、Python 3.16 で削除されます。 代わりに inspect.iscoroutinefunction() を使ってください。 (Jiahao Li と Kumar Aditya が gh-122875 で貢献しました。)

    • asyncio のポリシーシステムは非推奨となり、Python 3.16 で削除されます。 具体的には、以下のクラスと関数が非推奨です:

      • asyncio.AbstractEventLoopPolicy

      • asyncio.DefaultEventLoopPolicy

      • asyncio.WindowsSelectorEventLoopPolicy

      • asyncio.WindowsProactorEventLoopPolicy

      • asyncio.get_event_loop_policy()

      • asyncio.set_event_loop_policy()

      使いたいイベントループの実装を指定するには、asyncio.run() または asyncio.Runner の loop_factory を使ってください。

      例えば、Windows で asyncio.SelectorEventLoop を使うには、次のようにします。

      import asyncio
      
      async def main():
          ...
      
      asyncio.run(main(), loop_factory=asyncio.SelectorEventLoop)
      

      (Kumar Aditya が gh-127949 で貢献しました。)

  • builtins:

    • 真偽値に対するビット単位の反転 ~True や ~False は、直感に反する意外な結果 (-2 と -1) になるため、Python 3.12 から非推奨です。 真偽値の論理否定には、代わりに not x を使ってください。 元の整数値のビット単位の反転が必要になるまれな場合には、明示的に int に変換してください (~int(x))。

  • functools:

    • functools.reduce() の Python 実装を、function や sequence をキーワード引数として指定して呼び出すことは、Python 3.14 から非推奨です。

  • logging:

    • strm 引数を持つカスタムログハンドラーへの対応は非推奨となり、Python 3.16 で削除予定です。 代わりに stream 引数を持つハンドラーを定義してください。 (Mariusz Felisiak が gh-115032 で貢献しました。)

  • mimetypes:

    • mimetypes.MimeTypes.add_type() で有効な拡張子は、'.' で始まるものか空のものです。 ドットのない拡張子は非推奨となり、Python 3.16 では ValueError が発生します。 (Hugo van Kemenade が gh-75223 で貢献しました。)

  • shutil:

    • ExecError 例外は Python 3.14 から非推奨です。 Python 3.4 以降は shutil のどの関数でも使われておらず、現在は RuntimeError の別名になっています。

  • symtable:

    • The symtable.Class.get_methods() method has been deprecated since Python 3.14.

  • sys:

    • The _enablelegacywindowsfsencoding() function has been deprecated since Python 3.13. Use the PYTHONLEGACYWINDOWSFSENCODING environment variable instead.

  • sysconfig:

    • sysconfig.expand_makefile_vars() 関数は Python 3.14 から非推奨です。 代わりに sysconfig.get_paths() の vars 引数を使ってください。

  • tarfile:

    • The undocumented and unused TarInfo.tarfile attribute has been deprecated since Python 3.13.