From b8b816de1fabaeb1ca9c30013b0d8fcbdf200af3 Mon Sep 17 00:00:00 2001 From: Atsuo Ishimoto Date: Sun, 6 Jul 2025 10:22:37 +0900 Subject: [PATCH 01/19] initial CLAUDE code test --- CLAUDE.md | 141 +++++++++++++++++++++++++++++++++++++++++++++ library/asyncio.po | 49 +++++++--------- 2 files changed, 162 insertions(+), 28 deletions(-) create mode 100644 CLAUDE.md diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100644 index 000000000..1e4b7a2dc --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1,141 @@ +# CLAUDE.md + +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. + +## Project Overview + +# GEMINI.md: python-docs-ja プロジェクト ガイドライン + +### 1. プロジェクト概要 + +このプロジェクトは、プログラミング言語Pythonの公式ドキュメントを日本語に翻訳する、Pythonプロジェクト公式の翻訳チームです。 + +### 2. 基本的なワークフロー + +翻訳作業は、ユーザーから指定された単一の `.po` ファイルに対して行います。一度に複数のファイルを扱ったり、まとめて翻訳したりはしません。 + +### 3. 翻訳作業のルール + +作業を行う際には、以下のルールを厳守してください。 + +#### 3.1. poファイルのフォーマットを維持する + +- 翻訳は gettext を利用した `.po` ファイル形式で行われます。 +- `msgid` (原文) と `msgstr` (訳文) のペアで構成されています。 +- **絶対に `.po` ファイルの構造を壊さないでください。** 翻訳対象は `msgstr` の中身だけです。 + +#### 3.2. reStructuredTextの構文を維持する + +- ドキュメントは reStructuredText で記述されています。 +- ``:mod:`` のようなロールや、`.. note::` のようなディレクティブ、リンクなどの構文を壊さないように、細心の注意を払って翻訳してください。 + +#### 3.3. 翻訳の進め方 + +- **既存翻訳の確認:** すでに翻訳されている箇所 (`msgstr` に記述がある箇所) は、原文 (`msgid`) の内容が正しく反映されているかを確認します。必要であれば、より適切で自然な表現に修正します。 +- **未翻訳部分の翻訳:** `msgstr` が空になっている未翻訳の部分は、他の部分の翻訳スタイルやトーンと違和感がないように、自然な日本語訳を作成・追加します。 + +#### 3.4. 翻訳品質の自動改善 + +翻訳作業時は、特別な指示がなくても以下の点を自動的にチェックし、読みにくい訳文を改善してください: + +- **不自然な表現の修正:** 「だったり」「させる」などの不自然な語尾や接続表現を自然な日本語に修正 +- **用語の統一:** 同じ概念を表す用語は一貫して使用(例:「並行処理」「並列処理」の使い分け) +- **技術用語の日本語化:** 一般的に日本語化されている用語は日本語で記述(例:「Transport」→「トランスポート」、「subprocesses」→「サブプロセス」) +- **語尾の統一:** 箇条書きなどでは語尾をですます調に統一 +- **読みやすさの向上:** 冗長な表現を簡潔にし、より自然で読みやすい日本語に改善 +- **文脈に適した表現:** 技術文書として適切な表現を選択 + +これらの改善は、翻訳の正確性を保ちながら、より自然で読みやすい日本語文書にするために行います。 + +### 4. 具体的な作業例 + +「`library/asyncio.po` を翻訳してください」という指示があった場合、以下の手順で作業を進めます。 + +1. `read_file` ツールで `library/asyncio.po` の内容を読み込みます。 +2. 未翻訳の箇所 (`msgstr ""`) を見つけます。 +3. reStructuredTextの構文に注意しながら、対応する `msgid` を翻訳し、`msgstr` に記述します。 +4. 既存の翻訳もレビューし、必要に応じて修正案を考えます。 +5. `replace` または `write_file` ツールを使い、変更を適用します。 + +## Repository Structure + +The repository is organized as follows: +- Root level: Core documentation files (about.po, bugs.po, copyright.po, etc.) +- `c-api/`: C API documentation translations +- `library/`: Standard library documentation translations +- `tutorial/`: Tutorial documentation translations +- `reference/`: Language reference translations +- `whatsnew/`: "What's New" documentation for different Python versions +- `deprecations/`: Deprecation notices +- `extending/`, `distributing/`, `installing/`: Advanced topics +- `faq/`, `howto/`: FAQ and how-to guides +- `using/`: Platform-specific usage guides + +## Common Development Commands + +### Build Documentation +```bash +make # Build HTML documentation locally +make htmlview # Build and open documentation in browser +``` + +### Translation Management +```bash +make todo # List remaining translation tasks and show progress +make fuzzy # Find fuzzy translation strings that need review +make wrap # Rewrap modified .po files to fix line lengths +``` + +### Quality Assurance +```bash +make verifs # Run all verification checks (spell, line-length, sphinx-lint) +make spell # Check spelling in translation files +make line-length # Check for lines exceeding 80 characters +make sphinx-lint # Run Sphinx linting on .po files +``` + +### Maintenance +```bash +make clean # Remove build artifacts and temporary files +scripts/update.sh # Pull latest translations from Transifex (requires setup) +``` + +## Prerequisites + +Before working with this repository, ensure you have the required dependencies: + +```bash +# Install CPython documentation build dependencies +python -m pip install -r venv/cpython/Doc/requirements.txt + +# Required tools (installed via pip or system package manager) +pip install powrap pospell pomerge potodo +``` + +## Translation Workflow + +1. **Translation Source**: Translations are managed via Transifex, not directly in this repository +2. **File Generation**: .po files are generated from Transifex translations +3. **Local Building**: Use `make` commands to build and verify translations locally +4. **Issue Reporting**: Report translation issues to [python-doc-ja repository](https://github.com/python-doc-ja/python-doc-ja/issues) + +## Architecture Notes + +- **CPython Integration**: The build system clones CPython repository into `venv/cpython/` and builds documentation using CPython's Sphinx configuration +- **Commit Tracking**: `CPYTHON_CURRENT_COMMIT` in Makefile tracks the specific CPython commit used for generating .po files +- **Excluded Files**: Older Python version documentation (2.x, 3.0-3.10) are excluded from translation +- **Language Configuration**: Target language is Japanese (`ja`), branch is `3.14` + +## File Format + +All translation files are in gettext .po format containing: +- Original English text (`msgid`) +- Japanese translation (`msgstr`) +- Translation metadata and comments +- Fuzzy markers for translations needing review + +## Pull Request Policy + +This repository does not accept pull requests. Translation changes must be made through the Transifex platform and will be automatically synchronized to this repository. + + diff --git a/library/asyncio.po b/library/asyncio.po index da4733bdf..ecd06954f 100644 --- a/library/asyncio.po +++ b/library/asyncio.po @@ -61,8 +61,8 @@ msgid "" "asyncio is a library to write **concurrent** code using the **async/await** " "syntax." msgstr "" -"asyncio は **async/await** 構文を使い **並行処理の** コードを書くためのライブ" -"ラリです。" +"asyncio は **async/await** 構文を使い **並行** コードを書くためのライブラ" +"リです。" #: ../../library/asyncio.rst:25 msgid "" @@ -79,27 +79,27 @@ msgid "" "asyncio is often a perfect fit for IO-bound and high-level **structured** " "network code." msgstr "" -"asyncio は多くの場合、 IOバウンドだったり高レベルの **構造化された** ネット" -"ワークコードに完璧に適しています。" +"asyncio は多くの場合、IOバウンドや高レベルの **構造化された** ネットワー" +"クコードに完璧に適しています。" #: ../../library/asyncio.rst:32 msgid "asyncio provides a set of **high-level** APIs to:" -msgstr "asyncio は次の目的で **高レベル** API を提供しています:" +msgstr "asyncio は以下の目的で **高レベル** API を提供しています:" #: ../../library/asyncio.rst:34 msgid "" ":ref:`run Python coroutines ` concurrently and have full control " "over their execution;" msgstr "" -"並行に :ref:`Python コルーチンを起動 ` し、実行全体を管理する" +"並行に :ref:`Python コルーチンを実行 ` し、その実行を完全に制御する" #: ../../library/asyncio.rst:37 msgid "perform :ref:`network IO and IPC `;" -msgstr ":ref:`ネットワーク IO と IPC ` を執り行う" +msgstr ":ref:`ネットワーク IO と IPC ` を実行する" #: ../../library/asyncio.rst:39 msgid "control :ref:`subprocesses `;" -msgstr ":ref:`subprocesses ` を管理する" +msgstr ":ref:`サブプロセス ` を管理する" #: ../../library/asyncio.rst:41 msgid "distribute tasks via :ref:`queues `;" @@ -107,15 +107,14 @@ msgstr ":ref:`キュー ` を使ってタスクを分散する" #: ../../library/asyncio.rst:43 msgid ":ref:`synchronize ` concurrent code;" -msgstr "並列処理のコードを :ref:`同期 ` させる" +msgstr "並行処理のコードを :ref:`同期 ` する" #: ../../library/asyncio.rst:45 msgid "" "Additionally, there are **low-level** APIs for *library and framework " "developers* to:" msgstr "" -"これに加えて、 *ライブラリやフレームワークの開発者* が次のことをするための **" -"低レベル** API があります:" +"さらに、*ライブラリやフレームワークの開発者*向けには以下の **低レベル** API があります:" #: ../../library/asyncio.rst:48 msgid "" @@ -124,48 +123,43 @@ msgid "" "`subprocesses `, handling :ref:`OS signals " "`, etc;" msgstr "" -":ref:`ネットワーク通信 ` 、 :ref:`サブプロセス " -"` の実行、 :ref:`OS シグナル " -"` の取り扱いなどのための非同期 API を提供する :ref:`" -"イベントループ ` の作成と管理を行う" +":ref:`イベントループ ` を作成・管理し、:ref:`ネットワーク通信 `、:ref:`サブプロセスの実行 `、:ref:`OS シグナルの取り扱い ` などのための非同期 API を提供する" #: ../../library/asyncio.rst:53 msgid "" "implement efficient protocols using :ref:`transports `;" msgstr "" -":ref:`Transport ` を使った効率的な protocol を" -"実装します" +":ref:`トランスポート ` を使った効率的なプロ" +"トコルを実装する" #: ../../library/asyncio.rst:56 msgid "" ":ref:`bridge ` callback-based libraries and code with async/" "await syntax." msgstr "" -"コールバックを用いたライブラリと async/await 構文を使ったコードの :ref:`橋渡" -"し `" +"コールバックベースのライブラリと async/await 構文を使ったコードを :ref:`ブリッジする `" #: ../../includes/wasm-notavail.rst:3 msgid "Availability" -msgstr "" +msgstr "利用可能性" #: ../../includes/wasm-notavail.rst:5 msgid "" "This module does not work or is not available on WebAssembly. See :ref:`wasm-" "availability` for more information." msgstr "" -"このモジュールは WebAssembly では動作しないか、利用不可です。詳しくは、:ref:" -"`wasm-availability` を見てください。" +"このモジュールは WebAssembly では動作しないか、利用できません。詳しくは :ref:`wasm-availability` を参照してください。" #: ../../library/asyncio.rst:64 msgid "asyncio REPL" -msgstr "" +msgstr "asyncio REPL" #: ../../library/asyncio.rst:65 msgid "" "You can experiment with an ``asyncio`` concurrent context in the :term:" "`REPL`:" -msgstr "" +msgstr "":term:`REPL` で ``asyncio`` の並行コンテキストを試すことができます:" #: ../../library/asyncio.rst:67 msgid "" @@ -184,18 +178,17 @@ msgid "" "Raises an :ref:`auditing event ` ``cpython.run_stdin`` with no " "arguments." msgstr "" -"引数無しで :ref:`監査イベント ` ``cpython.run_stdin`` を送出しま" -"す。 " +"引数なしで :ref:`監査イベント ` ``cpython.run_stdin`` を発生させます。" #: ../../library/asyncio.rst:79 msgid "(also 3.11.10, 3.10.15, 3.9.20, and 3.8.20) Emits audit events." -msgstr "" +msgstr "(3.11.10, 3.10.15, 3.9.20, 3.8.20 でも同様) 監査イベントを発行します。" #: ../../library/asyncio.rst:82 msgid "" "Uses PyREPL if possible, in which case :envvar:`PYTHONSTARTUP` is also " "executed. Emits audit events." -msgstr "" +msgstr "可能であれば PyREPL を使用し、その場合 :envvar:`PYTHONSTARTUP` も実行されます。監査イベントを発行します。" #: ../../library/asyncio.rst:90 msgid "Reference" From a52b353072bd6446e674376b1eec923271bd20ed Mon Sep 17 00:00:00 2001 From: Atsuo Ishimoto Date: Sun, 6 Jul 2025 13:37:42 +0900 Subject: [PATCH 02/19] heh --- CLAUDE.md | 63 ++++++++++++++++++++++++++++++++++++++++++++++++ requirements.txt | 1 + 2 files changed, 64 insertions(+) diff --git a/CLAUDE.md b/CLAUDE.md index 1e4b7a2dc..fe808f9c4 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -14,6 +14,8 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co 翻訳作業は、ユーザーから指定された単一の `.po` ファイルに対して行います。一度に複数のファイルを扱ったり、まとめて翻訳したりはしません。 + + ### 3. 翻訳作業のルール 作業を行う際には、以下のルールを厳守してください。 @@ -57,6 +59,67 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co 4. 既存の翻訳もレビューし、必要に応じて修正案を考えます。 5. `replace` または `write_file` ツールを使い、変更を適用します。 +#### 4.1 ファイルの分割 + +.poファイルのサイズが5kbを超える場合は、すべてをまとめて処理せず、splitpoコマンドでpoファイルを複数に分割してそれぞれを翻訳します。 + + +``` + splitpo -h +usage: splitpo [-h] [-o OUTPUT_DIR] [-e ENTRIES] input_file + +Split a .po file into chunks by entry count + +positional arguments: + input_file Input .po file to split + +options: + -h, --help show this help message and exit + -o, --output-dir OUTPUT_DIR + Output directory for split files + -e, --entries ENTRIES + Number of entries per split file (default: 100) + +``` + +実行例: + + `splitpo -o /tmp/split_pathlib -e 200 library/pathlib.po` + +このコマンドは、poファイルを200エントリごとに分割します。 + +Split files are named with the pattern `{original_name}_part_{number}.po`: +- `input.po` → `input_part_000.po`, `input_part_001.po`, etc. +- Number of digits adjusts to file count (minimum 3 digits) +- Numbering starts from 0 + +ファイル名をそのままソートすれば、元ファイルと同じ順番で並ぶようになっていますので、この順序で翻訳を進めてください。 + +それぞれのファイルの翻訳が終了したら、joinpoコマンドで分割したファイルを結合します。 + + +``` + joinpo -h +usage: joinpo [-h] -o OUTPUT input_files [input_files ...] + +Join split .po files back together + +positional arguments: + input_files Input .po files to join (supports wildcards) + +options: + -h, --help show this help message and exit + -o, --output OUTPUT Output .po file +``` + +実行例: + + `joinpo -o translated_pathlib.po /tmp/split_pathlib/*.po -o` + + + + + ## Repository Structure The repository is organized as follows: diff --git a/requirements.txt b/requirements.txt index 2c07cc170..07a409b6f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,3 +3,4 @@ git+https://github.com/sphinx-doc/sphinx-intl@6b3913fea5a8c9b819818b9b28b6d0d0b6 powrap pospell pomerge +translate-toolkit From 1495de45db1e771c4a04c77a67926c635223e739 Mon Sep 17 00:00:00 2001 From: Atsuo Ishimoto Date: Sun, 6 Jul 2025 14:23:50 +0900 Subject: [PATCH 03/19] update --- CLAUDE.md | 35 +++++++++++++++++++++++--- library/pathlib.po | 61 ++++++++++++++++++++++++++++++++++------------ 2 files changed, 77 insertions(+), 19 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index fe808f9c4..09a92bcf9 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -61,7 +61,7 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co #### 4.1 ファイルの分割 -.poファイルのサイズが5kbを超える場合は、すべてをまとめて処理せず、splitpoコマンドでpoファイルを複数に分割してそれぞれを翻訳します。 +.poファイルのサイズが20kbを超える場合は、すべてをまとめて処理せず、splitpoコマンドでpoファイルを50エントリずつに分割して、それぞれを翻訳します。 ``` @@ -84,9 +84,9 @@ options: 実行例: - `splitpo -o /tmp/split_pathlib -e 200 library/pathlib.po` + `splitpo -o /tmp/split_pathlib -e 50 library/pathlib.po` -このコマンドは、poファイルを200エントリごとに分割します。 +このコマンドは、poファイルを50エントリごとに分割します。 Split files are named with the pattern `{original_name}_part_{number}.po`: - `input.po` → `input_part_000.po`, `input_part_001.po`, etc. @@ -120,6 +120,35 @@ options: +### 4.2 翻訳の完全性 + +翻訳作業では、**翻訳が必要なすべてのエントリを必ず翻訳する**必要があります。一部だけを残すことは許可されません。 + +#### 翻訳が必要なエントリの判別 + +- **翻訳が必要**: 説明文、エラーメッセージ、ドキュメント本文など +- **翻訳不要(`msgstr ""`のまま)**: + - コード実行例(`>>> ...`形式のPythonコード) + - プログラムコードサンプル + - ファイルパス例 + - 設定値例 + - コマンド出力例 + +#### 翻訳作業の要件 + +1. **完全性の確保**: 翻訳が必要なすべてのエントリを必ず翻訳する +2. **抜け漏れなし**: 時間的制約に関係なく、すべての翻訳対象エントリを完了させる +3. **系統的な作業**: 分割ファイルでも各ファイルのすべての翻訳対象エントリを完了してから次に進む +4. **既存翻訳の確認**: 新規翻訳だけでなく、既存の翻訳についても品質をチェックし、必要に応じて改善する + +#### 翻訳完了の確認 + +翻訳作業を完了する前に、以下を確認してください: + +1. すべての説明文が翻訳されている +2. 既存翻訳の品質が改善されている +3. コード例等の翻訳不要な部分は適切に `msgstr ""` のまま残されている + ## Repository Structure The repository is organized as follows: diff --git a/library/pathlib.po b/library/pathlib.po index 6718cf008..b9ac243f0 100644 --- a/library/pathlib.po +++ b/library/pathlib.po @@ -45,13 +45,12 @@ msgid "" "operations without I/O, and :ref:`concrete paths `, which " "inherit from pure paths but also provide I/O operations." msgstr "" -"このモジュールはファイルシステムのパスを表すクラスを提供していて、様々なオペ" -"レーティングシステムについての適切な意味論をそれらのクラスに持たせていま" -"す。\n" -"Path クラスは :ref:`純粋パス ` と :ref:`具象パス ` からなります。\n" +"このモジュールは、さまざまなオペレーティングシステムに適した意味論を持つ" +"ファイルシステムパスを表すクラスを提供します。\n" +"パスクラスは :ref:`純粋パス ` と :ref:`具象パス ` に分かれています。\n" "純粋パスは I/O を伴わない純粋な計算操作を提供します。\n" -"具象パスは純粋パスを継承していますが、 I/O 操作も提供しています。" +"具象パスは純粋パスを継承し、さらに I/O 操作も提供します。" #: ../../library/pathlib.rst:21 msgid "" @@ -62,6 +61,12 @@ msgid "" "PosixPath subclasses PurePosixPath and Path, and WindowsPath\n" "subclasses PureWindowsPath and Path." msgstr "" +"pathlibで利用できるクラスの継承図です。最も基本的なクラスは\n" +"PurePathで、PurePosixPath、PureWindowsPath、Pathという\n" +"3つの直接的なサブクラスがあります。これら4つのクラスに加えて、\n" +"多重継承を使用する2つのクラスがあります:PosixPathは\n" +"PurePosixPathとPathのサブクラスで、WindowsPathは\n" +"PureWindowsPathとPathのサブクラスです。" #: ../../library/pathlib.rst:31 msgid "" @@ -70,10 +75,9 @@ msgid "" "instantiates a :ref:`concrete path ` for the platform the " "code is running on." msgstr "" -"あなたが今までこのモジュールを使用したことがない場合や、タスクに適しているの" -"がどのクラスかわからない場合は、 :class:`Path` はきっとあなたに必要なもので" -"しょう。\n" -":class:`Path` はコードが実行されているプラットフォーム用の :ref:`具象パス " +"このモジュールを使ったことがない場合や、どのクラスが適しているかわからない場合は、" +" :class:`Path` を使うのが最適です。\n" +":class:`Path` は、コードが実行されているプラットフォームに対応した :ref:`具象パス " "` のインスタンスを作成します。" #: ../../library/pathlib.rst:35 @@ -86,9 +90,9 @@ msgid "" "You cannot instantiate a :class:`WindowsPath` when running on Unix, but you " "can instantiate :class:`PureWindowsPath`." msgstr "" -"Unix マシン上で Windows のパスを扱いたいとき (またはその逆)。Unix 上で実行し" -"ているときに :class:`WindowsPath` のインスタンスを作成することはできません" -"が、:class:`PureWindowsPath` なら可能になります。" +"Unix マシン上で Windows のパスを扱いたい場合 (またはその逆)。Unix 上で " +":class:`WindowsPath` のインスタンスを作成することはできませんが、" +":class:`PureWindowsPath` なら可能です。" #: ../../library/pathlib.rst:40 msgid "" @@ -96,9 +100,9 @@ msgid "" "accessing the OS. In this case, instantiating one of the pure classes may be " "useful since those simply don't have any OS-accessing operations." msgstr "" -"実際に OS にアクセスすることなしにパスを操作するだけのコードを確認したいと" -"き。この場合、純粋クラスのインスタンスを一つ作成すれば、それが OS にアクセス" -"することはないので便利です。" +"実際に OS にアクセスせずにパスを操作するだけのコードにしたい場合。" +"この場合、純粋クラスのインスタンスを作成すれば、OS にアクセスする" +"操作がないため便利です。" #: ../../library/pathlib.rst:45 msgid ":pep:`428`: The pathlib module -- object-oriented filesystem paths." @@ -1587,6 +1591,9 @@ msgid "" "``False`` will be returned if the path is invalid, inaccessible or missing. " "Use :meth:`Path.stat` to distinguish between these cases." msgstr "" +"パスが既存のファイルまたはディレクトリを指している場合は ``True`` を返します。" +"パスが無効、アクセス不能、または存在しない場合は ``False`` を返します。" +"これらの場合を区別するには :meth:`Path.stat` を使用してください。" #: ../../library/pathlib.rst:1057 msgid "" @@ -1615,6 +1622,9 @@ msgid "" "something other than a regular file. Use :meth:`Path.stat` to distinguish " "between these cases." msgstr "" +"パスが通常のファイルを指している場合は ``True`` を返します。パスが無効、" +"アクセス不能、存在しない、または通常のファイル以外のものを指している場合は" +" ``False`` を返します。これらの場合を区別するには :meth:`Path.stat` を使用してください。" #: ../../library/pathlib.rst:1082 msgid "" @@ -1631,6 +1641,9 @@ msgid "" "something other than a directory. Use :meth:`Path.stat` to distinguish " "between these cases." msgstr "" +"パスがディレクトリを指している場合は ``True`` を返します。パスが無効、" +"アクセス不能、存在しない、またはディレクトリ以外のものを指している場合は" +" ``False`` を返します。これらの場合を区別するには :meth:`Path.stat` を使用してください。" #: ../../library/pathlib.rst:1096 msgid "" @@ -1647,6 +1660,10 @@ msgid "" "or missing, or if it points to something other than a symbolic link. Use :" "meth:`Path.stat` to distinguish between these cases." msgstr "" +"パスがシンボリックリンクを指している場合は、そのシンボリックリンクが壊れていても" +" ``True`` を返します。パスが無効、アクセス不能、存在しない、" +"またはシンボリックリンク以外のものを指している場合は ``False`` を返します。" +"これらの場合を区別するには :meth:`Path.stat` を使用してください。" #: ../../library/pathlib.rst:1113 msgid "" @@ -1687,6 +1704,9 @@ msgid "" "something other than a Unix socket. Use :meth:`Path.stat` to distinguish " "between these cases." msgstr "" +"パスが Unix ソケットを指している場合は ``True`` を返します。パスが無効、" +"アクセス不能、存在しない、または Unix ソケット以外のものを指している場合は" +" ``False`` を返します。これらの場合を区別するには :meth:`Path.stat` を使用してください。" #: ../../library/pathlib.rst:1145 msgid "" @@ -1694,6 +1714,9 @@ msgid "" "the path is invalid, inaccessible or missing, or if it points to something " "other than a FIFO. Use :meth:`Path.stat` to distinguish between these cases." msgstr "" +"パスが FIFO を指している場合は ``True`` を返します。パスが無効、" +"アクセス不能、存在しない、または FIFO 以外のものを指している場合は" +" ``False`` を返します。これらの場合を区別するには :meth:`Path.stat` を使用してください。" #: ../../library/pathlib.rst:1153 msgid "" @@ -1702,6 +1725,9 @@ msgid "" "something other than a block device. Use :meth:`Path.stat` to distinguish " "between these cases." msgstr "" +"パスがブロックデバイスを指している場合は ``True`` を返します。パスが無効、" +"アクセス不能、存在しない、またはブロックデバイス以外のものを指している場合は" +" ``False`` を返します。これらの場合を区別するには :meth:`Path.stat` を使用してください。" #: ../../library/pathlib.rst:1161 msgid "" @@ -1710,6 +1736,9 @@ msgid "" "something other than a character device. Use :meth:`Path.stat` to " "distinguish between these cases." msgstr "" +"パスがキャラクターデバイスを指している場合は ``True`` を返します。パスが無効、" +"アクセス不能、存在しない、またはキャラクターデバイス以外のものを指している場合は" +" ``False`` を返します。これらの場合を区別するには :meth:`Path.stat` を使用してください。" #: ../../library/pathlib.rst:1169 msgid "" From 1774e9b97218b8c8c63ed354fc9abc5522072ef7 Mon Sep 17 00:00:00 2001 From: Atsuo Ishimoto Date: Sun, 6 Jul 2025 14:24:12 +0900 Subject: [PATCH 04/19] heh --- library/dataclasses.po | 826 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 817 insertions(+), 9 deletions(-) diff --git a/library/dataclasses.po b/library/dataclasses.po index d5dc38ae7..12956e9c1 100644 --- a/library/dataclasses.po +++ b/library/dataclasses.po @@ -68,6 +68,17 @@ msgid "" " def total_cost(self) -> float:\n" " return self.unit_price * self.quantity_on_hand" msgstr "" +"from dataclasses import dataclass\n" +"\n" +"@dataclass\n" +"class InventoryItem:\n" +" \"\"\"Class for keeping track of an item in inventory.\"\"\"\n" +" name: str\n" +" unit_price: float\n" +" quantity_on_hand: int = 0\n" +"\n" +" def total_cost(self) -> float:\n" +" return self.unit_price * self.quantity_on_hand" #: ../../library/dataclasses.rst:34 msgid "will add, among other things, a :meth:`!__init__` that looks like::" @@ -81,6 +92,11 @@ msgid "" " self.unit_price = unit_price\n" " self.quantity_on_hand = quantity_on_hand" msgstr "" +"def __init__(self, name: str, unit_price: float, quantity_on_hand: int = " +"0):\n" +" self.name = name\n" +" self.unit_price = unit_price\n" +" self.quantity_on_hand = quantity_on_hand" #: ../../library/dataclasses.rst:41 msgid "" @@ -143,6 +159,9 @@ msgid "" "acts as if it has the default values documented in this signature. That is, " "these three uses of ``@dataclass`` are equivalent::" msgstr "" +"``@dataclass`` をパラメータなしの単純なデコレータとして使用した場合、" +"このシグネチャに記載されているデフォルト値を持つかのように動作します。" +"つまり、これら3つの ``@dataclass`` の使用法は等価です::" #: ../../library/dataclasses.rst:74 msgid "" @@ -160,21 +179,36 @@ msgid "" "class C:\n" " ..." msgstr "" +"@dataclass\n" +"class C:\n" +" ...\n" +"\n" +"@dataclass()\n" +"class C:\n" +" ...\n" +"\n" +"@dataclass(init=True, repr=True, eq=True, order=False, unsafe_hash=False, " +"frozen=False,\n" +" match_args=True, kw_only=False, slots=False, weakref_slot=False)\n" +"class C:\n" +" ..." #: ../../library/dataclasses.rst:87 msgid "The parameters to ``@dataclass`` are:" -msgstr "" +msgstr "``@dataclass`` のパラメータは以下の通りです:" #: ../../library/dataclasses.rst:89 msgid "" "*init*: If true (the default), a :meth:`~object.__init__` method will be " "generated." msgstr "" +"*init*: True(デフォルト)の場合、:meth:`~object.__init__` メソッドが生成されます。" #: ../../library/dataclasses.rst:92 msgid "" "If the class already defines :meth:`!__init__`, this parameter is ignored." msgstr "" +"クラスが既に :meth:`!__init__` を定義している場合、このパラメータは無視されます。" #: ../../library/dataclasses.rst:95 msgid "" @@ -185,11 +219,17 @@ msgid "" "example: ``InventoryItem(name='widget', unit_price=3.0, " "quantity_on_hand=10)``." msgstr "" +"*repr*: True(デフォルト)の場合、:meth:`~object.__repr__` メソッドが生成されます。" +"生成される repr 文字列には、クラス名と各フィールドの名前および repr が、" +"クラス内で定義された順序で含まれます。repr から除外するようにマークされた" +"フィールドは含まれません。例: ``InventoryItem(name='widget', unit_price=3.0, " +"quantity_on_hand=10)``。" #: ../../library/dataclasses.rst:102 msgid "" "If the class already defines :meth:`!__repr__`, this parameter is ignored." msgstr "" +"クラスが既に :meth:`!__repr__` を定義している場合、このパラメータは無視されます。" #: ../../library/dataclasses.rst:105 msgid "" @@ -198,11 +238,15 @@ msgid "" "fields, in order. Both instances in the comparison must be of the identical " "type." msgstr "" +"*eq*: True(デフォルト)の場合、:meth:`~object.__eq__` メソッドが生成されます。" +"このメソッドは、クラスがそのフィールドの順序でタプルであるかのように比較します。" +"比較する両方のインスタンスは同一の型である必要があります。" #: ../../library/dataclasses.rst:110 msgid "" "If the class already defines :meth:`!__eq__`, this parameter is ignored." msgstr "" +"クラスが既に :meth:`!__eq__` を定義している場合、このパラメータは無視されます。" #: ../../library/dataclasses.rst:113 msgid "" @@ -212,12 +256,19 @@ msgid "" "fields, in order. Both instances in the comparison must be of the identical " "type. If *order* is true and *eq* is false, a :exc:`ValueError` is raised." msgstr "" +"*order*: True(デフォルトは ``False``)の場合、:meth:`~object.__lt__`、" +":meth:`~object.__le__`、:meth:`~object.__gt__`、:meth:`~object.__ge__` " +"メソッドが生成されます。これらは、クラスがそのフィールドのタプルであるかのように" +"順序で比較します。比較する両方のインスタンスは同一の型である必要があります。" +"*order* が True で *eq* が False の場合、:exc:`ValueError` が発生します。" #: ../../library/dataclasses.rst:120 msgid "" "If the class already defines any of :meth:`!__lt__`, :meth:`!__le__`, :meth:" "`!__gt__`, or :meth:`!__ge__`, then :exc:`TypeError` is raised." msgstr "" +"クラスが既に :meth:`!__lt__`、:meth:`!__le__`、:meth:`!__gt__`、:meth:`!__ge__` の" +"いずれかを定義している場合、:exc:`TypeError` が発生します。" #: ../../library/dataclasses.rst:124 msgid "" @@ -226,6 +277,10 @@ msgid "" "generate a :meth:`~object.__hash__` method according to how *eq* and " "*frozen* are set. The default value is ``False``." msgstr "" +"*unsafe_hash*: True の場合、安全でない可能性があっても ``dataclasses`` に " +":meth:`~object.__hash__` メソッドの作成を強制します。そうでない場合は、*eq* " +"と *frozen* の設定に応じて :meth:`~object.__hash__` メソッドを生成します。" +"デフォルト値は ``False`` です。" #: ../../library/dataclasses.rst:130 msgid "" @@ -236,6 +291,11 @@ msgid "" "and behavior of :meth:`!__eq__`, and the values of the *eq* and *frozen* " "flags in the ``@dataclass`` decorator." msgstr "" +":meth:`!__hash__` は組み込み関数 :meth:`hash` や、辞書や集合などのハッシュ" +"コレクションにオブジェクトが追加される際に使われます。:meth:`!__hash__` を" +"持つということは、そのクラスのインスタンスが不変であることを意味します。" +"可変性は複雑な特性で、プログラマーの意図、:meth:`!__eq__` の存在と動作、" +"``@dataclass`` デコレータの *eq* と *frozen* フラグの値に依存します。" #: ../../library/dataclasses.rst:137 msgid "" @@ -245,6 +305,11 @@ msgid "" "attribute ``__hash__ = None`` has a specific meaning to Python, as described " "in the :meth:`!__hash__` documentation." msgstr "" +"デフォルトでは、``@dataclass`` は安全でない限り :meth:`~object.__hash__` " +"メソッドを暗黙的に追加しません。また、既存の明示的に定義された :meth:`!__hash__` " +"メソッドを追加または変更することもありません。クラス属性 ``__hash__ = None`` の" +"設定は、:meth:`!__hash__` のドキュメントで説明されているように、Python にとって" +"特別な意味を持ちます。" #: ../../library/dataclasses.rst:143 msgid "" @@ -255,6 +320,11 @@ msgid "" "logically immutable but can still be mutated. This is a specialized use case " "and should be considered carefully." msgstr "" +":meth:`!__hash__` が明示的に定義されていない、または ``None`` に設定されている場合、" +"``@dataclass`` は :meth:`!__hash__` メソッドを暗黙的に追加する *場合があります* 。" +"推奨されませんが、``unsafe_hash=True`` を使って ``@dataclass`` に :meth:`!__hash__` " +"メソッドの作成を強制できます。これは、クラスが論理的には不変であるにもかかわらず、" +"変更可能である場合にあたります。これは特殊な使用例であり、慣重に検討する必要があります。" #: ../../library/dataclasses.rst:150 msgid "" @@ -263,6 +333,9 @@ msgid "" "in your dataclass and set ``unsafe_hash=True``; this will result in a :exc:" "`TypeError`." msgstr "" +":meth:`!__hash__` メソッドの暗黙的な作成を支配するルールは以下の通りです。" +"データクラスで明示的な :meth:`!__hash__` メソッドを持ち、かつ ``unsafe_hash=True`` を" +"設定することはできません。これを行うと :exc:`TypeError` が発生します。" #: ../../library/dataclasses.rst:155 msgid "" @@ -274,6 +347,12 @@ msgid "" "used (if the superclass is :class:`object`, this means it will fall back to " "id-based hashing)." msgstr "" +"*eq* と *frozen* がともに True の場合、デフォルトで ``@dataclass`` が :meth:`!__hash__` " +"メソッドを生成します。*eq* が True で *frozen* が False の場合、:meth:`!__hash__` は " +"``None`` に設定され、ハッシュ化不可能としてマークされます(実際に可変であるため)。" +"*eq* が False の場合、:meth:`!__hash__` は変更されず、スーパークラスの :meth:`!__hash__` " +"メソッドが使用されます(スーパークラスが :class:`object` の場合、ID ベースの" +"ハッシュ化にフォールバックします)。" #: ../../library/dataclasses.rst:163 msgid "" @@ -282,6 +361,10 @@ msgid "" "`~object.__setattr__` or :meth:`~object.__delattr__` is defined in the " "class, then :exc:`TypeError` is raised. See the discussion below." msgstr "" +"*frozen*: True(デフォルトは ``False``)の場合、フィールドへの代入で例外が発生します。" +"これは読み取り専用の凍結されたインスタンスをエミュレートします。クラスで :meth:`~object.__setattr__` " +"または :meth:`~object.__delattr__` が定義されている場合、:exc:`TypeError` が発生します。" +"以下の説明を参照してください。" #: ../../library/dataclasses.rst:168 msgid "" @@ -292,6 +375,11 @@ msgid "" "__match_args__` is already defined in the class, then :attr:`!" "__match_args__` will not be generated." msgstr "" +"*match_args*: True(デフォルトは ``True``)の場合、生成された :meth:`~object.__init__` " +"メソッドの非キーワード専用パラメータのリストから :attr:`~object.__match_args__` タプルが" +"作成されます(:meth:`!__init__` が生成されない場合でも、上記を参照)。" +"False の場合、または :attr:`!__match_args__` がクラスで既に定義されている場合、" +":attr:`!__match_args__` は生成されません。" #: ../../library/dataclasses.rst:177 msgid "" @@ -302,10 +390,17 @@ msgid "" "is called. See the :term:`parameter` glossary entry for details. Also see " "the :const:`KW_ONLY` section." msgstr "" +"*kw_only*: True(デフォルト値は ``False``)の場合、すべてのフィールドが" +"キーワード専用としてマークされます。フィールドがキーワード専用としてマークされた場合、" +"唯一の効果は、:meth:`!__init__` が呼び出された際にキーワード専用フィールドから生成された " +":meth:`~object.__init__` パラメータをキーワードで指定する必要があることです。" +"詳細は :term:`parameter` 用語集のエントリを参照してください。" +"また、:const:`KW_ONLY` の節も参照してください。" #: ../../library/dataclasses.rst:185 msgid "Keyword-only fields are not included in :attr:`!__match_args__`." msgstr "" +"キーワード専用フィールドは :attr:`!__match_args__` に含まれません。" #: ../../library/dataclasses.rst:189 msgid "" @@ -314,6 +409,9 @@ msgid "" "original one. If :attr:`!__slots__` is already defined in the class, then :" "exc:`TypeError` is raised." msgstr "" +"*slots*: True(デフォルトは ``False``)の場合、:attr:`~object.__slots__` 属性が" +"生成され、元のクラスの代わりに新しいクラスが返されます。クラスで :attr:`!__slots__` が" +"既に定義されている場合、:exc:`TypeError` が発生します。" #: ../../library/dataclasses.rst:195 msgid "" @@ -322,6 +420,10 @@ msgid "" "``__init_subclass__`` with no parameters or use default values as a " "workaround. See :gh:`91126` for full details." msgstr "" +"``slots=True`` を使用している際にベースクラスの :meth:`~object.__init_subclass__` に" +"パラメータを渡すと :exc:`TypeError` が発生します。回避策として、パラメータなしで " +"``__init_subclass__`` を使用するか、デフォルト値を使用してください。" +"詳細は :gh:`91126` を参照してください。" #: ../../library/dataclasses.rst:203 msgid "" @@ -332,6 +434,13 @@ msgid "" "`fields` instead. To be able to determine inherited slots, base class :attr:" "`!__slots__` may be any iterable, but *not* an iterator." msgstr "" +"フィールド名がベースクラスの :attr:`!__slots__` に既に含まれている場合、" +":ref:`それらをオーバーライドする ` ことを防ぐため、" +"生成される :attr:`!__slots__` には含まれません。したがって、データクラスの" +"フィールド名を取得するために :attr:`!__slots__` を使用しないでください。" +"代わりに :func:`fields` を使用してください。継承されたスロットを判定できる" +"ようにするため、ベースクラスの :attr:`!__slots__` は任意のイテラブルですが、" +"イテレータではないものにできます。" #: ../../library/dataclasses.rst:213 msgid "" @@ -340,13 +449,17 @@ msgid "" "`. It is an error to specify ``weakref_slot=True`` without also " "specifying ``slots=True``." msgstr "" +"*weakref_slot*: True(デフォルトは ``False``)の場合、\"__weakref__\" という" +"名前のスロットを追加します。これは、インスタンスを :func:`weakref 対応 " +"` にするために必要です。``slots=True`` も指定せずに " +"``weakref_slot=True`` を指定するとエラーになります。" #: ../../library/dataclasses.rst:221 msgid "" "``field``\\s may optionally specify a default value, using normal Python " "syntax::" msgstr "" -"``フィールド`` には、通常の Python の文法でデフォルト値を指定できます。" +"``フィールド`` には、通常の Python の文法でデフォルト値を指定できます::" #: ../../library/dataclasses.rst:224 msgid "" @@ -355,16 +468,23 @@ msgid "" " a: int # 'a' has no default value\n" " b: int = 0 # assign a default value for 'b'" msgstr "" +"@dataclass\n" +"class C:\n" +" a: int # 'a' has no default value\n" +" b: int = 0 # assign a default value for 'b'" #: ../../library/dataclasses.rst:229 msgid "" "In this example, both :attr:`!a` and :attr:`!b` will be included in the " "added :meth:`~object.__init__` method, which will be defined as::" msgstr "" +"この例では、:attr:`!a` と :attr:`!b` の両方が追加される :meth:`~object.__init__` " +"メソッドに含まれ、以下のように定義されます::" #: ../../library/dataclasses.rst:232 msgid "def __init__(self, a: int, b: int = 0):" msgstr "" +"def __init__(self, a: int, b: int = 0):" #: ../../library/dataclasses.rst:234 msgid "" @@ -384,6 +504,10 @@ msgid "" "replace the default field value with a call to the provided :func:`!field` " "function. For example::" msgstr "" +"一般的で簡単な使用例では、他の機能は必要ありません。しかし、フィールドごとの" +"追加情報を必要とするデータクラスの機能がいくつかあります。この追加情報のニーズを" +"満たすために、デフォルトのフィールド値を提供された :func:`!field` 関数の呼び出しで" +"置き換えることができます。例えば::" #: ../../library/dataclasses.rst:246 msgid "" @@ -394,6 +518,12 @@ msgid "" "c = C()\n" "c.mylist += [1, 2, 3]" msgstr "" +"@dataclass\n" +"class C:\n" +" mylist: list[int] = field(default_factory=list)\n" +"\n" +"c = C()\n" +"c.mylist += [1, 2, 3]" #: ../../library/dataclasses.rst:253 msgid "" @@ -402,10 +532,15 @@ msgid "" "because ``None`` is a valid value for some parameters with a distinct " "meaning. No code should directly use the :const:`MISSING` value." msgstr "" +"上記のように、:const:`MISSING` 値はユーザーが一部のパラメータを提供したかどうかを" +"検出するために使用される番兵オブジェクトです。この番兵が使用されるのは、" +"``None`` が一部のパラメータにとって異なる意味を持つ有効な値であるためです。" +"コードは :const:`MISSING` 値を直接使用すべきではありません。" #: ../../library/dataclasses.rst:258 msgid "The parameters to :func:`!field` are:" msgstr "" +":func:`!field` のパラメータは以下の通りです:" #: ../../library/dataclasses.rst:260 msgid "" @@ -413,6 +548,8 @@ msgid "" "is needed because the :func:`!field` call itself replaces the normal " "position of the default value." msgstr "" +"*default*: 指定した場合、これがこのフィールドのデフォルト値になります。これが必要なのは、" +":func:`!field` の呼び出し自体がデフォルト値の通常の位置を置き換えるためです。" #: ../../library/dataclasses.rst:264 msgid "" @@ -422,18 +559,26 @@ msgid "" "discussed below. It is an error to specify both *default* and " "*default_factory*." msgstr "" +"*default_factory*: 指定した場合、このフィールドにデフォルト値が必要な際に呼び出される" +"引数なしの呼び出し可能オブジェクトである必要があります。他の用途の中でも、これは" +"後述するように可変なデフォルト値を持つフィールドを指定するために使用できます。" +"*default* と *default_factory* の両方を指定するとエラーになります。" #: ../../library/dataclasses.rst:270 msgid "" "*init*: If true (the default), this field is included as a parameter to the " "generated :meth:`~object.__init__` method." msgstr "" +"*init*: True(デフォルト)の場合、このフィールドは生成された :meth:`~object.__init__` " +"メソッドのパラメータとして含まれます。" #: ../../library/dataclasses.rst:273 msgid "" "*repr*: If true (the default), this field is included in the string returned " "by the generated :meth:`~object.__repr__` method." msgstr "" +"*repr*: True(デフォルト)の場合、このフィールドは生成された :meth:`~object.__repr__` " +"メソッドが返す文字列に含まれます。" #: ../../library/dataclasses.rst:276 msgid "" @@ -445,6 +590,12 @@ msgid "" "comparisons. Setting this value to anything other than ``None`` is " "discouraged." msgstr "" +"*hash*: これは bool または ``None`` です。True の場合、このフィールドは生成された " +":meth:`~object.__hash__` メソッドに含まれます。False の場合、このフィールドは" +"生成された :meth:`~object.__hash__` から除外されます。``None``(デフォルト)の場合、" +"*compare* の値を使用します。フィールドが比較に使用される場合はハッシュにも含まれる" +"べきであるため、通常はこれが期待される動作です。この値を ``None`` 以外に" +"設定することは推奨されません。" #: ../../library/dataclasses.rst:284 msgid "" @@ -465,6 +616,9 @@ msgid "" "equality and comparison methods (:meth:`~object.__eq__`, :meth:`~object." "__gt__`, et al.)." msgstr "" +"*compare*: True(デフォルト)の場合、このフィールドは生成された等価性" +"および比較メソッド(:meth:`~object.__eq__`、:meth:`~object.__gt__` など)" +"に含まれます。" #: ../../library/dataclasses.rst:294 msgid "" @@ -475,20 +629,29 @@ msgid "" "mechanism. Multiple third-parties can each have their own key, to use as a " "namespace in the metadata." msgstr "" +"*metadata*: これはマッピングまたは ``None`` です。``None`` は空の辞書として" +"扱われます。この値は :func:`~types.MappingProxyType` でラップされて読み取り" +"専用にされ、:class:`Field` オブジェクトで公開されます。データクラスでは" +"まったく使用されず、サードパーティ拡張メカニズムとして提供されています。" +"複数のサードパーティがそれぞれ独自のキーを持ち、メタデータ内の名前空間と" +"して使用できます。" #: ../../library/dataclasses.rst:302 msgid "" "*kw_only*: If true, this field will be marked as keyword-only. This is used " "when the generated :meth:`~object.__init__` method's parameters are computed." msgstr "" +"*kw_only*: True の場合、このフィールドはキーワード専用としてマークされます。" +"これは、生成された :meth:`~object.__init__` メソッドのパラメータが" +"計算される際に使用されます。" #: ../../library/dataclasses.rst:306 msgid "Keyword-only fields are also not included in :attr:`!__match_args__`." -msgstr "" +msgstr "キーワード専用フィールドも :attr:`!__match_args__` には含まれません。" #: ../../library/dataclasses.rst:310 msgid "*doc*: optional docstring for this field." -msgstr "" +msgstr "*doc*: このフィールドのオプションのドキュメント文字列。" #: ../../library/dataclasses.rst:314 msgid "" @@ -500,6 +663,12 @@ msgid "" "default values for the fields, just as if the default value itself were " "specified. For example, after::" msgstr "" +"フィールドのデフォルト値が :func:`!field` の呼び出しによって指定された場合、" +"このフィールドのクラス属性は指定された *default* 値で置き換えられます。" +"*default* が提供されない場合、クラス属性は削除されます。意図としては、" +":func:`@dataclass ` デコレータが実行された後、すべてのクラス属性が" +"フィールドのデフォルト値を含むようになり、まるでデフォルト値自体が指定された" +"かのようになることです。例えば、以下の後で::" #: ../../library/dataclasses.rst:323 msgid "" @@ -517,6 +686,8 @@ msgid "" "C.t` will be ``20``, and the class attributes :attr:`!C.x` and :attr:`!C.y` " "will not be set." msgstr "" +"クラス属性 :attr:`!C.z` は ``10`` 、クラス属性 :attr:`!C.t` は ``20`` に" +"なり、クラス属性 :attr:`!C.x` と :attr:`!C.y` は設定されません。" #: ../../library/dataclasses.rst:336 msgid "" @@ -525,14 +696,18 @@ msgid "" "method (see below). Users should never instantiate a :class:`!Field` object " "directly. Its documented attributes are:" msgstr "" +":class:`!Field` オブジェクトは定義された各フィールドを記述します。これらの" +"オブジェクトは内部的に作成され、:func:`fields` モジュールレベルメソッド" +"(以下を参照)によって返されます。ユーザーは :class:`!Field` オブジェクトを" +"直接インスタンス化してはいけません。文書化された属性は以下の通りです:" #: ../../library/dataclasses.rst:341 msgid ":attr:`!name`: The name of the field." -msgstr "" +msgstr ":attr:`!name`: フィールドの名前。" #: ../../library/dataclasses.rst:342 msgid ":attr:`!type`: The type of the field." -msgstr "" +msgstr ":attr:`!type`: フィールドの型。" #: ../../library/dataclasses.rst:343 msgid "" @@ -540,6 +715,9 @@ msgid "" "attr:`!hash`, :attr:`!compare`, :attr:`!metadata`, and :attr:`!kw_only` have " "the identical meaning and values as they do in the :func:`field` function." msgstr "" +":attr:`!default`、:attr:`!default_factory`、:attr:`!init`、:attr:`!repr`、" +":attr:`!hash`、:attr:`!compare`、:attr:`!metadata`、:attr:`!kw_only` は、" +":func:`field` 関数と同じ意味と値を持ちます。" #: ../../library/dataclasses.rst:347 msgid "" @@ -557,6 +735,11 @@ msgid "" "`fields` function nor used in any way except adding them as parameters to :" "meth:`~object.__init__` and an optional :meth:`__post_init__`." msgstr "" +"``InitVar[T]`` 型アノテーションは :ref:`初期化専用 ` " +"変数を記述します。:class:`!InitVar` でアノテーションされたフィールドは" +"疑似フィールドと見なされ、:func:`fields` 関数によって返されることも、" +":meth:`~object.__init__` とオプションの :meth:`__post_init__` のパラメータとして" +"追加される以外は一切使用されることもありません。" #: ../../library/dataclasses.rst:361 msgid "" @@ -579,10 +762,14 @@ msgid "" "``name: value`` pairs. dataclasses, dicts, lists, and tuples are recursed " "into. Other objects are copied with :func:`copy.deepcopy`." msgstr "" +"データクラス *obj* を辞書に変換します(ファクトリ関数 *dict_factory* を使用)。" +"各データクラスは、``name: value`` ペアとしてそのフィールドの辞書に変換されます。" +"データクラス、辞書、リスト、タプルは再帰的に処理されます。その他のオブジェクトは" +":func:`copy.deepcopy` でコピーされます。" #: ../../library/dataclasses.rst:374 msgid "Example of using :func:`!asdict` on nested dataclasses::" -msgstr "" +msgstr "ネストしたデータクラスでの :func:`!asdict` の使用例::" #: ../../library/dataclasses.rst:376 msgid "" @@ -604,7 +791,7 @@ msgstr "" #: ../../library/dataclasses.rst:391 ../../library/dataclasses.rst:411 msgid "To create a shallow copy, the following workaround may be used::" -msgstr "" +msgstr "浅いコピーを作成するには、以下の回避策を使用できます::" #: ../../library/dataclasses.rst:393 msgid "{field.name: getattr(obj, field.name) for field in fields(obj)}" @@ -614,6 +801,7 @@ msgstr "" msgid "" ":func:`!asdict` raises :exc:`TypeError` if *obj* is not a dataclass instance." msgstr "" +":func:`!asdict` は *obj* がデータクラスのインスタンスでない場合、:exc:`TypeError` を発生させます。" #: ../../library/dataclasses.rst:400 msgid "" @@ -622,6 +810,10 @@ msgid "" "values. dataclasses, dicts, lists, and tuples are recursed into. Other " "objects are copied with :func:`copy.deepcopy`." msgstr "" +"データクラス *obj* をタプルに変換します(ファクトリ関数 *tuple_factory* を使用)。" +"各データクラスはそのフィールド値のタプルに変換されます。データクラス、辞書、" +"リスト、タプルは再帰的に処理されます。その他のオブジェクトは :func:`copy.deepcopy` " +"でコピーされます。" #: ../../library/dataclasses.rst:406 msgid "Continuing from the previous example::" @@ -642,6 +834,7 @@ msgid "" ":func:`!astuple` raises :exc:`TypeError` if *obj* is not a dataclass " "instance." msgstr "" +":func:`!astuple` は *obj* がデータクラスのインスタンスでない場合、:exc:`TypeError` を発生させます。" #: ../../library/dataclasses.rst:420 msgid "" @@ -654,12 +847,21 @@ msgid "" "*slots*, and *weakref_slot* have the same meaning as they do in :func:" "`@dataclass `." msgstr "" +"*cls_name* という名前、*fields* で定義されたフィールド、*bases* で指定された" +"ベースクラス、*namespace* で指定された名前空間で初期化された新しいデータ" +"クラスを作成します。*fields* は、各要素が ``name``、``(name, type)``、または" +"``(name, type, Field)`` のいずれかであるイテラブルです。``name`` だけが指定された" +"場合、``type`` には :data:`typing.Any` が使用されます。*init*、*repr*、*eq*、" +"*order*、*unsafe_hash*、*frozen*、*match_args*、*kw_only*、*slots*、*weakref_slot* の" +"値は、:func:`@dataclass ` と同じ意味を持ちます。" #: ../../library/dataclasses.rst:430 msgid "" "If *module* is defined, the :attr:`!__module__` attribute of the dataclass " "is set to that value. By default, it is set to the module name of the caller." msgstr "" +"*module* が定義されている場合、データクラスの :attr:`!__module__` 属性はその値に" +"設定されます。デフォルトでは、呼び出し元のモジュール名に設定されます。" #: ../../library/dataclasses.rst:434 msgid "" @@ -668,6 +870,10 @@ msgid "" "keyword arguments as :func:`@dataclass `. By default, the :func:" "`@dataclass ` function is used." msgstr "" +"*decorator* パラメータは、データクラスの作成に使用される呼び出し可能オブジェクトです。" +"第一引数としてクラスオブジェクトを、:func:`@dataclass ` と同じ" +"キーワード引数を取る必要があります。デフォルトでは、:func:`@dataclass ` " +"関数が使用されます。" #: ../../library/dataclasses.rst:439 msgid "" @@ -676,6 +882,10 @@ msgid "" "`@dataclass ` function to convert that class to a dataclass. " "This function is provided as a convenience. For example::" msgstr "" +"この関数は厳密には必要ありません。:attr:`!__annotations__` で新しいクラスを" +"作成するどの Python メカニズムでも、そのクラスをデータクラスに変換するために" +":func:`@dataclass ` 関数を適用できるからです。この関数は便利さのために" +"提供されています。例えば::" #: ../../library/dataclasses.rst:445 msgid "" @@ -704,7 +914,7 @@ msgstr "" #: ../../library/dataclasses.rst:462 msgid "Added the *decorator* parameter." -msgstr "" +msgstr "*decorator* パラメータが追加されました。" #: ../../library/dataclasses.rst:467 msgid "" @@ -713,6 +923,9 @@ msgid "" "keys in *changes* are not field names of the given dataclass, raises :exc:" "`TypeError`." msgstr "" +"*obj* と同じ型の新しいオブジェクトを作成し、*changes* の値でフィールドを置き換えます。" +"*obj* がデータクラスでない場合、:exc:`TypeError` を発生させます。*changes* のキーが" +"指定されたデータクラスのフィールド名でない場合、:exc:`TypeError` を発生させます。" #: ../../library/dataclasses.rst:472 msgid "" @@ -720,6 +933,9 @@ msgid "" "method of the dataclass. This ensures that :meth:`__post_init__`, if " "present, is also called." msgstr "" +"新しく返されるオブジェクトは、データクラスの :meth:`~object.__init__` メソッドを" +"呼び出すことで作成されます。これにより、:meth:`__post_init__` が存在する場合は" +"それも呼び出されることが保証されます。" #: ../../library/dataclasses.rst:476 msgid "" @@ -727,12 +943,17 @@ msgid "" "on the call to :func:`!replace` so that they can be passed to :meth:`!" "__init__` and :meth:`__post_init__`." msgstr "" +"デフォルト値を持たない初期化専用変数が存在する場合、:func:`!replace` の呼び出しで" +"指定する必要があります。これにより、:meth:`!__init__` と :meth:`__post_init__` に" +"渡すことができます。" #: ../../library/dataclasses.rst:480 msgid "" "It is an error for *changes* to contain any fields that are defined as " "having ``init=False``. A :exc:`ValueError` will be raised in this case." msgstr "" +"*changes* に ``init=False`` として定義されたフィールドが含まれるのは" +"エラーです。この場合、:exc:`ValueError` が発生します。" #: ../../library/dataclasses.rst:484 msgid "" @@ -744,18 +965,27 @@ msgid "" "perhaps a custom :func:`!replace` (or similarly named) method which handles " "instance copying." msgstr "" +":func:`!replace` の呼び出し中に ``init=False`` フィールドがどのように動作するか" +"について注意してください。これらはソースオブジェクトからコピーされるのではなく、" +"初期化される場合は :meth:`__post_init__` で初期化されます。``init=False`` フィールドは" +"まれに慎重に使用されることが想定されています。使用する場合は、代替クラスコンストラクタ、" +"またはインスタンスコピーを処理するカスタム :func:`!replace`(または同様の名前の)" +"メソッドを用意することが賢明かもしれません。" #: ../../library/dataclasses.rst:493 msgid "" "Dataclass instances are also supported by generic function :func:`copy." "replace`." msgstr "" +"データクラスのインスタンスは汎用関数 :func:`copy.replace` もサポートしています。" #: ../../library/dataclasses.rst:497 msgid "" "Return ``True`` if its parameter is a dataclass (including subclasses of a " "dataclass) or an instance of one, otherwise return ``False``." msgstr "" +"パラメータがデータクラス(データクラスのサブクラスを含む)またはそのインスタンス" +"である場合は ``True`` を返し、そうでない場合は ``False`` を返します。" #: ../../library/dataclasses.rst:500 msgid "" @@ -812,6 +1042,8 @@ msgid "" "In a single dataclass, it is an error to specify more than one field whose " "type is :const:`!KW_ONLY`." msgstr "" +"単一のデータクラスで、型が :const:`!KW_ONLY` である複数のフィールドを" +"指定することはエラーになります。" #: ../../library/dataclasses.rst:540 msgid "" @@ -1048,6 +1280,9 @@ msgid "" "keyword-only fields, and :attr:`!Base.x` and :attr:`!D.z` are regular " "fields::" msgstr "" +"この例では、:attr:`!Base.y`、:attr:`!Base.w`、:attr:`!D.t` は" +"キーワード専用フィールドで、:attr:`!Base.x` と :attr:`!D.z` は" +"通常のフィールドです::" #: ../../library/dataclasses.rst:702 msgid "" @@ -1282,3 +1517,576 @@ msgid "" "assigned a descriptor object as its default value, the field will act like a " "normal field." msgstr "" +msgid "" +"@dataclass\n" +"class Point:\n" +" x: float\n" +" _: KW_ONLY\n" +" y: float\n" +" z: float\n" +"\n" +"p = Point(0, y=1.5, z=2.0)" +msgstr "" + +#: ../../library/dataclasses.rst:533 +msgid "" +"In a single dataclass, it is an error to specify more than one field whose " +"type is :const:`!KW_ONLY`." +msgstr "" +"単一のデータクラスで、型が :const:`!KW_ONLY` である複数のフィールドを" +"指定することはエラーになります。" + +#: ../../library/dataclasses.rst:540 +msgid "" +"Raised when an implicitly defined :meth:`~object.__setattr__` or :meth:" +"`~object.__delattr__` is called on a dataclass which was defined with " +"``frozen=True``. It is a subclass of :exc:`AttributeError`." +msgstr "" +"``frozen=True`` 付きで定義されたデータクラスで、暗黙的に定義された :meth:" +"`~object.__setattr__` または :meth:`~object.__delattr__` が呼び出されたときに" +"送出されます。これは :exc:`AttributeError` のサブクラスです。" + +#: ../../library/dataclasses.rst:547 +msgid "Post-init processing" +msgstr "初期化後の処理" + +#: ../../library/dataclasses.rst:551 +msgid "" +"When defined on the class, it will be called by the generated :meth:`~object." +"__init__`, normally as :meth:`!self.__post_init__`. However, if any " +"``InitVar`` fields are defined, they will also be passed to :meth:`!" +"__post_init__` in the order they were defined in the class. If no :meth:`!" +"__init__` method is generated, then :meth:`!__post_init__` will not " +"automatically be called." +msgstr "" +"クラスで定義された場合、通常は :meth:`!self.__post_init__` として、生成された" +":meth:`~object.__init__` によって呼び出されます。しかし、``InitVar`` フィールドが" +"定義されている場合、それらもクラスで定義された順序で :meth:`!__post_init__` に" +"渡されます。:meth:`!__init__` メソッドが生成されない場合、:meth:`!__post_init__` は" +"自動的に呼び出されません。" + +#: ../../library/dataclasses.rst:558 +msgid "" +"Among other uses, this allows for initializing field values that depend on " +"one or more other fields. For example::" +msgstr "" +"他の機能と組み合わせることで、他の 1 つ以上のフィールドに依存しているフィール" +"ドが初期化できます。\n" +"例えば次のようにできます::" + +#: ../../library/dataclasses.rst:561 +msgid "" +"@dataclass\n" +"class C:\n" +" a: float\n" +" b: float\n" +" c: float = field(init=False)\n" +"\n" +" def __post_init__(self):\n" +" self.c = self.a + self.b" +msgstr "" + +#: ../../library/dataclasses.rst:570 +msgid "" +"The :meth:`~object.__init__` method generated by :func:`@dataclass " +"` does not call base class :meth:`!__init__` methods. If the base " +"class has an :meth:`!__init__` method that has to be called, it is common to " +"call this method in a :meth:`__post_init__` method::" +msgstr "" +":func:`@dataclass ` によって生成された :meth:`~object.__init__` メソッドは、" +"ベースクラスの :meth:`!__init__` メソッドを呼び出しません。ベースクラスに" +"呼び出す必要がある :meth:`!__init__` メソッドがある場合、:meth:`__post_init__` " +"メソッドでこのメソッドを呼び出すのが一般的です::" + +#: ../../library/dataclasses.rst:575 +msgid "" +"class Rectangle:\n" +" def __init__(self, height, width):\n" +" self.height = height\n" +" self.width = width\n" +"\n" +"@dataclass\n" +"class Square(Rectangle):\n" +" side: float\n" +"\n" +" def __post_init__(self):\n" +" super().__init__(self.side, self.side)" +msgstr "" + +#: ../../library/dataclasses.rst:587 +msgid "" +"Note, however, that in general the dataclass-generated :meth:`!__init__` " +"methods don't need to be called, since the derived dataclass will take care " +"of initializing all fields of any base class that is a dataclass itself." +msgstr "" +"しかし、一般的にデータクラス生成の :meth:`!__init__` メソッドを呼び出す必要は" +"ありません。派生データクラスが、データクラスであるベースクラスのすべての" +"フィールドの初期化を行うためです。" + +#: ../../library/dataclasses.rst:591 +msgid "" +"See the section below on init-only variables for ways to pass parameters to :" +"meth:`!__post_init__`. Also see the warning about how :func:`replace` " +"handles ``init=False`` fields." +msgstr "" +"下にある初期化限定変数についての節で、 :meth:`!__post_init__` にパラメータを" +"渡す方法を参照してください。\n" +":func:`replace` が ``init=False`` であるフィールドをどう取り扱うかについての" +"警告も参照してください。" + +#: ../../library/dataclasses.rst:598 +msgid "Class variables" +msgstr "クラス変数" + +#: ../../library/dataclasses.rst:600 +msgid "" +"One of the few places where :func:`@dataclass ` actually inspects " +"the type of a field is to determine if a field is a class variable as " +"defined in :pep:`526`. It does this by checking if the type of the field " +"is :data:`typing.ClassVar`. If a field is a ``ClassVar``, it is excluded " +"from consideration as a field and is ignored by the dataclass mechanisms. " +"Such ``ClassVar`` pseudo-fields are not returned by the module-level :func:" +"`fields` function." +msgstr "" +":func:`@dataclass ` が実際にフィールドの型を検査する数少ない" +"場所の一つは、:pep:`526` で定義されているように、フィールドがクラス変数かどうかを" +"判定するためです。これは、フィールドの型が :data:`typing.ClassVar` かどうかを" +"チェックすることで行われます。フィールドが ``ClassVar`` の場合、フィールドとしての" +"考慮から除外され、データクラスメカニズムによって無視されます。このような" +"``ClassVar`` 疑似フィールドは、モジュールレベルの :func:`fields` 関数によって" +"返されません。" + +#: ../../library/dataclasses.rst:611 +msgid "Init-only variables" +msgstr "初期化限定変数" + +#: ../../library/dataclasses.rst:613 +msgid "" +"Another place where :func:`@dataclass ` inspects a type " +"annotation is to determine if a field is an init-only variable. It does " +"this by seeing if the type of a field is of type :class:`InitVar`. If a " +"field is an :class:`InitVar`, it is considered a pseudo-field called an init-" +"only field. As it is not a true field, it is not returned by the module-" +"level :func:`fields` function. Init-only fields are added as parameters to " +"the generated :meth:`~object.__init__` method, and are passed to the " +"optional :meth:`__post_init__` method. They are not otherwise used by " +"dataclasses." +msgstr "" +":func:`@dataclass ` が型アノテーションを検査するもう一つの場所は、" +"フィールドが初期化専用変数かどうかを判定するためです。これは、フィールドの型が" +":class:`InitVar` 型かどうかを確認することで行われます。フィールドが :class:`InitVar` の" +"場合、初期化専用フィールドと呼ばれる疑似フィールドとみなされます。真のフィールドでは" +"ないため、モジュールレベルの :func:`fields` 関数によって返されません。初期化専用" +"フィールドは、生成された :meth:`~object.__init__` メソッドのパラメータとして追加され、" +"オプションの :meth:`__post_init__` メソッドに渡されます。データクラスでは" +"それ以外に使用されることはありません。" + +#: ../../library/dataclasses.rst:623 +msgid "" +"For example, suppose a field will be initialized from a database, if a value " +"is not provided when creating the class::" +msgstr "" +"例えば、あるフィールドがデータベースから初期化されると仮定して、クラスを作成" +"するときには値が与えられない次の場合を考えます::" + +#: ../../library/dataclasses.rst:626 +msgid "" +"@dataclass\n" +"class C:\n" +" i: int\n" +" j: int | None = None\n" +" database: InitVar[DatabaseType | None] = None\n" +"\n" +" def __post_init__(self, database):\n" +" if self.j is None and database is not None:\n" +" self.j = database.lookup('j')\n" +"\n" +"c = C(10, database=my_database)" +msgstr "" + +#: ../../library/dataclasses.rst:638 +msgid "" +"In this case, :func:`fields` will return :class:`Field` objects for :attr:`!" +"i` and :attr:`!j`, but not for :attr:`!database`." +msgstr "" +"この場合、:func:`fields` は :attr:`!i` と :attr:`!j` に対して :class:`Field` オブジェクトを" +"返しますが、:attr:`!database` に対しては返しません。" + +#: ../../library/dataclasses.rst:644 +msgid "Frozen instances" +msgstr "凍結されたインスタンス" + +#: ../../library/dataclasses.rst:646 +msgid "" +"It is not possible to create truly immutable Python objects. However, by " +"passing ``frozen=True`` to the :func:`@dataclass ` decorator you " +"can emulate immutability. In that case, dataclasses will add :meth:`~object." +"__setattr__` and :meth:`~object.__delattr__` methods to the class. These " +"methods will raise a :exc:`FrozenInstanceError` when invoked." +msgstr "" +"真に不変なPythonオブジェクトを作成することは不可能です。しかし、:func:`@dataclass ` " +"デコレータに ``frozen=True`` を渡すことで、不変性をエミュレートできます。その場合、" +"データクラスはクラスに :meth:`~object.__setattr__` と :meth:`~object.__delattr__` メソッドを" +"追加します。これらのメソッドは呼び出されると :exc:`FrozenInstanceError` を発生させます。" + +#: ../../library/dataclasses.rst:652 +msgid "" +"There is a tiny performance penalty when using ``frozen=True``: :meth:" +"`~object.__init__` cannot use simple assignment to initialize fields, and " +"must use :meth:`!object.__setattr__`." +msgstr "" +"``frozen=True`` を使用する際には、わずかなパフォーマンスペナルティがあります。" +":meth:`~object.__init__` はフィールドを初期化するために単純な代入を使用できず、" +":meth:`!object.__setattr__` を使用する必要があります。" + +#: ../../library/dataclasses.rst:661 +msgid "Inheritance" +msgstr "継承" + +#: ../../library/dataclasses.rst:663 +msgid "" +"When the dataclass is being created by the :func:`@dataclass ` " +"decorator, it looks through all of the class's base classes in reverse MRO " +"(that is, starting at :class:`object`) and, for each dataclass that it " +"finds, adds the fields from that base class to an ordered mapping of fields. " +"After all of the base class fields are added, it adds its own fields to the " +"ordered mapping. All of the generated methods will use this combined, " +"calculated ordered mapping of fields. Because the fields are in insertion " +"order, derived classes override base classes. An example::" +msgstr "" +":func:`@dataclass ` デコレータによってデータクラスが作成される際、" +"クラスのすべてのベースクラスを逆MRO順(つまり :class:`object` から始まって)で調べ、" +"見つけた各データクラスについて、そのベースクラスのフィールドを順序付きフィールドマッピングに" +"追加します。すべてのベースクラスフィールドが追加された後、自身のフィールドを順序付き" +"マッピングに追加します。生成されるすべてのメソッドは、この組み合わされた計算済み順序付き" +"フィールドマッピングを使用します。フィールドは挿入順であるため、派生クラスは" +"ベースクラスをオーバーライドします。例::" + +#: ../../library/dataclasses.rst:673 +msgid "" +"@dataclass\n" +"class Base:\n" +" x: Any = 15.0\n" +" y: int = 0\n" +"\n" +"@dataclass\n" +"class C(Base):\n" +" z: int = 10\n" +" x: int = 15" +msgstr "" + +#: ../../library/dataclasses.rst:683 +msgid "" +"The final list of fields is, in order, :attr:`!x`, :attr:`!y`, :attr:`!z`. " +"The final type of :attr:`!x` is :class:`int`, as specified in class :class:`!" +"C`." +msgstr "" +"最終的なフィールドリストは、順序として :attr:`!x`、:attr:`!y`、:attr:`!z` です。" +":attr:`!x` の最終的な型は、クラス :class:`!C` で指定されたとおり :class:`int` です。" + +#: ../../library/dataclasses.rst:686 +msgid "" +"The generated :meth:`~object.__init__` method for :class:`!C` will look " +"like::" +msgstr ":class:`!C` の生成された :meth:`~object.__init__` メソッドは次のようになります::" + +#: ../../library/dataclasses.rst:688 +msgid "def __init__(self, x: int = 15, y: int = 0, z: int = 10):" +msgstr "" + +#: ../../library/dataclasses.rst:691 +msgid "Re-ordering of keyword-only parameters in :meth:`!__init__`" +msgstr ":meth:`!__init__` におけるキーワード専用パラメータの並び替え" + +#: ../../library/dataclasses.rst:693 +msgid "" +"After the parameters needed for :meth:`~object.__init__` are computed, any " +"keyword-only parameters are moved to come after all regular (non-keyword-" +"only) parameters. This is a requirement of how keyword-only parameters are " +"implemented in Python: they must come after non-keyword-only parameters." +msgstr "" +":meth:`~object.__init__` で必要なパラメータが算出されると、キーワード専用引数" +"は他の一般的な(非キーワード専用)パラメータの後に移動します。これは、すべて" +"のキーワード専用引数は、非キーワード専用パラメータの末尾にこなければならない" +"という、キーワード専用パラメータのPythonの実装の都合で必要なことです。" + +#: ../../library/dataclasses.rst:699 +msgid "" +"In this example, :attr:`!Base.y`, :attr:`!Base.w`, and :attr:`!D.t` are " +"keyword-only fields, and :attr:`!Base.x` and :attr:`!D.z` are regular " +"fields::" +msgstr "" +"この例では、:attr:`!Base.y`、:attr:`!Base.w`、:attr:`!D.t` は" +"キーワード専用フィールドで、:attr:`!Base.x` と :attr:`!D.z` は" +"通常のフィールドです::" + +#: ../../library/dataclasses.rst:702 +msgid "" +"@dataclass\n" +"class Base:\n" +" x: Any = 15.0\n" +" _: KW_ONLY\n" +" y: int = 0\n" +" w: int = 1\n" +"\n" +"@dataclass\n" +"class D(Base):\n" +" z: int = 10\n" +" t: int = field(kw_only=True, default=0)" +msgstr "" + +#: ../../library/dataclasses.rst:714 +msgid "The generated :meth:`!__init__` method for :class:`!D` will look like::" +msgstr ":class:`!D` の生成された :meth:`!__init__` メソッドは次のようになります::" + +#: ../../library/dataclasses.rst:716 +msgid "" +"def __init__(self, x: Any = 15.0, z: int = 10, *, y: int = 0, w: int = 1, t: " +"int = 0):" +msgstr "" + +#: ../../library/dataclasses.rst:718 +msgid "" +"Note that the parameters have been re-ordered from how they appear in the " +"list of fields: parameters derived from regular fields are followed by " +"parameters derived from keyword-only fields." +msgstr "" +"パラメータは、フィールドのリストの表示方法によって並べ替えられます。通常の" +"フィールドから派生したパラメータの後に、キーワードのみのフィールドから派生し" +"たパラメータが続きます。" + +#: ../../library/dataclasses.rst:722 +msgid "" +"The relative ordering of keyword-only parameters is maintained in the re-" +"ordered :meth:`!__init__` parameter list." +msgstr "" +"キーワード専用パラメータの相対的な順序は、並び替えられた :meth:`!__init__` " +"パラメータリストで維持されます。" + +#: ../../library/dataclasses.rst:727 +msgid "Default factory functions" +msgstr "デフォルトファクトリ関数" + +#: ../../library/dataclasses.rst:729 +msgid "" +"If a :func:`field` specifies a *default_factory*, it is called with zero " +"arguments when a default value for the field is needed. For example, to " +"create a new instance of a list, use::" +msgstr "" +":func:`field` が *default_factory* を指定している場合、フィールドのデフォルト値が必要な" +"ときに引数なしで呼び出されます。例えば、リストの新しいインスタンスを作成するには::" + +#: ../../library/dataclasses.rst:733 +msgid "mylist: list = field(default_factory=list)" +msgstr "" + +#: ../../library/dataclasses.rst:735 +msgid "" +"If a field is excluded from :meth:`~object.__init__` (using ``init=False``) " +"and the field also specifies *default_factory*, then the default factory " +"function will always be called from the generated :meth:`!__init__` " +"function. This happens because there is no other way to give the field an " +"initial value." +msgstr "" +"フィールドが :meth:`~object.__init__` から除外されており(``init=False`` を使用)、" +"かつフィールドが *default_factory* を指定している場合、デフォルトファクトリ関数は" +"常に生成された :meth:`!__init__` 関数から呼び出されます。これは、フィールドに" +"初期値を与える他の方法がないためです。" + +#: ../../library/dataclasses.rst:742 +msgid "Mutable default values" +msgstr "可変なデフォルト値" + +#: ../../library/dataclasses.rst:744 +msgid "" +"Python stores default member variable values in class attributes. Consider " +"this example, not using dataclasses::" +msgstr "" +"Python はメンバ変数のデフォルト値をクラス属性に保持します。\n" +"データクラスを使っていない、この例を考えてみましょう::" + +#: ../../library/dataclasses.rst:747 +msgid "" +"class C:\n" +" x = []\n" +" def add(self, element):\n" +" self.x.append(element)\n" +"\n" +"o1 = C()\n" +"o2 = C()\n" +"o1.add(1)\n" +"o2.add(2)\n" +"assert o1.x == [1, 2]\n" +"assert o1.x is o2.x" +msgstr "" + +#: ../../library/dataclasses.rst:759 +msgid "" +"Note that the two instances of class :class:`!C` share the same class " +"variable :attr:`!x`, as expected." +msgstr "" +"予想どおり、クラス :class:`!C` の2つのインスタンスは同じクラス変数 :attr:`!x` を" +"共有していることに注意してください。" + +#: ../../library/dataclasses.rst:762 +msgid "Using dataclasses, *if* this code was valid::" +msgstr "データクラスを使っているこのコードが *もし仮に* 有効なものだとしたら::" + +#: ../../library/dataclasses.rst:764 +msgid "" +"@dataclass\n" +"class D:\n" +" x: list = [] # This code raises ValueError\n" +" def add(self, element):\n" +" self.x.append(element)" +msgstr "" + +#: ../../library/dataclasses.rst:770 +msgid "it would generate code similar to::" +msgstr "データクラスは次のようなコードを生成するでしょう::" + +#: ../../library/dataclasses.rst:772 +msgid "" +"class D:\n" +" x = []\n" +" def __init__(self, x=x):\n" +" self.x = x\n" +" def add(self, element):\n" +" self.x.append(element)\n" +"\n" +"assert D().x is D().x" +msgstr "" + +#: ../../library/dataclasses.rst:781 +msgid "" +"This has the same issue as the original example using class :class:`!C`. " +"That is, two instances of class :class:`!D` that do not specify a value for :" +"attr:`!x` when creating a class instance will share the same copy of :attr:`!" +"x`. Because dataclasses just use normal Python class creation they also " +"share this behavior. There is no general way for Data Classes to detect " +"this condition. Instead, the :func:`@dataclass ` decorator will " +"raise a :exc:`ValueError` if it detects an unhashable default parameter. " +"The assumption is that if a value is unhashable, it is mutable. This is a " +"partial solution, but it does protect against many common errors." +msgstr "" +"これは、クラス :class:`!C` を使用した元の例と同じ問題を持っています。つまり、" +"クラスインスタンスを作成する際に :attr:`!x` の値を指定しないクラス :class:`!D` の" +"2つのインスタンスは、同じ :attr:`!x` のコピーを共有することになります。" +"データクラスは通常の Python クラス作成を使用するだけなので、この動作も共有します。" +"データクラスがこの状態を検出する一般的な方法はありません。代わりに、" +":func:`@dataclass ` デコレータは、ハッシュ化不可能なデフォルトパラメータを" +"検出した場合に :exc:`ValueError` を発生させます。値がハッシュ化不可能であれば可変である" +"という仮定です。これは部分的な解決策ですが、多くの一般的なエラーから保護します。" + +#: ../../library/dataclasses.rst:792 +msgid "" +"Using default factory functions is a way to create new instances of mutable " +"types as default values for fields::" +msgstr "" +"デフォルトファクトリ関数を使うのが、フィールドのデフォルト値として可変な型の" +"新しいインスタンスを作成する手段です::" + +#: ../../library/dataclasses.rst:795 +msgid "" +"@dataclass\n" +"class D:\n" +" x: list = field(default_factory=list)\n" +"\n" +"assert D().x is not D().x" +msgstr "" + +#: ../../library/dataclasses.rst:801 +msgid "" +"Instead of looking for and disallowing objects of type :class:`list`, :class:" +"`dict`, or :class:`set`, unhashable objects are now not allowed as default " +"values. Unhashability is used to approximate mutability." +msgstr "" +":class:`list`、:class:`dict`、:class:`set` 型のオブジェクトを探して禁止する代わりに、" +"ハッシュ化不可能なオブジェクトはデフォルト値として使用できなくなりました。" +"ハッシュ化不可能性は可変性を近似するために使用されます。" + +#: ../../library/dataclasses.rst:808 +msgid "Descriptor-typed fields" +msgstr "ディスクリプタ型フィールド" + +#: ../../library/dataclasses.rst:810 +msgid "" +"Fields that are assigned :ref:`descriptor objects ` as their " +"default value have the following special behaviors:" +msgstr "" +"デフォルト値として :ref:`ディスクリプタオブジェクト ` が割り当てられた" +"フィールドは、以下の特別な動作を持ちます:" + +#: ../../library/dataclasses.rst:813 +msgid "" +"The value for the field passed to the dataclass's :meth:`~object.__init__` " +"method is passed to the descriptor's :meth:`~object.__set__` method rather " +"than overwriting the descriptor object." +msgstr "" +"データクラスの :meth:`~object.__init__` メソッドに渡されたフィールドの値は、" +"ディスクリプタオブジェクトを上書きするのではなく、ディスクリプタの" +":meth:`~object.__set__` メソッドに渡されます。" + +#: ../../library/dataclasses.rst:817 +msgid "" +"Similarly, when getting or setting the field, the descriptor's :meth:" +"`~object.__get__` or :meth:`!__set__` method is called rather than returning " +"or overwriting the descriptor object." +msgstr "" +"同様に、フィールドを取得または設定する際は、ディスクリプタオブジェクトを" +"返したり上書きしたりするのではなく、ディスクリプタの :meth:`~object.__get__` " +"または :meth:`!__set__` メソッドが呼び出されます。" + +#: ../../library/dataclasses.rst:821 +msgid "" +"To determine whether a field contains a default value, :func:`@dataclass " +"` will call the descriptor's :meth:`!__get__` method using its " +"class access form: ``descriptor.__get__(obj=None, type=cls)``. If the " +"descriptor returns a value in this case, it will be used as the field's " +"default. On the other hand, if the descriptor raises :exc:`AttributeError` " +"in this situation, no default value will be provided for the field." +msgstr "" +"フィールドがデフォルト値を含むかどうかを判定するため、:func:`@dataclass ` は" +"クラスアクセス形式を使用してディスクリプタの :meth:`!__get__` メソッドを呼び出します:" +"``descriptor.__get__(obj=None, type=cls)`` 。この場合にディスクリプタが値を返す場合、" +"それがフィールドのデフォルトとして使用されます。一方、ディスクリプタがこの状況で" +":exc:`AttributeError` を発生させる場合、フィールドにデフォルト値は提供されません。" + +#: ../../library/dataclasses.rst:831 +msgid "" +"class IntConversionDescriptor:\n" +" def __init__(self, *, default):\n" +" self._default = default\n" +"\n" +" def __set_name__(self, owner, name):\n" +" self._name = \"_\" + name\n" +"\n" +" def __get__(self, obj, type):\n" +" if obj is None:\n" +" return self._default\n" +"\n" +" return getattr(obj, self._name, self._default)\n" +"\n" +" def __set__(self, obj, value):\n" +" setattr(obj, self._name, int(value))\n" +"\n" +"@dataclass\n" +"class InventoryItem:\n" +" quantity_on_hand: IntConversionDescriptor = " +"IntConversionDescriptor(default=100)\n" +"\n" +"i = InventoryItem()\n" +"print(i.quantity_on_hand) # 100\n" +"i.quantity_on_hand = 2.5 # calls __set__ with 2.5\n" +"print(i.quantity_on_hand) # 2" +msgstr "" + +#: ../../library/dataclasses.rst:856 +msgid "" +"Note that if a field is annotated with a descriptor type, but is not " +"assigned a descriptor object as its default value, the field will act like a " +"normal field." +msgstr "" +"フィールドがディスクリプタ型でアノテーションされているものの、デフォルト値として" +"ディスクリプタオブジェクトが割り当てられていない場合、フィールドは通常の" +"フィールドのように動作します。" From 31c285b1bfb60cac760219b3f9a1428deea3afeb Mon Sep 17 00:00:00 2001 From: Atsuo Ishimoto Date: Sun, 6 Jul 2025 14:41:18 +0900 Subject: [PATCH 05/19] heh --- library/dataclasses.po | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/library/dataclasses.po b/library/dataclasses.po index 12956e9c1..e5a6542f3 100644 --- a/library/dataclasses.po +++ b/library/dataclasses.po @@ -1005,8 +1005,7 @@ msgstr "" #: ../../library/dataclasses.rst:509 msgid "A sentinel value signifying a missing default or default_factory." -msgstr "" -"デフォルト値やdefault_factoryが設定されてない場合の番兵の値を設定します。" +msgstr "デフォルト値や default_factory が存在しないことを示す番兵値。" #: ../../library/dataclasses.rst:513 msgid "" @@ -1018,6 +1017,13 @@ msgid "" "meth:`~object.__init__` parameters that must be specified as keywords when " "the class is instantiated." msgstr "" +"型アノテーションとして使用される番兵値です。:const:`!KW_ONLY` の型を持つ疑似フィールドの " +"後にあるすべてのフィールドは、キーワード専用フィールドとしてマークされます。" +":const:`!KW_ONLY` 型の疑似フィールドは、その他の点では完全に無視されることに " +"注意してください。これには、そのようなフィールドの名前も含まれます。慣例により、 " +":const:`!KW_ONLY` フィールドには ``_`` という名前が使用されます。キーワード専用 " +"フィールドは、クラスがインスタンス化される際にキーワードとして指定する必要がある " +":meth:`~object.__init__` パラメータを表します。" #: ../../library/dataclasses.rst:522 msgid "" @@ -1068,6 +1074,11 @@ msgid "" "__init__` method is generated, then :meth:`!__post_init__` will not " "automatically be called." msgstr "" +"クラスで定義された場合、生成された :meth:`~object.__init__` によって、" +"通常は :meth:`!self.__post_init__` として呼び出されます。しかし、" +"``InitVar`` フィールドが定義されている場合、それらはクラスで定義された順序で " +":meth:`!__post_init__` にも渡されます。:meth:`!__init__` メソッドが生成されない場合、" +":meth:`!__post_init__` は自動的に呼び出されません。" #: ../../library/dataclasses.rst:558 msgid "" @@ -1097,6 +1108,10 @@ msgid "" "class has an :meth:`!__init__` method that has to be called, it is common to " "call this method in a :meth:`__post_init__` method::" msgstr "" +":func:`@dataclass ` によって生成された :meth:`~object.__init__` メソッドは、" +"ベースクラスの :meth:`!__init__` メソッドを呼び出しません。ベースクラスに呼び出す" +"必要がある :meth:`!__init__` メソッドがある場合、このメソッドを :meth:`__post_init__` " +"メソッドで呼び出すのが一般的です::" #: ../../library/dataclasses.rst:575 msgid "" @@ -1119,6 +1134,9 @@ msgid "" "methods don't need to be called, since the derived dataclass will take care " "of initializing all fields of any base class that is a dataclass itself." msgstr "" +"ただし、一般的にはデータクラス生成の :meth:`!__init__` メソッドを呼び出す" +"必要はないことに注意してください。派生データクラスが、それ自体がデータクラス" +"であるベースクラスのすべてのフィールドの初期化を処理するためです。" #: ../../library/dataclasses.rst:591 msgid "" @@ -1145,6 +1163,12 @@ msgid "" "Such ``ClassVar`` pseudo-fields are not returned by the module-level :func:" "`fields` function." msgstr "" +":func:`@dataclass ` が実際にフィールドの型を検査する数少ない場所の一つは、" +"フィールドが :pep:`526` で定義されたクラス変数かどうかを判定することです。" +"これは、フィールドの型が :data:`typing.ClassVar` かどうかをチェックすることで行われます。" +"フィールドが ``ClassVar`` の場合、フィールドとしての考慮から除外され、" +"データクラスのメカニズムによって無視されます。そのような ``ClassVar`` 疑似フィールドは、" +"モジュールレベルの :func:`fields` 関数によって返されません。" #: ../../library/dataclasses.rst:611 msgid "Init-only variables" @@ -1447,16 +1471,21 @@ msgid "" "`dict`, or :class:`set`, unhashable objects are now not allowed as default " "values. Unhashability is used to approximate mutability." msgstr "" +":class:`list`、:class:`dict`、:class:`set` 型のオブジェクトを探して禁止する代わりに、" +"現在はハッシュ化不可能なオブジェクトはデフォルト値として許可されていません。" +"ハッシュ化不可能性は可変性を近似するために使用されます。" #: ../../library/dataclasses.rst:808 msgid "Descriptor-typed fields" -msgstr "" +msgstr "ディスクリプタ型フィールド" #: ../../library/dataclasses.rst:810 msgid "" "Fields that are assigned :ref:`descriptor objects ` as their " "default value have the following special behaviors:" msgstr "" +"デフォルト値として :ref:`ディスクリプタオブジェクト ` が割り当てられたフィールドは、" +"以下の特別な動作をします:" #: ../../library/dataclasses.rst:813 msgid "" From b7ecb96390396988a658bf37e972dfb6fe44049d Mon Sep 17 00:00:00 2001 From: Atsuo Ishimoto Date: Sun, 6 Jul 2025 18:14:39 +0900 Subject: [PATCH 06/19] update pathlib --- library/pathlib.po | 2 ++ requirements.txt | 1 + 2 files changed, 3 insertions(+) diff --git a/library/pathlib.po b/library/pathlib.po index b9ac243f0..2e624a3db 100644 --- a/library/pathlib.po +++ b/library/pathlib.po @@ -2715,6 +2715,8 @@ msgid "" "include the *path* as a prefix, unlike the results of ``glob." "glob(root_dir=path)``." msgstr "" +"pathlib の ``path.glob()`` や ``path.rglob()`` の戻り値は、" +"``glob.glob(root_dir=path)`` の結果とは異なり、*path* をプレフィックスとして含みます。" #: ../../library/pathlib.rst:1840 msgid "" diff --git a/requirements.txt b/requirements.txt index 07a409b6f..3cd8cf489 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,3 +4,4 @@ powrap pospell pomerge translate-toolkit +splitpo \ No newline at end of file From 3e51fa483fb7c7c6df2752558b69e194efb301d8 Mon Sep 17 00:00:00 2001 From: Atsuo Ishimoto Date: Sun, 6 Jul 2025 18:54:23 +0900 Subject: [PATCH 07/19] update dataclasses.po --- CLAUDE.md | 92 ++++++++++++++++++++ library/dataclasses.po | 187 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 270 insertions(+), 9 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index 09a92bcf9..61a134c26 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -149,6 +149,98 @@ options: 2. 既存翻訳の品質が改善されている 3. コード例等の翻訳不要な部分は適切に `msgstr ""` のまま残されている +### 4.3 翻訳作業完了前の必須チェック手順(最終確認) + +**重要**: 翻訳作業の最後には、**必ず**以下の手順を実行して未翻訳部分が残っていないか確認してください。この手順は翻訳作業の品質を保証するために必須です。 + +#### 最終チェックスクリプトの実行 + +翻訳対象ファイルに対して以下のPythonスクリプトを実行し、未翻訳のテキストエントリが残っていないか確認します: + +```python +python3 -c " +import re +with open('対象ファイル.po', 'r', encoding='utf-8') as f: + content = f.read() + +# POエントリを分割して真に空のものをカウント +entries = re.split(r'\n\n(?=#)', content) +empty_count = 0 + +for i, entry in enumerate(entries): + if 'msgid' in entry and 'msgstr \"\"' in entry: + lines = entry.strip().split('\n') + msgstr_started = False + is_empty = True + + # msgidの内容をチェック + msgid_content = '' + for line in lines: + if line.startswith('msgid'): + msgid_content = line + elif line.startswith('\"') and not msgstr_started: + msgid_content += line + + # コードサンプルでないテキストエントリかチェック + is_code_only = ('def ' in msgid_content or + 'class ' in msgid_content or + 'assert ' in msgid_content or + 'print(' in msgid_content or + 'return ' in msgid_content or + msgid_content.count('\\\\\"') > 2) + + for line in lines: + if line.startswith('msgstr'): + msgstr_started = True + if '\"\"' in line and len(line.strip()) > 9: + is_empty = False + break + elif msgstr_started and line.startswith('\"'): + is_empty = False + break + + if is_empty and not is_code_only: + empty_count += 1 + print(f'未翻訳テキストエントリ {i+1}:') + print(msgid_content[:200] + '...' if len(msgid_content) > 200 else msgid_content) + print('---') + +print(f'残り未翻訳テキストエントリ数: {empty_count}') +if empty_count == 0: + print('✅ All translatable text entries have been translated!') +else: + print('⚠️ 未翻訳のテキストエントリが残っています。これらを翻訳してから作業を完了してください。') +" +``` + +#### チェック結果の処理 + +1. **未翻訳エントリが見つからない場合(empty_count = 0)**: + - 翻訳作業完了 + - 「✅ All translatable text entries have been translated!」が表示されることを確認 + +2. **未翻訳エントリが見つかった場合**: + - **必ず**すべてのエントリを翻訳してから作業を完了する + - 翻訳方針: + - **コードサンプル**: `def`、`class`、`assert`、`print`、`return`等を含む場合は通常そのままコピー + - **説明文**: 日本語に翻訳 + - **エラーメッセージ**: 日本語に翻訳 + - **ドキュメント文字列**: 日本語に翻訳 + - **技術用語**: 既存の翻訳スタイルに合わせて統一 + +3. **再チェック**: + - 未翻訳エントリを修正後、再度スクリプトを実行 + - 「残り未翻訳テキストエントリ数: 0」になるまで繰り返す + +#### このチェックが重要な理由 + +- 分割→翻訳→結合の過程で翻訳が失われる場合がある +- 大きなファイルでは一部のエントリが見落とされる可能性がある +- 翻訳の品質と完全性を保証するため +- ユーザーに未完成の翻訳を提供することを防ぐため + +**注意**: この最終チェックを省略してはいけません。翻訳作業の品質保証において必須の手順です。 + ## Repository Structure The repository is organized as follows: diff --git a/library/dataclasses.po b/library/dataclasses.po index e5a6542f3..739134058 100644 --- a/library/dataclasses.po +++ b/library/dataclasses.po @@ -679,6 +679,12 @@ msgid "" " z: int = field(repr=False, default=10)\n" " t: int = 20" msgstr "" +"@dataclass\n" +"class C:\n" +" x: int\n" +" y: int = field(repr=False)\n" +" z: int = field(repr=False, default=10)\n" +" t: int = 20" #: ../../library/dataclasses.rst:330 msgid "" @@ -788,6 +794,20 @@ msgid "" "c = C([Point(0, 0), Point(10, 4)])\n" "assert asdict(c) == {'mylist': [{'x': 0, 'y': 0}, {'x': 10, 'y': 4}]}" msgstr "" +"@dataclass\n" +"class Point:\n" +" x: int\n" +" y: int\n" +"\n" +"@dataclass\n" +"class C:\n" +" mylist: list[Point]\n" +"\n" +"p = Point(10, 20)\n" +"assert asdict(p) == {'x': 10, 'y': 20}\n" +"\n" +"c = C([Point(0, 0), Point(10, 4)])\n" +"assert asdict(c) == {'mylist': [{'x': 0, 'y': 0}, {'x': 10, 'y': 4}]}" #: ../../library/dataclasses.rst:391 ../../library/dataclasses.rst:411 msgid "To create a shallow copy, the following workaround may be used::" @@ -795,7 +815,7 @@ msgstr "浅いコピーを作成するには、以下の回避策を使用でき #: ../../library/dataclasses.rst:393 msgid "{field.name: getattr(obj, field.name) for field in fields(obj)}" -msgstr "" +msgstr "{field.name: getattr(obj, field.name) for field in fields(obj)}" #: ../../library/dataclasses.rst:395 msgid "" @@ -824,10 +844,12 @@ msgid "" "assert astuple(p) == (10, 20)\n" "assert astuple(c) == ([(0, 0), (10, 4)],)" msgstr "" +"assert astuple(p) == (10, 20)\n" +"assert astuple(c) == ([(0, 0), (10, 4)],)" #: ../../library/dataclasses.rst:413 msgid "tuple(getattr(obj, field.name) for field in dataclasses.fields(obj))" -msgstr "" +msgstr "tuple(getattr(obj, field.name) for field in dataclasses.fields(obj))" #: ../../library/dataclasses.rst:415 msgid "" @@ -895,6 +917,11 @@ msgid "" " ('z', int, field(default=5))],\n" " namespace={'add_one': lambda self: self.x + 1})" msgstr "" +"C = make_dataclass('C',\n" +" [('x', int),\n" +" 'y',\n" +" ('z', int, field(default=5))],\n" +" namespace={'add_one': lambda self: self.x + 1})" #: ../../library/dataclasses.rst:451 msgid "Is equivalent to::" @@ -911,6 +938,14 @@ msgid "" " def add_one(self):\n" " return self.x + 1" msgstr "" +"@dataclass\n" +"class C:\n" +" x: int\n" +" y: 'typing.Any'\n" +" z: int = 5\n" +"\n" +" def add_one(self):\n" +" return self.x + 1" #: ../../library/dataclasses.rst:462 msgid "Added the *decorator* parameter." @@ -1002,6 +1037,8 @@ msgid "" "def is_dataclass_instance(obj):\n" " return is_dataclass(obj) and not isinstance(obj, type)" msgstr "" +"def is_dataclass_instance(obj):\n" +" return is_dataclass(obj) and not isinstance(obj, type)" #: ../../library/dataclasses.rst:509 msgid "A sentinel value signifying a missing default or default_factory." @@ -1042,6 +1079,14 @@ msgid "" "\n" "p = Point(0, y=1.5, z=2.0)" msgstr "" +"@dataclass\n" +"class Point:\n" +" x: float\n" +" _: KW_ONLY\n" +" y: float\n" +" z: float\n" +"\n" +"p = Point(0, y=1.5, z=2.0)" #: ../../library/dataclasses.rst:533 msgid "" @@ -1085,9 +1130,7 @@ msgid "" "Among other uses, this allows for initializing field values that depend on " "one or more other fields. For example::" msgstr "" -"他の機能と組み合わせることで、他の 1 つ以上のフィールドに依存しているフィール" -"ドが初期化できます。\n" -"例えば次のようにできます::" +"他の用途に加えて、1つ以上の他のフィールドに依存するフィールド値を初期化できます。例えば::" #: ../../library/dataclasses.rst:561 msgid "" @@ -1100,6 +1143,14 @@ msgid "" " def __post_init__(self):\n" " self.c = self.a + self.b" msgstr "" +"@dataclass\n" +"class C:\n" +" a: float\n" +" b: float\n" +" c: float = field(init=False)\n" +"\n" +" def __post_init__(self):\n" +" self.c = self.a + self.b" #: ../../library/dataclasses.rst:570 msgid "" @@ -1127,6 +1178,17 @@ msgid "" " def __post_init__(self):\n" " super().__init__(self.side, self.side)" msgstr "" +"class Rectangle:\n" +" def __init__(self, height, width):\n" +" self.height = height\n" +" self.width = width\n" +"\n" +"@dataclass\n" +"class Square(Rectangle):\n" +" side: float\n" +"\n" +" def __post_init__(self):\n" +" super().__init__(self.side, self.side)" #: ../../library/dataclasses.rst:587 msgid "" @@ -1186,6 +1248,14 @@ msgid "" "optional :meth:`__post_init__` method. They are not otherwise used by " "dataclasses." msgstr "" +":func:`@dataclass ` が型アノテーションを検査するもう一つの場所は、" +"フィールドが初期化専用変数かどうかを判定することです。これは、フィールドの型が" +":class:`InitVar` 型かどうかを確認することで行われます。フィールドが :class:`InitVar` の場合、" +"初期化専用フィールドと呼ばれる疑似フィールドと見なされます。真のフィールドではないため、" +"モジュールレベルの :func:`fields` 関数によって返されません。初期化専用フィールドは" +"生成された :meth:`~object.__init__` メソッドにパラメータとして追加され、" +"オプションの :meth:`__post_init__` メソッドに渡されます。それ以外では" +"データクラスによって使用されません。" #: ../../library/dataclasses.rst:623 msgid "" @@ -1209,12 +1279,25 @@ msgid "" "\n" "c = C(10, database=my_database)" msgstr "" +"@dataclass\n" +"class C:\n" +" i: int\n" +" j: int | None = None\n" +" database: InitVar[DatabaseType | None] = None\n" +"\n" +" def __post_init__(self, database):\n" +" if self.j is None and database is not None:\n" +" self.j = database.lookup('j')\n" +"\n" +"c = C(10, database=my_database)" #: ../../library/dataclasses.rst:638 msgid "" "In this case, :func:`fields` will return :class:`Field` objects for :attr:`!" "i` and :attr:`!j`, but not for :attr:`!database`." msgstr "" +"この場合、:func:`fields` は :attr:`!i` と :attr:`!j` に対して :class:`Field` オブジェクトを" +"返しますが、:attr:`!database` に対しては返しません。" #: ../../library/dataclasses.rst:644 msgid "Frozen instances" @@ -1228,6 +1311,10 @@ msgid "" "__setattr__` and :meth:`~object.__delattr__` methods to the class. These " "methods will raise a :exc:`FrozenInstanceError` when invoked." msgstr "" +"真に不変なPythonオブジェクトを作成することは不可能です。しかし、:func:`@dataclass ` " +"デコレータに ``frozen=True`` を渡すことで、不変性をエミュレートできます。その場合、" +"データクラスはクラスに :meth:`~object.__setattr__` と :meth:`~object.__delattr__` メソッドを" +"追加します。これらのメソッドは呼び出されると :exc:`FrozenInstanceError` を発生させます。" #: ../../library/dataclasses.rst:652 msgid "" @@ -1235,6 +1322,9 @@ msgid "" "`~object.__init__` cannot use simple assignment to initialize fields, and " "must use :meth:`!object.__setattr__`." msgstr "" +"``frozen=True`` を使用する際には、わずかなパフォーマンスペナルティがあります。" +":meth:`~object.__init__` はフィールドを初期化するために単純な代入を使用できず、" +":meth:`!object.__setattr__` を使用する必要があります。" #: ../../library/dataclasses.rst:661 msgid "Inheritance" @@ -1284,7 +1374,7 @@ msgstr "" #: ../../library/dataclasses.rst:691 msgid "Re-ordering of keyword-only parameters in :meth:`!__init__`" -msgstr "" +msgstr ":meth:`!__init__` におけるキーワード専用パラメータの並び替え" #: ../../library/dataclasses.rst:693 msgid "" @@ -1325,7 +1415,7 @@ msgstr "" #: ../../library/dataclasses.rst:714 msgid "The generated :meth:`!__init__` method for :class:`!D` will look like::" -msgstr "" +msgstr ":class:`!D` の生成された :meth:`!__init__` メソッドは次のようになります::" #: ../../library/dataclasses.rst:716 msgid "" @@ -1362,7 +1452,7 @@ msgstr "" #: ../../library/dataclasses.rst:733 msgid "mylist: list = field(default_factory=list)" -msgstr "" +msgstr "mylist: list = field(default_factory=list)" #: ../../library/dataclasses.rst:735 msgid "" @@ -1447,6 +1537,14 @@ msgid "" "The assumption is that if a value is unhashable, it is mutable. This is a " "partial solution, but it does protect against many common errors." msgstr "" +"これは、クラス :class:`!C` を使用した元の例と同じ問題を持っています。つまり、" +"クラスインスタンスを作成する際に :attr:`!x` の値を指定しないクラス :class:`!D` の" +"2つのインスタンスは、同じ :attr:`!x` のコピーを共有することになります。" +"データクラスは通常の Python クラス作成を使用するだけなので、この動作も共有します。" +"データクラスがこの状態を検出する一般的な方法はありません。代わりに、" +":func:`@dataclass ` デコレータは、ハッシュ化不可能なデフォルトパラメータを" +"検出した場合に :exc:`ValueError` を発生させます。値がハッシュ化不可能であれば可変である" +"という仮定です。これは部分的な解決策ですが、多くの一般的なエラーから保護します。" #: ../../library/dataclasses.rst:792 msgid "" @@ -1732,6 +1830,17 @@ msgid "" "\n" "c = C(10, database=my_database)" msgstr "" +"@dataclass\n" +"class C:\n" +" i: int\n" +" j: int | None = None\n" +" database: InitVar[DatabaseType | None] = None\n" +"\n" +" def __post_init__(self, database):\n" +" if self.j is None and database is not None:\n" +" self.j = database.lookup('j')\n" +"\n" +"c = C(10, database=my_database)" #: ../../library/dataclasses.rst:638 msgid "" @@ -1740,6 +1849,8 @@ msgid "" msgstr "" "この場合、:func:`fields` は :attr:`!i` と :attr:`!j` に対して :class:`Field` オブジェクトを" "返しますが、:attr:`!database` に対しては返しません。" +"この場合、:func:`fields` は :attr:`!i` と :attr:`!j` に対して :class:`Field` オブジェクトを" +"返しますが、:attr:`!database` に対しては返しません。" #: ../../library/dataclasses.rst:644 msgid "Frozen instances" @@ -1757,6 +1868,10 @@ msgstr "" "デコレータに ``frozen=True`` を渡すことで、不変性をエミュレートできます。その場合、" "データクラスはクラスに :meth:`~object.__setattr__` と :meth:`~object.__delattr__` メソッドを" "追加します。これらのメソッドは呼び出されると :exc:`FrozenInstanceError` を発生させます。" +"真に不変なPythonオブジェクトを作成することは不可能です。しかし、:func:`@dataclass ` " +"デコレータに ``frozen=True`` を渡すことで、不変性をエミュレートできます。その場合、" +"データクラスはクラスに :meth:`~object.__setattr__` と :meth:`~object.__delattr__` メソッドを" +"追加します。これらのメソッドは呼び出されると :exc:`FrozenInstanceError` を発生させます。" #: ../../library/dataclasses.rst:652 msgid "" @@ -1767,6 +1882,9 @@ msgstr "" "``frozen=True`` を使用する際には、わずかなパフォーマンスペナルティがあります。" ":meth:`~object.__init__` はフィールドを初期化するために単純な代入を使用できず、" ":meth:`!object.__setattr__` を使用する必要があります。" +"``frozen=True`` を使用する際には、わずかなパフォーマンスペナルティがあります。" +":meth:`~object.__init__` はフィールドを初期化するために単純な代入を使用できず、" +":meth:`!object.__setattr__` を使用する必要があります。" #: ../../library/dataclasses.rst:661 msgid "Inheritance" @@ -1907,7 +2025,7 @@ msgstr "" #: ../../library/dataclasses.rst:733 msgid "mylist: list = field(default_factory=list)" -msgstr "" +msgstr "mylist: list = field(default_factory=list)" #: ../../library/dataclasses.rst:735 msgid "" @@ -1969,6 +2087,11 @@ msgid "" " def add(self, element):\n" " self.x.append(element)" msgstr "" +"@dataclass\n" +"class D:\n" +" x: list = [] # This code raises ValueError\n" +" def add(self, element):\n" +" self.x.append(element)" #: ../../library/dataclasses.rst:770 msgid "it would generate code similar to::" @@ -1985,6 +2108,14 @@ msgid "" "\n" "assert D().x is D().x" msgstr "" +"class D:\n" +" x = []\n" +" def __init__(self, x=x):\n" +" self.x = x\n" +" def add(self, element):\n" +" self.x.append(element)\n" +"\n" +"assert D().x is D().x" #: ../../library/dataclasses.rst:781 msgid "" @@ -2006,6 +2137,14 @@ msgstr "" ":func:`@dataclass ` デコレータは、ハッシュ化不可能なデフォルトパラメータを" "検出した場合に :exc:`ValueError` を発生させます。値がハッシュ化不可能であれば可変である" "という仮定です。これは部分的な解決策ですが、多くの一般的なエラーから保護します。" +"これは、クラス :class:`!C` を使用した元の例と同じ問題を持っています。つまり、" +"クラスインスタンスを作成する際に :attr:`!x` の値を指定しないクラス :class:`!D` の" +"2つのインスタンスは、同じ :attr:`!x` のコピーを共有することになります。" +"データクラスは通常の Python クラス作成を使用するだけなので、この動作も共有します。" +"データクラスがこの状態を検出する一般的な方法はありません。代わりに、" +":func:`@dataclass ` デコレータは、ハッシュ化不可能なデフォルトパラメータを" +"検出した場合に :exc:`ValueError` を発生させます。値がハッシュ化不可能であれば可変である" +"という仮定です。これは部分的な解決策ですが、多くの一般的なエラーから保護します。" #: ../../library/dataclasses.rst:792 msgid "" @@ -2023,6 +2162,11 @@ msgid "" "\n" "assert D().x is not D().x" msgstr "" +"@dataclass\n" +"class D:\n" +" x: list = field(default_factory=list)\n" +"\n" +"assert D().x is not D().x" #: ../../library/dataclasses.rst:801 msgid "" @@ -2109,6 +2253,31 @@ msgid "" "i.quantity_on_hand = 2.5 # calls __set__ with 2.5\n" "print(i.quantity_on_hand) # 2" msgstr "" +"class IntConversionDescriptor:\n" +" def __init__(self, *, default):\n" +" self._default = default\n" +"\n" +" def __set_name__(self, owner, name):\n" +" self._name = \"_\" + name\n" +"\n" +" def __get__(self, obj, type):\n" +" if obj is None:\n" +" return self._default\n" +"\n" +" return getattr(obj, self._name, self._default)\n" +"\n" +" def __set__(self, obj, value):\n" +" setattr(obj, self._name, int(value))\n" +"\n" +"@dataclass\n" +"class InventoryItem:\n" +" quantity_on_hand: IntConversionDescriptor = " +"IntConversionDescriptor(default=100)\n" +"\n" +"i = InventoryItem()\n" +"print(i.quantity_on_hand) # 100\n" +"i.quantity_on_hand = 2.5 # calls __set__ with 2.5\n" +"print(i.quantity_on_hand) # 2" #: ../../library/dataclasses.rst:856 msgid "" From 433828e0cdce16037b0d298d9891eafa58d31af7 Mon Sep 17 00:00:00 2001 From: Atsuo Ishimoto Date: Sun, 6 Jul 2025 19:29:09 +0900 Subject: [PATCH 08/19] update --- CLAUDE.md | 79 ++++++++++++++++++++ library/dataclasses.po | 163 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 239 insertions(+), 3 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index 61a134c26..82078f6a6 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -241,6 +241,85 @@ else: **注意**: この最終チェックを省略してはいけません。翻訳作業の品質保証において必須の手順です。 +### 4.4 翻訳漏れ防止のための必須手順 + +翻訳漏れを完全に防ぐため、以下の手順を**必ず**実行してください: + +#### 翻訳作業開始前の事前確認 + +1. **重複エントリの検出**: +```bash +# 同じmsgidが複数回登場していないかチェック +rg -o 'msgid "[^"]*"' ファイル名.po | sort | uniq -d +``` + +2. **未翻訳エントリの総数把握**: +```bash +# 翻訳前の未翻訳エントリ数を記録 +python3 -c " +import re +with open('ファイル名.po', 'r', encoding='utf-8') as f: + content = f.read() +print(f'翻訳前未翻訳エントリ数: {len(re.findall(r\"msgstr \\\"\\\"\", content))}') +" +``` + +#### 翻訳作業中の段階的確認 + +3. **定期的な進捗確認**: + - 50エントリごとに翻訳状況をチェック + - 重複エントリを発見した場合は**すべて**翻訳する + +4. **分割ファイル処理時の特別措置**: + - 各分割ファイルの翻訳完了後、即座に未翻訳エントリ数をチェック + - 結合前に各分割ファイルの翻訳完了を確認 + +#### 翻訳作業完了前の厳格な最終チェック + +5. **最終チェックスクリプト(改良版)**: +```python +python3 -c " +import re +with open('ファイル名.po', 'r', encoding='utf-8') as f: + content = f.read() + +# 重複エントリも含めてすべての未翻訳エントリをチェック +all_entries = re.findall(r'(#: [^\n]+\nmsgid[^m]+?msgstr \"\")', content, re.DOTALL) +untranslated_text = [] + +for entry in all_entries: + # コードサンプルを除外 + if not any(marker in entry for marker in ['def ', 'class ', 'assert ', 'print(', 'return ', '>>>', 'import ', 'raise ']): + untranslated_text.append(entry[:200]) + +print(f'未翻訳テキストエントリ数: {len(untranslated_text)}') +if untranslated_text: + print('\\n未翻訳エントリ:') + for i, entry in enumerate(untranslated_text, 1): + print(f'{i}: {entry}...') + print('---') + print('\\n⚠️ これらのエントリを翻訳してから作業を完了してください。') +else: + print('✅ すべての翻訳対象エントリが翻訳済みです!') +" +``` + +#### 品質保証のための二重チェック + +6. **翻訳完了後の検証**: + - 翻訳前後の未翻訳エントリ数の差分を確認 + - 重複エントリがすべて翻訳されていることを確認 + - 既存翻訳の品質向上も完了していることを確認 + +#### 緊急時の対応 + +7. **翻訳漏れ発見時の対応**: + - 発見した未翻訳エントリを即座に記録 + - 同じ`msgid`の他のエントリも確認 + - 翻訳完了まで作業を継続 + +**重要**: この手順を省略することは品質保証上許可されません。すべての翻訳対象エントリが完了するまで作業を継続してください。 + ## Repository Structure The repository is organized as follows: diff --git a/library/dataclasses.po b/library/dataclasses.po index 739134058..4edde4318 100644 --- a/library/dataclasses.po +++ b/library/dataclasses.po @@ -324,7 +324,7 @@ msgstr "" "``@dataclass`` は :meth:`!__hash__` メソッドを暗黙的に追加する *場合があります* 。" "推奨されませんが、``unsafe_hash=True`` を使って ``@dataclass`` に :meth:`!__hash__` " "メソッドの作成を強制できます。これは、クラスが論理的には不変であるにもかかわらず、" -"変更可能である場合にあたります。これは特殊な使用例であり、慣重に検討する必要があります。" +"変更可能である場合にあたります。これは特殊な使用例であり、慎重に検討する必要があります。" #: ../../library/dataclasses.rst:150 msgid "" @@ -1341,6 +1341,13 @@ msgid "" "calculated ordered mapping of fields. Because the fields are in insertion " "order, derived classes override base classes. An example::" msgstr "" +":func:`@dataclass ` デコレータによってデータクラスが作成される際、" +"すべてのクラスのベースクラスを逆 MRO 順(つまり :class:`object` から開始)で" +"調べ、見つけたデータクラスごとに、そのベースクラスのフィールドをフィールドの" +"順序付きマッピングに追加します。すべてのベースクラスのフィールドが追加された後、" +"独自のフィールドを順序付きマッピングに追加します。生成されたすべてのメソッドは、" +"この組み合わされた、計算された順序付きフィールドマッピングを使用します。" +"フィールドは挿入順であるため、派生クラスはベースクラスをオーバーライドします。例::" #: ../../library/dataclasses.rst:673 msgid "" @@ -1354,6 +1361,15 @@ msgid "" " z: int = 10\n" " x: int = 15" msgstr "" +"@dataclass\n" +"class Base:\n" +" x: Any = 15.0\n" +" y: int = 0\n" +"\n" +"@dataclass\n" +"class C(Base):\n" +" z: int = 10\n" +" x: int = 15" #: ../../library/dataclasses.rst:683 msgid "" @@ -1361,16 +1377,19 @@ msgid "" "The final type of :attr:`!x` is :class:`int`, as specified in class :class:`!" "C`." msgstr "" +"フィールドの最終的なリストは、順番に :attr:`!x`、:attr:`!y`、:attr:`!z` です。" +":attr:`!x` の最終的な型は、クラス :class:`!C` で指定されたとおり :class:`int` です。" #: ../../library/dataclasses.rst:686 msgid "" "The generated :meth:`~object.__init__` method for :class:`!C` will look " "like::" msgstr "" +":class:`!C` の生成された :meth:`~object.__init__` メソッドは次のようになります::" #: ../../library/dataclasses.rst:688 msgid "def __init__(self, x: int = 15, y: int = 0, z: int = 10):" -msgstr "" +msgstr "def __init__(self, x: int = 15, y: int = 0, z: int = 10):" #: ../../library/dataclasses.rst:691 msgid "Re-ordering of keyword-only parameters in :meth:`!__init__`" @@ -1412,6 +1431,17 @@ msgid "" " z: int = 10\n" " t: int = field(kw_only=True, default=0)" msgstr "" +"@dataclass\n" +"class Base:\n" +" x: Any = 15.0\n" +" _: KW_ONLY\n" +" y: int = 0\n" +" w: int = 1\n" +"\n" +"@dataclass\n" +"class D(Base):\n" +" z: int = 10\n" +" t: int = field(kw_only=True, default=0)" #: ../../library/dataclasses.rst:714 msgid "The generated :meth:`!__init__` method for :class:`!D` will look like::" @@ -1422,6 +1452,8 @@ msgid "" "def __init__(self, x: Any = 15.0, z: int = 10, *, y: int = 0, w: int = 1, t: " "int = 0):" msgstr "" +"def __init__(self, x: Any = 15.0, z: int = 10, *, y: int = 0, w: int = 1, t: " +"int = 0):" #: ../../library/dataclasses.rst:718 msgid "" @@ -1438,6 +1470,8 @@ msgid "" "The relative ordering of keyword-only parameters is maintained in the re-" "ordered :meth:`!__init__` parameter list." msgstr "" +"キーワード専用パラメータの相対的な順序は、並び替えられた :meth:`!__init__` " +"パラメータリストで維持されます。" #: ../../library/dataclasses.rst:727 msgid "Default factory functions" @@ -1449,6 +1483,9 @@ msgid "" "arguments when a default value for the field is needed. For example, to " "create a new instance of a list, use::" msgstr "" +":func:`field` が *default_factory* を指定した場合、フィールドのデフォルト値が必要な際に" +"引数なしで呼び出されます。例えば、リストの新しいインスタンスを作成するには、" +"以下を使用します::" #: ../../library/dataclasses.rst:733 msgid "mylist: list = field(default_factory=list)" @@ -1462,6 +1499,10 @@ msgid "" "function. This happens because there is no other way to give the field an " "initial value." msgstr "" +"フィールドが :meth:`~object.__init__` から除外され(``init=False`` を使用)、" +"かつそのフィールドが *default_factory* も指定している場合、デフォルトファクトリ" +"関数は生成された :meth:`!__init__` 関数から必ず呼び出されます。" +"これは、フィールドに初期値を与える他の方法がないためです。" #: ../../library/dataclasses.rst:742 msgid "Mutable default values" @@ -1489,12 +1530,24 @@ msgid "" "assert o1.x == [1, 2]\n" "assert o1.x is o2.x" msgstr "" +"class C:\n" +" x = []\n" +" def add(self, element):\n" +" self.x.append(element)\n" +"\n" +"o1 = C()\n" +"o2 = C()\n" +"o1.add(1)\n" +"o2.add(2)\n" +"assert o1.x == [1, 2]\n" +"assert o1.x is o2.x" #: ../../library/dataclasses.rst:759 msgid "" "Note that the two instances of class :class:`!C` share the same class " "variable :attr:`!x`, as expected." msgstr "" +"予想どおり、クラス :class:`!C` の 2 つのインスタンスは同じクラス変数 :attr:`!x` を共有していることに注意してください。" #: ../../library/dataclasses.rst:762 msgid "Using dataclasses, *if* this code was valid::" @@ -1508,6 +1561,11 @@ msgid "" " def add(self, element):\n" " self.x.append(element)" msgstr "" +"@dataclass\n" +"class D:\n" +" x: list = [] # This code raises ValueError\n" +" def add(self, element):\n" +" self.x.append(element)" #: ../../library/dataclasses.rst:770 msgid "it would generate code similar to::" @@ -1591,6 +1649,9 @@ msgid "" "method is passed to the descriptor's :meth:`~object.__set__` method rather " "than overwriting the descriptor object." msgstr "" +"データクラスの :meth:`~object.__init__` メソッドに渡されたフィールドの値は、" +"ディスクリプタオブジェクトを上書きするのではなく、ディスクリプタの :meth:`~object.__set__` " +"メソッドに渡されます。" #: ../../library/dataclasses.rst:817 msgid "" @@ -1598,6 +1659,9 @@ msgid "" "`~object.__get__` or :meth:`!__set__` method is called rather than returning " "or overwriting the descriptor object." msgstr "" +"同様に、フィールドの取得または設定時には、ディスクリプタオブジェクトを返したり" +"上書きしたりするのではなく、ディスクリプタの :meth:`~object.__get__` または :meth:`!__set__` " +"メソッドが呼び出されます。" #: ../../library/dataclasses.rst:821 msgid "" @@ -1608,6 +1672,11 @@ msgid "" "default. On the other hand, if the descriptor raises :exc:`AttributeError` " "in this situation, no default value will be provided for the field." msgstr "" +"フィールドがデフォルト値を含んでいるかどうかを判定するため、:func:`@dataclass ` は" +"クラスアクセス形式を使用してディスクリプタの :meth:`!__get__` メソッドを呼び出します: " +"``descriptor.__get__(obj=None, type=cls)``。この場合にディスクリプタが値を返す場合、" +"それがフィールドのデフォルト値として使用されます。一方、この状況でディスクリプタが " +":exc:`AttributeError` を発生させる場合、フィールドにデフォルト値は提供されません。" #: ../../library/dataclasses.rst:831 msgid "" @@ -1637,6 +1706,31 @@ msgid "" "i.quantity_on_hand = 2.5 # calls __set__ with 2.5\n" "print(i.quantity_on_hand) # 2" msgstr "" +"class IntConversionDescriptor:\n" +" def __init__(self, *, default):\n" +" self._default = default\n" +"\n" +" def __set_name__(self, owner, name):\n" +" self._name = \"_\" + name\n" +"\n" +" def __get__(self, obj, type):\n" +" if obj is None:\n" +" return self._default\n" +"\n" +" return getattr(obj, self._name, self._default)\n" +"\n" +" def __set__(self, obj, value):\n" +" setattr(obj, self._name, int(value))\n" +"\n" +"@dataclass\n" +"class InventoryItem:\n" +" quantity_on_hand: IntConversionDescriptor = " +"IntConversionDescriptor(default=100)\n" +"\n" +"i = InventoryItem()\n" +"print(i.quantity_on_hand) # 100\n" +"i.quantity_on_hand = 2.5 # calls __set__ with 2.5\n" +"print(i.quantity_on_hand) # 2" #: ../../library/dataclasses.rst:856 msgid "" @@ -1644,6 +1738,9 @@ msgid "" "assigned a descriptor object as its default value, the field will act like a " "normal field." msgstr "" +"フィールドがディスクリプタ型でアノテーションされているが、デフォルト値として" +"ディスクリプタオブジェクトが割り当てられていない場合、フィールドは通常のフィールドのように" +"動作します。" msgid "" "@dataclass\n" "class Point:\n" @@ -1654,6 +1751,14 @@ msgid "" "\n" "p = Point(0, y=1.5, z=2.0)" msgstr "" +"@dataclass\n" +"class Point:\n" +" x: float\n" +" _: KW_ONLY\n" +" y: float\n" +" z: float\n" +"\n" +"p = Point(0, y=1.5, z=2.0)" #: ../../library/dataclasses.rst:533 msgid "" @@ -1712,6 +1817,14 @@ msgid "" " def __post_init__(self):\n" " self.c = self.a + self.b" msgstr "" +"@dataclass\n" +"class C:\n" +" a: float\n" +" b: float\n" +" c: float = field(init=False)\n" +"\n" +" def __post_init__(self):\n" +" self.c = self.a + self.b" #: ../../library/dataclasses.rst:570 msgid "" @@ -1739,6 +1852,17 @@ msgid "" " def __post_init__(self):\n" " super().__init__(self.side, self.side)" msgstr "" +"class Rectangle:\n" +" def __init__(self, height, width):\n" +" self.height = height\n" +" self.width = width\n" +"\n" +"@dataclass\n" +"class Square(Rectangle):\n" +" side: float\n" +"\n" +" def __post_init__(self):\n" +" super().__init__(self.side, self.side)" #: ../../library/dataclasses.rst:587 msgid "" @@ -1921,6 +2045,15 @@ msgid "" " z: int = 10\n" " x: int = 15" msgstr "" +"@dataclass\n" +"class Base:\n" +" x: Any = 15.0\n" +" y: int = 0\n" +"\n" +"@dataclass\n" +"class C(Base):\n" +" z: int = 10\n" +" x: int = 15" #: ../../library/dataclasses.rst:683 msgid "" @@ -1939,7 +2072,7 @@ msgstr ":class:`!C` の生成された :meth:`~object.__init__` メソッドは #: ../../library/dataclasses.rst:688 msgid "def __init__(self, x: int = 15, y: int = 0, z: int = 10):" -msgstr "" +msgstr "def __init__(self, x: int = 15, y: int = 0, z: int = 10):" #: ../../library/dataclasses.rst:691 msgid "Re-ordering of keyword-only parameters in :meth:`!__init__`" @@ -1981,6 +2114,17 @@ msgid "" " z: int = 10\n" " t: int = field(kw_only=True, default=0)" msgstr "" +"@dataclass\n" +"class Base:\n" +" x: Any = 15.0\n" +" _: KW_ONLY\n" +" y: int = 0\n" +" w: int = 1\n" +"\n" +"@dataclass\n" +"class D(Base):\n" +" z: int = 10\n" +" t: int = field(kw_only=True, default=0)" #: ../../library/dataclasses.rst:714 msgid "The generated :meth:`!__init__` method for :class:`!D` will look like::" @@ -1991,6 +2135,8 @@ msgid "" "def __init__(self, x: Any = 15.0, z: int = 10, *, y: int = 0, w: int = 1, t: " "int = 0):" msgstr "" +"def __init__(self, x: Any = 15.0, z: int = 10, *, y: int = 0, w: int = 1, t: " +"int = 0):" #: ../../library/dataclasses.rst:718 msgid "" @@ -2066,6 +2212,17 @@ msgid "" "assert o1.x == [1, 2]\n" "assert o1.x is o2.x" msgstr "" +"class C:\n" +" x = []\n" +" def add(self, element):\n" +" self.x.append(element)\n" +"\n" +"o1 = C()\n" +"o2 = C()\n" +"o1.add(1)\n" +"o2.add(2)\n" +"assert o1.x == [1, 2]\n" +"assert o1.x is o2.x" #: ../../library/dataclasses.rst:759 msgid "" From ef5c9734472532cfb32d5945580d45c438aaa78d Mon Sep 17 00:00:00 2001 From: Atsuo Ishimoto Date: Sun, 6 Jul 2025 20:03:37 +0900 Subject: [PATCH 09/19] update pathlib --- CLAUDE.md | 6 +- library/pathlib.po | 289 ++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 277 insertions(+), 18 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index 82078f6a6..a09c80a41 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -61,7 +61,7 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co #### 4.1 ファイルの分割 -.poファイルのサイズが20kbを超える場合は、すべてをまとめて処理せず、splitpoコマンドでpoファイルを50エントリずつに分割して、それぞれを翻訳します。 +.poファイルのサイズが20kbを超える場合は、すべてをまとめて処理せず、splitpoコマンドでpoファイルを30エントリずつに分割して、それぞれを翻訳します。 ``` @@ -84,9 +84,9 @@ options: 実行例: - `splitpo -o /tmp/split_pathlib -e 50 library/pathlib.po` + `splitpo -o /tmp/split_pathlib -e 30 library/pathlib.po` -このコマンドは、poファイルを50エントリごとに分割します。 +このコマンドは、poファイルを30エントリごとに分割します。 Split files are named with the pattern `{original_name}_part_{number}.po`: - `input.po` → `input_part_000.po`, `input_part_001.po`, etc. diff --git a/library/pathlib.po b/library/pathlib.po index 2e624a3db..144d3c566 100644 --- a/library/pathlib.po +++ b/library/pathlib.po @@ -500,6 +500,12 @@ msgid "" ">>> str(p)\n" "'c:\\\\Program Files'" msgstr "" +">>> p = PurePath('/etc')\n" +">>> str(p)\n" +"'/etc'\n" +">>> p = PureWindowsPath('c:/Program Files')\n" +">>> str(p)\n" +"'c:\\\\Program Files'" #: ../../library/pathlib.rst:270 msgid "" @@ -514,6 +520,8 @@ msgid "" ">>> bytes(p)\n" "b'/etc'" msgstr "" +">>> bytes(p)\n" +"b'/etc'" #: ../../library/pathlib.rst:277 msgid "" @@ -548,6 +556,13 @@ msgid "" ">>> p.parts\n" "('c:\\\\', 'Program Files', 'PSF')" msgstr "" +">>> p = PurePath('/usr/bin/python3')\n" +">>> p.parts\n" +"('/', 'usr', 'bin', 'python3')\n" +"\n" +">>> p = PureWindowsPath('c:/Program Files/PSF')\n" +">>> p.parts\n" +"('c:\\\\', 'Program Files', 'PSF')" #: ../../library/pathlib.rst:299 msgid "(note how the drive and local root are regrouped in a single part)" @@ -582,6 +597,12 @@ msgid "" ">>> PurePosixPath('/etc').drive\n" "''" msgstr "" +">>> PureWindowsPath('c:/Program Files/').drive\n" +"'c:'\n" +">>> PureWindowsPath('/Program Files/').drive\n" +"''\n" +">>> PurePosixPath('/etc').drive\n" +"''" #: ../../library/pathlib.rst:329 msgid "UNC shares are also considered drives::" @@ -592,6 +613,8 @@ msgid "" ">>> PureWindowsPath('//host/share/foo.txt').drive\n" "'\\\\\\\\host\\\\share'" msgstr "" +">>> PureWindowsPath('//host/share/foo.txt').drive\n" +"'\\\\\\\\host\\\\share'" #: ../../library/pathlib.rst:336 msgid "A string representing the (local or global) root, if any::" @@ -606,6 +629,12 @@ msgid "" ">>> PurePosixPath('/etc').root\n" "'/'" msgstr "" +">>> PureWindowsPath('c:/Program Files/').root\n" +"'\\\\'\n" +">>> PureWindowsPath('c:Program Files/').root\n" +"''\n" +">>> PurePosixPath('/etc').root\n" +"'/'" #: ../../library/pathlib.rst:345 msgid "UNC shares always have a root::" @@ -616,6 +645,8 @@ msgid "" ">>> PureWindowsPath('//host/share').root\n" "'\\\\'" msgstr "" +">>> PureWindowsPath('//host/share').root\n" +"'\\\\'" #: ../../library/pathlib.rst:350 msgid "" @@ -634,6 +665,12 @@ msgid "" ">>> PurePosixPath('////etc').root\n" "'/'" msgstr "" +">>> PurePosixPath('//etc').root\n" +"'//'\n" +">>> PurePosixPath('///etc').root\n" +"'/'\n" +">>> PurePosixPath('////etc').root\n" +"'/'" #: ../../library/pathlib.rst:362 msgid "" @@ -651,6 +688,8 @@ msgid "" "an implementation-defined manner, although more than two leading slashes " "shall be treated as a single slash.\"*" msgstr "" +"*\"2つの連続するスラッシュで始まるパス名は実装定義の方法で解釈される場合がありますが、" +"3つ以上の先頭スラッシュは単一のスラッシュとして扱われます。\"*" #: ../../library/pathlib.rst:372 msgid "The concatenation of the drive and root::" @@ -667,6 +706,14 @@ msgid "" ">>> PureWindowsPath('//host/share').anchor\n" "'\\\\\\\\host\\\\share\\\\'" msgstr "" +">>> PureWindowsPath('c:/Program Files/').anchor\n" +"'c:\\\\'\n" +">>> PureWindowsPath('c:Program Files/').anchor\n" +"'c:'\n" +">>> PurePosixPath('/etc').anchor\n" +"'/'\n" +">>> PureWindowsPath('//host/share').anchor\n" +"'\\\\\\\\host\\\\share\\\\'" #: ../../library/pathlib.rst:386 msgid "" @@ -684,6 +731,13 @@ msgid "" ">>> p.parents[2]\n" "PureWindowsPath('c:/')" msgstr "" +">>> p = PureWindowsPath('c:/foo/bar/setup.py')\n" +">>> p.parents[0]\n" +"PureWindowsPath('c:/foo/bar')\n" +">>> p.parents[1]\n" +"PureWindowsPath('c:/foo')\n" +">>> p.parents[2]\n" +"PureWindowsPath('c:/')" #: ../../library/pathlib.rst:397 msgid "" @@ -785,7 +839,7 @@ msgstr "一般的にはファイル拡張子と呼ばれています。" #: ../../library/pathlib.rst:460 ../../library/pathlib.rst:475 msgid "A single dot (\"``.``\") is considered a valid suffix." -msgstr "" +msgstr "単一のドット (``\".``\") は有効なサフィックスとみなされます。" #: ../../library/pathlib.rst:464 msgid "A list of the path's suffixes, often called file extensions::" @@ -864,6 +918,8 @@ msgid "" "This method is string-based; it neither accesses the filesystem nor treats " "\"``..``\" segments specially. The following code is equivalent:" msgstr "" +"このメソッドは文字列ベースです。ファイルシステムにアクセスしたり、" +"\"``..``\" セグメントを特別に扱うことはありません。以下のコードは等価です:" #: ../../library/pathlib.rst:542 msgid "" @@ -887,12 +943,16 @@ msgid "" "Windows path names that contain a colon, or end with a dot or a space, are " "considered reserved. UNC paths may be reserved." msgstr "" +"コロンを含む、またはドットやスペースで終わる Windows パス名は予約されています。" +"UNC パスも予約されている場合があります。" #: ../../library/pathlib.rst:555 msgid "" "This method is deprecated; use :func:`os.path.isreserved` to detect reserved " "paths on Windows." msgstr "" +"このメソッドは非推奨です。Windows で予約されたパスを検出するには " +":func:`os.path.isreserved` を使用してください。" #: ../../library/pathlib.rst:561 msgid "" @@ -973,6 +1033,10 @@ msgid "" "\"``**``\" isn't supported (it acts like non-recursive \"``*``\"), and if a " "relative pattern is provided, then matching is done from the right::" msgstr "" +"このメソッドは :meth:`~PurePath.full_match` と似ていますが、空のパターンは " +"許可されません (:exc:`ValueError` が発生します)。再帰ワイルドカード " +"\"``**``\" はサポートされていません (非再帰の \"``*``\" のように動作します)。" +"相対パターンが提供された場合、マッチングは右から行われます::" #: ../../library/pathlib.rst:613 msgid "" @@ -1051,6 +1115,11 @@ msgid "" "*walk_up* option as it assumes that no symlinks are present in the path; " "call :meth:`~Path.resolve` first if necessary to resolve symlinks." msgstr "" +"この関数は :class:`PurePath` の一部であり、文字列を使用して動作します。" +"基礎となるファイル構造をチェックしたりアクセスしたりしません。" +"これは *walk_up* オプションに影響を与える可能性があります。" +"パスにシンボリックリンクが存在しないことを前提としているためです。" +"必要に応じて、最初に :meth:`~Path.resolve` を呼び出してシンボリックリンクを解決してください。" #: ../../library/pathlib.rst:665 msgid "" @@ -1148,6 +1217,8 @@ msgid "" "A single dot (\"``.``\") is considered a valid suffix. In previous " "versions, :exc:`ValueError` is raised if a single dot is supplied." msgstr "" +"単一のドット (\"``.``\") は有効なサフィックスとみなされます。以前のバージョンでは、" +"単一のドットが提供された場合 :exc:`ValueError` が発生していました。" #: ../../library/pathlib.rst:738 msgid "" @@ -1156,6 +1227,10 @@ msgid "" "such as from :attr:`parent` and :meth:`relative_to`. Subclasses may override " "this method to pass information to derivative paths, for example::" msgstr "" +"指定された *pathsegments* を組み合わせて、同じタイプの新しいパスオブジェクトを作成します。" +"このメソッドは :attr:`parent` や :meth:`relative_to` などから派生パスが作成される" +"たびに呼び出されます。サブクラスはこのメソッドをオーバーライドして、" +"派生パスに情報を渡すことができます。例::" #: ../../library/pathlib.rst:743 msgid "" @@ -1280,6 +1355,8 @@ msgid "" "Some concrete path methods can raise an :exc:`OSError` if a system call " "fails (for example because the path doesn't exist)." msgstr "" +"一部の具象パスメソッドは、システムコールが失敗した場合 " +"(例えばパスが存在しない場合) に :exc:`OSError` を発生させる可能性があります。" #: ../../library/pathlib.rst:834 msgid "Parsing and generating URIs" @@ -1290,12 +1367,16 @@ msgid "" "Concrete path objects can be created from, and represented as, 'file' URIs " "conforming to :rfc:`8089`." msgstr "" +"具象パスオブジェクトは :rfc:`8089` に準拠した 'file' URI から作成したり、" +"'file' URI として表現したりできます。" #: ../../library/pathlib.rst:841 msgid "" "File URIs are not portable across machines with different :ref:`filesystem " "encodings `." msgstr "" +"File URI は異なる :ref:`filesystem encodings ` を持つマシン間での" +"移植性はありません。" #: ../../library/pathlib.rst:846 msgid "Return a new path object from parsing a 'file' URI. For example::" @@ -1309,7 +1390,7 @@ msgstr "" #: ../../library/pathlib.rst:851 msgid "On Windows, DOS device and UNC paths may be parsed from URIs::" -msgstr "" +msgstr "Windows では、DOS デバイスや UNC パスを URI からパースできます::" #: ../../library/pathlib.rst:853 msgid "" @@ -1321,7 +1402,7 @@ msgstr "" #: ../../library/pathlib.rst:858 msgid "Several variant forms are supported::" -msgstr "" +msgstr "いくつかのバリアント形式がサポートされています::" #: ../../library/pathlib.rst:860 msgid "" @@ -1340,6 +1421,8 @@ msgid "" ":exc:`ValueError` is raised if the URI does not start with ``file:``, or the " "parsed path isn't absolute." msgstr "" +"URI が ``file:`` で始まらない、またはパースされたパスが絶対パスでない場合、" +":exc:`ValueError` が発生します。" #: ../../library/pathlib.rst:874 msgid "" @@ -1347,6 +1430,9 @@ msgid "" "if the authority isn't empty or ``localhost``, then on Windows a UNC path is " "returned (as before), and on other platforms a :exc:`ValueError` is raised." msgstr "" +"URL 権限がローカルホスト名と一致する場合、それは破棄されます。それ以外で、" +"権限が空でないか ``localhost`` でない場合、Windows では UNC パスが返され (以前と同じ)、" +"他のプラットフォームでは :exc:`ValueError` が発生します。" #: ../../library/pathlib.rst:883 msgid "" @@ -1372,6 +1458,8 @@ msgid "" "possible but deprecated. The method's use of :func:`os.fsencode` makes it " "strictly impure." msgstr "" +":class:`Path` ではなく :class:`PurePath` からこのメソッドを呼び出すことは可能ですが、非推奨です。" +"このメソッドの :func:`os.fsencode` の使用が、厳密には純粋でないものにしています。" #: ../../library/pathlib.rst:903 msgid "Expanding and resolving paths" @@ -1480,6 +1568,9 @@ msgid "" "resolved as far as possible and any remainder is appended without checking " "whether it exists." msgstr "" +"パスが存在しないかシンボリックリンクループが検出され、*strict* が ``True`` の場合、" +":exc:`OSError` が発生します。*strict* が ``False`` の場合、パスは可能な限り解決され、" +"残りの部分は存在をチェックせずに追加されます。" #: ../../library/pathlib.rst:977 msgid "The *strict* parameter was added (pre-3.6 behavior is strict)." @@ -1491,6 +1582,9 @@ msgid "" "strict mode, and no exception is raised in non-strict mode. In previous " "versions, :exc:`RuntimeError` is raised no matter the value of *strict*." msgstr "" +"シンボリックリンクループは他のエラーと同じように扱われます。ストリクトモードでは " +":exc:`OSError` が発生し、非ストリクトモードでは例外は発生しません。以前のバージョンでは、" +"*strict* の値に関係なく :exc:`RuntimeError` が発生していました。" #: ../../library/pathlib.rst:988 msgid "" @@ -1775,6 +1869,9 @@ msgid "" "help reduce the number of system calls needed when switching on file type. " "For example::" msgstr "" +"ファイルタイプ情報のクエリをサポートする :class:`~pathlib.types.PathInfo` オブジェクトです。" +"このオブジェクトは結果をキャッシュするメソッドを公開し、ファイルタイプを切り替える際に" +"必要なシステムコール数を減らすのに役立ちます。例::" #: ../../library/pathlib.rst:1195 msgid "" @@ -1798,6 +1895,9 @@ msgid "" "the parent directory. Merely accessing :attr:`Path.info` does not perform " "any filesystem queries." msgstr "" +"パスが :meth:`Path.iterdir` から生成された場合、この属性は親ディレクトリのスキャンから得られた" +"ファイルタイプに関する情報で初期化されます。単に :attr:`Path.info` にアクセスするだけでは" +"ファイルシステムクエリは実行されません。" #: ../../library/pathlib.rst:1212 msgid "" @@ -1806,6 +1906,9 @@ msgid "" "this attribute. There is no way to reset the cache; instead you can create a " "new path object with an empty info cache via ``p = Path(p)``." msgstr "" +"最新の情報を取得するには、この属性のメソッドではなく :meth:`Path.is_dir`、" +":meth:`~Path.is_file`、:meth:`~Path.is_symlink` を呼び出すのが最適です。キャッシュをリセットする方法はありません。" +"代わりに ``p = Path(p)`` で空の情報キャッシュを持つ新しいパスオブジェクトを作成できます。" #: ../../library/pathlib.rst:1221 msgid "Reading and writing files" @@ -2003,6 +2106,8 @@ msgid "" "suppressed. In previous versions, such exceptions are suppressed in many " "cases, but not all." msgstr "" +"ファイルシステムのスキャンで発生した :exc:`OSError` 例外はすべて抑制されます。" +"以前のバージョンでは、このような例外は多くの場合に抑制されましたが、すべてではありませんでした。" #: ../../library/pathlib.rst:1379 msgid "" @@ -2029,6 +2134,8 @@ msgid "" "Generate the file names in a directory tree by walking the tree either top-" "down or bottom-up." msgstr "" +"ディレクトリツリーをトップダウンまたはボトムアップでたどって、" +"ディレクトリツリー内のファイル名を生成します。" #: ../../library/pathlib.rst:1402 msgid "" @@ -2036,6 +2143,9 @@ msgid "" "but excluding '.' and '..'), the method yields a 3-tuple of ``(dirpath, " "dirnames, filenames)``." msgstr "" +"*self* をルートとするディレクトリツリー内の各ディレクトリ (*self* を含みますが、" +"'.' と '..' は除きます) に対し、このメソッドは ``(dirpath, dirnames, filenames)`` の" +"3-タプルを yield します。" #: ../../library/pathlib.rst:1406 msgid "" @@ -2046,6 +2156,11 @@ msgid "" "begins with *self*) to a file or directory in *dirpath*, do ``dirpath / " "name``. Whether or not the lists are sorted is file system-dependent." msgstr "" +"*dirpath* は現在たどっているディレクトリへの :class:`Path` です。" +"*dirnames* は *dirpath* 内のサブディレクトリ名の文字列リストです (``'.'`` と ``'..'`` は除きます)。" +"*filenames* は *dirpath* 内のディレクトリ以外のファイル名の文字列リストです。" +"*dirpath* 内のファイルまたはディレクトリへのフルパス (*self* から始まる) を得るには、" +"``dirpath / name`` とします。リストがソートされているかどうかはファイルシステムに依存します。" #: ../../library/pathlib.rst:1414 msgid "" @@ -2057,6 +2172,11 @@ msgid "" "*top_down*, the list of subdirectories is retrieved before the triples for " "the directory and its subdirectories are walked." msgstr "" +"オプション引数 *top_down* が真 (デフォルト) の場合、ディレクトリのタプルは" +"そのサブディレクトリのタプルよりも先に生成されます (ディレクトリはトップダウンでたどられます)。" +"*top_down* が偽の場合、ディレクトリのタプルはそのすべてのサブディレクトリのタプルの後に" +"生成されます (ディレクトリはボトムアップでたどられます)。*top_down* の値に関係なく、" +"サブディレクトリのリストはディレクトリとそのサブディレクトリがたどられる前に取得されます。" #: ../../library/pathlib.rst:1422 msgid "" @@ -2070,6 +2190,13 @@ msgid "" "of :meth:`Path.walk` since the directories in *dirnames* have already been " "generated by the time *dirnames* is yielded to the caller." msgstr "" +"*top_down* が真の場合、呼び出し元は *dirnames* リストをインプレースで変更でき (例えば、" +":keyword:`del` やスライス代入を使用)、:meth:`Path.walk` は *dirnames* に残っている名前の" +"サブディレクトリにのみ再帰します。これは検索を省く、訪問の特定の順序を強制する、" +"または :meth:`Path.walk` が再開される前に呼び出し元が作成またはリネームしたディレクトリを" +":meth:`Path.walk` に知らせるために使用できます。*top_down* が偽の場合に *dirnames* を変更しても、" +"*dirnames* が呼び出し元に yield される時点で *dirnames* 内のディレクトリはすでに生成されているため、" +":meth:`Path.walk` の動作に影響を与えません。" #: ../../library/pathlib.rst:1432 msgid "" @@ -2079,6 +2206,11 @@ msgid "" "error to continue the walk or re-raise it to stop the walk. Note that the " "filename is available as the ``filename`` attribute of the exception object." msgstr "" +"デフォルトでは、:func:`os.scandir` からのエラーは無視されます。オプション引数" +"*on_error* が指定された場合、それは呼び出し可能であるべきです。:exc:`OSError` インスタンスを" +"一つの引数として呼び出されます。この呼び出し可能オブジェクトはエラーを処理してたどることを" +"継続したり、それを再発生させてたどることを停止したりできます。ファイル名は例外オブジェクトの" +"``filename`` 属性として利用できることに注意してください。" #: ../../library/pathlib.rst:1438 msgid "" @@ -2088,6 +2220,10 @@ msgid "" "their targets, and consequently visit directories pointed to by symlinks " "(where supported)." msgstr "" +"デフォルトでは、:meth:`Path.walk` はシンボリックリンクをたどらず、代わりに *filenames* リストに" +"追加します。*follow_symlinks* を真に設定すると、シンボリックリンクを解決し、そのターゲットに" +"応じて *dirnames* や *filenames* に配置し、結果的にシンボリックリンクが指すディレクトリを" +"訪問します (サポートされている場合)。" #: ../../library/pathlib.rst:1445 msgid "" @@ -2107,18 +2243,26 @@ msgid "" "try to descend into it. To prevent such behavior, remove directories from " "*dirnames* as appropriate." msgstr "" +":meth:`Path.walk` は、たどっているディレクトリが実行中に変更されないことを仮定しています。" +"例えば、*dirnames* のディレクトリがシンボリックリンクに置き換えられ、*follow_symlinks* が偽の場合でも、" +":meth:`Path.walk` は依然としてそこに降りていこうとします。このような動作を防ぐために、" +"適切に *dirnames* からディレクトリを削除してください。" #: ../../library/pathlib.rst:1458 msgid "" "Unlike :func:`os.walk`, :meth:`Path.walk` lists symlinks to directories in " "*filenames* if *follow_symlinks* is false." msgstr "" +":func:`os.walk` とは異なり、*follow_symlinks* が偽の場合、:meth:`Path.walk` は" +"ディレクトリへのシンボリックリンクを *filenames* にリストします。" #: ../../library/pathlib.rst:1461 msgid "" "This example displays the number of bytes used by all files in each " "directory, while ignoring ``__pycache__`` directories::" msgstr "" +"この例では、``__pycache__`` ディレクトリを無視しながら、各ディレクトリ内の" +"すべてのファイルが使用するバイト数を表示します::" #: ../../library/pathlib.rst:1464 msgid "" @@ -2143,6 +2287,8 @@ msgid "" "Walking the tree bottom-up is essential as :func:`rmdir` doesn't allow " "deleting a directory before it is empty::" msgstr "" +"次の例は :func:`shutil.rmtree` の簡単な実装です。:func:`rmdir` はディレクトリが空になる前に" +"それを削除することを許可しないため、ツリーをボトムアップでたどることが不可欠です::" #: ../../library/pathlib.rst:1481 msgid "" @@ -2155,6 +2301,14 @@ msgid "" " for name in dirs:\n" " (root / name).rmdir()" msgstr "" +"# ディレクトリ \"top\" からアクセス可能なすべてを削除します。\n" +"# 注意: これは危険です!例えば、top == Path('/') の場合、\n" +"# すべてのファイルを削除する可能性があります。\n" +"for root, dirs, files in top.walk(top_down=False):\n" +" for name in files:\n" +" (root / name).unlink()\n" +" for name in dirs:\n" +" (root / name).rmdir()" #: ../../library/pathlib.rst:1494 msgid "Creating files and directories" @@ -2179,6 +2333,8 @@ msgid "" "The :meth:`~Path.open`, :meth:`~Path.write_text` and :meth:`~Path." "write_bytes` methods are often used to create files." msgstr "" +":meth:`~Path.open`、:meth:`~Path.write_text`、:meth:`~Path.write_bytes` メソッドは" +"ファイルを作成するためにしばしば使用されます。" #: ../../library/pathlib.rst:1511 msgid "" @@ -2222,6 +2378,8 @@ msgid "" "given path already exists in the file system and is not a directory (same " "behavior as the POSIX ``mkdir -p`` command)." msgstr "" +"*exist_ok* が真の場合、指定されたパスがファイルシステムに既に存在し、かつディレクトリでない" +"場合を除いて、:exc:`FileExistsError` は発生しません (POSIX の ``mkdir -p`` コマンドと同じ動作)。" #: ../../library/pathlib.rst:1530 msgid "The *exist_ok* parameter was added." @@ -2229,7 +2387,7 @@ msgstr "*exist_ok* 引数が追加されました。" #: ../../library/pathlib.rst:1536 msgid "Make this path a symbolic link pointing to *target*." -msgstr "" +msgstr "このパスを *target* を指すシンボリックリンクにします。" #: ../../library/pathlib.rst:1538 msgid "" @@ -2290,13 +2448,15 @@ msgstr "" #: ../../library/pathlib.rst:1580 msgid "Copying, moving and deleting" -msgstr "" +msgstr "コピー、移動、削除" #: ../../library/pathlib.rst:1584 msgid "" "Copy this file or directory tree to the given *target*, and return a new :" "class:`!Path` instance pointing to *target*." msgstr "" +"このファイルまたはディレクトリツリーを指定された *target* にコピーし、*target* を指す" +"新しい :class:`!Path` インスタンスを返します。" #: ../../library/pathlib.rst:1587 msgid "" @@ -2305,6 +2465,9 @@ msgid "" "default), the symlink's target is copied. Otherwise, the symlink is " "recreated at the destination." msgstr "" +"ソースがファイルの場合、ターゲットが既存のファイルであれば置き換えられます。" +"ソースがシンボリックリンクで *follow_symlinks* が真 (デフォルト) の場合、シンボリックリンクの" +"ターゲットがコピーされます。そうでなければ、シンボリックリンクが宛先で再作成されます。" #: ../../library/pathlib.rst:1592 msgid "" @@ -2315,6 +2478,11 @@ msgid "" "argument has no effect when copying files on Windows (where metadata is " "always preserved)." msgstr "" +"*preserve_metadata* が偽 (デフォルト) の場合、ディレクトリ構造とファイルデータのみが" +"コピーされることが保証されます。*preserve_metadata* を真に設定すると、" +"サポートされている場合にファイルやディレクトリのアクセス権限、フラグ、最終アクセス時刻、" +"変更時刻、拡張属性がコピーされることが保証されます。この引数は Windows でファイルを" +"コピーする際には効果がありません (メタデータは常に保存されます)。" #: ../../library/pathlib.rst:1600 msgid "" @@ -2322,6 +2490,9 @@ msgid "" "performs a lightweight copy, where data blocks are only copied when " "modified. This is known as copy-on-write." msgstr "" +"オペレーティングシステムとファイルシステムがサポートしている場合、このメソッドは" +"軽量コピーを実行し、データブロックは変更時にのみコピーされます。" +"これはコピーオンライトと呼ばれます。" #: ../../library/pathlib.rst:1610 msgid "" @@ -2329,6 +2500,9 @@ msgid "" "be an existing directory. Other arguments are handled identically to :meth:" "`Path.copy`. Returns a new :class:`!Path` instance pointing to the copy." msgstr "" +"このファイルまたはディレクトリツリーを指定された *target_dir* にコピーします。" +"*target_dir* は既存のディレクトリである必要があります。他の引数は :meth:`Path.copy` と同じように処理されます。" +"コピーを指す新しい :class:`!Path` インスタンスを返します。" #: ../../library/pathlib.rst:1620 msgid "" @@ -2373,6 +2547,7 @@ msgid "" "It is implemented in terms of :func:`os.rename` and gives the same " "guarantees." msgstr "" +"これは :func:`os.rename` を使用して実装され、同じ保証を提供します。" #: ../../library/pathlib.rst:1641 ../../library/pathlib.rst:1655 msgid "Added return value, return the new :class:`!Path` instance." @@ -2393,6 +2568,8 @@ msgid "" "Move this file or directory tree to the given *target*, and return a new :" "class:`!Path` instance pointing to *target*." msgstr "" +"このファイルまたはディレクトリツリーを指定された *target* に移動し、*target* を指す" +"新しい :class:`!Path` インスタンスを返します。" #: ../../library/pathlib.rst:1664 msgid "" @@ -2401,6 +2578,9 @@ msgid "" "point to the same file or directory, or the *target* is a non-empty " "directory, then :exc:`OSError` is raised." msgstr "" +"*target* が存在しない場合は作成されます。このパスと *target* の両方が既存のファイルの場合、" +"ターゲットが上書きされます。両方のパスが同じファイルまたはディレクトリを指しているか、" +"*target* が空でないディレクトリの場合、:exc:`OSError` が発生します。" #: ../../library/pathlib.rst:1669 msgid "" @@ -2408,6 +2588,8 @@ msgid "" "`os.replace`. Otherwise, this path is copied (preserving metadata and " "symlinks) and then deleted." msgstr "" +"両方のパスが同じファイルシステム上にある場合、移動は :func:`os.replace` で実行されます。" +"そうでなければ、このパスがコピーされ (メタデータとシンボリックリンクを保持して) 削除されます。" #: ../../library/pathlib.rst:1678 msgid "" @@ -2415,6 +2597,9 @@ msgid "" "be an existing directory. Returns a new :class:`!Path` instance pointing to " "the moved path." msgstr "" +"このファイルまたはディレクトリツリーを指定された *target_dir* に移動します。" +"*target_dir* は既存のディレクトリである必要があります。移動したパスを指す" +"新しい :class:`!Path` インスタンスを返します。" #: ../../library/pathlib.rst:1687 msgid "" @@ -2535,37 +2720,39 @@ msgstr "" #: ../../library/pathlib.rst:1770 msgid "Pattern language" -msgstr "" +msgstr "パターン言語" #: ../../library/pathlib.rst:1772 msgid "" "The following wildcards are supported in patterns for :meth:`~PurePath." "full_match`, :meth:`~Path.glob` and :meth:`~Path.rglob`:" msgstr "" +":meth:`~PurePath.full_match`、:meth:`~Path.glob`、:meth:`~Path.rglob` のパターンでは" +"以下のワイルドカードがサポートされています:" #: ../../library/pathlib.rst:1775 msgid "``**`` (entire segment)" -msgstr "" +msgstr "``**`` (セグメント全体)" #: ../../library/pathlib.rst:1776 msgid "Matches any number of file or directory segments, including zero." -msgstr "" +msgstr "ゼロを含め、任意の数のファイルまたはディレクトリセグメントにマッチします。" #: ../../library/pathlib.rst:1777 msgid "``*`` (entire segment)" -msgstr "" +msgstr "``*`` (セグメント全体)" #: ../../library/pathlib.rst:1778 msgid "Matches one file or directory segment." -msgstr "" +msgstr "一つのファイルまたはディレクトリセグメントにマッチします。" #: ../../library/pathlib.rst:1779 msgid "``*`` (part of a segment)" -msgstr "" +msgstr "``*`` (セグメントの一部)" #: ../../library/pathlib.rst:1780 msgid "Matches any number of non-separator characters, including zero." -msgstr "" +msgstr "ゼロを含め、任意の数のセパレータ以外の文字にマッチします。" #: ../../library/pathlib.rst:1781 msgid "``?``" @@ -2573,7 +2760,7 @@ msgstr "``?``" #: ../../library/pathlib.rst:1782 msgid "Matches one non-separator character." -msgstr "" +msgstr "一つのセパレータ以外の文字にマッチします。" #: ../../library/pathlib.rst:1783 msgid "``[seq]``" @@ -2586,6 +2773,9 @@ msgid "" "lowercase ASCII letter. Multiple ranges can be combined: ``[a-zA-Z0-9_]`` " "matches any ASCII letter, digit, or underscore." msgstr "" +"*seq* 内の一文字にマッチします。*seq* は文字のシーケンスです。範囲表現がサポートされています。" +"例えば、``[a-z]`` は任意の小文字 ASCII 文字にマッチします。複数の範囲を組み合わせることもできます:" +"``[a-zA-Z0-9_]`` は任意の ASCII 文字、数字、またはアンダースコアにマッチします。" #: ../../library/pathlib.rst:1788 msgid "``[!seq]``" @@ -2596,6 +2786,7 @@ msgid "" "Matches one character not in *seq*, where *seq* follows the same rules as " "above." msgstr "" +"*seq* に含まれない一文字にマッチします。*seq* は上記と同じルールに従います。" #: ../../library/pathlib.rst:1791 msgid "" @@ -2607,7 +2798,7 @@ msgstr "" #: ../../library/pathlib.rst:1794 msgid "The \"``**``\" wildcard enables recursive globbing. A few examples:" -msgstr "" +msgstr "\"``**``\" ワイルドカードは再帰的な glob を有効にします。いくつかの例:" #: ../../library/pathlib.rst:1797 msgid "Pattern" @@ -2655,24 +2846,32 @@ msgid "" "Globbing with the \"``**``\" wildcard visits every directory in the tree. " "Large directory trees may take a long time to search." msgstr "" +"\"``**``\" ワイルドカードでの glob はツリー内のすべてのディレクトリを訪問します。" +"大きなディレクトリツリーの検索には長時間かかる場合があります。" #: ../../library/pathlib.rst:1809 msgid "" "Globbing with a pattern that ends with \"``**``\" returns both files and " "directories. In previous versions, only directories were returned." msgstr "" +"\"``**``\" で終わるパターンでの glob はファイルとディレクトリの両方を返します。" +"以前のバージョンでは、ディレクトリのみが返されていました。" #: ../../library/pathlib.rst:1813 msgid "" "In :meth:`Path.glob` and :meth:`~Path.rglob`, a trailing slash may be added " "to the pattern to match only directories." msgstr "" +":meth:`Path.glob` と :meth:`~Path.rglob` では、ディレクトリのみにマッチさせるために" +"パターンの末尾にスラッシュを追加できます。" #: ../../library/pathlib.rst:1816 msgid "" "Globbing with a pattern that ends with a pathname components separator (:" "data:`~os.sep` or :data:`~os.altsep`) returns only directories." msgstr "" +"パス名コンポーネントセパレータ (:data:`~os.sep` または :data:`~os.altsep`) で終わる" +"パターンでの glob はディレクトリのみを返します。" #: ../../library/pathlib.rst:1822 msgid "Comparison to the :mod:`glob` module" @@ -2683,18 +2882,24 @@ msgid "" "The patterns accepted and results generated by :meth:`Path.glob` and :meth:" "`Path.rglob` differ slightly from those by the :mod:`glob` module:" msgstr "" +":meth:`Path.glob` と :meth:`Path.rglob` が受け入れるパターンと生成する結果は、" +":mod:`glob` モジュールのものと少し異なります:" #: ../../library/pathlib.rst:1827 msgid "" "Files beginning with a dot are not special in pathlib. This is like passing " "``include_hidden=True`` to :func:`glob.glob`." msgstr "" +"pathlib ではドットで始まるファイルは特別ではありません。これは :func:`glob.glob` に" +"``include_hidden=True`` を渡すのと同じです。" #: ../../library/pathlib.rst:1829 msgid "" "\"``**``\" pattern components are always recursive in pathlib. This is like " "passing ``recursive=True`` to :func:`glob.glob`." msgstr "" +"pathlib では \"``**``\" パターンコンポーネントは常に再帰的です。これは :func:`glob.glob` に" +"``recursive=True`` を渡すのと同じです。" #: ../../library/pathlib.rst:1831 msgid "" @@ -2702,12 +2907,17 @@ msgid "" "This behaviour has no equivalent in :func:`glob.glob`, but you can pass " "``recurse_symlinks=True`` to :meth:`Path.glob` for compatible behaviour." msgstr "" +"pathlib ではデフォルトで \"``**``\" パターンコンポーネントはシンボリックリンクをたどりません。" +"この動作は :func:`glob.glob` には同等のものがありませんが、互換性のために" +":meth:`Path.glob` に ``recurse_symlinks=True`` を渡すことができます。" #: ../../library/pathlib.rst:1834 msgid "" "Like all :class:`PurePath` and :class:`Path` objects, the values returned " "from :meth:`Path.glob` and :meth:`Path.rglob` don't include trailing slashes." msgstr "" +"すべての :class:`PurePath` および :class:`Path` オブジェクトと同様に、" +":meth:`Path.glob` と :meth:`Path.rglob` から返される値には末尾スラッシュは含まれません。" #: ../../library/pathlib.rst:1837 msgid "" @@ -2725,10 +2935,13 @@ msgid "" "results of ``glob.glob(root_dir=path)`` never include an empty string that " "would correspond to *path*." msgstr "" +"pathlib の ``path.glob()`` と ``path.rglob()`` から返される値は、例えば \"``**``\" で glob するときなどに" +"*path* 自体を含む場合があります。一方、``glob.glob(root_dir=path)`` の結果には *path* に対応する" +"空文字列は絶対に含まれません。" #: ../../library/pathlib.rst:1847 msgid "Comparison to the :mod:`os` and :mod:`os.path` modules" -msgstr ":mod:`os` と :mod:`os.path` モジュールの比較" +msgstr ":mod:`os` と :mod:`os.path` モジュールとの比較" #: ../../library/pathlib.rst:1849 msgid "" @@ -2738,6 +2951,11 @@ msgid "" "level ``str`` and ``bytes`` objects, which is a more *procedural* approach. " "Some users consider the object-oriented style to be more readable." msgstr "" +"pathlib は :class:`PurePath` と :class:`Path` オブジェクトを使用してパス操作を実装しており、" +"*オブジェクト指向* であると言われています。一方、:mod:`os` と :mod:`os.path` モジュールは" +"低レベルの ``str`` や ``bytes`` オブジェクトで動作する関数を提供しており、" +"より *手続き型* のアプローチです。一部のユーザーはオブジェクト指向スタイルの方が" +"読みやすいと考えています。" #: ../../library/pathlib.rst:1855 msgid "" @@ -2745,6 +2963,9 @@ msgid "" "ref:`paths relative to directory descriptors `. These features " "aren't available in pathlib." msgstr "" +":mod:`os` と :mod:`os.path` の多くの関数は ``bytes`` パスや" +":ref:`ディレクトリディスクリプタ相対パス ` をサポートしています。" +"これらの機能は pathlib では利用できません。" #: ../../library/pathlib.rst:1859 msgid "" @@ -2752,6 +2973,9 @@ msgid "" "`os.path` modules, are written in C and are very speedy. pathlib is written " "in pure Python and is often slower, but rarely slow enough to matter." msgstr "" +"Python の ``str`` や ``bytes`` 型、および :mod:`os` や :mod:`os.path` モジュールの一部は" +"C で書かれており、非常に高速です。pathlib は純粋な Python で書かれており、" +"しばしば遅くなりますが、問題になるほど遅いことはあまりありません。" #: ../../library/pathlib.rst:1863 msgid "" @@ -2761,11 +2985,16 @@ msgid "" "are involved, :meth:`Path.absolute` preserves these segments for greater " "safety." msgstr "" +"pathlib のパス正規化は :mod:`os.path` よりも少し主張があり、一貫性があります。" +"例えば、:func:`os.path.abspath` はパスから \"``..``\" セグメントを削除しますが、" +"シンボリックリンクが関わっている場合に意味が変わる可能性があります。" +":meth:`Path.absolute` はより高い安全性のためにこれらのセグメントを保持します。" #: ../../library/pathlib.rst:1868 msgid "" "pathlib's path normalization may render it unsuitable for some applications:" msgstr "" +"pathlib のパス正規化により、一部のアプリケーションには不適切になる場合があります:" #: ../../library/pathlib.rst:1870 msgid "" @@ -2790,6 +3019,7 @@ msgid "" "As a consequence of these differences, pathlib is not a drop-in replacement " "for :mod:`os.path`." msgstr "" +"これらの違いの結果として、pathlib は :mod:`os.path` のドロップイン置換ではありません。" #: ../../library/pathlib.rst:1886 msgid "Corresponding tools" @@ -3070,6 +3300,10 @@ msgid "" "is a lexical operation that raises :exc:`ValueError` when its inputs' " "anchors differ (e.g. if one path is absolute and the other relative.)" msgstr "" +":func:`os.path.relpath` は :func:`~os.path.abspath` を呼び出してパスを絶対パスにし、" +"\"``..``\" 部分を削除します。一方、:meth:`PurePath.relative_to` は入力のアンカーが異なる場合" +"(例えば一方が絶対パスでもう一方が相対パスの場合) に :exc:`ValueError` を発生させる" +"字句操作です。" #: ../../library/pathlib.rst:1933 msgid "" @@ -3077,6 +3311,8 @@ msgid "" "can't be resolved, whereas :meth:`Path.expanduser` raises :exc:" "`RuntimeError`." msgstr "" +":func:`os.path.expanduser` はホームディレクトリが解決できない場合にパスを変更せずに返しますが、" +":meth:`Path.expanduser` は :exc:`RuntimeError` を発生させます。" #: ../../library/pathlib.rst:1936 msgid "" @@ -3084,6 +3320,9 @@ msgid "" "symlinks, which may change the meaning of the path, whereas :meth:`Path." "absolute` leaves any \"``..``\" components in the path." msgstr "" +":func:`os.path.abspath` はシンボリックリンクを解決せずに \"``..``\" コンポーネントを削除し、" +"パスの意味を変える可能性があります。一方、:meth:`Path.absolute` はパス内の" +"\"``..``\" コンポーネントをそのまま残します。" #: ../../library/pathlib.rst:1939 msgid "" @@ -3091,6 +3330,9 @@ msgid "" "*dirnames* and *filenames*, whereas :meth:`Path.walk` categorizes all " "symlinks into *filenames* when *follow_symlinks* is false (the default.)" msgstr "" +":func:`os.walk` はパスを *dirnames* と *filenames* に分類する際に常にシンボリックリンクをたどります。" +"一方、:meth:`Path.walk` は *follow_symlinks* が偽 (デフォルト) の場合、すべてのシンボリックリンクを" +"*filenames* に分類します。" #: ../../library/pathlib.rst:1945 msgid "Protocols" @@ -3100,6 +3342,7 @@ msgstr "プロトコル" msgid "" "The :mod:`pathlib.types` module provides types for static type checking." msgstr "" +":mod:`pathlib.types` モジュールは静的型チェック用の型を提供します。" #: ../../library/pathlib.rst:1958 msgid "" @@ -3107,18 +3350,24 @@ msgid "" "info>` attribute. Implementations may return cached results from their " "methods." msgstr "" +":attr:`Path.info ` 属性を記述する :class:`typing.Protocol` です。" +"実装はメソッドからキャッシュされた結果を返す場合があります。" #: ../../library/pathlib.rst:1964 msgid "" "Return ``True`` if the path is an existing file or directory, or any other " "kind of file; return ``False`` if the path doesn't exist." msgstr "" +"パスが既存のファイル、ディレクトリ、またはその他の種類のファイルである場合は ``True`` を返します。" +"パスが存在しない場合は ``False`` を返します。" #: ../../library/pathlib.rst:1967 msgid "" "If *follow_symlinks* is ``False``, return ``True`` for symlinks without " "checking if their targets exist." msgstr "" +"*follow_symlinks* が ``False`` の場合、ターゲットが存在するかどうかをチェックせずに、" +"シンボリックリンクに対して ``True`` を返します。" #: ../../library/pathlib.rst:1972 msgid "" @@ -3126,6 +3375,8 @@ msgid "" "directory; return ``False`` if the path is (or points to) any other kind of " "file, or if it doesn't exist." msgstr "" +"パスがディレクトリ、またはディレクトリを指すシンボリックリンクである場合は ``True`` を返します。" +"パスがその他の種類のファイルであるか、または存在しない場合は ``False`` を返します。" #: ../../library/pathlib.rst:1976 msgid "" @@ -3133,6 +3384,8 @@ msgid "" "directory (without following symlinks); return ``False`` if the path is any " "other kind of file, or if it doesn't exist." msgstr "" +"*follow_symlinks* が ``False`` の場合、パスがディレクトリである場合のみ「シンボリックリンクをたどらずに」" +" ``True`` を返します。パスがその他の種類のファイルであるか、または存在しない場合は ``False`` を返します。" #: ../../library/pathlib.rst:1982 msgid "" @@ -3140,6 +3393,8 @@ msgid "" "file; return ``False`` if the path is (or points to) a directory or other " "non-file, or if it doesn't exist." msgstr "" +"パスがファイル、またはファイルを指すシンボリックリンクである場合は ``True`` を返します。" +"パスがディレクトリ、その他のファイル以外であるか、または存在しない場合は ``False`` を返します。" #: ../../library/pathlib.rst:1986 msgid "" @@ -3147,6 +3402,8 @@ msgid "" "file (without following symlinks); return ``False`` if the path is a " "directory or other non-file, or if it doesn't exist." msgstr "" +"*follow_symlinks* が ``False`` の場合、パスがファイルである場合のみ「シンボリックリンクをたどらずに」" +" ``True`` を返します。パスがディレクトリ、その他のファイル以外であるか、または存在しない場合は ``False`` を返します。" #: ../../library/pathlib.rst:1992 msgid "" @@ -3154,6 +3411,8 @@ msgid "" "``False`` if the path is a directory or any kind of file, or if it doesn't " "exist." msgstr "" +"パスがシンボリックリンクである場合 (リンク先が破損していても) ``True`` を返します。" +"パスがディレクトリ、その他の種類のファイルであるか、または存在しない場合は ``False`` を返します。" #: ../../library/pathlib.rst:11 msgid "path" From 54cfd2ef7b58db3298586209d26efb183b517b8e Mon Sep 17 00:00:00 2001 From: Atsuo Ishimoto Date: Sun, 6 Jul 2025 22:25:01 +0900 Subject: [PATCH 10/19] translate library/types --- library/types.po | 49 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 13 deletions(-) diff --git a/library/types.po b/library/types.po index 65797f54c..7eaa1d17b 100644 --- a/library/types.po +++ b/library/types.po @@ -149,7 +149,7 @@ msgstr "``__prepare__`` 名前空間フックの導入" #: ../../library/types.rst:74 msgid "Resolve MRO entries dynamically as specified by :pep:`560`." -msgstr "" +msgstr ":pep:`560` で指定されたとおりに MRO エントリを動的に解決します。" #: ../../library/types.rst:76 msgid "" @@ -160,6 +160,7 @@ msgid "" "it doesn't have an :meth:`!__mro_entries__` method, then it is included in " "the return tuple unchanged." msgstr "" +"この関数は、 *bases* 内にある :class:`type` のインスタンスでないアイテムを探し、 :meth:`~object.__mro_entries__` メソッドを持つオブジェクトを、このメソッドを呼び出した結果をアンパックしたものに置き換えたタプルを返します。 *bases* のアイテムが :class:`type` のインスタンスである場合、または :meth:`!__mro_entries__` メソッドを持たない場合は、戻り値のタプルには変更されずに含まれます。" #: ../../library/types.rst:87 msgid "" @@ -168,6 +169,7 @@ msgid "" "(following the mechanisms laid out in :pep:`560`). This is useful for " "introspecting :ref:`Generics `." msgstr "" +"いずれかの基底クラスに対して :meth:`~object.__mro_entries__` メソッドが呼び出される前に、 *cls* の基底クラスとして元々与えられたオブジェクトのタプルを返します (:pep:`560` で定められた仕組みに従って)。これは :ref:`ジェネリクス ` の内省に有用です。" #: ../../library/types.rst:92 msgid "" @@ -176,6 +178,7 @@ msgid "" "``__orig_bases__`` attribute, :attr:`cls.__bases__ ` is " "returned." msgstr "" +"``__orig_bases__`` 属性を持つクラスの場合、この関数は ``cls.__orig_bases__`` の値を返します。 ``__orig_bases__`` 属性を持たないクラスの場合、 :attr:`cls.__bases__ ` が返されます。" #: ../../library/types.rst:97 msgid "Examples::" @@ -304,6 +307,7 @@ msgid "" "The type of :ref:`code objects ` such as returned by :func:" "`compile`." msgstr "" +":func:`compile` によって返されるような :ref:`コードオブジェクト ` の型です。" #: ../../library/types.rst:193 msgid "" @@ -321,12 +325,14 @@ msgid "" "required by the initializer. The audit event only occurs for direct " "instantiation of code objects, and is not raised for normal compilation." msgstr "" +"監査対象の引数は、イニシャライザの必要とする名前や位置と一致しない可能性があることに注意してください。この監査イベントは、コードオブジェクトの直接インスタンス化の場合にのみ発生し、通常のコンパイル時には発生しません。" #: ../../library/types.rst:201 msgid "" "The type for cell objects: such objects are used as containers for a " "function's :term:`closure variables `." msgstr "" +"セルオブジェクトの型です。このオブジェクトは、関数の :term:`クロージャ変数 ` のコンテナとして使用されます。" #: ../../library/types.rst:209 msgid "The type of methods of user-defined class instances." @@ -347,12 +353,14 @@ msgid "" "The type of methods of some built-in data types and base classes such as :" "meth:`object.__init__` or :meth:`object.__lt__`." msgstr "" +":meth:`object.__init__` や :meth:`object.__lt__` のような、一部の組み込みデータ型や基底クラスのメソッドの型です。" #: ../../library/types.rst:230 msgid "" "The type of *bound* methods of some built-in data types and base classes. " "For example it is the type of :code:`object().__str__`." msgstr "" +"一部の組み込みデータ型や基底クラスの *バインドされた* メソッドの型です。例えば、 :code:`object().__str__` の型です。" #: ../../library/types.rst:238 msgid "The type of :data:`NotImplemented`." @@ -362,12 +370,14 @@ msgstr ":data:`NotImplemented` の型です。" msgid "" "The type of methods of some built-in data types such as :meth:`str.join`." msgstr "" +":meth:`str.join` のような、一部の組み込みデータ型のメソッドの型です。" #: ../../library/types.rst:252 msgid "" "The type of *unbound* class methods of some built-in data types such as " "``dict.__dict__['fromkeys']``." msgstr "" +"``dict.__dict__['fromkeys']`` のような、一部の組み込みデータ型の *アンバインドされた* クラスメソッドの型です。" #: ../../library/types.rst:260 msgid "" @@ -379,17 +389,18 @@ msgstr "" #: ../../library/types.rst:265 msgid ":ref:`Documentation on module objects `" -msgstr "" +msgstr ":ref:`モジュールオブジェクトのドキュメント `" #: ../../library/types.rst:266 msgid "" "Provides details on the special attributes that can be found on instances " "of :class:`!ModuleType`." msgstr "" +":class:`!ModuleType` のインスタンスにおいて見つかる特殊属性の詳細を提供しています。" #: ../../library/types.rst:269 msgid ":func:`importlib.util.module_from_spec`" -msgstr "" +msgstr ":func:`importlib.util.module_from_spec`" #: ../../library/types.rst:270 msgid "" @@ -399,6 +410,7 @@ msgid "" "ModuleType` instances which ensures the various attributes are set " "appropriately." msgstr "" +":class:`!ModuleType` コンストラクタを使用して作成したモジュールは、多くの特殊属性が未設定であるか、デフォルト値に設定された状態で作成されます。 :func:`!module_from_spec` は、さまざまな属性が適切に設定されることを保証する、より堅牢な :class:`!ModuleType` インスタンスの作成方法を提供しています。" #: ../../library/types.rst:278 msgid "The type of :data:`Ellipsis`." @@ -409,6 +421,7 @@ msgid "" "The type of :ref:`parameterized generics ` such as " "``list[int]``." msgstr "" +"``list[int]`` のような :ref:`パラメータ化されたジェネリクス ` の型です。" #: ../../library/types.rst:287 msgid "" @@ -416,6 +429,7 @@ msgid "" "``tuple`` or ``dict``. ``t_args`` should be a :class:`tuple` (possibly of " "length 1) of types which parameterize ``t_origin``::" msgstr "" +"``t_origin`` は、 ``list`` 、 ``tuple`` 、 ``dict`` のような、パラメータ化されていないジェネリッククラスであるべきです。 ``t_args`` は、 ``t_origin`` をパラメータ化する型の (長さは 1 であるかもしれない) :class:`tuple` であるべきです。::" #: ../../library/types.rst:291 msgid "" @@ -429,15 +443,15 @@ msgstr "" #: ../../library/types.rst:300 msgid "This type can now be subclassed." -msgstr "" +msgstr "この型は今はサブクラス化できます。" #: ../../library/types.rst:305 msgid ":ref:`Generic Alias Types`" -msgstr "" +msgstr ":ref:`ジェネリックエイリアス型 `" #: ../../library/types.rst:306 msgid "In-depth documentation on instances of :class:`!types.GenericAlias`" -msgstr "" +msgstr ":class:`!types.GenericAlias` のインスタンスに関する詳細なドキュメント" #: ../../library/types.rst:308 msgid ":pep:`585` - Type Hinting Generics In Standard Collections" @@ -446,15 +460,15 @@ msgstr "" #: ../../library/types.rst:309 msgid "Introducing the :class:`!types.GenericAlias` class" -msgstr "" +msgstr ":class:`!types.GenericAlias` クラスの紹介" #: ../../library/types.rst:313 msgid "The type of :ref:`union type expressions`." -msgstr "" +msgstr ":ref:`合集型表現 ` の型です。" #: ../../library/types.rst:319 msgid "This is now an alias for :class:`typing.Union`." -msgstr "" +msgstr "現在これは :class:`typing.Union` のエイリアスです。" #: ../../library/types.rst:323 msgid "" @@ -470,12 +484,14 @@ msgid "" "available attributes and operations, and guidance on creating tracebacks " "dynamically." msgstr "" +"利用可能な属性と操作、およびトレースバックの動的作成のガイダンスについては、 :ref:`言語リファレンス ` を参照してください。" #: ../../library/types.rst:332 msgid "" "The type of :ref:`frame objects ` such as found in :attr:`tb." "tb_frame ` if ``tb`` is a traceback object." msgstr "" +"``tb`` がトレースバックオブジェクトの場合、 :attr:`tb.tb_frame ` にあるような :ref:`フレームオブジェクト ` の型です。" #: ../../library/types.rst:338 msgid "" @@ -485,6 +501,7 @@ msgid "" "purpose as the :class:`property` type, but for classes defined in extension " "modules." msgstr "" +":attr:`FrameType.f_locals ` や ``array.array.typecode`` のような、拡張モジュールにおいて ``PyGetSetDef`` で定義されたオブジェクトの型です。この型はオブジェクトの属性の記述子として使用され、 :class:`property` 型と同じ目的を持ちますが、こちらは拡張モジュールで定義されたクラスのためのものです。" #: ../../library/types.rst:347 msgid "" @@ -506,6 +523,7 @@ msgid "" "will be added as an attribute on the class. This allows the slot to appear " "in the class's :attr:`~type.__dict__`." msgstr "" +"さらに、 :attr:`~object.__slots__` 属性でクラスが定義された場合、各スロットに対して :class:`!MemberDescriptorType` のインスタンスがクラスの属性として追加されます。これによりスロットがクラスの :attr:`~type.__dict__` に現れるようになります。" #: ../../library/types.rst:358 msgid "" @@ -530,6 +548,7 @@ msgid "" "Updated to support the new union (``|``) operator from :pep:`584`, which " "simply delegates to the underlying mapping." msgstr "" +":pep:`584` からの新しい合集演算子 (``|``) をサポートするように更新されました。これは単に元になったマッピングに委託します。" #: ../../library/types.rst:376 msgid "" @@ -590,15 +609,15 @@ msgstr "元になったマッピングの values に対する新しいビュー #: ../../library/types.rst:418 msgid "Return a reverse iterator over the keys of the underlying mapping." -msgstr "" +msgstr "元になったマッピングのキーを逆順で繰り返すイテレータを返します。" #: ../../library/types.rst:424 msgid "Return a hash of the underlying mapping." -msgstr "" +msgstr "元になったマッピングのハッシュを返します。" #: ../../library/types.rst:430 msgid "The type of :ref:`capsule objects `." -msgstr "" +msgstr ":ref:`カプセルオブジェクト ` の型です。" #: ../../library/types.rst:436 msgid "Additional Utility Classes and Functions" @@ -617,6 +636,7 @@ msgid "" "Unlike :class:`object`, with :class:`!SimpleNamespace` you can add and " "remove attributes." msgstr "" +":class:`object` とは異なり、 :class:`!SimpleNamespace` では属性を追加したり削除したりできます。" #: ../../library/types.rst:446 msgid "" @@ -628,6 +648,7 @@ msgid "" "key-value pairs from that argument (either a mapping object or an :term:" "`iterable` object producing key-value pairs). All such keys must be strings." msgstr "" +":py:class:`SimpleNamespace` オブジェクトは :class:`dict` と同じ方法で初期化できます。つまり、キーワード引数、単一の位置引数、または両方で初期化できます。キーワード引数で初期化した場合、それらは直接元になる名前空間に追加されます。また、位置引数で初期化した場合、元になる名前空間はその引数からのキーバリューペアで更新されます (マッピングオブジェクトまたはキーバリューペアを生成する :term:`イテラブル ` オブジェクト)。このようなキーはすべて文字列でなければなりません。" #: ../../library/types.rst:457 msgid "The type is roughly equivalent to the following code::" @@ -665,16 +686,18 @@ msgstr "" msgid "" ":class:`!SimpleNamespace` objects are supported by :func:`copy.replace`." msgstr "" +":class:`!SimpleNamespace` オブジェクトは :func:`copy.replace` でサポートされます。" #: ../../library/types.rst:481 msgid "" "Attribute order in the repr changed from alphabetical to insertion (like " "``dict``)." msgstr "" +"repr の属性の順序がアルファベット順から挿入順 (``dict`` のように) に変更されました。" #: ../../library/types.rst:485 msgid "Added support for an optional positional argument." -msgstr "" +msgstr "オプションの位置引数のサポートが追加されました。" #: ../../library/types.rst:490 msgid "Route attribute access on a class to __getattr__." From 6ffd591cc68ec43cfeb581d9b72c21b6ae9241cb Mon Sep 17 00:00:00 2001 From: Atsuo Ishimoto Date: Sun, 6 Jul 2025 22:36:33 +0900 Subject: [PATCH 11/19] =?UTF-8?q?=E5=90=88=E9=9B=86=E5=9E=8B->=E3=83=A6?= =?UTF-8?q?=E3=83=8B=E3=82=AA=E3=83=B3=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/types.po | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/types.po b/library/types.po index 7eaa1d17b..91a88a9c3 100644 --- a/library/types.po +++ b/library/types.po @@ -464,7 +464,7 @@ msgstr ":class:`!types.GenericAlias` クラスの紹介" #: ../../library/types.rst:313 msgid "The type of :ref:`union type expressions`." -msgstr ":ref:`合集型表現 ` の型です。" +msgstr ":ref:`ユニオン型式 ` の型です。" #: ../../library/types.rst:319 msgid "This is now an alias for :class:`typing.Union`." From 843f7f11d2e56c419d4fcedb28bdffbb97d1aba7 Mon Sep 17 00:00:00 2001 From: Atsuo Ishimoto Date: Sun, 6 Jul 2025 22:56:29 +0900 Subject: [PATCH 12/19] update library/asyncio.po --- library/asyncio.po | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/asyncio.po b/library/asyncio.po index ecd06954f..52a98899d 100644 --- a/library/asyncio.po +++ b/library/asyncio.po @@ -91,7 +91,7 @@ msgid "" ":ref:`run Python coroutines ` concurrently and have full control " "over their execution;" msgstr "" -"並行に :ref:`Python コルーチンを実行 ` し、その実行を完全に制御する" +"並行に :ref:`Python コルーチンを実行 ` し、その実行を完全に制御する;" #: ../../library/asyncio.rst:37 msgid "perform :ref:`network IO and IPC `;" @@ -159,7 +159,7 @@ msgstr "asyncio REPL" msgid "" "You can experiment with an ``asyncio`` concurrent context in the :term:" "`REPL`:" -msgstr "":term:`REPL` で ``asyncio`` の並行コンテキストを試すことができます:" +msgstr ":term:`REPL` で ``asyncio`` の並行コンテキストを試すことができます:" #: ../../library/asyncio.rst:67 msgid "" From 4e8c85b4f5a7faa60c268d3b2c26856026035243 Mon Sep 17 00:00:00 2001 From: Atsuo Ishimoto Date: Mon, 7 Jul 2025 05:58:00 +0900 Subject: [PATCH 13/19] restore lib/dataclasses.po --- library/dataclasses.po | 1205 +--------------------------------------- 1 file changed, 21 insertions(+), 1184 deletions(-) diff --git a/library/dataclasses.po b/library/dataclasses.po index 4edde4318..d5dc38ae7 100644 --- a/library/dataclasses.po +++ b/library/dataclasses.po @@ -68,17 +68,6 @@ msgid "" " def total_cost(self) -> float:\n" " return self.unit_price * self.quantity_on_hand" msgstr "" -"from dataclasses import dataclass\n" -"\n" -"@dataclass\n" -"class InventoryItem:\n" -" \"\"\"Class for keeping track of an item in inventory.\"\"\"\n" -" name: str\n" -" unit_price: float\n" -" quantity_on_hand: int = 0\n" -"\n" -" def total_cost(self) -> float:\n" -" return self.unit_price * self.quantity_on_hand" #: ../../library/dataclasses.rst:34 msgid "will add, among other things, a :meth:`!__init__` that looks like::" @@ -92,11 +81,6 @@ msgid "" " self.unit_price = unit_price\n" " self.quantity_on_hand = quantity_on_hand" msgstr "" -"def __init__(self, name: str, unit_price: float, quantity_on_hand: int = " -"0):\n" -" self.name = name\n" -" self.unit_price = unit_price\n" -" self.quantity_on_hand = quantity_on_hand" #: ../../library/dataclasses.rst:41 msgid "" @@ -159,9 +143,6 @@ msgid "" "acts as if it has the default values documented in this signature. That is, " "these three uses of ``@dataclass`` are equivalent::" msgstr "" -"``@dataclass`` をパラメータなしの単純なデコレータとして使用した場合、" -"このシグネチャに記載されているデフォルト値を持つかのように動作します。" -"つまり、これら3つの ``@dataclass`` の使用法は等価です::" #: ../../library/dataclasses.rst:74 msgid "" @@ -179,36 +160,21 @@ msgid "" "class C:\n" " ..." msgstr "" -"@dataclass\n" -"class C:\n" -" ...\n" -"\n" -"@dataclass()\n" -"class C:\n" -" ...\n" -"\n" -"@dataclass(init=True, repr=True, eq=True, order=False, unsafe_hash=False, " -"frozen=False,\n" -" match_args=True, kw_only=False, slots=False, weakref_slot=False)\n" -"class C:\n" -" ..." #: ../../library/dataclasses.rst:87 msgid "The parameters to ``@dataclass`` are:" -msgstr "``@dataclass`` のパラメータは以下の通りです:" +msgstr "" #: ../../library/dataclasses.rst:89 msgid "" "*init*: If true (the default), a :meth:`~object.__init__` method will be " "generated." msgstr "" -"*init*: True(デフォルト)の場合、:meth:`~object.__init__` メソッドが生成されます。" #: ../../library/dataclasses.rst:92 msgid "" "If the class already defines :meth:`!__init__`, this parameter is ignored." msgstr "" -"クラスが既に :meth:`!__init__` を定義している場合、このパラメータは無視されます。" #: ../../library/dataclasses.rst:95 msgid "" @@ -219,17 +185,11 @@ msgid "" "example: ``InventoryItem(name='widget', unit_price=3.0, " "quantity_on_hand=10)``." msgstr "" -"*repr*: True(デフォルト)の場合、:meth:`~object.__repr__` メソッドが生成されます。" -"生成される repr 文字列には、クラス名と各フィールドの名前および repr が、" -"クラス内で定義された順序で含まれます。repr から除外するようにマークされた" -"フィールドは含まれません。例: ``InventoryItem(name='widget', unit_price=3.0, " -"quantity_on_hand=10)``。" #: ../../library/dataclasses.rst:102 msgid "" "If the class already defines :meth:`!__repr__`, this parameter is ignored." msgstr "" -"クラスが既に :meth:`!__repr__` を定義している場合、このパラメータは無視されます。" #: ../../library/dataclasses.rst:105 msgid "" @@ -238,15 +198,11 @@ msgid "" "fields, in order. Both instances in the comparison must be of the identical " "type." msgstr "" -"*eq*: True(デフォルト)の場合、:meth:`~object.__eq__` メソッドが生成されます。" -"このメソッドは、クラスがそのフィールドの順序でタプルであるかのように比較します。" -"比較する両方のインスタンスは同一の型である必要があります。" #: ../../library/dataclasses.rst:110 msgid "" "If the class already defines :meth:`!__eq__`, this parameter is ignored." msgstr "" -"クラスが既に :meth:`!__eq__` を定義している場合、このパラメータは無視されます。" #: ../../library/dataclasses.rst:113 msgid "" @@ -256,19 +212,12 @@ msgid "" "fields, in order. Both instances in the comparison must be of the identical " "type. If *order* is true and *eq* is false, a :exc:`ValueError` is raised." msgstr "" -"*order*: True(デフォルトは ``False``)の場合、:meth:`~object.__lt__`、" -":meth:`~object.__le__`、:meth:`~object.__gt__`、:meth:`~object.__ge__` " -"メソッドが生成されます。これらは、クラスがそのフィールドのタプルであるかのように" -"順序で比較します。比較する両方のインスタンスは同一の型である必要があります。" -"*order* が True で *eq* が False の場合、:exc:`ValueError` が発生します。" #: ../../library/dataclasses.rst:120 msgid "" "If the class already defines any of :meth:`!__lt__`, :meth:`!__le__`, :meth:" "`!__gt__`, or :meth:`!__ge__`, then :exc:`TypeError` is raised." msgstr "" -"クラスが既に :meth:`!__lt__`、:meth:`!__le__`、:meth:`!__gt__`、:meth:`!__ge__` の" -"いずれかを定義している場合、:exc:`TypeError` が発生します。" #: ../../library/dataclasses.rst:124 msgid "" @@ -277,10 +226,6 @@ msgid "" "generate a :meth:`~object.__hash__` method according to how *eq* and " "*frozen* are set. The default value is ``False``." msgstr "" -"*unsafe_hash*: True の場合、安全でない可能性があっても ``dataclasses`` に " -":meth:`~object.__hash__` メソッドの作成を強制します。そうでない場合は、*eq* " -"と *frozen* の設定に応じて :meth:`~object.__hash__` メソッドを生成します。" -"デフォルト値は ``False`` です。" #: ../../library/dataclasses.rst:130 msgid "" @@ -291,11 +236,6 @@ msgid "" "and behavior of :meth:`!__eq__`, and the values of the *eq* and *frozen* " "flags in the ``@dataclass`` decorator." msgstr "" -":meth:`!__hash__` は組み込み関数 :meth:`hash` や、辞書や集合などのハッシュ" -"コレクションにオブジェクトが追加される際に使われます。:meth:`!__hash__` を" -"持つということは、そのクラスのインスタンスが不変であることを意味します。" -"可変性は複雑な特性で、プログラマーの意図、:meth:`!__eq__` の存在と動作、" -"``@dataclass`` デコレータの *eq* と *frozen* フラグの値に依存します。" #: ../../library/dataclasses.rst:137 msgid "" @@ -305,11 +245,6 @@ msgid "" "attribute ``__hash__ = None`` has a specific meaning to Python, as described " "in the :meth:`!__hash__` documentation." msgstr "" -"デフォルトでは、``@dataclass`` は安全でない限り :meth:`~object.__hash__` " -"メソッドを暗黙的に追加しません。また、既存の明示的に定義された :meth:`!__hash__` " -"メソッドを追加または変更することもありません。クラス属性 ``__hash__ = None`` の" -"設定は、:meth:`!__hash__` のドキュメントで説明されているように、Python にとって" -"特別な意味を持ちます。" #: ../../library/dataclasses.rst:143 msgid "" @@ -320,11 +255,6 @@ msgid "" "logically immutable but can still be mutated. This is a specialized use case " "and should be considered carefully." msgstr "" -":meth:`!__hash__` が明示的に定義されていない、または ``None`` に設定されている場合、" -"``@dataclass`` は :meth:`!__hash__` メソッドを暗黙的に追加する *場合があります* 。" -"推奨されませんが、``unsafe_hash=True`` を使って ``@dataclass`` に :meth:`!__hash__` " -"メソッドの作成を強制できます。これは、クラスが論理的には不変であるにもかかわらず、" -"変更可能である場合にあたります。これは特殊な使用例であり、慎重に検討する必要があります。" #: ../../library/dataclasses.rst:150 msgid "" @@ -333,9 +263,6 @@ msgid "" "in your dataclass and set ``unsafe_hash=True``; this will result in a :exc:" "`TypeError`." msgstr "" -":meth:`!__hash__` メソッドの暗黙的な作成を支配するルールは以下の通りです。" -"データクラスで明示的な :meth:`!__hash__` メソッドを持ち、かつ ``unsafe_hash=True`` を" -"設定することはできません。これを行うと :exc:`TypeError` が発生します。" #: ../../library/dataclasses.rst:155 msgid "" @@ -347,12 +274,6 @@ msgid "" "used (if the superclass is :class:`object`, this means it will fall back to " "id-based hashing)." msgstr "" -"*eq* と *frozen* がともに True の場合、デフォルトで ``@dataclass`` が :meth:`!__hash__` " -"メソッドを生成します。*eq* が True で *frozen* が False の場合、:meth:`!__hash__` は " -"``None`` に設定され、ハッシュ化不可能としてマークされます(実際に可変であるため)。" -"*eq* が False の場合、:meth:`!__hash__` は変更されず、スーパークラスの :meth:`!__hash__` " -"メソッドが使用されます(スーパークラスが :class:`object` の場合、ID ベースの" -"ハッシュ化にフォールバックします)。" #: ../../library/dataclasses.rst:163 msgid "" @@ -361,10 +282,6 @@ msgid "" "`~object.__setattr__` or :meth:`~object.__delattr__` is defined in the " "class, then :exc:`TypeError` is raised. See the discussion below." msgstr "" -"*frozen*: True(デフォルトは ``False``)の場合、フィールドへの代入で例外が発生します。" -"これは読み取り専用の凍結されたインスタンスをエミュレートします。クラスで :meth:`~object.__setattr__` " -"または :meth:`~object.__delattr__` が定義されている場合、:exc:`TypeError` が発生します。" -"以下の説明を参照してください。" #: ../../library/dataclasses.rst:168 msgid "" @@ -375,11 +292,6 @@ msgid "" "__match_args__` is already defined in the class, then :attr:`!" "__match_args__` will not be generated." msgstr "" -"*match_args*: True(デフォルトは ``True``)の場合、生成された :meth:`~object.__init__` " -"メソッドの非キーワード専用パラメータのリストから :attr:`~object.__match_args__` タプルが" -"作成されます(:meth:`!__init__` が生成されない場合でも、上記を参照)。" -"False の場合、または :attr:`!__match_args__` がクラスで既に定義されている場合、" -":attr:`!__match_args__` は生成されません。" #: ../../library/dataclasses.rst:177 msgid "" @@ -390,17 +302,10 @@ msgid "" "is called. See the :term:`parameter` glossary entry for details. Also see " "the :const:`KW_ONLY` section." msgstr "" -"*kw_only*: True(デフォルト値は ``False``)の場合、すべてのフィールドが" -"キーワード専用としてマークされます。フィールドがキーワード専用としてマークされた場合、" -"唯一の効果は、:meth:`!__init__` が呼び出された際にキーワード専用フィールドから生成された " -":meth:`~object.__init__` パラメータをキーワードで指定する必要があることです。" -"詳細は :term:`parameter` 用語集のエントリを参照してください。" -"また、:const:`KW_ONLY` の節も参照してください。" #: ../../library/dataclasses.rst:185 msgid "Keyword-only fields are not included in :attr:`!__match_args__`." msgstr "" -"キーワード専用フィールドは :attr:`!__match_args__` に含まれません。" #: ../../library/dataclasses.rst:189 msgid "" @@ -409,9 +314,6 @@ msgid "" "original one. If :attr:`!__slots__` is already defined in the class, then :" "exc:`TypeError` is raised." msgstr "" -"*slots*: True(デフォルトは ``False``)の場合、:attr:`~object.__slots__` 属性が" -"生成され、元のクラスの代わりに新しいクラスが返されます。クラスで :attr:`!__slots__` が" -"既に定義されている場合、:exc:`TypeError` が発生します。" #: ../../library/dataclasses.rst:195 msgid "" @@ -420,10 +322,6 @@ msgid "" "``__init_subclass__`` with no parameters or use default values as a " "workaround. See :gh:`91126` for full details." msgstr "" -"``slots=True`` を使用している際にベースクラスの :meth:`~object.__init_subclass__` に" -"パラメータを渡すと :exc:`TypeError` が発生します。回避策として、パラメータなしで " -"``__init_subclass__`` を使用するか、デフォルト値を使用してください。" -"詳細は :gh:`91126` を参照してください。" #: ../../library/dataclasses.rst:203 msgid "" @@ -434,13 +332,6 @@ msgid "" "`fields` instead. To be able to determine inherited slots, base class :attr:" "`!__slots__` may be any iterable, but *not* an iterator." msgstr "" -"フィールド名がベースクラスの :attr:`!__slots__` に既に含まれている場合、" -":ref:`それらをオーバーライドする ` ことを防ぐため、" -"生成される :attr:`!__slots__` には含まれません。したがって、データクラスの" -"フィールド名を取得するために :attr:`!__slots__` を使用しないでください。" -"代わりに :func:`fields` を使用してください。継承されたスロットを判定できる" -"ようにするため、ベースクラスの :attr:`!__slots__` は任意のイテラブルですが、" -"イテレータではないものにできます。" #: ../../library/dataclasses.rst:213 msgid "" @@ -449,17 +340,13 @@ msgid "" "`. It is an error to specify ``weakref_slot=True`` without also " "specifying ``slots=True``." msgstr "" -"*weakref_slot*: True(デフォルトは ``False``)の場合、\"__weakref__\" という" -"名前のスロットを追加します。これは、インスタンスを :func:`weakref 対応 " -"` にするために必要です。``slots=True`` も指定せずに " -"``weakref_slot=True`` を指定するとエラーになります。" #: ../../library/dataclasses.rst:221 msgid "" "``field``\\s may optionally specify a default value, using normal Python " "syntax::" msgstr "" -"``フィールド`` には、通常の Python の文法でデフォルト値を指定できます::" +"``フィールド`` には、通常の Python の文法でデフォルト値を指定できます。" #: ../../library/dataclasses.rst:224 msgid "" @@ -468,23 +355,16 @@ msgid "" " a: int # 'a' has no default value\n" " b: int = 0 # assign a default value for 'b'" msgstr "" -"@dataclass\n" -"class C:\n" -" a: int # 'a' has no default value\n" -" b: int = 0 # assign a default value for 'b'" #: ../../library/dataclasses.rst:229 msgid "" "In this example, both :attr:`!a` and :attr:`!b` will be included in the " "added :meth:`~object.__init__` method, which will be defined as::" msgstr "" -"この例では、:attr:`!a` と :attr:`!b` の両方が追加される :meth:`~object.__init__` " -"メソッドに含まれ、以下のように定義されます::" #: ../../library/dataclasses.rst:232 msgid "def __init__(self, a: int, b: int = 0):" msgstr "" -"def __init__(self, a: int, b: int = 0):" #: ../../library/dataclasses.rst:234 msgid "" @@ -504,10 +384,6 @@ msgid "" "replace the default field value with a call to the provided :func:`!field` " "function. For example::" msgstr "" -"一般的で簡単な使用例では、他の機能は必要ありません。しかし、フィールドごとの" -"追加情報を必要とするデータクラスの機能がいくつかあります。この追加情報のニーズを" -"満たすために、デフォルトのフィールド値を提供された :func:`!field` 関数の呼び出しで" -"置き換えることができます。例えば::" #: ../../library/dataclasses.rst:246 msgid "" @@ -518,12 +394,6 @@ msgid "" "c = C()\n" "c.mylist += [1, 2, 3]" msgstr "" -"@dataclass\n" -"class C:\n" -" mylist: list[int] = field(default_factory=list)\n" -"\n" -"c = C()\n" -"c.mylist += [1, 2, 3]" #: ../../library/dataclasses.rst:253 msgid "" @@ -532,15 +402,10 @@ msgid "" "because ``None`` is a valid value for some parameters with a distinct " "meaning. No code should directly use the :const:`MISSING` value." msgstr "" -"上記のように、:const:`MISSING` 値はユーザーが一部のパラメータを提供したかどうかを" -"検出するために使用される番兵オブジェクトです。この番兵が使用されるのは、" -"``None`` が一部のパラメータにとって異なる意味を持つ有効な値であるためです。" -"コードは :const:`MISSING` 値を直接使用すべきではありません。" #: ../../library/dataclasses.rst:258 msgid "The parameters to :func:`!field` are:" msgstr "" -":func:`!field` のパラメータは以下の通りです:" #: ../../library/dataclasses.rst:260 msgid "" @@ -548,8 +413,6 @@ msgid "" "is needed because the :func:`!field` call itself replaces the normal " "position of the default value." msgstr "" -"*default*: 指定した場合、これがこのフィールドのデフォルト値になります。これが必要なのは、" -":func:`!field` の呼び出し自体がデフォルト値の通常の位置を置き換えるためです。" #: ../../library/dataclasses.rst:264 msgid "" @@ -559,26 +422,18 @@ msgid "" "discussed below. It is an error to specify both *default* and " "*default_factory*." msgstr "" -"*default_factory*: 指定した場合、このフィールドにデフォルト値が必要な際に呼び出される" -"引数なしの呼び出し可能オブジェクトである必要があります。他の用途の中でも、これは" -"後述するように可変なデフォルト値を持つフィールドを指定するために使用できます。" -"*default* と *default_factory* の両方を指定するとエラーになります。" #: ../../library/dataclasses.rst:270 msgid "" "*init*: If true (the default), this field is included as a parameter to the " "generated :meth:`~object.__init__` method." msgstr "" -"*init*: True(デフォルト)の場合、このフィールドは生成された :meth:`~object.__init__` " -"メソッドのパラメータとして含まれます。" #: ../../library/dataclasses.rst:273 msgid "" "*repr*: If true (the default), this field is included in the string returned " "by the generated :meth:`~object.__repr__` method." msgstr "" -"*repr*: True(デフォルト)の場合、このフィールドは生成された :meth:`~object.__repr__` " -"メソッドが返す文字列に含まれます。" #: ../../library/dataclasses.rst:276 msgid "" @@ -590,12 +445,6 @@ msgid "" "comparisons. Setting this value to anything other than ``None`` is " "discouraged." msgstr "" -"*hash*: これは bool または ``None`` です。True の場合、このフィールドは生成された " -":meth:`~object.__hash__` メソッドに含まれます。False の場合、このフィールドは" -"生成された :meth:`~object.__hash__` から除外されます。``None``(デフォルト)の場合、" -"*compare* の値を使用します。フィールドが比較に使用される場合はハッシュにも含まれる" -"べきであるため、通常はこれが期待される動作です。この値を ``None`` 以外に" -"設定することは推奨されません。" #: ../../library/dataclasses.rst:284 msgid "" @@ -616,9 +465,6 @@ msgid "" "equality and comparison methods (:meth:`~object.__eq__`, :meth:`~object." "__gt__`, et al.)." msgstr "" -"*compare*: True(デフォルト)の場合、このフィールドは生成された等価性" -"および比較メソッド(:meth:`~object.__eq__`、:meth:`~object.__gt__` など)" -"に含まれます。" #: ../../library/dataclasses.rst:294 msgid "" @@ -629,29 +475,20 @@ msgid "" "mechanism. Multiple third-parties can each have their own key, to use as a " "namespace in the metadata." msgstr "" -"*metadata*: これはマッピングまたは ``None`` です。``None`` は空の辞書として" -"扱われます。この値は :func:`~types.MappingProxyType` でラップされて読み取り" -"専用にされ、:class:`Field` オブジェクトで公開されます。データクラスでは" -"まったく使用されず、サードパーティ拡張メカニズムとして提供されています。" -"複数のサードパーティがそれぞれ独自のキーを持ち、メタデータ内の名前空間と" -"して使用できます。" #: ../../library/dataclasses.rst:302 msgid "" "*kw_only*: If true, this field will be marked as keyword-only. This is used " "when the generated :meth:`~object.__init__` method's parameters are computed." msgstr "" -"*kw_only*: True の場合、このフィールドはキーワード専用としてマークされます。" -"これは、生成された :meth:`~object.__init__` メソッドのパラメータが" -"計算される際に使用されます。" #: ../../library/dataclasses.rst:306 msgid "Keyword-only fields are also not included in :attr:`!__match_args__`." -msgstr "キーワード専用フィールドも :attr:`!__match_args__` には含まれません。" +msgstr "" #: ../../library/dataclasses.rst:310 msgid "*doc*: optional docstring for this field." -msgstr "*doc*: このフィールドのオプションのドキュメント文字列。" +msgstr "" #: ../../library/dataclasses.rst:314 msgid "" @@ -663,12 +500,6 @@ msgid "" "default values for the fields, just as if the default value itself were " "specified. For example, after::" msgstr "" -"フィールドのデフォルト値が :func:`!field` の呼び出しによって指定された場合、" -"このフィールドのクラス属性は指定された *default* 値で置き換えられます。" -"*default* が提供されない場合、クラス属性は削除されます。意図としては、" -":func:`@dataclass ` デコレータが実行された後、すべてのクラス属性が" -"フィールドのデフォルト値を含むようになり、まるでデフォルト値自体が指定された" -"かのようになることです。例えば、以下の後で::" #: ../../library/dataclasses.rst:323 msgid "" @@ -679,12 +510,6 @@ msgid "" " z: int = field(repr=False, default=10)\n" " t: int = 20" msgstr "" -"@dataclass\n" -"class C:\n" -" x: int\n" -" y: int = field(repr=False)\n" -" z: int = field(repr=False, default=10)\n" -" t: int = 20" #: ../../library/dataclasses.rst:330 msgid "" @@ -692,8 +517,6 @@ msgid "" "C.t` will be ``20``, and the class attributes :attr:`!C.x` and :attr:`!C.y` " "will not be set." msgstr "" -"クラス属性 :attr:`!C.z` は ``10`` 、クラス属性 :attr:`!C.t` は ``20`` に" -"なり、クラス属性 :attr:`!C.x` と :attr:`!C.y` は設定されません。" #: ../../library/dataclasses.rst:336 msgid "" @@ -702,18 +525,14 @@ msgid "" "method (see below). Users should never instantiate a :class:`!Field` object " "directly. Its documented attributes are:" msgstr "" -":class:`!Field` オブジェクトは定義された各フィールドを記述します。これらの" -"オブジェクトは内部的に作成され、:func:`fields` モジュールレベルメソッド" -"(以下を参照)によって返されます。ユーザーは :class:`!Field` オブジェクトを" -"直接インスタンス化してはいけません。文書化された属性は以下の通りです:" #: ../../library/dataclasses.rst:341 msgid ":attr:`!name`: The name of the field." -msgstr ":attr:`!name`: フィールドの名前。" +msgstr "" #: ../../library/dataclasses.rst:342 msgid ":attr:`!type`: The type of the field." -msgstr ":attr:`!type`: フィールドの型。" +msgstr "" #: ../../library/dataclasses.rst:343 msgid "" @@ -721,9 +540,6 @@ msgid "" "attr:`!hash`, :attr:`!compare`, :attr:`!metadata`, and :attr:`!kw_only` have " "the identical meaning and values as they do in the :func:`field` function." msgstr "" -":attr:`!default`、:attr:`!default_factory`、:attr:`!init`、:attr:`!repr`、" -":attr:`!hash`、:attr:`!compare`、:attr:`!metadata`、:attr:`!kw_only` は、" -":func:`field` 関数と同じ意味と値を持ちます。" #: ../../library/dataclasses.rst:347 msgid "" @@ -741,11 +557,6 @@ msgid "" "`fields` function nor used in any way except adding them as parameters to :" "meth:`~object.__init__` and an optional :meth:`__post_init__`." msgstr "" -"``InitVar[T]`` 型アノテーションは :ref:`初期化専用 ` " -"変数を記述します。:class:`!InitVar` でアノテーションされたフィールドは" -"疑似フィールドと見なされ、:func:`fields` 関数によって返されることも、" -":meth:`~object.__init__` とオプションの :meth:`__post_init__` のパラメータとして" -"追加される以外は一切使用されることもありません。" #: ../../library/dataclasses.rst:361 msgid "" @@ -768,14 +579,10 @@ msgid "" "``name: value`` pairs. dataclasses, dicts, lists, and tuples are recursed " "into. Other objects are copied with :func:`copy.deepcopy`." msgstr "" -"データクラス *obj* を辞書に変換します(ファクトリ関数 *dict_factory* を使用)。" -"各データクラスは、``name: value`` ペアとしてそのフィールドの辞書に変換されます。" -"データクラス、辞書、リスト、タプルは再帰的に処理されます。その他のオブジェクトは" -":func:`copy.deepcopy` でコピーされます。" #: ../../library/dataclasses.rst:374 msgid "Example of using :func:`!asdict` on nested dataclasses::" -msgstr "ネストしたデータクラスでの :func:`!asdict` の使用例::" +msgstr "" #: ../../library/dataclasses.rst:376 msgid "" @@ -794,34 +601,19 @@ msgid "" "c = C([Point(0, 0), Point(10, 4)])\n" "assert asdict(c) == {'mylist': [{'x': 0, 'y': 0}, {'x': 10, 'y': 4}]}" msgstr "" -"@dataclass\n" -"class Point:\n" -" x: int\n" -" y: int\n" -"\n" -"@dataclass\n" -"class C:\n" -" mylist: list[Point]\n" -"\n" -"p = Point(10, 20)\n" -"assert asdict(p) == {'x': 10, 'y': 20}\n" -"\n" -"c = C([Point(0, 0), Point(10, 4)])\n" -"assert asdict(c) == {'mylist': [{'x': 0, 'y': 0}, {'x': 10, 'y': 4}]}" #: ../../library/dataclasses.rst:391 ../../library/dataclasses.rst:411 msgid "To create a shallow copy, the following workaround may be used::" -msgstr "浅いコピーを作成するには、以下の回避策を使用できます::" +msgstr "" #: ../../library/dataclasses.rst:393 msgid "{field.name: getattr(obj, field.name) for field in fields(obj)}" -msgstr "{field.name: getattr(obj, field.name) for field in fields(obj)}" +msgstr "" #: ../../library/dataclasses.rst:395 msgid "" ":func:`!asdict` raises :exc:`TypeError` if *obj* is not a dataclass instance." msgstr "" -":func:`!asdict` は *obj* がデータクラスのインスタンスでない場合、:exc:`TypeError` を発生させます。" #: ../../library/dataclasses.rst:400 msgid "" @@ -830,10 +622,6 @@ msgid "" "values. dataclasses, dicts, lists, and tuples are recursed into. Other " "objects are copied with :func:`copy.deepcopy`." msgstr "" -"データクラス *obj* をタプルに変換します(ファクトリ関数 *tuple_factory* を使用)。" -"各データクラスはそのフィールド値のタプルに変換されます。データクラス、辞書、" -"リスト、タプルは再帰的に処理されます。その他のオブジェクトは :func:`copy.deepcopy` " -"でコピーされます。" #: ../../library/dataclasses.rst:406 msgid "Continuing from the previous example::" @@ -844,19 +632,16 @@ msgid "" "assert astuple(p) == (10, 20)\n" "assert astuple(c) == ([(0, 0), (10, 4)],)" msgstr "" -"assert astuple(p) == (10, 20)\n" -"assert astuple(c) == ([(0, 0), (10, 4)],)" #: ../../library/dataclasses.rst:413 msgid "tuple(getattr(obj, field.name) for field in dataclasses.fields(obj))" -msgstr "tuple(getattr(obj, field.name) for field in dataclasses.fields(obj))" +msgstr "" #: ../../library/dataclasses.rst:415 msgid "" ":func:`!astuple` raises :exc:`TypeError` if *obj* is not a dataclass " "instance." msgstr "" -":func:`!astuple` は *obj* がデータクラスのインスタンスでない場合、:exc:`TypeError` を発生させます。" #: ../../library/dataclasses.rst:420 msgid "" @@ -869,21 +654,12 @@ msgid "" "*slots*, and *weakref_slot* have the same meaning as they do in :func:" "`@dataclass `." msgstr "" -"*cls_name* という名前、*fields* で定義されたフィールド、*bases* で指定された" -"ベースクラス、*namespace* で指定された名前空間で初期化された新しいデータ" -"クラスを作成します。*fields* は、各要素が ``name``、``(name, type)``、または" -"``(name, type, Field)`` のいずれかであるイテラブルです。``name`` だけが指定された" -"場合、``type`` には :data:`typing.Any` が使用されます。*init*、*repr*、*eq*、" -"*order*、*unsafe_hash*、*frozen*、*match_args*、*kw_only*、*slots*、*weakref_slot* の" -"値は、:func:`@dataclass ` と同じ意味を持ちます。" #: ../../library/dataclasses.rst:430 msgid "" "If *module* is defined, the :attr:`!__module__` attribute of the dataclass " "is set to that value. By default, it is set to the module name of the caller." msgstr "" -"*module* が定義されている場合、データクラスの :attr:`!__module__` 属性はその値に" -"設定されます。デフォルトでは、呼び出し元のモジュール名に設定されます。" #: ../../library/dataclasses.rst:434 msgid "" @@ -892,10 +668,6 @@ msgid "" "keyword arguments as :func:`@dataclass `. By default, the :func:" "`@dataclass ` function is used." msgstr "" -"*decorator* パラメータは、データクラスの作成に使用される呼び出し可能オブジェクトです。" -"第一引数としてクラスオブジェクトを、:func:`@dataclass ` と同じ" -"キーワード引数を取る必要があります。デフォルトでは、:func:`@dataclass ` " -"関数が使用されます。" #: ../../library/dataclasses.rst:439 msgid "" @@ -904,10 +676,6 @@ msgid "" "`@dataclass ` function to convert that class to a dataclass. " "This function is provided as a convenience. For example::" msgstr "" -"この関数は厳密には必要ありません。:attr:`!__annotations__` で新しいクラスを" -"作成するどの Python メカニズムでも、そのクラスをデータクラスに変換するために" -":func:`@dataclass ` 関数を適用できるからです。この関数は便利さのために" -"提供されています。例えば::" #: ../../library/dataclasses.rst:445 msgid "" @@ -917,11 +685,6 @@ msgid "" " ('z', int, field(default=5))],\n" " namespace={'add_one': lambda self: self.x + 1})" msgstr "" -"C = make_dataclass('C',\n" -" [('x', int),\n" -" 'y',\n" -" ('z', int, field(default=5))],\n" -" namespace={'add_one': lambda self: self.x + 1})" #: ../../library/dataclasses.rst:451 msgid "Is equivalent to::" @@ -938,18 +701,10 @@ msgid "" " def add_one(self):\n" " return self.x + 1" msgstr "" -"@dataclass\n" -"class C:\n" -" x: int\n" -" y: 'typing.Any'\n" -" z: int = 5\n" -"\n" -" def add_one(self):\n" -" return self.x + 1" #: ../../library/dataclasses.rst:462 msgid "Added the *decorator* parameter." -msgstr "*decorator* パラメータが追加されました。" +msgstr "" #: ../../library/dataclasses.rst:467 msgid "" @@ -958,9 +713,6 @@ msgid "" "keys in *changes* are not field names of the given dataclass, raises :exc:" "`TypeError`." msgstr "" -"*obj* と同じ型の新しいオブジェクトを作成し、*changes* の値でフィールドを置き換えます。" -"*obj* がデータクラスでない場合、:exc:`TypeError` を発生させます。*changes* のキーが" -"指定されたデータクラスのフィールド名でない場合、:exc:`TypeError` を発生させます。" #: ../../library/dataclasses.rst:472 msgid "" @@ -968,9 +720,6 @@ msgid "" "method of the dataclass. This ensures that :meth:`__post_init__`, if " "present, is also called." msgstr "" -"新しく返されるオブジェクトは、データクラスの :meth:`~object.__init__` メソッドを" -"呼び出すことで作成されます。これにより、:meth:`__post_init__` が存在する場合は" -"それも呼び出されることが保証されます。" #: ../../library/dataclasses.rst:476 msgid "" @@ -978,17 +727,12 @@ msgid "" "on the call to :func:`!replace` so that they can be passed to :meth:`!" "__init__` and :meth:`__post_init__`." msgstr "" -"デフォルト値を持たない初期化専用変数が存在する場合、:func:`!replace` の呼び出しで" -"指定する必要があります。これにより、:meth:`!__init__` と :meth:`__post_init__` に" -"渡すことができます。" #: ../../library/dataclasses.rst:480 msgid "" "It is an error for *changes* to contain any fields that are defined as " "having ``init=False``. A :exc:`ValueError` will be raised in this case." msgstr "" -"*changes* に ``init=False`` として定義されたフィールドが含まれるのは" -"エラーです。この場合、:exc:`ValueError` が発生します。" #: ../../library/dataclasses.rst:484 msgid "" @@ -1000,27 +744,18 @@ msgid "" "perhaps a custom :func:`!replace` (or similarly named) method which handles " "instance copying." msgstr "" -":func:`!replace` の呼び出し中に ``init=False`` フィールドがどのように動作するか" -"について注意してください。これらはソースオブジェクトからコピーされるのではなく、" -"初期化される場合は :meth:`__post_init__` で初期化されます。``init=False`` フィールドは" -"まれに慎重に使用されることが想定されています。使用する場合は、代替クラスコンストラクタ、" -"またはインスタンスコピーを処理するカスタム :func:`!replace`(または同様の名前の)" -"メソッドを用意することが賢明かもしれません。" #: ../../library/dataclasses.rst:493 msgid "" "Dataclass instances are also supported by generic function :func:`copy." "replace`." msgstr "" -"データクラスのインスタンスは汎用関数 :func:`copy.replace` もサポートしています。" #: ../../library/dataclasses.rst:497 msgid "" "Return ``True`` if its parameter is a dataclass (including subclasses of a " "dataclass) or an instance of one, otherwise return ``False``." msgstr "" -"パラメータがデータクラス(データクラスのサブクラスを含む)またはそのインスタンス" -"である場合は ``True`` を返し、そうでない場合は ``False`` を返します。" #: ../../library/dataclasses.rst:500 msgid "" @@ -1037,12 +772,11 @@ msgid "" "def is_dataclass_instance(obj):\n" " return is_dataclass(obj) and not isinstance(obj, type)" msgstr "" -"def is_dataclass_instance(obj):\n" -" return is_dataclass(obj) and not isinstance(obj, type)" #: ../../library/dataclasses.rst:509 msgid "A sentinel value signifying a missing default or default_factory." -msgstr "デフォルト値や default_factory が存在しないことを示す番兵値。" +msgstr "" +"デフォルト値やdefault_factoryが設定されてない場合の番兵の値を設定します。" #: ../../library/dataclasses.rst:513 msgid "" @@ -1054,13 +788,6 @@ msgid "" "meth:`~object.__init__` parameters that must be specified as keywords when " "the class is instantiated." msgstr "" -"型アノテーションとして使用される番兵値です。:const:`!KW_ONLY` の型を持つ疑似フィールドの " -"後にあるすべてのフィールドは、キーワード専用フィールドとしてマークされます。" -":const:`!KW_ONLY` 型の疑似フィールドは、その他の点では完全に無視されることに " -"注意してください。これには、そのようなフィールドの名前も含まれます。慣例により、 " -":const:`!KW_ONLY` フィールドには ``_`` という名前が使用されます。キーワード専用 " -"フィールドは、クラスがインスタンス化される際にキーワードとして指定する必要がある " -":meth:`~object.__init__` パラメータを表します。" #: ../../library/dataclasses.rst:522 msgid "" @@ -1079,22 +806,12 @@ msgid "" "\n" "p = Point(0, y=1.5, z=2.0)" msgstr "" -"@dataclass\n" -"class Point:\n" -" x: float\n" -" _: KW_ONLY\n" -" y: float\n" -" z: float\n" -"\n" -"p = Point(0, y=1.5, z=2.0)" #: ../../library/dataclasses.rst:533 msgid "" "In a single dataclass, it is an error to specify more than one field whose " "type is :const:`!KW_ONLY`." msgstr "" -"単一のデータクラスで、型が :const:`!KW_ONLY` である複数のフィールドを" -"指定することはエラーになります。" #: ../../library/dataclasses.rst:540 msgid "" @@ -1119,18 +836,15 @@ msgid "" "__init__` method is generated, then :meth:`!__post_init__` will not " "automatically be called." msgstr "" -"クラスで定義された場合、生成された :meth:`~object.__init__` によって、" -"通常は :meth:`!self.__post_init__` として呼び出されます。しかし、" -"``InitVar`` フィールドが定義されている場合、それらはクラスで定義された順序で " -":meth:`!__post_init__` にも渡されます。:meth:`!__init__` メソッドが生成されない場合、" -":meth:`!__post_init__` は自動的に呼び出されません。" #: ../../library/dataclasses.rst:558 msgid "" "Among other uses, this allows for initializing field values that depend on " "one or more other fields. For example::" msgstr "" -"他の用途に加えて、1つ以上の他のフィールドに依存するフィールド値を初期化できます。例えば::" +"他の機能と組み合わせることで、他の 1 つ以上のフィールドに依存しているフィール" +"ドが初期化できます。\n" +"例えば次のようにできます::" #: ../../library/dataclasses.rst:561 msgid "" @@ -1143,14 +857,6 @@ msgid "" " def __post_init__(self):\n" " self.c = self.a + self.b" msgstr "" -"@dataclass\n" -"class C:\n" -" a: float\n" -" b: float\n" -" c: float = field(init=False)\n" -"\n" -" def __post_init__(self):\n" -" self.c = self.a + self.b" #: ../../library/dataclasses.rst:570 msgid "" @@ -1159,10 +865,6 @@ msgid "" "class has an :meth:`!__init__` method that has to be called, it is common to " "call this method in a :meth:`__post_init__` method::" msgstr "" -":func:`@dataclass ` によって生成された :meth:`~object.__init__` メソッドは、" -"ベースクラスの :meth:`!__init__` メソッドを呼び出しません。ベースクラスに呼び出す" -"必要がある :meth:`!__init__` メソッドがある場合、このメソッドを :meth:`__post_init__` " -"メソッドで呼び出すのが一般的です::" #: ../../library/dataclasses.rst:575 msgid "" @@ -1178,17 +880,6 @@ msgid "" " def __post_init__(self):\n" " super().__init__(self.side, self.side)" msgstr "" -"class Rectangle:\n" -" def __init__(self, height, width):\n" -" self.height = height\n" -" self.width = width\n" -"\n" -"@dataclass\n" -"class Square(Rectangle):\n" -" side: float\n" -"\n" -" def __post_init__(self):\n" -" super().__init__(self.side, self.side)" #: ../../library/dataclasses.rst:587 msgid "" @@ -1196,9 +887,6 @@ msgid "" "methods don't need to be called, since the derived dataclass will take care " "of initializing all fields of any base class that is a dataclass itself." msgstr "" -"ただし、一般的にはデータクラス生成の :meth:`!__init__` メソッドを呼び出す" -"必要はないことに注意してください。派生データクラスが、それ自体がデータクラス" -"であるベースクラスのすべてのフィールドの初期化を処理するためです。" #: ../../library/dataclasses.rst:591 msgid "" @@ -1225,12 +913,6 @@ msgid "" "Such ``ClassVar`` pseudo-fields are not returned by the module-level :func:" "`fields` function." msgstr "" -":func:`@dataclass ` が実際にフィールドの型を検査する数少ない場所の一つは、" -"フィールドが :pep:`526` で定義されたクラス変数かどうかを判定することです。" -"これは、フィールドの型が :data:`typing.ClassVar` かどうかをチェックすることで行われます。" -"フィールドが ``ClassVar`` の場合、フィールドとしての考慮から除外され、" -"データクラスのメカニズムによって無視されます。そのような ``ClassVar`` 疑似フィールドは、" -"モジュールレベルの :func:`fields` 関数によって返されません。" #: ../../library/dataclasses.rst:611 msgid "Init-only variables" @@ -1248,14 +930,6 @@ msgid "" "optional :meth:`__post_init__` method. They are not otherwise used by " "dataclasses." msgstr "" -":func:`@dataclass ` が型アノテーションを検査するもう一つの場所は、" -"フィールドが初期化専用変数かどうかを判定することです。これは、フィールドの型が" -":class:`InitVar` 型かどうかを確認することで行われます。フィールドが :class:`InitVar` の場合、" -"初期化専用フィールドと呼ばれる疑似フィールドと見なされます。真のフィールドではないため、" -"モジュールレベルの :func:`fields` 関数によって返されません。初期化専用フィールドは" -"生成された :meth:`~object.__init__` メソッドにパラメータとして追加され、" -"オプションの :meth:`__post_init__` メソッドに渡されます。それ以外では" -"データクラスによって使用されません。" #: ../../library/dataclasses.rst:623 msgid "" @@ -1279,25 +953,12 @@ msgid "" "\n" "c = C(10, database=my_database)" msgstr "" -"@dataclass\n" -"class C:\n" -" i: int\n" -" j: int | None = None\n" -" database: InitVar[DatabaseType | None] = None\n" -"\n" -" def __post_init__(self, database):\n" -" if self.j is None and database is not None:\n" -" self.j = database.lookup('j')\n" -"\n" -"c = C(10, database=my_database)" #: ../../library/dataclasses.rst:638 msgid "" "In this case, :func:`fields` will return :class:`Field` objects for :attr:`!" "i` and :attr:`!j`, but not for :attr:`!database`." msgstr "" -"この場合、:func:`fields` は :attr:`!i` と :attr:`!j` に対して :class:`Field` オブジェクトを" -"返しますが、:attr:`!database` に対しては返しません。" #: ../../library/dataclasses.rst:644 msgid "Frozen instances" @@ -1311,10 +972,6 @@ msgid "" "__setattr__` and :meth:`~object.__delattr__` methods to the class. These " "methods will raise a :exc:`FrozenInstanceError` when invoked." msgstr "" -"真に不変なPythonオブジェクトを作成することは不可能です。しかし、:func:`@dataclass ` " -"デコレータに ``frozen=True`` を渡すことで、不変性をエミュレートできます。その場合、" -"データクラスはクラスに :meth:`~object.__setattr__` と :meth:`~object.__delattr__` メソッドを" -"追加します。これらのメソッドは呼び出されると :exc:`FrozenInstanceError` を発生させます。" #: ../../library/dataclasses.rst:652 msgid "" @@ -1322,9 +979,6 @@ msgid "" "`~object.__init__` cannot use simple assignment to initialize fields, and " "must use :meth:`!object.__setattr__`." msgstr "" -"``frozen=True`` を使用する際には、わずかなパフォーマンスペナルティがあります。" -":meth:`~object.__init__` はフィールドを初期化するために単純な代入を使用できず、" -":meth:`!object.__setattr__` を使用する必要があります。" #: ../../library/dataclasses.rst:661 msgid "Inheritance" @@ -1341,13 +995,6 @@ msgid "" "calculated ordered mapping of fields. Because the fields are in insertion " "order, derived classes override base classes. An example::" msgstr "" -":func:`@dataclass ` デコレータによってデータクラスが作成される際、" -"すべてのクラスのベースクラスを逆 MRO 順(つまり :class:`object` から開始)で" -"調べ、見つけたデータクラスごとに、そのベースクラスのフィールドをフィールドの" -"順序付きマッピングに追加します。すべてのベースクラスのフィールドが追加された後、" -"独自のフィールドを順序付きマッピングに追加します。生成されたすべてのメソッドは、" -"この組み合わされた、計算された順序付きフィールドマッピングを使用します。" -"フィールドは挿入順であるため、派生クラスはベースクラスをオーバーライドします。例::" #: ../../library/dataclasses.rst:673 msgid "" @@ -1361,15 +1008,6 @@ msgid "" " z: int = 10\n" " x: int = 15" msgstr "" -"@dataclass\n" -"class Base:\n" -" x: Any = 15.0\n" -" y: int = 0\n" -"\n" -"@dataclass\n" -"class C(Base):\n" -" z: int = 10\n" -" x: int = 15" #: ../../library/dataclasses.rst:683 msgid "" @@ -1377,23 +1015,20 @@ msgid "" "The final type of :attr:`!x` is :class:`int`, as specified in class :class:`!" "C`." msgstr "" -"フィールドの最終的なリストは、順番に :attr:`!x`、:attr:`!y`、:attr:`!z` です。" -":attr:`!x` の最終的な型は、クラス :class:`!C` で指定されたとおり :class:`int` です。" #: ../../library/dataclasses.rst:686 msgid "" "The generated :meth:`~object.__init__` method for :class:`!C` will look " "like::" msgstr "" -":class:`!C` の生成された :meth:`~object.__init__` メソッドは次のようになります::" #: ../../library/dataclasses.rst:688 msgid "def __init__(self, x: int = 15, y: int = 0, z: int = 10):" -msgstr "def __init__(self, x: int = 15, y: int = 0, z: int = 10):" +msgstr "" #: ../../library/dataclasses.rst:691 msgid "Re-ordering of keyword-only parameters in :meth:`!__init__`" -msgstr ":meth:`!__init__` におけるキーワード専用パラメータの並び替え" +msgstr "" #: ../../library/dataclasses.rst:693 msgid "" @@ -1413,9 +1048,6 @@ msgid "" "keyword-only fields, and :attr:`!Base.x` and :attr:`!D.z` are regular " "fields::" msgstr "" -"この例では、:attr:`!Base.y`、:attr:`!Base.w`、:attr:`!D.t` は" -"キーワード専用フィールドで、:attr:`!Base.x` と :attr:`!D.z` は" -"通常のフィールドです::" #: ../../library/dataclasses.rst:702 msgid "" @@ -1431,29 +1063,16 @@ msgid "" " z: int = 10\n" " t: int = field(kw_only=True, default=0)" msgstr "" -"@dataclass\n" -"class Base:\n" -" x: Any = 15.0\n" -" _: KW_ONLY\n" -" y: int = 0\n" -" w: int = 1\n" -"\n" -"@dataclass\n" -"class D(Base):\n" -" z: int = 10\n" -" t: int = field(kw_only=True, default=0)" #: ../../library/dataclasses.rst:714 msgid "The generated :meth:`!__init__` method for :class:`!D` will look like::" -msgstr ":class:`!D` の生成された :meth:`!__init__` メソッドは次のようになります::" +msgstr "" #: ../../library/dataclasses.rst:716 msgid "" "def __init__(self, x: Any = 15.0, z: int = 10, *, y: int = 0, w: int = 1, t: " "int = 0):" msgstr "" -"def __init__(self, x: Any = 15.0, z: int = 10, *, y: int = 0, w: int = 1, t: " -"int = 0):" #: ../../library/dataclasses.rst:718 msgid "" @@ -1470,8 +1089,6 @@ msgid "" "The relative ordering of keyword-only parameters is maintained in the re-" "ordered :meth:`!__init__` parameter list." msgstr "" -"キーワード専用パラメータの相対的な順序は、並び替えられた :meth:`!__init__` " -"パラメータリストで維持されます。" #: ../../library/dataclasses.rst:727 msgid "Default factory functions" @@ -1483,13 +1100,10 @@ msgid "" "arguments when a default value for the field is needed. For example, to " "create a new instance of a list, use::" msgstr "" -":func:`field` が *default_factory* を指定した場合、フィールドのデフォルト値が必要な際に" -"引数なしで呼び出されます。例えば、リストの新しいインスタンスを作成するには、" -"以下を使用します::" #: ../../library/dataclasses.rst:733 msgid "mylist: list = field(default_factory=list)" -msgstr "mylist: list = field(default_factory=list)" +msgstr "" #: ../../library/dataclasses.rst:735 msgid "" @@ -1499,10 +1113,6 @@ msgid "" "function. This happens because there is no other way to give the field an " "initial value." msgstr "" -"フィールドが :meth:`~object.__init__` から除外され(``init=False`` を使用)、" -"かつそのフィールドが *default_factory* も指定している場合、デフォルトファクトリ" -"関数は生成された :meth:`!__init__` 関数から必ず呼び出されます。" -"これは、フィールドに初期値を与える他の方法がないためです。" #: ../../library/dataclasses.rst:742 msgid "Mutable default values" @@ -1530,24 +1140,12 @@ msgid "" "assert o1.x == [1, 2]\n" "assert o1.x is o2.x" msgstr "" -"class C:\n" -" x = []\n" -" def add(self, element):\n" -" self.x.append(element)\n" -"\n" -"o1 = C()\n" -"o2 = C()\n" -"o1.add(1)\n" -"o2.add(2)\n" -"assert o1.x == [1, 2]\n" -"assert o1.x is o2.x" #: ../../library/dataclasses.rst:759 msgid "" "Note that the two instances of class :class:`!C` share the same class " "variable :attr:`!x`, as expected." msgstr "" -"予想どおり、クラス :class:`!C` の 2 つのインスタンスは同じクラス変数 :attr:`!x` を共有していることに注意してください。" #: ../../library/dataclasses.rst:762 msgid "Using dataclasses, *if* this code was valid::" @@ -1561,11 +1159,6 @@ msgid "" " def add(self, element):\n" " self.x.append(element)" msgstr "" -"@dataclass\n" -"class D:\n" -" x: list = [] # This code raises ValueError\n" -" def add(self, element):\n" -" self.x.append(element)" #: ../../library/dataclasses.rst:770 msgid "it would generate code similar to::" @@ -1595,14 +1188,6 @@ msgid "" "The assumption is that if a value is unhashable, it is mutable. This is a " "partial solution, but it does protect against many common errors." msgstr "" -"これは、クラス :class:`!C` を使用した元の例と同じ問題を持っています。つまり、" -"クラスインスタンスを作成する際に :attr:`!x` の値を指定しないクラス :class:`!D` の" -"2つのインスタンスは、同じ :attr:`!x` のコピーを共有することになります。" -"データクラスは通常の Python クラス作成を使用するだけなので、この動作も共有します。" -"データクラスがこの状態を検出する一般的な方法はありません。代わりに、" -":func:`@dataclass ` デコレータは、ハッシュ化不可能なデフォルトパラメータを" -"検出した場合に :exc:`ValueError` を発生させます。値がハッシュ化不可能であれば可変である" -"という仮定です。これは部分的な解決策ですが、多くの一般的なエラーから保護します。" #: ../../library/dataclasses.rst:792 msgid "" @@ -1627,21 +1212,16 @@ msgid "" "`dict`, or :class:`set`, unhashable objects are now not allowed as default " "values. Unhashability is used to approximate mutability." msgstr "" -":class:`list`、:class:`dict`、:class:`set` 型のオブジェクトを探して禁止する代わりに、" -"現在はハッシュ化不可能なオブジェクトはデフォルト値として許可されていません。" -"ハッシュ化不可能性は可変性を近似するために使用されます。" #: ../../library/dataclasses.rst:808 msgid "Descriptor-typed fields" -msgstr "ディスクリプタ型フィールド" +msgstr "" #: ../../library/dataclasses.rst:810 msgid "" "Fields that are assigned :ref:`descriptor objects ` as their " "default value have the following special behaviors:" msgstr "" -"デフォルト値として :ref:`ディスクリプタオブジェクト ` が割り当てられたフィールドは、" -"以下の特別な動作をします:" #: ../../library/dataclasses.rst:813 msgid "" @@ -1649,9 +1229,6 @@ msgid "" "method is passed to the descriptor's :meth:`~object.__set__` method rather " "than overwriting the descriptor object." msgstr "" -"データクラスの :meth:`~object.__init__` メソッドに渡されたフィールドの値は、" -"ディスクリプタオブジェクトを上書きするのではなく、ディスクリプタの :meth:`~object.__set__` " -"メソッドに渡されます。" #: ../../library/dataclasses.rst:817 msgid "" @@ -1659,9 +1236,6 @@ msgid "" "`~object.__get__` or :meth:`!__set__` method is called rather than returning " "or overwriting the descriptor object." msgstr "" -"同様に、フィールドの取得または設定時には、ディスクリプタオブジェクトを返したり" -"上書きしたりするのではなく、ディスクリプタの :meth:`~object.__get__` または :meth:`!__set__` " -"メソッドが呼び出されます。" #: ../../library/dataclasses.rst:821 msgid "" @@ -1672,11 +1246,6 @@ msgid "" "default. On the other hand, if the descriptor raises :exc:`AttributeError` " "in this situation, no default value will be provided for the field." msgstr "" -"フィールドがデフォルト値を含んでいるかどうかを判定するため、:func:`@dataclass ` は" -"クラスアクセス形式を使用してディスクリプタの :meth:`!__get__` メソッドを呼び出します: " -"``descriptor.__get__(obj=None, type=cls)``。この場合にディスクリプタが値を返す場合、" -"それがフィールドのデフォルト値として使用されます。一方、この状況でディスクリプタが " -":exc:`AttributeError` を発生させる場合、フィールドにデフォルト値は提供されません。" #: ../../library/dataclasses.rst:831 msgid "" @@ -1706,735 +1275,6 @@ msgid "" "i.quantity_on_hand = 2.5 # calls __set__ with 2.5\n" "print(i.quantity_on_hand) # 2" msgstr "" -"class IntConversionDescriptor:\n" -" def __init__(self, *, default):\n" -" self._default = default\n" -"\n" -" def __set_name__(self, owner, name):\n" -" self._name = \"_\" + name\n" -"\n" -" def __get__(self, obj, type):\n" -" if obj is None:\n" -" return self._default\n" -"\n" -" return getattr(obj, self._name, self._default)\n" -"\n" -" def __set__(self, obj, value):\n" -" setattr(obj, self._name, int(value))\n" -"\n" -"@dataclass\n" -"class InventoryItem:\n" -" quantity_on_hand: IntConversionDescriptor = " -"IntConversionDescriptor(default=100)\n" -"\n" -"i = InventoryItem()\n" -"print(i.quantity_on_hand) # 100\n" -"i.quantity_on_hand = 2.5 # calls __set__ with 2.5\n" -"print(i.quantity_on_hand) # 2" - -#: ../../library/dataclasses.rst:856 -msgid "" -"Note that if a field is annotated with a descriptor type, but is not " -"assigned a descriptor object as its default value, the field will act like a " -"normal field." -msgstr "" -"フィールドがディスクリプタ型でアノテーションされているが、デフォルト値として" -"ディスクリプタオブジェクトが割り当てられていない場合、フィールドは通常のフィールドのように" -"動作します。" -msgid "" -"@dataclass\n" -"class Point:\n" -" x: float\n" -" _: KW_ONLY\n" -" y: float\n" -" z: float\n" -"\n" -"p = Point(0, y=1.5, z=2.0)" -msgstr "" -"@dataclass\n" -"class Point:\n" -" x: float\n" -" _: KW_ONLY\n" -" y: float\n" -" z: float\n" -"\n" -"p = Point(0, y=1.5, z=2.0)" - -#: ../../library/dataclasses.rst:533 -msgid "" -"In a single dataclass, it is an error to specify more than one field whose " -"type is :const:`!KW_ONLY`." -msgstr "" -"単一のデータクラスで、型が :const:`!KW_ONLY` である複数のフィールドを" -"指定することはエラーになります。" - -#: ../../library/dataclasses.rst:540 -msgid "" -"Raised when an implicitly defined :meth:`~object.__setattr__` or :meth:" -"`~object.__delattr__` is called on a dataclass which was defined with " -"``frozen=True``. It is a subclass of :exc:`AttributeError`." -msgstr "" -"``frozen=True`` 付きで定義されたデータクラスで、暗黙的に定義された :meth:" -"`~object.__setattr__` または :meth:`~object.__delattr__` が呼び出されたときに" -"送出されます。これは :exc:`AttributeError` のサブクラスです。" - -#: ../../library/dataclasses.rst:547 -msgid "Post-init processing" -msgstr "初期化後の処理" - -#: ../../library/dataclasses.rst:551 -msgid "" -"When defined on the class, it will be called by the generated :meth:`~object." -"__init__`, normally as :meth:`!self.__post_init__`. However, if any " -"``InitVar`` fields are defined, they will also be passed to :meth:`!" -"__post_init__` in the order they were defined in the class. If no :meth:`!" -"__init__` method is generated, then :meth:`!__post_init__` will not " -"automatically be called." -msgstr "" -"クラスで定義された場合、通常は :meth:`!self.__post_init__` として、生成された" -":meth:`~object.__init__` によって呼び出されます。しかし、``InitVar`` フィールドが" -"定義されている場合、それらもクラスで定義された順序で :meth:`!__post_init__` に" -"渡されます。:meth:`!__init__` メソッドが生成されない場合、:meth:`!__post_init__` は" -"自動的に呼び出されません。" - -#: ../../library/dataclasses.rst:558 -msgid "" -"Among other uses, this allows for initializing field values that depend on " -"one or more other fields. For example::" -msgstr "" -"他の機能と組み合わせることで、他の 1 つ以上のフィールドに依存しているフィール" -"ドが初期化できます。\n" -"例えば次のようにできます::" - -#: ../../library/dataclasses.rst:561 -msgid "" -"@dataclass\n" -"class C:\n" -" a: float\n" -" b: float\n" -" c: float = field(init=False)\n" -"\n" -" def __post_init__(self):\n" -" self.c = self.a + self.b" -msgstr "" -"@dataclass\n" -"class C:\n" -" a: float\n" -" b: float\n" -" c: float = field(init=False)\n" -"\n" -" def __post_init__(self):\n" -" self.c = self.a + self.b" - -#: ../../library/dataclasses.rst:570 -msgid "" -"The :meth:`~object.__init__` method generated by :func:`@dataclass " -"` does not call base class :meth:`!__init__` methods. If the base " -"class has an :meth:`!__init__` method that has to be called, it is common to " -"call this method in a :meth:`__post_init__` method::" -msgstr "" -":func:`@dataclass ` によって生成された :meth:`~object.__init__` メソッドは、" -"ベースクラスの :meth:`!__init__` メソッドを呼び出しません。ベースクラスに" -"呼び出す必要がある :meth:`!__init__` メソッドがある場合、:meth:`__post_init__` " -"メソッドでこのメソッドを呼び出すのが一般的です::" - -#: ../../library/dataclasses.rst:575 -msgid "" -"class Rectangle:\n" -" def __init__(self, height, width):\n" -" self.height = height\n" -" self.width = width\n" -"\n" -"@dataclass\n" -"class Square(Rectangle):\n" -" side: float\n" -"\n" -" def __post_init__(self):\n" -" super().__init__(self.side, self.side)" -msgstr "" -"class Rectangle:\n" -" def __init__(self, height, width):\n" -" self.height = height\n" -" self.width = width\n" -"\n" -"@dataclass\n" -"class Square(Rectangle):\n" -" side: float\n" -"\n" -" def __post_init__(self):\n" -" super().__init__(self.side, self.side)" - -#: ../../library/dataclasses.rst:587 -msgid "" -"Note, however, that in general the dataclass-generated :meth:`!__init__` " -"methods don't need to be called, since the derived dataclass will take care " -"of initializing all fields of any base class that is a dataclass itself." -msgstr "" -"しかし、一般的にデータクラス生成の :meth:`!__init__` メソッドを呼び出す必要は" -"ありません。派生データクラスが、データクラスであるベースクラスのすべての" -"フィールドの初期化を行うためです。" - -#: ../../library/dataclasses.rst:591 -msgid "" -"See the section below on init-only variables for ways to pass parameters to :" -"meth:`!__post_init__`. Also see the warning about how :func:`replace` " -"handles ``init=False`` fields." -msgstr "" -"下にある初期化限定変数についての節で、 :meth:`!__post_init__` にパラメータを" -"渡す方法を参照してください。\n" -":func:`replace` が ``init=False`` であるフィールドをどう取り扱うかについての" -"警告も参照してください。" - -#: ../../library/dataclasses.rst:598 -msgid "Class variables" -msgstr "クラス変数" - -#: ../../library/dataclasses.rst:600 -msgid "" -"One of the few places where :func:`@dataclass ` actually inspects " -"the type of a field is to determine if a field is a class variable as " -"defined in :pep:`526`. It does this by checking if the type of the field " -"is :data:`typing.ClassVar`. If a field is a ``ClassVar``, it is excluded " -"from consideration as a field and is ignored by the dataclass mechanisms. " -"Such ``ClassVar`` pseudo-fields are not returned by the module-level :func:" -"`fields` function." -msgstr "" -":func:`@dataclass ` が実際にフィールドの型を検査する数少ない" -"場所の一つは、:pep:`526` で定義されているように、フィールドがクラス変数かどうかを" -"判定するためです。これは、フィールドの型が :data:`typing.ClassVar` かどうかを" -"チェックすることで行われます。フィールドが ``ClassVar`` の場合、フィールドとしての" -"考慮から除外され、データクラスメカニズムによって無視されます。このような" -"``ClassVar`` 疑似フィールドは、モジュールレベルの :func:`fields` 関数によって" -"返されません。" - -#: ../../library/dataclasses.rst:611 -msgid "Init-only variables" -msgstr "初期化限定変数" - -#: ../../library/dataclasses.rst:613 -msgid "" -"Another place where :func:`@dataclass ` inspects a type " -"annotation is to determine if a field is an init-only variable. It does " -"this by seeing if the type of a field is of type :class:`InitVar`. If a " -"field is an :class:`InitVar`, it is considered a pseudo-field called an init-" -"only field. As it is not a true field, it is not returned by the module-" -"level :func:`fields` function. Init-only fields are added as parameters to " -"the generated :meth:`~object.__init__` method, and are passed to the " -"optional :meth:`__post_init__` method. They are not otherwise used by " -"dataclasses." -msgstr "" -":func:`@dataclass ` が型アノテーションを検査するもう一つの場所は、" -"フィールドが初期化専用変数かどうかを判定するためです。これは、フィールドの型が" -":class:`InitVar` 型かどうかを確認することで行われます。フィールドが :class:`InitVar` の" -"場合、初期化専用フィールドと呼ばれる疑似フィールドとみなされます。真のフィールドでは" -"ないため、モジュールレベルの :func:`fields` 関数によって返されません。初期化専用" -"フィールドは、生成された :meth:`~object.__init__` メソッドのパラメータとして追加され、" -"オプションの :meth:`__post_init__` メソッドに渡されます。データクラスでは" -"それ以外に使用されることはありません。" - -#: ../../library/dataclasses.rst:623 -msgid "" -"For example, suppose a field will be initialized from a database, if a value " -"is not provided when creating the class::" -msgstr "" -"例えば、あるフィールドがデータベースから初期化されると仮定して、クラスを作成" -"するときには値が与えられない次の場合を考えます::" - -#: ../../library/dataclasses.rst:626 -msgid "" -"@dataclass\n" -"class C:\n" -" i: int\n" -" j: int | None = None\n" -" database: InitVar[DatabaseType | None] = None\n" -"\n" -" def __post_init__(self, database):\n" -" if self.j is None and database is not None:\n" -" self.j = database.lookup('j')\n" -"\n" -"c = C(10, database=my_database)" -msgstr "" -"@dataclass\n" -"class C:\n" -" i: int\n" -" j: int | None = None\n" -" database: InitVar[DatabaseType | None] = None\n" -"\n" -" def __post_init__(self, database):\n" -" if self.j is None and database is not None:\n" -" self.j = database.lookup('j')\n" -"\n" -"c = C(10, database=my_database)" - -#: ../../library/dataclasses.rst:638 -msgid "" -"In this case, :func:`fields` will return :class:`Field` objects for :attr:`!" -"i` and :attr:`!j`, but not for :attr:`!database`." -msgstr "" -"この場合、:func:`fields` は :attr:`!i` と :attr:`!j` に対して :class:`Field` オブジェクトを" -"返しますが、:attr:`!database` に対しては返しません。" -"この場合、:func:`fields` は :attr:`!i` と :attr:`!j` に対して :class:`Field` オブジェクトを" -"返しますが、:attr:`!database` に対しては返しません。" - -#: ../../library/dataclasses.rst:644 -msgid "Frozen instances" -msgstr "凍結されたインスタンス" - -#: ../../library/dataclasses.rst:646 -msgid "" -"It is not possible to create truly immutable Python objects. However, by " -"passing ``frozen=True`` to the :func:`@dataclass ` decorator you " -"can emulate immutability. In that case, dataclasses will add :meth:`~object." -"__setattr__` and :meth:`~object.__delattr__` methods to the class. These " -"methods will raise a :exc:`FrozenInstanceError` when invoked." -msgstr "" -"真に不変なPythonオブジェクトを作成することは不可能です。しかし、:func:`@dataclass ` " -"デコレータに ``frozen=True`` を渡すことで、不変性をエミュレートできます。その場合、" -"データクラスはクラスに :meth:`~object.__setattr__` と :meth:`~object.__delattr__` メソッドを" -"追加します。これらのメソッドは呼び出されると :exc:`FrozenInstanceError` を発生させます。" -"真に不変なPythonオブジェクトを作成することは不可能です。しかし、:func:`@dataclass ` " -"デコレータに ``frozen=True`` を渡すことで、不変性をエミュレートできます。その場合、" -"データクラスはクラスに :meth:`~object.__setattr__` と :meth:`~object.__delattr__` メソッドを" -"追加します。これらのメソッドは呼び出されると :exc:`FrozenInstanceError` を発生させます。" - -#: ../../library/dataclasses.rst:652 -msgid "" -"There is a tiny performance penalty when using ``frozen=True``: :meth:" -"`~object.__init__` cannot use simple assignment to initialize fields, and " -"must use :meth:`!object.__setattr__`." -msgstr "" -"``frozen=True`` を使用する際には、わずかなパフォーマンスペナルティがあります。" -":meth:`~object.__init__` はフィールドを初期化するために単純な代入を使用できず、" -":meth:`!object.__setattr__` を使用する必要があります。" -"``frozen=True`` を使用する際には、わずかなパフォーマンスペナルティがあります。" -":meth:`~object.__init__` はフィールドを初期化するために単純な代入を使用できず、" -":meth:`!object.__setattr__` を使用する必要があります。" - -#: ../../library/dataclasses.rst:661 -msgid "Inheritance" -msgstr "継承" - -#: ../../library/dataclasses.rst:663 -msgid "" -"When the dataclass is being created by the :func:`@dataclass ` " -"decorator, it looks through all of the class's base classes in reverse MRO " -"(that is, starting at :class:`object`) and, for each dataclass that it " -"finds, adds the fields from that base class to an ordered mapping of fields. " -"After all of the base class fields are added, it adds its own fields to the " -"ordered mapping. All of the generated methods will use this combined, " -"calculated ordered mapping of fields. Because the fields are in insertion " -"order, derived classes override base classes. An example::" -msgstr "" -":func:`@dataclass ` デコレータによってデータクラスが作成される際、" -"クラスのすべてのベースクラスを逆MRO順(つまり :class:`object` から始まって)で調べ、" -"見つけた各データクラスについて、そのベースクラスのフィールドを順序付きフィールドマッピングに" -"追加します。すべてのベースクラスフィールドが追加された後、自身のフィールドを順序付き" -"マッピングに追加します。生成されるすべてのメソッドは、この組み合わされた計算済み順序付き" -"フィールドマッピングを使用します。フィールドは挿入順であるため、派生クラスは" -"ベースクラスをオーバーライドします。例::" - -#: ../../library/dataclasses.rst:673 -msgid "" -"@dataclass\n" -"class Base:\n" -" x: Any = 15.0\n" -" y: int = 0\n" -"\n" -"@dataclass\n" -"class C(Base):\n" -" z: int = 10\n" -" x: int = 15" -msgstr "" -"@dataclass\n" -"class Base:\n" -" x: Any = 15.0\n" -" y: int = 0\n" -"\n" -"@dataclass\n" -"class C(Base):\n" -" z: int = 10\n" -" x: int = 15" - -#: ../../library/dataclasses.rst:683 -msgid "" -"The final list of fields is, in order, :attr:`!x`, :attr:`!y`, :attr:`!z`. " -"The final type of :attr:`!x` is :class:`int`, as specified in class :class:`!" -"C`." -msgstr "" -"最終的なフィールドリストは、順序として :attr:`!x`、:attr:`!y`、:attr:`!z` です。" -":attr:`!x` の最終的な型は、クラス :class:`!C` で指定されたとおり :class:`int` です。" - -#: ../../library/dataclasses.rst:686 -msgid "" -"The generated :meth:`~object.__init__` method for :class:`!C` will look " -"like::" -msgstr ":class:`!C` の生成された :meth:`~object.__init__` メソッドは次のようになります::" - -#: ../../library/dataclasses.rst:688 -msgid "def __init__(self, x: int = 15, y: int = 0, z: int = 10):" -msgstr "def __init__(self, x: int = 15, y: int = 0, z: int = 10):" - -#: ../../library/dataclasses.rst:691 -msgid "Re-ordering of keyword-only parameters in :meth:`!__init__`" -msgstr ":meth:`!__init__` におけるキーワード専用パラメータの並び替え" - -#: ../../library/dataclasses.rst:693 -msgid "" -"After the parameters needed for :meth:`~object.__init__` are computed, any " -"keyword-only parameters are moved to come after all regular (non-keyword-" -"only) parameters. This is a requirement of how keyword-only parameters are " -"implemented in Python: they must come after non-keyword-only parameters." -msgstr "" -":meth:`~object.__init__` で必要なパラメータが算出されると、キーワード専用引数" -"は他の一般的な(非キーワード専用)パラメータの後に移動します。これは、すべて" -"のキーワード専用引数は、非キーワード専用パラメータの末尾にこなければならない" -"という、キーワード専用パラメータのPythonの実装の都合で必要なことです。" - -#: ../../library/dataclasses.rst:699 -msgid "" -"In this example, :attr:`!Base.y`, :attr:`!Base.w`, and :attr:`!D.t` are " -"keyword-only fields, and :attr:`!Base.x` and :attr:`!D.z` are regular " -"fields::" -msgstr "" -"この例では、:attr:`!Base.y`、:attr:`!Base.w`、:attr:`!D.t` は" -"キーワード専用フィールドで、:attr:`!Base.x` と :attr:`!D.z` は" -"通常のフィールドです::" - -#: ../../library/dataclasses.rst:702 -msgid "" -"@dataclass\n" -"class Base:\n" -" x: Any = 15.0\n" -" _: KW_ONLY\n" -" y: int = 0\n" -" w: int = 1\n" -"\n" -"@dataclass\n" -"class D(Base):\n" -" z: int = 10\n" -" t: int = field(kw_only=True, default=0)" -msgstr "" -"@dataclass\n" -"class Base:\n" -" x: Any = 15.0\n" -" _: KW_ONLY\n" -" y: int = 0\n" -" w: int = 1\n" -"\n" -"@dataclass\n" -"class D(Base):\n" -" z: int = 10\n" -" t: int = field(kw_only=True, default=0)" - -#: ../../library/dataclasses.rst:714 -msgid "The generated :meth:`!__init__` method for :class:`!D` will look like::" -msgstr ":class:`!D` の生成された :meth:`!__init__` メソッドは次のようになります::" - -#: ../../library/dataclasses.rst:716 -msgid "" -"def __init__(self, x: Any = 15.0, z: int = 10, *, y: int = 0, w: int = 1, t: " -"int = 0):" -msgstr "" -"def __init__(self, x: Any = 15.0, z: int = 10, *, y: int = 0, w: int = 1, t: " -"int = 0):" - -#: ../../library/dataclasses.rst:718 -msgid "" -"Note that the parameters have been re-ordered from how they appear in the " -"list of fields: parameters derived from regular fields are followed by " -"parameters derived from keyword-only fields." -msgstr "" -"パラメータは、フィールドのリストの表示方法によって並べ替えられます。通常の" -"フィールドから派生したパラメータの後に、キーワードのみのフィールドから派生し" -"たパラメータが続きます。" - -#: ../../library/dataclasses.rst:722 -msgid "" -"The relative ordering of keyword-only parameters is maintained in the re-" -"ordered :meth:`!__init__` parameter list." -msgstr "" -"キーワード専用パラメータの相対的な順序は、並び替えられた :meth:`!__init__` " -"パラメータリストで維持されます。" - -#: ../../library/dataclasses.rst:727 -msgid "Default factory functions" -msgstr "デフォルトファクトリ関数" - -#: ../../library/dataclasses.rst:729 -msgid "" -"If a :func:`field` specifies a *default_factory*, it is called with zero " -"arguments when a default value for the field is needed. For example, to " -"create a new instance of a list, use::" -msgstr "" -":func:`field` が *default_factory* を指定している場合、フィールドのデフォルト値が必要な" -"ときに引数なしで呼び出されます。例えば、リストの新しいインスタンスを作成するには::" - -#: ../../library/dataclasses.rst:733 -msgid "mylist: list = field(default_factory=list)" -msgstr "mylist: list = field(default_factory=list)" - -#: ../../library/dataclasses.rst:735 -msgid "" -"If a field is excluded from :meth:`~object.__init__` (using ``init=False``) " -"and the field also specifies *default_factory*, then the default factory " -"function will always be called from the generated :meth:`!__init__` " -"function. This happens because there is no other way to give the field an " -"initial value." -msgstr "" -"フィールドが :meth:`~object.__init__` から除外されており(``init=False`` を使用)、" -"かつフィールドが *default_factory* を指定している場合、デフォルトファクトリ関数は" -"常に生成された :meth:`!__init__` 関数から呼び出されます。これは、フィールドに" -"初期値を与える他の方法がないためです。" - -#: ../../library/dataclasses.rst:742 -msgid "Mutable default values" -msgstr "可変なデフォルト値" - -#: ../../library/dataclasses.rst:744 -msgid "" -"Python stores default member variable values in class attributes. Consider " -"this example, not using dataclasses::" -msgstr "" -"Python はメンバ変数のデフォルト値をクラス属性に保持します。\n" -"データクラスを使っていない、この例を考えてみましょう::" - -#: ../../library/dataclasses.rst:747 -msgid "" -"class C:\n" -" x = []\n" -" def add(self, element):\n" -" self.x.append(element)\n" -"\n" -"o1 = C()\n" -"o2 = C()\n" -"o1.add(1)\n" -"o2.add(2)\n" -"assert o1.x == [1, 2]\n" -"assert o1.x is o2.x" -msgstr "" -"class C:\n" -" x = []\n" -" def add(self, element):\n" -" self.x.append(element)\n" -"\n" -"o1 = C()\n" -"o2 = C()\n" -"o1.add(1)\n" -"o2.add(2)\n" -"assert o1.x == [1, 2]\n" -"assert o1.x is o2.x" - -#: ../../library/dataclasses.rst:759 -msgid "" -"Note that the two instances of class :class:`!C` share the same class " -"variable :attr:`!x`, as expected." -msgstr "" -"予想どおり、クラス :class:`!C` の2つのインスタンスは同じクラス変数 :attr:`!x` を" -"共有していることに注意してください。" - -#: ../../library/dataclasses.rst:762 -msgid "Using dataclasses, *if* this code was valid::" -msgstr "データクラスを使っているこのコードが *もし仮に* 有効なものだとしたら::" - -#: ../../library/dataclasses.rst:764 -msgid "" -"@dataclass\n" -"class D:\n" -" x: list = [] # This code raises ValueError\n" -" def add(self, element):\n" -" self.x.append(element)" -msgstr "" -"@dataclass\n" -"class D:\n" -" x: list = [] # This code raises ValueError\n" -" def add(self, element):\n" -" self.x.append(element)" - -#: ../../library/dataclasses.rst:770 -msgid "it would generate code similar to::" -msgstr "データクラスは次のようなコードを生成するでしょう::" - -#: ../../library/dataclasses.rst:772 -msgid "" -"class D:\n" -" x = []\n" -" def __init__(self, x=x):\n" -" self.x = x\n" -" def add(self, element):\n" -" self.x.append(element)\n" -"\n" -"assert D().x is D().x" -msgstr "" -"class D:\n" -" x = []\n" -" def __init__(self, x=x):\n" -" self.x = x\n" -" def add(self, element):\n" -" self.x.append(element)\n" -"\n" -"assert D().x is D().x" - -#: ../../library/dataclasses.rst:781 -msgid "" -"This has the same issue as the original example using class :class:`!C`. " -"That is, two instances of class :class:`!D` that do not specify a value for :" -"attr:`!x` when creating a class instance will share the same copy of :attr:`!" -"x`. Because dataclasses just use normal Python class creation they also " -"share this behavior. There is no general way for Data Classes to detect " -"this condition. Instead, the :func:`@dataclass ` decorator will " -"raise a :exc:`ValueError` if it detects an unhashable default parameter. " -"The assumption is that if a value is unhashable, it is mutable. This is a " -"partial solution, but it does protect against many common errors." -msgstr "" -"これは、クラス :class:`!C` を使用した元の例と同じ問題を持っています。つまり、" -"クラスインスタンスを作成する際に :attr:`!x` の値を指定しないクラス :class:`!D` の" -"2つのインスタンスは、同じ :attr:`!x` のコピーを共有することになります。" -"データクラスは通常の Python クラス作成を使用するだけなので、この動作も共有します。" -"データクラスがこの状態を検出する一般的な方法はありません。代わりに、" -":func:`@dataclass ` デコレータは、ハッシュ化不可能なデフォルトパラメータを" -"検出した場合に :exc:`ValueError` を発生させます。値がハッシュ化不可能であれば可変である" -"という仮定です。これは部分的な解決策ですが、多くの一般的なエラーから保護します。" -"これは、クラス :class:`!C` を使用した元の例と同じ問題を持っています。つまり、" -"クラスインスタンスを作成する際に :attr:`!x` の値を指定しないクラス :class:`!D` の" -"2つのインスタンスは、同じ :attr:`!x` のコピーを共有することになります。" -"データクラスは通常の Python クラス作成を使用するだけなので、この動作も共有します。" -"データクラスがこの状態を検出する一般的な方法はありません。代わりに、" -":func:`@dataclass ` デコレータは、ハッシュ化不可能なデフォルトパラメータを" -"検出した場合に :exc:`ValueError` を発生させます。値がハッシュ化不可能であれば可変である" -"という仮定です。これは部分的な解決策ですが、多くの一般的なエラーから保護します。" - -#: ../../library/dataclasses.rst:792 -msgid "" -"Using default factory functions is a way to create new instances of mutable " -"types as default values for fields::" -msgstr "" -"デフォルトファクトリ関数を使うのが、フィールドのデフォルト値として可変な型の" -"新しいインスタンスを作成する手段です::" - -#: ../../library/dataclasses.rst:795 -msgid "" -"@dataclass\n" -"class D:\n" -" x: list = field(default_factory=list)\n" -"\n" -"assert D().x is not D().x" -msgstr "" -"@dataclass\n" -"class D:\n" -" x: list = field(default_factory=list)\n" -"\n" -"assert D().x is not D().x" - -#: ../../library/dataclasses.rst:801 -msgid "" -"Instead of looking for and disallowing objects of type :class:`list`, :class:" -"`dict`, or :class:`set`, unhashable objects are now not allowed as default " -"values. Unhashability is used to approximate mutability." -msgstr "" -":class:`list`、:class:`dict`、:class:`set` 型のオブジェクトを探して禁止する代わりに、" -"ハッシュ化不可能なオブジェクトはデフォルト値として使用できなくなりました。" -"ハッシュ化不可能性は可変性を近似するために使用されます。" - -#: ../../library/dataclasses.rst:808 -msgid "Descriptor-typed fields" -msgstr "ディスクリプタ型フィールド" - -#: ../../library/dataclasses.rst:810 -msgid "" -"Fields that are assigned :ref:`descriptor objects ` as their " -"default value have the following special behaviors:" -msgstr "" -"デフォルト値として :ref:`ディスクリプタオブジェクト ` が割り当てられた" -"フィールドは、以下の特別な動作を持ちます:" - -#: ../../library/dataclasses.rst:813 -msgid "" -"The value for the field passed to the dataclass's :meth:`~object.__init__` " -"method is passed to the descriptor's :meth:`~object.__set__` method rather " -"than overwriting the descriptor object." -msgstr "" -"データクラスの :meth:`~object.__init__` メソッドに渡されたフィールドの値は、" -"ディスクリプタオブジェクトを上書きするのではなく、ディスクリプタの" -":meth:`~object.__set__` メソッドに渡されます。" - -#: ../../library/dataclasses.rst:817 -msgid "" -"Similarly, when getting or setting the field, the descriptor's :meth:" -"`~object.__get__` or :meth:`!__set__` method is called rather than returning " -"or overwriting the descriptor object." -msgstr "" -"同様に、フィールドを取得または設定する際は、ディスクリプタオブジェクトを" -"返したり上書きしたりするのではなく、ディスクリプタの :meth:`~object.__get__` " -"または :meth:`!__set__` メソッドが呼び出されます。" - -#: ../../library/dataclasses.rst:821 -msgid "" -"To determine whether a field contains a default value, :func:`@dataclass " -"` will call the descriptor's :meth:`!__get__` method using its " -"class access form: ``descriptor.__get__(obj=None, type=cls)``. If the " -"descriptor returns a value in this case, it will be used as the field's " -"default. On the other hand, if the descriptor raises :exc:`AttributeError` " -"in this situation, no default value will be provided for the field." -msgstr "" -"フィールドがデフォルト値を含むかどうかを判定するため、:func:`@dataclass ` は" -"クラスアクセス形式を使用してディスクリプタの :meth:`!__get__` メソッドを呼び出します:" -"``descriptor.__get__(obj=None, type=cls)`` 。この場合にディスクリプタが値を返す場合、" -"それがフィールドのデフォルトとして使用されます。一方、ディスクリプタがこの状況で" -":exc:`AttributeError` を発生させる場合、フィールドにデフォルト値は提供されません。" - -#: ../../library/dataclasses.rst:831 -msgid "" -"class IntConversionDescriptor:\n" -" def __init__(self, *, default):\n" -" self._default = default\n" -"\n" -" def __set_name__(self, owner, name):\n" -" self._name = \"_\" + name\n" -"\n" -" def __get__(self, obj, type):\n" -" if obj is None:\n" -" return self._default\n" -"\n" -" return getattr(obj, self._name, self._default)\n" -"\n" -" def __set__(self, obj, value):\n" -" setattr(obj, self._name, int(value))\n" -"\n" -"@dataclass\n" -"class InventoryItem:\n" -" quantity_on_hand: IntConversionDescriptor = " -"IntConversionDescriptor(default=100)\n" -"\n" -"i = InventoryItem()\n" -"print(i.quantity_on_hand) # 100\n" -"i.quantity_on_hand = 2.5 # calls __set__ with 2.5\n" -"print(i.quantity_on_hand) # 2" -msgstr "" -"class IntConversionDescriptor:\n" -" def __init__(self, *, default):\n" -" self._default = default\n" -"\n" -" def __set_name__(self, owner, name):\n" -" self._name = \"_\" + name\n" -"\n" -" def __get__(self, obj, type):\n" -" if obj is None:\n" -" return self._default\n" -"\n" -" return getattr(obj, self._name, self._default)\n" -"\n" -" def __set__(self, obj, value):\n" -" setattr(obj, self._name, int(value))\n" -"\n" -"@dataclass\n" -"class InventoryItem:\n" -" quantity_on_hand: IntConversionDescriptor = " -"IntConversionDescriptor(default=100)\n" -"\n" -"i = InventoryItem()\n" -"print(i.quantity_on_hand) # 100\n" -"i.quantity_on_hand = 2.5 # calls __set__ with 2.5\n" -"print(i.quantity_on_hand) # 2" #: ../../library/dataclasses.rst:856 msgid "" @@ -2442,6 +1282,3 @@ msgid "" "assigned a descriptor object as its default value, the field will act like a " "normal field." msgstr "" -"フィールドがディスクリプタ型でアノテーションされているものの、デフォルト値として" -"ディスクリプタオブジェクトが割り当てられていない場合、フィールドは通常の" -"フィールドのように動作します。" From 114b7e3c46f59ff5181bad2137046afd040f8010 Mon Sep 17 00:00:00 2001 From: Atsuo Ishimoto Date: Mon, 7 Jul 2025 07:06:09 +0900 Subject: [PATCH 14/19] add workflow --- CLAUDE.md | 122 ++++++++++++----- check_translation_progress.py | 175 ++++++++++++++++++++++++ library/dataclasses.po | 192 +++++++++++++++++--------- translate_workflow.py | 246 ++++++++++++++++++++++++++++++++++ 4 files changed, 640 insertions(+), 95 deletions(-) create mode 100644 check_translation_progress.py create mode 100755 translate_workflow.py diff --git a/CLAUDE.md b/CLAUDE.md index a09c80a41..0d8a1ef08 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -53,17 +53,69 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co 「`library/asyncio.po` を翻訳してください」という指示があった場合、以下の手順で作業を進めます。 -1. `read_file` ツールで `library/asyncio.po` の内容を読み込みます。 -2. 未翻訳の箇所 (`msgstr ""`) を見つけます。 -3. reStructuredTextの構文に注意しながら、対応する `msgid` を翻訳し、`msgstr` に記述します。 -4. 既存の翻訳もレビューし、必要に応じて修正案を考えます。 -5. `replace` または `write_file` ツールを使い、変更を適用します。 +**重要**: 翻訳作業は必ず `translate_workflow.py` スクリプトを使用して実行してください。 -#### 4.1 ファイルの分割 +1. **翻訳ワークフロー開始**: + ```bash + python3 translate_workflow.py library/asyncio.po + ``` -.poファイルのサイズが20kbを超える場合は、すべてをまとめて処理せず、splitpoコマンドでpoファイルを30エントリずつに分割して、それぞれを翻訳します。 +2. **作業の自動判定**: + - スクリプトが既存の作業状況を自動チェック + - 未着手の場合: 自動的にファイル分割(20KB超の場合) + - 作業中の場合: 次に翻訳すべきファイルを表示 + - 完了済みの場合: 自動的にファイル結合と最終チェック +3. **翻訳作業の実行**: + - 表示された分割ファイルを順次翻訳 + - 各ファイル完了後、`.splitted_done/` ディレクトリに移動 + - 翻訳完了後、再度スクリプトを実行して次のファイルへ +4. **完了確認**: + - 全ファイル翻訳完了後、自動的に結合処理 + - 最終的な翻訳漏れチェックを実行 + - 元のファイルが更新されて翻訳が完了 + - 一時ファイル(`.splitted/`, `.splitted_done/`)は自動削除 + +#### 4.0 翻訳ワークフローシステム + +翻訳作業は中断・再開が可能な専用システムで管理されます。 + +**ディレクトリ構造**: +``` +.splitted/ # 分割ファイル格納 + └── [ファイル名]/ # ファイル固有ディレクトリ +.splitted_done/ # 翻訳完了ファイル格納 + └── [ファイル名]/ # ファイル固有ディレクトリ +``` + +**基本コマンド**: +```bash +# 翻訳開始/再開 +python3 translate_workflow.py [ファイル名].po + +# 状況確認 +python3 translate_workflow.py --status [ファイル名].po + +# 完了ファイル結合 +python3 translate_workflow.py --join [ファイル名].po +``` + +**作業フロー**: +1. 20KB以下のファイル: 直接翻訳 +2. 20KB超のファイル: 30エントリずつ自動分割 +3. 各分割ファイルの翻訳完了後、`.splitted_done/` に移動 +4. 全分割ファイル完了後、自動結合と最終チェック + +このシステムにより、作業の中断・再開が確実に行え、翻訳漏れを防止できます。 + +#### 4.1 ファイルの分割(自動化済み) + +**注意**: 以下の手動分割手順は `translate_workflow.py` により自動化されています。直接実行する必要はありません。 + +.poファイルのサイズが20kbを超える場合は、translate_workflow.pyが自動的にsplitpoコマンドでpoファイルを30エントリずつに分割して、それぞれを翻訳します。 + +**手動実行時の参考コマンド**: ``` splitpo -h usage: splitpo [-h] [-o OUTPUT_DIR] [-e ENTRIES] input_file @@ -79,24 +131,18 @@ options: Output directory for split files -e, --entries ENTRIES Number of entries per split file (default: 100) - ``` -実行例: - - `splitpo -o /tmp/split_pathlib -e 30 library/pathlib.po` +**自動実行例**: + `translate_workflow.py` が実行: `splitpo -o .splitted/pathlib -e 30 library/pathlib.po` -このコマンドは、poファイルを30エントリごとに分割します。 - -Split files are named with the pattern `{original_name}_part_{number}.po`: +**分割ファイル命名規則**: - `input.po` → `input_part_000.po`, `input_part_001.po`, etc. - Number of digits adjusts to file count (minimum 3 digits) - Numbering starts from 0 -ファイル名をそのままソートすれば、元ファイルと同じ順番で並ぶようになっていますので、この順序で翻訳を進めてください。 - -それぞれのファイルの翻訳が終了したら、joinpoコマンドで分割したファイルを結合します。 - +**結合処理**: +翻訳完了後、`translate_workflow.py` が自動的にjoinpoコマンドで分割したファイルを結合します。 ``` joinpo -h @@ -112,9 +158,11 @@ options: -o, --output OUTPUT Output .po file ``` -実行例: - - `joinpo -o translated_pathlib.po /tmp/split_pathlib/*.po -o` +**自動実行例**: + `translate_workflow.py` が実行: + 1. `joinpo -o translated_pathlib.po .splitted_done/pathlib/*.po` + 2. 元のファイルを翻訳済みファイルで更新 + 3. 一時ファイルとディレクトリを削除 @@ -149,13 +197,13 @@ options: 2. 既存翻訳の品質が改善されている 3. コード例等の翻訳不要な部分は適切に `msgstr ""` のまま残されている -### 4.3 翻訳作業完了前の必須チェック手順(最終確認) +### 4.3 翻訳作業完了前の必須チェック手順(自動化済み) -**重要**: 翻訳作業の最後には、**必ず**以下の手順を実行して未翻訳部分が残っていないか確認してください。この手順は翻訳作業の品質を保証するために必須です。 +**重要**: 以下の最終チェック手順は `translate_workflow.py` により自動化されています。翻訳完了時に自動実行されますが、必要に応じて手動でも実行できます。 -#### 最終チェックスクリプトの実行 +#### 最終チェックスクリプトの実行(自動化済み) -翻訳対象ファイルに対して以下のPythonスクリプトを実行し、未翻訳のテキストエントリが残っていないか確認します: +`translate_workflow.py` が翻訳完了時に自動実行するチェックスクリプトです。手動実行時は以下のPythonスクリプトを実行し、未翻訳のテキストエントリが残っていないか確認します: ```python python3 -c " @@ -241,11 +289,13 @@ else: **注意**: この最終チェックを省略してはいけません。翻訳作業の品質保証において必須の手順です。 -### 4.4 翻訳漏れ防止のための必須手順 +### 4.4 翻訳漏れ防止のための必須手順(自動化済み) + +**重要**: 以下の翻訳漏れ防止手順は `translate_workflow.py` により自動化されています。手動実行時の参考として記載しています。 -翻訳漏れを完全に防ぐため、以下の手順を**必ず**実行してください: +#### 翻訳作業開始前の事前確認(自動化済み) -#### 翻訳作業開始前の事前確認 +`translate_workflow.py` が自動実行する確認項目: 1. **重複エントリの検出**: ```bash @@ -267,16 +317,18 @@ print(f'翻訳前未翻訳エントリ数: {len(re.findall(r\"msgstr \\\"\\\"\", #### 翻訳作業中の段階的確認 3. **定期的な進捗確認**: - - 50エントリごとに翻訳状況をチェック + - `translate_workflow.py` が進捗状況を自動表示 - 重複エントリを発見した場合は**すべて**翻訳する 4. **分割ファイル処理時の特別措置**: - - 各分割ファイルの翻訳完了後、即座に未翻訳エントリ数をチェック - - 結合前に各分割ファイルの翻訳完了を確認 + - 各分割ファイルの翻訳完了後、`.splitted_done/` ディレクトリに自動移動 + - 結合前に各分割ファイルの翻訳完了を自動確認 -#### 翻訳作業完了前の厳格な最終チェック +#### 翻訳作業完了前の厳格な最終チェック(自動化済み) 5. **最終チェックスクリプト(改良版)**: +`translate_workflow.py` が自動実行するチェックスクリプト: + ```python python3 -c " import re @@ -307,8 +359,8 @@ else: #### 品質保証のための二重チェック 6. **翻訳完了後の検証**: - - 翻訳前後の未翻訳エントリ数の差分を確認 - - 重複エントリがすべて翻訳されていることを確認 + - `translate_workflow.py` が翻訳前後の未翻訳エントリ数の差分を自動確認 + - 重複エントリがすべて翻訳されていることを自動確認 - 既存翻訳の品質向上も完了していることを確認 #### 緊急時の対応 @@ -318,7 +370,7 @@ else: - 同じ`msgid`の他のエントリも確認 - 翻訳完了まで作業を継続 -**重要**: この手順を省略することは品質保証上許可されません。すべての翻訳対象エントリが完了するまで作業を継続してください。 +**重要**: `translate_workflow.py` を使用することで、これらの手順が自動化され、翻訳品質が保証されます。 ## Repository Structure diff --git a/check_translation_progress.py b/check_translation_progress.py new file mode 100644 index 000000000..e2f24d233 --- /dev/null +++ b/check_translation_progress.py @@ -0,0 +1,175 @@ +#!/usr/bin/env python3 +""" +翻訳進捗チェックツール +分割された翻訳ファイルの進捗を確認し、作業再開をサポートします。 +""" + +import os +import sys +import re +from pathlib import Path +from typing import Dict, List, Tuple, Optional + + +def get_split_info(po_file: str) -> Tuple[str, str, str]: + """ + ファイルパスから分割作業用のディレクトリパスを取得 + Returns: (base_name, splitted_dir, done_dir) + """ + po_path = Path(po_file) + base_name = po_path.stem + + # ファイル固有のディレクトリを作成 + splitted_dir = Path(".splitted") / base_name + done_dir = Path(".splitted_done") / base_name + + return base_name, splitted_dir, done_dir + + +def check_split_files(splitted_dir: Path) -> List[Path]: + """分割ファイルの一覧を取得""" + if not splitted_dir.exists(): + return [] + + split_files = list(splitted_dir.glob("*_part_*.po")) + return sorted(split_files) + + +def check_done_files(done_dir: Path) -> List[Path]: + """完了ファイルの一覧を取得""" + if not done_dir.exists(): + return [] + + done_files = list(done_dir.glob("*_part_*.po")) + return sorted(done_files) + + +def get_untranslated_count(po_file: Path) -> int: + """POファイルの未翻訳エントリ数を取得""" + try: + with open(po_file, 'r', encoding='utf-8') as f: + content = f.read() + + # 未翻訳エントリを検出 + all_entries = re.findall(r'(#: [^\n]+\nmsgid[^m]+?msgstr "")', content, re.DOTALL) + untranslated_text = [] + + for entry in all_entries: + # コードサンプルを除外 + if not any(marker in entry for marker in ['def ', 'class ', 'assert ', 'print(', 'return ', '>>>', 'import ', 'raise ']): + untranslated_text.append(entry) + + return len(untranslated_text) + except Exception: + return -1 + + +def analyze_progress(po_file: str) -> Dict: + """翻訳進捗を分析""" + base_name, splitted_dir, done_dir = get_split_info(po_file) + + # 元ファイルの存在確認 + original_exists = os.path.exists(po_file) + + # 分割ファイルの確認 + split_files = check_split_files(splitted_dir) + done_files = check_done_files(done_dir) + + # 各ファイルの未翻訳エントリ数を取得 + split_status = {} + for split_file in split_files: + untranslated = get_untranslated_count(split_file) + split_status[split_file.name] = { + 'path': split_file, + 'untranslated': untranslated, + 'completed': untranslated == 0 + } + + done_status = {} + for done_file in done_files: + untranslated = get_untranslated_count(done_file) + done_status[done_file.name] = { + 'path': done_file, + 'untranslated': untranslated, + 'completed': untranslated == 0 + } + + return { + 'base_name': base_name, + 'original_file': po_file, + 'original_exists': original_exists, + 'splitted_dir': splitted_dir, + 'done_dir': done_dir, + 'split_files': split_files, + 'done_files': done_files, + 'split_status': split_status, + 'done_status': done_status, + 'has_work_in_progress': len(split_files) > 0 or len(done_files) > 0 + } + + +def print_progress_report(progress: Dict): + """進捗レポートを表示""" + print(f"=== 翻訳進捗レポート: {progress['base_name']} ===") + print(f"元ファイル: {progress['original_file']} ({'存在' if progress['original_exists'] else '不存在'})") + print(f"分割作業ディレクトリ: {progress['splitted_dir']}") + print(f"完了ディレクトリ: {progress['done_dir']}") + + if not progress['has_work_in_progress']: + print("✅ 作業中のファイルはありません") + return + + print("\n--- 作業中ファイル ---") + for filename, status in progress['split_status'].items(): + status_mark = "✅" if status['completed'] else "🔄" + print(f"{status_mark} {filename}: 未翻訳{status['untranslated']}件") + + print("\n--- 完了ファイル ---") + for filename, status in progress['done_status'].items(): + status_mark = "✅" if status['completed'] else "⚠️" + print(f"{status_mark} {filename}: 未翻訳{status['untranslated']}件") + + # 次の作業提案 + incomplete_splits = [f for f, s in progress['split_status'].items() if not s['completed']] + if incomplete_splits: + print(f"\n📋 次の作業: {incomplete_splits[0]} の翻訳を継続") + else: + print("\n📋 次の作業: 完了ファイルの結合") + + +def get_next_action(progress: Dict) -> str: + """次に実行すべきアクションを取得""" + if not progress['has_work_in_progress']: + return "start_fresh" + + # 作業中ファイルに未完了があるか確認 + incomplete_splits = [f for f, s in progress['split_status'].items() if not s['completed']] + if incomplete_splits: + return "continue_translation" + + # すべて完了している場合は結合 + if progress['done_files']: + return "join_files" + + return "unknown" + + +def main(): + if len(sys.argv) != 2: + print("使用法: python check_translation_progress.py ") + sys.exit(1) + + po_file = sys.argv[1] + if not os.path.exists(po_file): + print(f"エラー: ファイル '{po_file}' が見つかりません") + sys.exit(1) + + progress = analyze_progress(po_file) + print_progress_report(progress) + + action = get_next_action(progress) + print(f"\n🎯 推奨アクション: {action}") + + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/library/dataclasses.po b/library/dataclasses.po index d5dc38ae7..4f2d3c6fd 100644 --- a/library/dataclasses.po +++ b/library/dataclasses.po @@ -143,6 +143,9 @@ msgid "" "acts as if it has the default values documented in this signature. That is, " "these three uses of ``@dataclass`` are equivalent::" msgstr "" +"``@dataclass`` をパラメータなしの単純なデコレータとして使用した場合、この " +"シグネチャで説明されているデフォルト値が指定されたかのように動作します。つま " +"り、以下の3つの ``@dataclass`` の使用法は同等です::" #: ../../library/dataclasses.rst:74 msgid "" @@ -163,18 +166,22 @@ msgstr "" #: ../../library/dataclasses.rst:87 msgid "The parameters to ``@dataclass`` are:" -msgstr "" +msgstr "``@dataclass`` のパラメータは以下のとおりです:" #: ../../library/dataclasses.rst:89 msgid "" "*init*: If true (the default), a :meth:`~object.__init__` method will be " "generated." msgstr "" +"*init*: True (デフォルト) の場合、 :meth:`~object.__init__` メソッドが生成さ " +"れます。" #: ../../library/dataclasses.rst:92 msgid "" "If the class already defines :meth:`!__init__`, this parameter is ignored." msgstr "" +"クラスが既に :meth:`!__init__` を定義している場合、このパラメータは無視されま " +"す。" #: ../../library/dataclasses.rst:95 msgid "" @@ -185,11 +192,18 @@ msgid "" "example: ``InventoryItem(name='widget', unit_price=3.0, " "quantity_on_hand=10)``." msgstr "" +"*repr*: True (デフォルト) の場合、 :meth:`~object.__repr__` メソッドが生成さ " +"れます。生成された repr 文字列には、クラス名と各フィールドの名前とそれぞれの " +"repr が、クラスで定義された順序で含まれます。repr から除外されるよう印がつけ " +"られたフィールドは含まれません。例: ``InventoryItem(name='widget', " +"unit_price=3.0, quantity_on_hand=10)``" #: ../../library/dataclasses.rst:102 msgid "" "If the class already defines :meth:`!__repr__`, this parameter is ignored." msgstr "" +"クラスが既に :meth:`!__repr__` を定義している場合、このパラメータは無視されま " +"す。" #: ../../library/dataclasses.rst:105 msgid "" @@ -198,11 +212,16 @@ msgid "" "fields, in order. Both instances in the comparison must be of the identical " "type." msgstr "" +"*eq*: True (デフォルト) の場合、 :meth:`~object.__eq__` メソッドが生成されま " +"す。このメソッドは、クラスがフィールドのタプルであるかのように順序付けて比較 " +"します。比較される両方のインスタンスは同一の型である必要があります。" #: ../../library/dataclasses.rst:110 msgid "" "If the class already defines :meth:`!__eq__`, this parameter is ignored." msgstr "" +"クラスが既に :meth:`!__eq__` を定義している場合、このパラメータは無視されま " +"す。" #: ../../library/dataclasses.rst:113 msgid "" @@ -212,12 +231,20 @@ msgid "" "fields, in order. Both instances in the comparison must be of the identical " "type. If *order* is true and *eq* is false, a :exc:`ValueError` is raised." msgstr "" +"*order*: True (デフォルトは ``False``) の場合、 :meth:`~object.__lt__`、 " +":meth:`~object.__le__`、 :meth:`~object.__gt__`、 :meth:`~object.__ge__` メ " +"ソッドが生成されます。これらは、クラスがフィールドのタプルであるかのように順 " +"序付けて比較します。比較される両方のインスタンスは同一の型である必要がありま " +"す。 *order* が true で *eq* が false の場合、 :exc:`ValueError` が発生しま " +"す。" #: ../../library/dataclasses.rst:120 msgid "" "If the class already defines any of :meth:`!__lt__`, :meth:`!__le__`, :meth:" "`!__gt__`, or :meth:`!__ge__`, then :exc:`TypeError` is raised." msgstr "" +"クラスが既に :meth:`!__lt__`、 :meth:`!__le__`、 :meth:`!__gt__`、 :meth:`!" +"__ge__` のいずれかを定義している場合、 :exc:`TypeError` が発生します。" #: ../../library/dataclasses.rst:124 msgid "" @@ -226,6 +253,10 @@ msgid "" "generate a :meth:`~object.__hash__` method according to how *eq* and " "*frozen* are set. The default value is ``False``." msgstr "" +"*unsafe_hash*: True の場合、安全でない可能性があってもデータクラスに :meth:" +"`~object.__hash__` メソッドを強制的に作成させます。そうでない場合は、 *eq* と " +"*frozen* の設定に応じて :meth:`~object.__hash__` メソッドを生成します。デフォ " +"ルト値は ``False`` です。" #: ../../library/dataclasses.rst:130 msgid "" @@ -236,6 +267,12 @@ msgid "" "and behavior of :meth:`!__eq__`, and the values of the *eq* and *frozen* " "flags in the ``@dataclass`` decorator." msgstr "" +":meth:`!__hash__` は組み込み関数 :meth:`hash` で使用され、また辞書や集合な " +"どのハッシュ化コレクションにオブジェクトが追加されるときに使用されます。 " +":meth:`!__hash__` を持つということは、クラスのインスタンスが不変であることを " +"意味します。可変性は、プログラマーの意図、 :meth:`!__eq__` の存在と動作、 " +"``@dataclass`` デコレータの *eq* と *frozen* フラグの値に依存する複雑な性質 " +"です。" #: ../../library/dataclasses.rst:137 msgid "" @@ -245,6 +282,11 @@ msgid "" "attribute ``__hash__ = None`` has a specific meaning to Python, as described " "in the :meth:`!__hash__` documentation." msgstr "" +"デフォルトでは、 ``@dataclass`` は安全でない限り、 :meth:`~object.__hash__` " +"メソッドを暗黙的に追加しません。また、既に明示的に定義されている :meth:`!" +"__hash__` メソッドを追加したり変更したりしません。クラス属性 ``__hash__ = " +"None`` の設定は、 :meth:`!__hash__` ドキュメントで説明されているように、 " +"Python にとって特別な意味があります。" #: ../../library/dataclasses.rst:143 msgid "" @@ -255,6 +297,12 @@ msgid "" "logically immutable but can still be mutated. This is a specialized use case " "and should be considered carefully." msgstr "" +":meth:`!__hash__` が明示的に定義されていない場合、または ``None`` に設定され " +"ている場合、 ``@dataclass`` は暗黙的に :meth:`!__hash__` メソッドを追加 *する " +"可能性があります* 。推奨されませんが、 ``unsafe_hash=True`` を使って " +"``@dataclass`` に :meth:`!__hash__` メソッドを強制的に作成させることができま " +"す。これは、クラスが論理的には不変だが、まだ変更される可能性がある場合に該当 " +"します。これは特殊な使用例であり、慎重に検討する必要があります。" #: ../../library/dataclasses.rst:150 msgid "" @@ -263,6 +311,9 @@ msgid "" "in your dataclass and set ``unsafe_hash=True``; this will result in a :exc:" "`TypeError`." msgstr "" +"以下は :meth:`!__hash__` メソッドの暗黙的な作成を管理するルールです。データ " +"クラスで明示的に :meth:`!__hash__` メソッドを定義し、同時に ``unsafe_hash=True`` " +"を設定することはできません。これは :exc:`TypeError` を発生させます。" #: ../../library/dataclasses.rst:155 msgid "" @@ -274,6 +325,9 @@ msgid "" "used (if the superclass is :class:`object`, this means it will fall back to " "id-based hashing)." msgstr "" +"*eq* と *frozen* がどちらも true の場合、デフォルトで ``@dataclass`` は :meth:`!" +"__hash__` メソッドを生成します。 *eq* が true で *frozen* が false の場合、 " +":meth:`!__hash__` は ``None`` に設定され、ハッシュ化不可能とマークされます(変更可能なので、実際にそうです)。 *eq* が false の場合、 :meth:`!__hash__` は変更されずに残され、スーパークラスの :meth:`!__hash__` メソッドが使用されます(スーパークラスが :class:`object` の場合、これは id ベースのハッシュ化にフォールバックすることを意味します)。" #: ../../library/dataclasses.rst:163 msgid "" @@ -282,6 +336,7 @@ msgid "" "`~object.__setattr__` or :meth:`~object.__delattr__` is defined in the " "class, then :exc:`TypeError` is raised. See the discussion below." msgstr "" +"*frozen*: True (デフォルトは ``False``) の場合、フィールドへの代入で例外が発生します。これは読み取り専用の凍結インスタンスをエミュレートします。 :meth:`~object.__setattr__` または :meth:`~object.__delattr__` がクラスで定義されている場合、 :exc:`TypeError` が発生します。以下の議論を参照してください。" #: ../../library/dataclasses.rst:168 msgid "" @@ -292,6 +347,7 @@ msgid "" "__match_args__` is already defined in the class, then :attr:`!" "__match_args__` will not be generated." msgstr "" +"*match_args*: True (デフォルトは ``True``) の場合、生成された :meth:`~object.__init__` メソッドの非キーワード専用パラメータのリストから :attr:`~object.__match_args__` タプルが作成されます(:meth:`!__init__` が生成されない場合でも、上記を参照)。False の場合、または :attr:`!__match_args__` がクラスで既に定義されている場合、 :attr:`!__match_args__` は生成されません。" #: ../../library/dataclasses.rst:177 msgid "" @@ -302,10 +358,11 @@ msgid "" "is called. See the :term:`parameter` glossary entry for details. Also see " "the :const:`KW_ONLY` section." msgstr "" +"*kw_only*: True (デフォルト値は ``False``) の場合、すべてのフィールドがキーワード専用としてマークされます。フィールドがキーワード専用としてマークされた場合、唯一の効果は、キーワード専用フィールドから生成された :meth:`~object.__init__` パラメータは、 :meth:`!__init__` が呼び出されるときにキーワードで指定しなければならないことです。詳細については :term:`parameter` の用語集エントリを参照してください。また、 :const:`KW_ONLY` セクションも参照してください。" #: ../../library/dataclasses.rst:185 msgid "Keyword-only fields are not included in :attr:`!__match_args__`." -msgstr "" +msgstr "キーワード専用フィールドは :attr:`!__match_args__` に含まれません。" #: ../../library/dataclasses.rst:189 msgid "" @@ -314,6 +371,7 @@ msgid "" "original one. If :attr:`!__slots__` is already defined in the class, then :" "exc:`TypeError` is raised." msgstr "" +"*slots*: True (デフォルトは ``False``) の場合、 :attr:`~object.__slots__` 属性が生成され、元のクラスの代わりに新しいクラスが返されます。 :attr:`!__slots__` がクラスで既に定義されている場合、 :exc:`TypeError` が発生します。" #: ../../library/dataclasses.rst:195 msgid "" @@ -322,6 +380,7 @@ msgid "" "``__init_subclass__`` with no parameters or use default values as a " "workaround. See :gh:`91126` for full details." msgstr "" +"``slots=True`` を使用するときにベースクラスの :meth:`~object.__init_subclass__` にパラメータを渡すと :exc:`TypeError` が発生します。回避策として、パラメータのない ``__init_subclass__`` を使用するか、デフォルト値を使用してください。詳細については :gh:`91126` を参照してください。" #: ../../library/dataclasses.rst:203 msgid "" @@ -332,6 +391,7 @@ msgid "" "`fields` instead. To be able to determine inherited slots, base class :attr:" "`!__slots__` may be any iterable, but *not* an iterator." msgstr "" +"フィールド名がベースクラスの :attr:`!__slots__` に既に含まれている場合、それらを :ref:`上書きする ` ことを防ぐために、生成される :attr:`!__slots__` には含まれません。したがって、データクラスのフィールド名を取得するために :attr:`!__slots__` を使用しないでください。代わりに :func:`fields` を使用してください。継承されたスロットを判定できるように、ベースクラスの :attr:`!__slots__` は任意のイテラブルであることができますが、イテレータは *できません* 。" #: ../../library/dataclasses.rst:213 msgid "" @@ -340,13 +400,14 @@ msgid "" "`. It is an error to specify ``weakref_slot=True`` without also " "specifying ``slots=True``." msgstr "" +"*weakref_slot*: True (デフォルトは ``False``) の場合、\"__weakref__\" という名前のスロットを追加します。これはインスタンスを :func:`weakref可能 ` にするために必要です。 ``slots=True`` を指定せずに ``weakref_slot=True`` を指定するとエラーになります。" #: ../../library/dataclasses.rst:221 msgid "" "``field``\\s may optionally specify a default value, using normal Python " "syntax::" msgstr "" -"``フィールド`` には、通常の Python の文法でデフォルト値を指定できます。" +"``フィールド`` には、通常の Python の文法でデフォルト値を指定できます::" #: ../../library/dataclasses.rst:224 msgid "" @@ -361,6 +422,7 @@ msgid "" "In this example, both :attr:`!a` and :attr:`!b` will be included in the " "added :meth:`~object.__init__` method, which will be defined as::" msgstr "" +"この例では、 :attr:`!a` と :attr:`!b` の両方が追加される :meth:`~object.__init__` メソッドに含まれ、以下のように定義されます::" #: ../../library/dataclasses.rst:232 msgid "def __init__(self, a: int, b: int = 0):" @@ -384,6 +446,7 @@ msgid "" "replace the default field value with a call to the provided :func:`!field` " "function. For example::" msgstr "" +"一般的で簡単な使用例では、他の機能は必要ありません。しかし、フィールドごとの追加情報を必要とするデータクラスの機能があります。この追加情報の必要性を満たすために、デフォルトのフィールド値を提供された :func:`!field` 関数の呼び出しで置き換えることができます。例えば::" #: ../../library/dataclasses.rst:246 msgid "" @@ -402,10 +465,11 @@ msgid "" "because ``None`` is a valid value for some parameters with a distinct " "meaning. No code should directly use the :const:`MISSING` value." msgstr "" +"上記の通り、 :const:`MISSING` 値は、ユーザーが一部のパラメータを提供しているかどうかを検出するために使用されるセンチネルオブジェクトです。このセンチネルが使用されるのは、 ``None`` が一部のパラメータに対して異なる意味を持つ有効な値だからです。どのコードも :const:`MISSING` 値を直接使用してはいけません。" #: ../../library/dataclasses.rst:258 msgid "The parameters to :func:`!field` are:" -msgstr "" +msgstr ":func:`!field` のパラメータは以下のとおりです:" #: ../../library/dataclasses.rst:260 msgid "" @@ -413,6 +477,7 @@ msgid "" "is needed because the :func:`!field` call itself replaces the normal " "position of the default value." msgstr "" +"*default*: 指定された場合、これがこのフィールドのデフォルト値になります。これが必要なのは、 :func:`!field` 呼び出し自体がデフォルト値の通常の位置を置き換えるからです。" #: ../../library/dataclasses.rst:264 msgid "" @@ -422,18 +487,21 @@ msgid "" "discussed below. It is an error to specify both *default* and " "*default_factory*." msgstr "" +"*default_factory*: 指定された場合、このフィールドのデフォルト値が必要なときに呼び出される引数なしの呼び出し可能オブジェクトである必要があります。これは、以下で議論するように、可変のデフォルト値を持つフィールドを指定するために使用できます。 *default* と *default_factory* の両方を指定することはエラーです。" #: ../../library/dataclasses.rst:270 msgid "" "*init*: If true (the default), this field is included as a parameter to the " "generated :meth:`~object.__init__` method." msgstr "" +"*init*: True (デフォルト) の場合、このフィールドは生成される :meth:`~object.__init__` メソッドのパラメータとして含まれます。" #: ../../library/dataclasses.rst:273 msgid "" "*repr*: If true (the default), this field is included in the string returned " "by the generated :meth:`~object.__repr__` method." msgstr "" +"*repr*: True (デフォルト) の場合、このフィールドは生成される :meth:`~object.__repr__` メソッドが返す文字列に含まれます。" #: ../../library/dataclasses.rst:276 msgid "" @@ -445,6 +513,7 @@ msgid "" "comparisons. Setting this value to anything other than ``None`` is " "discouraged." msgstr "" +"*hash*: これは bool または ``None`` です。True の場合、このフィールドは生成される :meth:`~object.__hash__` メソッドに含まれます。False の場合、このフィールドは生成される :meth:`~object.__hash__` から除外されます。 ``None`` (デフォルト) の場合、 *compare* の値を使用します。これは、フィールドが比較に使用される場合はハッシュにも含まれるべきであるため、通常は期待される動作です。この値を ``None`` 以外に設定することは推奨されません。" #: ../../library/dataclasses.rst:284 msgid "" @@ -465,6 +534,7 @@ msgid "" "equality and comparison methods (:meth:`~object.__eq__`, :meth:`~object." "__gt__`, et al.)." msgstr "" +"*compare*: True (デフォルト) の場合、このフィールドは生成される等価性と比較メソッド (:meth:`~object.__eq__`、 :meth:`~object.__gt__` など) に含まれます。" #: ../../library/dataclasses.rst:294 msgid "" @@ -475,20 +545,22 @@ msgid "" "mechanism. Multiple third-parties can each have their own key, to use as a " "namespace in the metadata." msgstr "" +"*metadata*: これはマッピングまたは ``None`` です。 ``None`` は空の辞書として扱われます。この値は読み取り専用にするために :func:`~types.MappingProxyType` にラップされ、 :class:`Field` オブジェクトで公開されます。これはデータクラスでは全く使用されず、サードパーティの拡張メカニズムとして提供されています。複数のサードパーティがそれぞれ独自のキーを持ち、メタデータ内のネームスペースとして使用できます。" #: ../../library/dataclasses.rst:302 msgid "" "*kw_only*: If true, this field will be marked as keyword-only. This is used " "when the generated :meth:`~object.__init__` method's parameters are computed." msgstr "" +"*kw_only*: True の場合、このフィールドはキーワード専用としてマークされます。これは生成される :meth:`~object.__init__` メソッドのパラメータが計算されるときに使用されます。" #: ../../library/dataclasses.rst:306 msgid "Keyword-only fields are also not included in :attr:`!__match_args__`." -msgstr "" +msgstr "キーワード専用フィールドは :attr:`!__match_args__` にも含まれません。" #: ../../library/dataclasses.rst:310 msgid "*doc*: optional docstring for this field." -msgstr "" +msgstr "*doc*: このフィールドのオプションのドキュメント文字列。" #: ../../library/dataclasses.rst:314 msgid "" @@ -500,6 +572,7 @@ msgid "" "default values for the fields, just as if the default value itself were " "specified. For example, after::" msgstr "" +"フィールドのデフォルト値が :func:`!field` の呼び出しで指定された場合、このフィールドのクラス属性は指定された *default* 値で置き換えられます。 *default* が提供されない場合、クラス属性は削除されます。意図は、 :func:`@dataclass ` デコレータが実行された後、クラス属性がすべてフィールドのデフォルト値を含むようにすることです。これは、デフォルト値自体が指定された場合と同じです。例えば、以下の後::" #: ../../library/dataclasses.rst:323 msgid "" @@ -516,7 +589,7 @@ msgid "" "The class attribute :attr:`!C.z` will be ``10``, the class attribute :attr:`!" "C.t` will be ``20``, and the class attributes :attr:`!C.x` and :attr:`!C.y` " "will not be set." -msgstr "" +msgstr "クラス属性 :attr:`!C.z` は ``10`` 、クラス属性 :attr:`!C.t` は ``20`` になり、クラス属性 :attr:`!C.x` と :attr:`!C.y` は設定されません。" #: ../../library/dataclasses.rst:336 msgid "" @@ -524,22 +597,22 @@ msgid "" "created internally, and are returned by the :func:`fields` module-level " "method (see below). Users should never instantiate a :class:`!Field` object " "directly. Its documented attributes are:" -msgstr "" +msgstr ":class:`!Field` オブジェクトは、定義された各フィールドを説明します。これらのオブジェクトは内部的に作成され、:func:`fields` モジュールレベルメソッド(以下を参照)によって返されます。ユーザーは :class:`!Field` オブジェクトを直接インスタンス化すべきではありません。文書化されている属性は以下の通りです:" #: ../../library/dataclasses.rst:341 msgid ":attr:`!name`: The name of the field." -msgstr "" +msgstr ":attr:`!name`: フィールドの名前。" #: ../../library/dataclasses.rst:342 msgid ":attr:`!type`: The type of the field." -msgstr "" +msgstr ":attr:`!type`: フィールドの型。" #: ../../library/dataclasses.rst:343 msgid "" ":attr:`!default`, :attr:`!default_factory`, :attr:`!init`, :attr:`!repr`, :" "attr:`!hash`, :attr:`!compare`, :attr:`!metadata`, and :attr:`!kw_only` have " "the identical meaning and values as they do in the :func:`field` function." -msgstr "" +msgstr ":attr:`!default`, :attr:`!default_factory`, :attr:`!init`, :attr:`!repr`, :attr:`!hash`, :attr:`!compare`, :attr:`!metadata`, :attr:`!kw_only` は、:func:`field` 関数と同じ意味と値を持ちます。" #: ../../library/dataclasses.rst:347 msgid "" @@ -556,7 +629,7 @@ msgid "" "are considered pseudo-fields, and thus are neither returned by the :func:" "`fields` function nor used in any way except adding them as parameters to :" "meth:`~object.__init__` and an optional :meth:`__post_init__`." -msgstr "" +msgstr "``InitVar[T]`` 型アノテーションは、:ref:`init-only ` 変数を記述します。:class:`!InitVar` でアノテーションされたフィールドは疑似フィールドとみなされ、したがって :func:`fields` 関数によって返されることも、:meth:`~object.__init__` および オプションの :meth:`__post_init__` にパラメータとして追加する以外の方法で使用されることもありません。" #: ../../library/dataclasses.rst:361 msgid "" @@ -578,11 +651,11 @@ msgid "" "*dict_factory*). Each dataclass is converted to a dict of its fields, as " "``name: value`` pairs. dataclasses, dicts, lists, and tuples are recursed " "into. Other objects are copied with :func:`copy.deepcopy`." -msgstr "" +msgstr "データクラス *obj* を(ファクトリ関数 *dict_factory* を使用して)辞書に変換します。各データクラスは ``name: value`` のペアとして、そのフィールドの辞書に変換されます。データクラス、辞書、リスト、タプルは再帰的に処理されます。他のオブジェクトは :func:`copy.deepcopy` でコピーされます。" #: ../../library/dataclasses.rst:374 msgid "Example of using :func:`!asdict` on nested dataclasses::" -msgstr "" +msgstr "ネストしたデータクラスに対して :func:`!asdict` を使用する例::" #: ../../library/dataclasses.rst:376 msgid "" @@ -604,7 +677,7 @@ msgstr "" #: ../../library/dataclasses.rst:391 ../../library/dataclasses.rst:411 msgid "To create a shallow copy, the following workaround may be used::" -msgstr "" +msgstr "浅いコピーを作成するには、以下の回避策を使用できます::" #: ../../library/dataclasses.rst:393 msgid "{field.name: getattr(obj, field.name) for field in fields(obj)}" @@ -613,7 +686,7 @@ msgstr "" #: ../../library/dataclasses.rst:395 msgid "" ":func:`!asdict` raises :exc:`TypeError` if *obj* is not a dataclass instance." -msgstr "" +msgstr ":func:`!asdict` は、*obj* がデータクラスのインスタンスでない場合に :exc:`TypeError` を発生させます。" #: ../../library/dataclasses.rst:400 msgid "" @@ -621,7 +694,7 @@ msgid "" "*tuple_factory*). Each dataclass is converted to a tuple of its field " "values. dataclasses, dicts, lists, and tuples are recursed into. Other " "objects are copied with :func:`copy.deepcopy`." -msgstr "" +msgstr "データクラス *obj* を(ファクトリ関数 *tuple_factory* を使用して)タプルに変換します。各データクラスは、そのフィールド値のタプルに変換されます。データクラス、辞書、リスト、タプルは再帰的に処理されます。他のオブジェクトは :func:`copy.deepcopy` でコピーされます。" #: ../../library/dataclasses.rst:406 msgid "Continuing from the previous example::" @@ -641,7 +714,7 @@ msgstr "" msgid "" ":func:`!astuple` raises :exc:`TypeError` if *obj* is not a dataclass " "instance." -msgstr "" +msgstr ":func:`!astuple` は、*obj* がデータクラスのインスタンスでない場合に :exc:`TypeError` を発生させます。" #: ../../library/dataclasses.rst:420 msgid "" @@ -653,13 +726,13 @@ msgid "" "*repr*, *eq*, *order*, *unsafe_hash*, *frozen*, *match_args*, *kw_only*, " "*slots*, and *weakref_slot* have the same meaning as they do in :func:" "`@dataclass `." -msgstr "" +msgstr "名前が *cls_name* で、*fields* で定義されたフィールドを持ち、*bases* で指定された基底クラスを持ち、*namespace* で指定された名前空間で初期化された新しいデータクラスを作成します。*fields* は反復可能オブジェクトで、各要素は ``name``、``(name, type)``、または ``(name, type, Field)`` のいずれかです。``name`` のみが指定された場合は、``type`` に :data:`typing.Any` が使用されます。*init*、*repr*、*eq*、*order*、*unsafe_hash*、*frozen*、*match_args*、*kw_only*、*slots*、*weakref_slot* の値は、:func:`@dataclass ` と同じ意味を持ちます。" #: ../../library/dataclasses.rst:430 msgid "" "If *module* is defined, the :attr:`!__module__` attribute of the dataclass " "is set to that value. By default, it is set to the module name of the caller." -msgstr "" +msgstr "*module* が定義されている場合、データクラスの :attr:`!__module__` 属性がその値に設定されます。デフォルトでは、呼び出し元のモジュール名に設定されます。" #: ../../library/dataclasses.rst:434 msgid "" @@ -667,7 +740,7 @@ msgid "" "dataclass. It should take the class object as a first argument and the same " "keyword arguments as :func:`@dataclass `. By default, the :func:" "`@dataclass ` function is used." -msgstr "" +msgstr "*decorator* パラメータは、データクラスを作成するために使用される呼び出し可能オブジェクトです。第1引数としてクラスオブジェクトを取り、:func:`@dataclass ` と同じキーワード引数を取る必要があります。デフォルトでは、:func:`@dataclass ` 関数が使用されます。" #: ../../library/dataclasses.rst:439 msgid "" @@ -675,7 +748,7 @@ msgid "" "creating a new class with :attr:`!__annotations__` can then apply the :func:" "`@dataclass ` function to convert that class to a dataclass. " "This function is provided as a convenience. For example::" -msgstr "" +msgstr "この関数は厳密には必須ではありません。:attr:`!__annotations__` を持つ新しいクラスを作成するためのPythonのメカニズムであれば、そのクラスに :func:`@dataclass ` 関数を適用してデータクラスに変換できるからです。この関数は便宜上提供されています。例::" #: ../../library/dataclasses.rst:445 msgid "" @@ -704,7 +777,7 @@ msgstr "" #: ../../library/dataclasses.rst:462 msgid "Added the *decorator* parameter." -msgstr "" +msgstr "*decorator* パラメータが追加されました。" #: ../../library/dataclasses.rst:467 msgid "" @@ -712,27 +785,27 @@ msgid "" "from *changes*. If *obj* is not a Data Class, raises :exc:`TypeError`. If " "keys in *changes* are not field names of the given dataclass, raises :exc:" "`TypeError`." -msgstr "" +msgstr "*obj* と同じ型の新しいオブジェクトを作成し、*changes* からの値でフィールドを置き換えます。*obj* がデータクラスでない場合は、:exc:`TypeError` を発生させます。*changes* のキーが指定されたデータクラスのフィールド名でない場合は、:exc:`TypeError` を発生させます。" #: ../../library/dataclasses.rst:472 msgid "" "The newly returned object is created by calling the :meth:`~object.__init__` " "method of the dataclass. This ensures that :meth:`__post_init__`, if " "present, is also called." -msgstr "" +msgstr "新しく返されるオブジェクトは、データクラスの :meth:`~object.__init__` メソッドを呼び出すことで作成されます。これにより、:meth:`__post_init__` が存在する場合には確実に呼び出されます。" #: ../../library/dataclasses.rst:476 msgid "" "Init-only variables without default values, if any exist, must be specified " "on the call to :func:`!replace` so that they can be passed to :meth:`!" "__init__` and :meth:`__post_init__`." -msgstr "" +msgstr "デフォルト値を持たない初期化限定変数が存在する場合、:func:`!replace` の呼び出しで指定する必要があります。これにより、:meth:`!__init__` と :meth:`__post_init__` に渡すことができます。" #: ../../library/dataclasses.rst:480 msgid "" "It is an error for *changes* to contain any fields that are defined as " "having ``init=False``. A :exc:`ValueError` will be raised in this case." -msgstr "" +msgstr "*changes* に ``init=False`` として定義されたフィールドが含まれている場合はエラーになります。この場合、:exc:`ValueError` が発生します。" #: ../../library/dataclasses.rst:484 msgid "" @@ -743,19 +816,19 @@ msgid "" "they are used, it might be wise to have alternate class constructors, or " "perhaps a custom :func:`!replace` (or similarly named) method which handles " "instance copying." -msgstr "" +msgstr ":func:`!replace` の呼び出し時に ``init=False`` フィールドがどのように動作するかについて注意してください。これらは元のオブジェクトからコピーされるのではなく、初期化される場合には :meth:`__post_init__` で初期化されます。``init=False`` フィールドは稀に、かつ慎重に使用されることが期待されます。もし使用する場合は、代替のクラスコンストラクタを持つか、インスタンスのコピーを処理するカスタム :func:`!replace` (または同様の名前の)メソッドを持つことが賢明かもしれません。" #: ../../library/dataclasses.rst:493 msgid "" "Dataclass instances are also supported by generic function :func:`copy." "replace`." -msgstr "" +msgstr "データクラスのインスタンスは、ジェネリック関数 :func:`copy.replace` でもサポートされています。" #: ../../library/dataclasses.rst:497 msgid "" "Return ``True`` if its parameter is a dataclass (including subclasses of a " "dataclass) or an instance of one, otherwise return ``False``." -msgstr "" +msgstr "引数がデータクラス(データクラスのサブクラスを含む)またはそのインスタンスの場合は ``True`` を返し、そうでなければ ``False`` を返します。" #: ../../library/dataclasses.rst:500 msgid "" @@ -775,8 +848,7 @@ msgstr "" #: ../../library/dataclasses.rst:509 msgid "A sentinel value signifying a missing default or default_factory." -msgstr "" -"デフォルト値やdefault_factoryが設定されてない場合の番兵の値を設定します。" +msgstr "デフォルト値やdefault_factoryが設定されていない場合の番兵値です。" #: ../../library/dataclasses.rst:513 msgid "" @@ -787,7 +859,7 @@ msgid "" "``_`` is used for a :const:`!KW_ONLY` field. Keyword-only fields signify :" "meth:`~object.__init__` parameters that must be specified as keywords when " "the class is instantiated." -msgstr "" +msgstr "型アノテーションとして使用される番兵値です。:const:`!KW_ONLY` 型の疑似フィールドの後にあるフィールドは、すべてキーワード専用フィールドとしてマークされます。:const:`!KW_ONLY` 型の疑似フィールドは、それ以外では完全に無視されることに注意してください。これには、そのようなフィールドの名前も含まれます。慣例により、:const:`!KW_ONLY` フィールドには ``_`` という名前が使用されます。キーワード専用フィールドは、クラスがインスタンス化される際にキーワードとして指定する必要がある :meth:`~object.__init__` パラメータを示します。" #: ../../library/dataclasses.rst:522 msgid "" @@ -811,7 +883,7 @@ msgstr "" msgid "" "In a single dataclass, it is an error to specify more than one field whose " "type is :const:`!KW_ONLY`." -msgstr "" +msgstr "単一のデータクラスで、型が :const:`!KW_ONLY` のフィールドを複数指定するとエラーになります。" #: ../../library/dataclasses.rst:540 msgid "" @@ -835,7 +907,7 @@ msgid "" "__post_init__` in the order they were defined in the class. If no :meth:`!" "__init__` method is generated, then :meth:`!__post_init__` will not " "automatically be called." -msgstr "" +msgstr "クラスで定義された場合、生成された :meth:`~object.__init__` によって、通常は :meth:`!self.__post_init__` として呼び出されます。ただし、``InitVar`` フィールドが定義されている場合、それらもクラスで定義された順序で :meth:`!__post_init__` に渡されます。:meth:`!__init__` メソッドが生成されない場合、:meth:`!__post_init__` は自動的に呼び出されません。" #: ../../library/dataclasses.rst:558 msgid "" @@ -864,7 +936,7 @@ msgid "" "` does not call base class :meth:`!__init__` methods. If the base " "class has an :meth:`!__init__` method that has to be called, it is common to " "call this method in a :meth:`__post_init__` method::" -msgstr "" +msgstr ":func:`@dataclass ` によって生成される :meth:`~object.__init__` メソッドは、基底クラスの :meth:`!__init__` メソッドを呼び出しません。基底クラスに呼び出さなければならない :meth:`!__init__` メソッドがある場合、:meth:`__post_init__` メソッドでこのメソッドを呼び出すのが一般的です::" #: ../../library/dataclasses.rst:575 msgid "" @@ -886,7 +958,7 @@ msgid "" "Note, however, that in general the dataclass-generated :meth:`!__init__` " "methods don't need to be called, since the derived dataclass will take care " "of initializing all fields of any base class that is a dataclass itself." -msgstr "" +msgstr "ただし、一般的には、データクラスで生成された :meth:`!__init__` メソッドを呼び出す必要はありません。これは、派生データクラスが、それ自身がデータクラスである基底クラスのすべてのフィールドを初期化してくれるからです。" #: ../../library/dataclasses.rst:591 msgid "" @@ -912,7 +984,7 @@ msgid "" "from consideration as a field and is ignored by the dataclass mechanisms. " "Such ``ClassVar`` pseudo-fields are not returned by the module-level :func:" "`fields` function." -msgstr "" +msgstr ":func:`@dataclass ` が実際にフィールドの型を調べる数少ない場所の一つは、フィールドが :pep:`526` で定義されたクラス変数かどうかを判定することです。これは、フィールドの型が :data:`typing.ClassVar` かどうかをチェックすることで実行されます。フィールドが ``ClassVar`` の場合、それはフィールドとしての考慮から除外され、データクラスのメカニズムによって無視されます。このような ``ClassVar`` 疑似フィールドは、モジュールレベルの :func:`fields` 関数によって返されません。" #: ../../library/dataclasses.rst:611 msgid "Init-only variables" @@ -929,7 +1001,7 @@ msgid "" "the generated :meth:`~object.__init__` method, and are passed to the " "optional :meth:`__post_init__` method. They are not otherwise used by " "dataclasses." -msgstr "" +msgstr ":func:`@dataclass ` が型アノテーションを調べるもう一つの場所は、フィールドが初期化限定変数かどうかを判定することです。これは、フィールドの型が :class:`InitVar` 型かどうかを調べることで実行されます。フィールドが :class:`InitVar` の場合、それは初期化限定フィールドと呼ばれる疑似フィールドとみなされます。これは真のフィールドではないため、モジュールレベルの :func:`fields` 関数によって返されません。初期化限定フィールドは、生成された :meth:`~object.__init__` メソッドにパラメータとして追加され、オプションの :meth:`__post_init__` メソッドに渡されます。それ以外ではデータクラスで使用されません。" #: ../../library/dataclasses.rst:623 msgid "" @@ -958,7 +1030,7 @@ msgstr "" msgid "" "In this case, :func:`fields` will return :class:`Field` objects for :attr:`!" "i` and :attr:`!j`, but not for :attr:`!database`." -msgstr "" +msgstr "この場合、:func:`fields` は :attr:`!i` と :attr:`!j` の :class:`Field` オブジェクトを返しますが、:attr:`!database` のものは返しません。" #: ../../library/dataclasses.rst:644 msgid "Frozen instances" @@ -971,14 +1043,14 @@ msgid "" "can emulate immutability. In that case, dataclasses will add :meth:`~object." "__setattr__` and :meth:`~object.__delattr__` methods to the class. These " "methods will raise a :exc:`FrozenInstanceError` when invoked." -msgstr "" +msgstr "真に不変のPythonオブジェクトを作成することはできません。しかし、:func:`@dataclass ` デコレータに ``frozen=True`` を渡すことで、不変性をエミュレートできます。その場合、データクラスはクラスに :meth:`~object.__setattr__` と :meth:`~object.__delattr__` メソッドを追加します。これらのメソッドは、呼び出されたときに :exc:`FrozenInstanceError` を発生させます。" #: ../../library/dataclasses.rst:652 msgid "" "There is a tiny performance penalty when using ``frozen=True``: :meth:" "`~object.__init__` cannot use simple assignment to initialize fields, and " "must use :meth:`!object.__setattr__`." -msgstr "" +msgstr "``frozen=True`` を使用するとわずかなパフォーマンスペナルティがあります: :meth:`~object.__init__` はフィールドを初期化するために単純な代入を使用できず、:meth:`!object.__setattr__` を使用しなければなりません。" #: ../../library/dataclasses.rst:661 msgid "Inheritance" @@ -994,7 +1066,7 @@ msgid "" "ordered mapping. All of the generated methods will use this combined, " "calculated ordered mapping of fields. Because the fields are in insertion " "order, derived classes override base classes. An example::" -msgstr "" +msgstr ":func:`@dataclass ` デコレータによってデータクラスが作成されるとき、それはクラスのすべての基底クラスを逆MRO(つまり、:class:`object` から始まる)でルックアップし、見つかった各データクラスに対して、その基底クラスのフィールドを順序付きフィールドマッピングに追加します。すべての基底クラスフィールドが追加された後、自身のフィールドを順序付きマッピングに追加します。生成されたすべてのメソッドは、この結合され、計算された順序付きフィールドマッピングを使用します。フィールドは挿入順なので、派生クラスが基底クラスをオーバーライドします。例::" #: ../../library/dataclasses.rst:673 msgid "" @@ -1014,13 +1086,13 @@ msgid "" "The final list of fields is, in order, :attr:`!x`, :attr:`!y`, :attr:`!z`. " "The final type of :attr:`!x` is :class:`int`, as specified in class :class:`!" "C`." -msgstr "" +msgstr "フィールドの最終リストは、順序に :attr:`!x`、:attr:`!y`、:attr:`!z` です。:attr:`!x` の最終型は、クラス :class:`!C` で指定された通り :class:`int` です。" #: ../../library/dataclasses.rst:686 msgid "" "The generated :meth:`~object.__init__` method for :class:`!C` will look " "like::" -msgstr "" +msgstr ":class:`!C` のために生成された :meth:`~object.__init__` メソッドは、次のようになります::" #: ../../library/dataclasses.rst:688 msgid "def __init__(self, x: int = 15, y: int = 0, z: int = 10):" @@ -1028,7 +1100,7 @@ msgstr "" #: ../../library/dataclasses.rst:691 msgid "Re-ordering of keyword-only parameters in :meth:`!__init__`" -msgstr "" +msgstr ":meth:`!__init__` 内のキーワード専用パラメータの並び替え" #: ../../library/dataclasses.rst:693 msgid "" @@ -1047,7 +1119,7 @@ msgid "" "In this example, :attr:`!Base.y`, :attr:`!Base.w`, and :attr:`!D.t` are " "keyword-only fields, and :attr:`!Base.x` and :attr:`!D.z` are regular " "fields::" -msgstr "" +msgstr "この例では、:attr:`!Base.y`、:attr:`!Base.w`、:attr:`!D.t` はキーワード専用フィールドで、:attr:`!Base.x` と :attr:`!D.z` は通常のフィールドです::" #: ../../library/dataclasses.rst:702 msgid "" @@ -1066,7 +1138,7 @@ msgstr "" #: ../../library/dataclasses.rst:714 msgid "The generated :meth:`!__init__` method for :class:`!D` will look like::" -msgstr "" +msgstr ":class:`!D` のために生成された :meth:`!__init__` メソッドは、次のようになります::" #: ../../library/dataclasses.rst:716 msgid "" @@ -1088,7 +1160,7 @@ msgstr "" msgid "" "The relative ordering of keyword-only parameters is maintained in the re-" "ordered :meth:`!__init__` parameter list." -msgstr "" +msgstr "キーワード専用パラメータの相対的な順序は、並び替えられた :meth:`!__init__` パラメータリストで維持されます。" #: ../../library/dataclasses.rst:727 msgid "Default factory functions" @@ -1099,7 +1171,7 @@ msgid "" "If a :func:`field` specifies a *default_factory*, it is called with zero " "arguments when a default value for the field is needed. For example, to " "create a new instance of a list, use::" -msgstr "" +msgstr ":func:`field` が *default_factory* を指定している場合、フィールドのデフォルト値が必要なときに、引数なしで呼び出されます。たとえば、リストの新しいインスタンスを作成するには、次のように使用します::" #: ../../library/dataclasses.rst:733 msgid "mylist: list = field(default_factory=list)" @@ -1112,7 +1184,7 @@ msgid "" "function will always be called from the generated :meth:`!__init__` " "function. This happens because there is no other way to give the field an " "initial value." -msgstr "" +msgstr "フィールドが(``init=False`` を使用して):meth:`~object.__init__` から除外され、かつフィールドが *default_factory* も指定している場合、デフォルトファクトリ関数は常に生成された :meth:`!__init__` 関数から呼び出されます。これは、フィールドに初期値を与える他の方法がないためです。" #: ../../library/dataclasses.rst:742 msgid "Mutable default values" @@ -1145,7 +1217,7 @@ msgstr "" msgid "" "Note that the two instances of class :class:`!C` share the same class " "variable :attr:`!x`, as expected." -msgstr "" +msgstr "クラス :class:`!C` の2つのインスタンスが、期待どおり同じクラス変数 :attr:`!x` を共有していることに注意してください。" #: ../../library/dataclasses.rst:762 msgid "Using dataclasses, *if* this code was valid::" @@ -1187,7 +1259,7 @@ msgid "" "raise a :exc:`ValueError` if it detects an unhashable default parameter. " "The assumption is that if a value is unhashable, it is mutable. This is a " "partial solution, but it does protect against many common errors." -msgstr "" +msgstr "これは、クラス :class:`!C` を使用した元の例と同じ問題を持ちます。つまり、クラスインスタンスの作成時に :attr:`!x` の値を指定しないクラス :class:`!D` の2つのインスタンスは、同じ :attr:`!x` のコピーを共有します。データクラスは単に通常のPythonクラス作成を使用するため、この動作も共有します。データクラスがこの状態を検出する一般的な方法はありません。代わりに、:func:`@dataclass ` デコレータは、ハッシュ化不可能なデフォルトパラメータを検出した場合に :exc:`ValueError` を発生させます。値がハッシュ化不可能であれば可変であるという仮定です。これは部分的な解決策ですが、多くの一般的なエラーを保護します。" #: ../../library/dataclasses.rst:792 msgid "" @@ -1211,31 +1283,31 @@ msgid "" "Instead of looking for and disallowing objects of type :class:`list`, :class:" "`dict`, or :class:`set`, unhashable objects are now not allowed as default " "values. Unhashability is used to approximate mutability." -msgstr "" +msgstr ":class:`list`、:class:`dict`、:class:`set` 型のオブジェクトを探して禁止する代わりに、ハッシュ化不可能なオブジェクトはデフォルト値として許可されなくなりました。ハッシュ化不可能性が可変性の近似として使用されます。" #: ../../library/dataclasses.rst:808 msgid "Descriptor-typed fields" -msgstr "" +msgstr "ディスクリプタ型フィールド" #: ../../library/dataclasses.rst:810 msgid "" "Fields that are assigned :ref:`descriptor objects ` as their " "default value have the following special behaviors:" -msgstr "" +msgstr "デフォルト値として :ref:`descriptor objects ` が割り当てられたフィールドは、以下の特別な動作をします:" #: ../../library/dataclasses.rst:813 msgid "" "The value for the field passed to the dataclass's :meth:`~object.__init__` " "method is passed to the descriptor's :meth:`~object.__set__` method rather " "than overwriting the descriptor object." -msgstr "" +msgstr "データクラスの :meth:`~object.__init__` メソッドに渡されたフィールドの値は、ディスクリプタオブジェクトを上書きするのではなく、ディスクリプタの :meth:`~object.__set__` メソッドに渡されます。" #: ../../library/dataclasses.rst:817 msgid "" "Similarly, when getting or setting the field, the descriptor's :meth:" "`~object.__get__` or :meth:`!__set__` method is called rather than returning " "or overwriting the descriptor object." -msgstr "" +msgstr "同様に、フィールドを取得または設定するときには、ディスクリプタオブジェクトを返したり上書きしたりするのではなく、ディスクリプタの :meth:`~object.__get__` または :meth:`!__set__` メソッドが呼び出されます。" #: ../../library/dataclasses.rst:821 msgid "" @@ -1245,7 +1317,7 @@ msgid "" "descriptor returns a value in this case, it will be used as the field's " "default. On the other hand, if the descriptor raises :exc:`AttributeError` " "in this situation, no default value will be provided for the field." -msgstr "" +msgstr "フィールドがデフォルト値を含んでいるかどうかを判定するために、:func:`@dataclass ` はクラスアクセス形式:``descriptor.__get__(obj=None, type=cls)`` を使用してディスクリプタの :meth:`!__get__` メソッドを呼び出します。この場合ディスクリプタが値を返す場合、それがフィールドのデフォルトとして使用されます。一方、ディスクリプタがこの状況で :exc:`AttributeError` を発生させる場合、フィールドにはデフォルト値が提供されません。" #: ../../library/dataclasses.rst:831 msgid "" @@ -1281,4 +1353,4 @@ msgid "" "Note that if a field is annotated with a descriptor type, but is not " "assigned a descriptor object as its default value, the field will act like a " "normal field." -msgstr "" +msgstr "フィールドがディスクリプタ型でアノテーションされているが、デフォルト値としてディスクリプタオブジェクトが割り当てられていない場合、フィールドは通常のフィールドのように動作することに注意してください。" diff --git a/translate_workflow.py b/translate_workflow.py new file mode 100755 index 000000000..3f48e1eb8 --- /dev/null +++ b/translate_workflow.py @@ -0,0 +1,246 @@ +#!/usr/bin/env python3 +""" +Translation workflow management script for python-docs-ja project. + +This script provides resumable translation workflow by: +1. Splitting large .po files into manageable chunks +2. Tracking translation progress +3. Resuming from interruptions +4. Joining completed translations back together +""" + +import os +import sys +import glob +import subprocess +import argparse +from pathlib import Path + + +def get_file_size_kb(filepath): + """Get file size in KB.""" + return os.path.getsize(filepath) / 1024 + + +def get_base_filename(filepath): + """Get base filename without extension.""" + return Path(filepath).stem + + +def check_existing_work(po_file): + """Check for existing split files or completed work.""" + base_name = get_base_filename(po_file) + + # Check for existing split files + splitted_dir = f".splitted/{base_name}" + done_dir = f".splitted_done/{base_name}" + + existing_splits = [] + completed_splits = [] + + if os.path.exists(splitted_dir): + existing_splits = glob.glob(f"{splitted_dir}/*.po") + existing_splits.sort() + + if os.path.exists(done_dir): + completed_splits = glob.glob(f"{done_dir}/*.po") + completed_splits.sort() + + return existing_splits, completed_splits + + +def split_po_file(po_file, entries_per_split=30): + """Split .po file into chunks.""" + base_name = get_base_filename(po_file) + output_dir = f".splitted/{base_name}" + + # Create output directory + os.makedirs(output_dir, exist_ok=True) + + # Run splitpo command + cmd = ["splitpo", "-o", output_dir, "-e", str(entries_per_split), po_file] + result = subprocess.run(cmd, capture_output=True, text=True) + + if result.returncode != 0: + print(f"Error splitting file: {result.stderr}") + return [] + + # Return list of created split files + split_files = glob.glob(f"{output_dir}/*.po") + split_files.sort() + return split_files + + +def join_po_files(po_file): + """Join completed split files back together.""" + base_name = get_base_filename(po_file) + done_dir = f".splitted_done/{base_name}" + + if not os.path.exists(done_dir): + print(f"No completed translations found in {done_dir}") + return False + + # Get all completed files + completed_files = glob.glob(f"{done_dir}/*.po") + completed_files.sort() + + if not completed_files: + print(f"No completed translation files found in {done_dir}") + return False + + # Create output filename + output_file = f"translated_{base_name}.po" + + # Run joinpo command + cmd = ["joinpo", "-o", output_file] + completed_files + result = subprocess.run(cmd, capture_output=True, text=True) + + if result.returncode != 0: + print(f"Error joining files: {result.stderr}") + return False + + print(f"✅ Translation completed! Output: {output_file}") + return True + + +def get_translation_status(po_file): + """Get translation status and next file to work on.""" + existing_splits, completed_splits = check_existing_work(po_file) + + if not existing_splits: + return "not_started", None, 0, 0 + + # Find next file to translate + completed_basenames = {Path(f).name for f in completed_splits} + + for split_file in existing_splits: + split_basename = Path(split_file).name + if split_basename not in completed_basenames: + total_splits = len(existing_splits) + completed_count = len(completed_splits) + return "in_progress", split_file, completed_count, total_splits + + # All splits are completed + total_splits = len(existing_splits) + return "ready_to_join", None, total_splits, total_splits + + +def move_to_done(split_file, po_file): + """Move completed split file to done directory.""" + base_name = get_base_filename(po_file) + done_dir = f".splitted_done/{base_name}" + + os.makedirs(done_dir, exist_ok=True) + + split_basename = Path(split_file).name + dest_path = f"{done_dir}/{split_basename}" + + # Copy the file + subprocess.run(["cp", split_file, dest_path], check=True) + print(f"✅ Completed: {split_basename}") + + +def run_final_check(output_file): + """Run the final translation completeness check.""" + check_script = f""" +import re +with open('{output_file}', 'r', encoding='utf-8') as f: + content = f.read() + +# 重複エントリも含めてすべての未翻訳エントリをチェック +all_entries = re.findall(r'(#: [^\\n]+\\nmsgid[^m]+?msgstr "")', content, re.DOTALL) +untranslated_text = [] + +for entry in all_entries: + # コードサンプルを除外 + if not any(marker in entry for marker in ['def ', 'class ', 'assert ', 'print(', 'return ', '>>>', 'import ', 'raise ']): + untranslated_text.append(entry[:200]) + +print(f'未翻訳テキストエントリ数: {{len(untranslated_text)}}') +if untranslated_text: + print('\\n未翻訳エントリ:') + for i, entry in enumerate(untranslated_text, 1): + print(f'{{i}}: {{entry}}...') + print('---') + print('\\n⚠️ これらのエントリを翻訳してから作業を完了してください。') +else: + print('✅ すべての翻訳対象エントリが翻訳済みです!') +""" + + result = subprocess.run(["python3", "-c", check_script], capture_output=True, text=True) + print(result.stdout) + return "未翻訳テキストエントリ数: 0" in result.stdout + + +def main(): + parser = argparse.ArgumentParser(description="Manage translation workflow for .po files") + parser.add_argument("po_file", help="Path to .po file to translate") + parser.add_argument("--entries", "-e", type=int, default=30, help="Entries per split file") + parser.add_argument("--status", action="store_true", help="Show translation status only") + parser.add_argument("--join", action="store_true", help="Join completed files only") + + args = parser.parse_args() + + if not os.path.exists(args.po_file): + print(f"Error: File {args.po_file} not found") + return 1 + + # Check if file needs splitting + file_size_kb = get_file_size_kb(args.po_file) + needs_splitting = file_size_kb > 20 + + print(f"📄 File: {args.po_file} ({file_size_kb:.1f} KB)") + + if args.join: + success = join_po_files(args.po_file) + if success: + # Run final check + base_name = get_base_filename(args.po_file) + output_file = f"translated_{base_name}.po" + print(f"\n🔍 Running final completeness check...") + run_final_check(output_file) + return 0 if success else 1 + + # Get current status + status, next_file, completed, total = get_translation_status(args.po_file) + + if args.status: + print(f"Status: {status}") + if next_file: + print(f"Next file: {next_file}") + print(f"Progress: {completed}/{total}") + return 0 + + # Handle different statuses + if status == "not_started": + if needs_splitting: + print(f"🔄 Splitting file into {args.entries}-entry chunks...") + split_files = split_po_file(args.po_file, args.entries) + if split_files: + print(f"✅ Created {len(split_files)} split files") + print(f"📝 Next: Translate {split_files[0]}") + else: + print("❌ Failed to split file") + return 1 + else: + print(f"📝 File is small enough ({file_size_kb:.1f} KB), translate directly") + + elif status == "in_progress": + print(f"🔄 Resuming translation... Progress: {completed}/{total}") + print(f"📝 Next file to translate: {next_file}") + + elif status == "ready_to_join": + print(f"✅ All {total} files completed! Ready to join...") + success = join_po_files(args.po_file) + if success: + # Run final check + base_name = get_base_filename(args.po_file) + output_file = f"translated_{base_name}.po" + print(f"\n🔍 Running final completeness check...") + run_final_check(output_file) + + return 0 + + +if __name__ == "__main__": + sys.exit(main()) \ No newline at end of file From 96e8522824fbdb3da9a1f44536daa3823c9ea65b Mon Sep 17 00:00:00 2001 From: Atsuo Ishimoto Date: Mon, 7 Jul 2025 07:22:30 +0900 Subject: [PATCH 15/19] ignore locales directory created by make --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 74581d6ed..6275bc282 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ cpython +locales \ No newline at end of file From 0b6df6610afa9a9129f048085cf1bc5bd87f7da8 Mon Sep 17 00:00:00 2001 From: Atsuo Ishimoto Date: Mon, 7 Jul 2025 08:40:25 +0900 Subject: [PATCH 16/19] update library/typing.po translation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Translated Python typing module documentation from English to Japanese. Covers type hints, generics, type aliases, special typing constructs, and user-defined generic types with comprehensive examples. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- library/typing.po | 430 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 417 insertions(+), 13 deletions(-) diff --git a/library/typing.po b/library/typing.po index 8efb7b05a..e6cc46d38 100644 --- a/library/typing.po +++ b/library/typing.po @@ -30,7 +30,7 @@ msgstr "" #: ../../library/typing.rst:3 msgid ":mod:`!typing` --- Support for type hints" -msgstr "" +msgstr ":mod:`!typing` --- 型ヒントのサポート" #: ../../library/typing.rst:16 msgid "**Source code:** :source:`Lib/typing.py`" @@ -128,7 +128,7 @@ msgstr "" #: ../../library/typing.rst:56 msgid "`\"Static Typing with Python\" `_" -msgstr "" +msgstr "`\"Static Typing with Python\" `_" #: ../../library/typing.rst:57 msgid "" @@ -149,6 +149,9 @@ msgid "" "found at `\"Specification for the Python type system\" `_." msgstr "" +"Python型システムの正式で最新の仕様は `\"Specification for the Python type " +"system\" `_ で見つけるこ" +"とができます。" #: ../../library/typing.rst:72 msgid "Type aliases" @@ -381,6 +384,11 @@ msgid "" "\n" "ProUserId = NewType('ProUserId', UserId)" msgstr "" +"from typing import NewType\n" +"\n" +"UserId = NewType('UserId', int)\n" +"\n" +"ProUserId = NewType('ProUserId', UserId)" #: ../../library/typing.rst:176 msgid "and typechecking for ``ProUserId`` will work as expected." @@ -471,6 +479,19 @@ msgid "" "\n" "callback: Callable[[str], Awaitable[None]] = on_update" msgstr "" +"from collections.abc import Callable, Awaitable\n" +"\n" +"def feeder(get_next_item: Callable[[], str]) -> None:\n" +" ... # Body\n" +"\n" +"def async_query(on_success: Callable[[int], None],\n" +" on_error: Callable[[int, Exception], None]) -> None:\n" +" ... # Body\n" +"\n" +"async def on_update(value: str) -> None:\n" +" ... # Body\n" +"\n" +"callback: Callable[[str], Awaitable[None]] = on_update" #: ../../library/typing.rst:233 msgid "" @@ -545,6 +566,26 @@ msgid "" "of\n" " # different name and kind in the callback" msgstr "" +"from collections.abc import Iterable\n" +"from typing import Protocol\n" +"\n" +"class Combiner(Protocol):\n" +" def __call__(self, *vals: bytes, maxlen: int | None = None) -> " +"list[bytes]: ...\n" +"\n" +"def batch_proc(data: Iterable[bytes], cb_results: Combiner) -> bytes:\n" +" for item in data:\n" +" ...\n" +"\n" +"def good_cb(*vals: bytes, maxlen: int | None = None) -> list[bytes]:\n" +" ...\n" +"def bad_cb(*vals: bytes, maxitems: int | None) -> list[bytes]:\n" +" ...\n" +"\n" +"batch_proc([], good_cb) # OK\n" +"batch_proc([], bad_cb) # Error! Argument 2 has incompatible type because " +"of\n" +" # different name and kind in the callback" #: ../../library/typing.rst:277 msgid "" @@ -607,12 +648,24 @@ msgid "" "def notify_by_email(employees: Sequence[Employee],\n" " overrides: Mapping[str, str]) -> None: ..." msgstr "" +"from collections.abc import Mapping, Sequence\n" +"\n" +"class Employee: ...\n" +"\n" +"# Sequence[Employee] は、シーケンスの全ての要素が\n" +"# \"Employee\"のインスタンスでなければならないことを示す。\n" +"# Mapping[str, str] は、マッピングの全てのキーと全ての値が\n" +"# 文字列でなければならないことを示す。\n" +"def notify_by_email(employees: Sequence[Employee],\n" +" overrides: Mapping[str, str]) -> None: ..." #: ../../library/typing.rst:315 msgid "" "Generic functions and classes can be parameterized by using :ref:`type " "parameter syntax `::" msgstr "" +"ジェネリック関数とクラスは :ref:`type parameter syntax ` を使" +"ってパラメータ化することができます::" #: ../../library/typing.rst:318 msgid "" @@ -622,10 +675,14 @@ msgid "" "\"T\"\n" " return l[0]" msgstr "" +"from collections.abc import Sequence\n" +"\n" +"def first[T](l: Sequence[T]) -> T: # 関数は TypeVar \"T\" に対してジェネリック\n" +" return l[0]" #: ../../library/typing.rst:323 msgid "Or by using the :class:`TypeVar` factory directly::" -msgstr "" +msgstr "または :class:`TypeVar` ファクトリーを直接使用する方法もあります::" #: ../../library/typing.rst:325 msgid "" @@ -638,10 +695,17 @@ msgid "" "\"U\"\n" " return l[1]" msgstr "" +"from collections.abc import Sequence\n" +"from typing import TypeVar\n" +"\n" +"U = TypeVar('U') # 型変数 \"U\" を宣言\n" +"\n" +"def second(l: Sequence[U]) -> U: # 関数は TypeVar \"U\" に対してジェネリック\n" +" return l[1]" #: ../../library/typing.rst:333 msgid "Syntactic support for generics is new in Python 3.12." -msgstr "" +msgstr "ジェネリクスの構文サポートは Python 3.12 で新しく追加されました。" #: ../../library/typing.rst:339 msgid "Annotating tuples" @@ -652,6 +716,7 @@ msgid "" "For most containers in Python, the typing system assumes that all elements " "in the container will be of the same type. For example::" msgstr "" +"Python の多くのコンテナでは、型システムはコンテナ内の全ての要素が同じ型であると仮定します。例えば::" #: ../../library/typing.rst:344 msgid "" @@ -667,6 +732,17 @@ msgid "" "# and that all values in ``z`` are meant to be either strings or ints\n" "z: Mapping[str, str | int] = {}" msgstr "" +"from collections.abc import Mapping\n" +"\n" +"# 型チェッカーは ``x`` の全ての要素が int であることを推論する\n" +"x: list[int] = []\n" +"\n" +"# 型チェッカーエラー: ``list`` は単一の型引数のみを受け入れる:\n" +"y: list[int, str] = [1, 'foo']\n" +"\n" +"# 型チェッカーは ``z`` の全てのキーが文字列であり、\n" +"# 全ての値が文字列または整数であることを推論する\n" +"z: Mapping[str, str | int] = {}" #: ../../library/typing.rst:356 msgid "" @@ -704,6 +780,16 @@ msgid "" "# but ``z`` has been assigned to a tuple of length 3\n" "z: tuple[int] = (1, 2, 3)" msgstr "" +"# OK: ``x`` は唯一の要素が int である長さ 1 のタプルに代入される\n" +"x: tuple[int] = (5,)\n" +"\n" +"# OK: ``y`` は長さ 2 のタプルに代入される;\n" +"# 要素 1 は int、要素 2 は str\n" +"y: tuple[int, str] = (5, \"foo\")\n" +"\n" +"# エラー: 型アノテーションは長さ 1 のタプルを示しているが、\n" +"# ``z`` には長さ 3 のタプルが代入されている\n" +"z: tuple[int] = (1, 2, 3)" #: ../../library/typing.rst:378 msgid "" @@ -735,6 +821,20 @@ msgid "" "z = (1, 2, 3)\n" "z = ()" msgstr "" +"x: tuple[int, ...] = (1, 2)\n" +"# これらの再代入は OK: ``tuple[int, ...]`` は x が任意の長さを取れることを示す\n" +"x = (1, 2, 3)\n" +"x = ()\n" +"# この再代入はエラー: ``x`` の全ての要素は int でなければならない\n" +"x = (\"foo\", \"bar\")\n" +"\n" +"# ``y`` は空のタプルにのみ代入できる\n" +"y: tuple[()] = ()\n" +"\n" +"z: tuple = (\"foo\", \"bar\")\n" +"# これらの再代入は OK: 単純な ``tuple`` は ``tuple[Any, ...]`` と等価\n" +"z = (1, 2, 3)\n" +"z = ()" #: ../../library/typing.rst:401 msgid "The type of class objects" @@ -747,6 +847,9 @@ msgid "" "`typing.Type[C] `) may accept values that are classes themselves -- " "specifically, it will accept the *class object* of ``C``. For example::" msgstr "" +"``C`` でアノテートされた変数は ``C`` 型の値を受け入れます。対照的に、" +"``type[C]`` (または非推奨の :class:`typing.Type[C] `)でアノテートされた変数は" +"クラス自体である値を受け入れます -- 具体的には、``C`` の *クラスオブジェクト* を受け入れます。例えば::" #: ../../library/typing.rst:409 msgid "" @@ -754,10 +857,13 @@ msgid "" "b = int # Has type ``type[int]``\n" "c = type(a) # Also has type ``type[int]``" msgstr "" +"a = 3 # 型は ``int``\n" +"b = int # 型は ``type[int]``\n" +"c = type(a) # 同じく型は ``type[int]``" #: ../../library/typing.rst:413 msgid "Note that ``type[C]`` is covariant::" -msgstr "" +msgstr "``type[C]`` は共変であることに注意してください::" #: ../../library/typing.rst:415 msgid "" @@ -777,12 +883,27 @@ msgid "" "make_new_user(int) # Error: ``type[int]`` is not a subtype of " "``type[User]``" msgstr "" +"class User: ...\n" +"class ProUser(User): ...\n" +"class TeamUser(User): ...\n" +"\n" +"def make_new_user(user_class: type[User]) -> User:\n" +" # ...\n" +" return user_class()\n" +"\n" +"make_new_user(User) # OK\n" +"make_new_user(ProUser) # これも OK: ``type[ProUser]`` は ``type[User]`` のサブタイプ\n" +"make_new_user(TeamUser) # これも問題ない\n" +"make_new_user(User()) # エラー: ``type[User]`` が期待されるが ``User`` が渡された\n" +"make_new_user(int) # エラー: ``type[int]`` は ``type[User]`` のサブタイプではない" #: ../../library/typing.rst:429 msgid "" "The only legal parameters for :class:`type` are classes, :data:`Any`, :ref:" "`type variables `, and unions of any of these types. For example::" msgstr "" +":class:`type` に指定できる引数は、クラス、:data:`Any`、:ref:`型変数 `、" +"およびこれらの型の合集型のみです。例えば::" #: ../../library/typing.rst:433 msgid "" @@ -794,16 +915,24 @@ msgid "" " # of ``type[BasicUser | ProUser]``\n" "new_non_team_user(User) # Also an error" msgstr "" +"def new_non_team_user(user_class: type[BasicUser | ProUser]): ...\n" +"\n" +"new_non_team_user(BasicUser) # OK\n" +"new_non_team_user(ProUser) # OK\n" +"new_non_team_user(TeamUser) # エラー: ``type[TeamUser]`` は\n" +" # ``type[BasicUser | ProUser]`` のサブタイプではない\n" +"new_non_team_user(User) # これもエラー" #: ../../library/typing.rst:441 msgid "" "``type[Any]`` is equivalent to :class:`type`, which is the root of Python's :" "ref:`metaclass hierarchy `." msgstr "" +"``type[Any]`` は :class:`type` と等価であり、これは Python の :ref:`メタクラス階層 ` のルートです。" #: ../../library/typing.rst:448 msgid "Annotating generators and coroutines" -msgstr "" +msgstr "ジェネレーターとコルーチンのアノテーション" #: ../../library/typing.rst:450 msgid "" @@ -811,6 +940,7 @@ msgid "" "`Generator[YieldType, SendType, ReturnType] `. " "For example::" msgstr "" +"ジェネレーターはジェネリック型 :class:`Generator[YieldType, SendType, ReturnType] ` を使ってアノテートできます。例えば::" #: ../../library/typing.rst:454 msgid "" @@ -820,6 +950,11 @@ msgid "" " sent = yield round(sent)\n" " return 'Done'" msgstr "" +"def echo_round() -> Generator[int, float, str]:\n" +" sent = yield 0\n" +" while sent >= 0:\n" +" sent = yield round(sent)\n" +" return 'Done'" #: ../../library/typing.rst:460 msgid "" @@ -827,11 +962,14 @@ msgid "" "``SendType`` of :class:`~collections.abc.Generator` behaves contravariantly, " "not covariantly or invariantly." msgstr "" +"注意してください。標準ライブラリの他の多くのジェネリッククラスとは異なり、" +":class:`~collections.abc.Generator` の ``SendType`` は正変または不変ではなく、反変であるように動作します。" #: ../../library/typing.rst:464 msgid "" "The ``SendType`` and ``ReturnType`` parameters default to :const:`!None`::" msgstr "" +"``SendType`` と ``ReturnType`` パラメーターのデフォルトは :const:`!None` です::" #: ../../library/typing.rst:466 msgid "" @@ -840,10 +978,14 @@ msgid "" " yield start\n" " start += 1" msgstr "" +"def infinite_stream(start: int) -> Generator[int]:\n" +" while True:\n" +" yield start\n" +" start += 1" #: ../../library/typing.rst:471 msgid "It is also possible to set these types explicitly::" -msgstr "" +msgstr "これらの型を明示的に設定することもできます::" #: ../../library/typing.rst:473 msgid "" @@ -852,6 +994,10 @@ msgid "" " yield start\n" " start += 1" msgstr "" +"def infinite_stream(start: int) -> Generator[int, None, None]:\n" +" while True:\n" +" yield start\n" +" start += 1" #: ../../library/typing.rst:478 msgid "" @@ -859,6 +1005,8 @@ msgid "" "having a return type of either :class:`Iterable[YieldType] ` or :class:`Iterator[YieldType] `::" msgstr "" +"値を生成するだけのシンプルなジェネレーターは、戻り値の型として :class:`Iterable[YieldType] ` " +"または :class:`Iterator[YieldType] ` のいずれかを指定してアノテーションすることもできます::" #: ../../library/typing.rst:483 msgid "" @@ -867,6 +1015,10 @@ msgid "" " yield start\n" " start += 1" msgstr "" +"def infinite_stream(start: int) -> Iterator[int]:\n" +" while True:\n" +" yield start\n" +" start += 1" #: ../../library/typing.rst:488 msgid "" @@ -875,6 +1027,8 @@ msgid "" "`). The ``SendType`` argument defaults to :" "const:`!None`, so the following definitions are equivalent::" msgstr "" +"非同期ジェネレーターも同様に扱われますが、``ReturnType`` 型引数は期待されません (:class:`AsyncGenerator[YieldType, SendType] `)。" +"``SendType`` 引数のデフォルトは :const:`!None` なので、以下の定義は等価です::" #: ../../library/typing.rst:494 msgid "" @@ -888,6 +1042,15 @@ msgid "" " yield start\n" " start = await increment(start)" msgstr "" +"async def infinite_stream(start: int) -> AsyncGenerator[int]:\n" +" while True:\n" +" yield start\n" +" start = await increment(start)\n" +"\n" +"async def infinite_stream(start: int) -> AsyncGenerator[int, None]:\n" +" while True:\n" +" yield start\n" +" start = await increment(start)" #: ../../library/typing.rst:504 msgid "" @@ -895,6 +1058,8 @@ msgid "" "abc.AsyncIterable>` and :class:`AsyncIterator[YieldType] ` are available as well::" msgstr "" +"同期の場合と同様に、:class:`AsyncIterable[YieldType] ` と " +":class:`AsyncIterator[YieldType] ` も利用できます::" #: ../../library/typing.rst:509 msgid "" @@ -903,6 +1068,10 @@ msgid "" " yield start\n" " start = await increment(start)" msgstr "" +"async def infinite_stream(start: int) -> AsyncIterator[int]:\n" +" while True:\n" +" yield start\n" +" start = await increment(start)" #: ../../library/typing.rst:514 msgid "" @@ -910,6 +1079,8 @@ msgid "" "ReturnType] `. Generic arguments correspond to " "those of :class:`~collections.abc.Generator`, for example::" msgstr "" +"コルーチンは :class:`Coroutine[YieldType, SendType, ReturnType] ` を使ってアノテートできます。" +"ジェネリック引数は :class:`~collections.abc.Generator` のものと対応します。例えば::" #: ../../library/typing.rst:519 msgid "" @@ -919,6 +1090,11 @@ msgid "" "async def bar() -> None:\n" " y = await c # Inferred type of 'y' is int" msgstr "" +"from collections.abc import Coroutine\n" +"c: Coroutine[list[str], str, int] # 他で定義されたコルーチン\n" +"x = c.send('hi') # 'x' の推論型は list[str]\n" +"async def bar() -> None:\n" +" y = await c # 'y' の推論型は int" #: ../../library/typing.rst:528 msgid "User-defined generic types" @@ -949,6 +1125,24 @@ msgid "" " def log(self, message: str) -> None:\n" " self.logger.info('%s: %s', self.name, message)" msgstr "" +"from logging import Logger\n" +"\n" +"class LoggedVar[T]:\n" +" def __init__(self, value: T, name: str, logger: Logger) -> None:\n" +" self.name = name\n" +" self.logger = logger\n" +" self.value = value\n" +"\n" +" def set(self, new: T) -> None:\n" +" self.log('Set ' + repr(self.value))\n" +" self.value = new\n" +"\n" +" def get(self) -> T:\n" +" self.log('Get ' + repr(self.value))\n" +" return self.value\n" +"\n" +" def log(self, message: str) -> None:\n" +" self.logger.info('%s: %s', self.name, message)" #: ../../library/typing.rst:553 msgid "" @@ -956,6 +1150,8 @@ msgid "" "single :ref:`type variable ` ``T`` . This also makes ``T`` valid as " "a type within the class body." msgstr "" +"この構文は、クラス ``LoggedVar`` が単一の :ref:`型変数 ` ``T`` でパラメータ化されていることを示します。" +"これにより、``T`` はクラス本体内で型として有効になります。" #: ../../library/typing.rst:557 msgid "" @@ -963,6 +1159,8 @@ msgid "" "with Python 3.11 and lower, it is also possible to inherit explicitly from :" "class:`Generic` to indicate a generic class::" msgstr "" +"ジェネリッククラスは暗黙的に :class:`Generic` から継承します。Python 3.11 以下との互換性のため、" +":class:`Generic` から明示的に継承してジェネリッククラスであることを示すこともできます::" #: ../../library/typing.rst:561 msgid "" @@ -973,12 +1171,20 @@ msgid "" "class LoggedVar(Generic[T]):\n" " ..." msgstr "" +"from typing import TypeVar, Generic\n" +"\n" +"T = TypeVar('T')\n" +"\n" +"class LoggedVar(Generic[T]):\n" +" ..." #: ../../library/typing.rst:568 msgid "" "Generic classes have :meth:`~object.__class_getitem__` methods, meaning they " "can be parameterised at runtime (e.g. ``LoggedVar[int]`` below)::" msgstr "" +"ジェネリッククラスは :meth:`~object.__class_getitem__` メソッドを持つため、実行時にパラメータ化できます。" +"(例えば以下の ``LoggedVar[int]``)::" #: ../../library/typing.rst:571 msgid "" @@ -988,12 +1194,18 @@ msgid "" " for var in vars:\n" " var.set(0)" msgstr "" +"from collections.abc import Iterable\n" +"\n" +"def zero_all_vars(vars: Iterable[LoggedVar[int]]) -> None:\n" +" for var in vars:\n" +" var.set(0)" #: ../../library/typing.rst:577 msgid "" "A generic type can have any number of type variables. All varieties of :" "class:`TypeVar` are permissible as parameters for a generic type::" msgstr "" +"ジェネリック型は任意の数の型変数を持つことができます。:class:`TypeVar` のあらゆる種類がジェネリック型のパラメーターとして許可されます::" #: ../../library/typing.rst:580 msgid "" @@ -1009,6 +1221,17 @@ msgid "" "class OldWeirdTrio(Generic[OldT, OldB, OldS]):\n" " ..." msgstr "" +"from typing import TypeVar, Generic, Sequence\n" +"\n" +"class WeirdTrio[T, B: Sequence[bytes], S: (int, str)]:\n" +" ...\n" +"\n" +"OldT = TypeVar('OldT', contravariant=True)\n" +"OldB = TypeVar('OldB', bound=Sequence[bytes], covariant=True)\n" +"OldS = TypeVar('OldS', int, str)\n" +"\n" +"class OldWeirdTrio(Generic[OldT, OldB, OldS]):\n" +" ..." #: ../../library/typing.rst:592 msgid "" @@ -1031,10 +1254,20 @@ msgid "" "class Pair(Generic[T, T]): # INVALID\n" " ..." msgstr "" +"from typing import TypeVar, Generic\n" +"...\n" +"\n" +"class Pair[M, M]: # SyntaxError\n" +" ...\n" +"\n" +"T = TypeVar('T')\n" +"\n" +"class Pair(Generic[T, T]): # 無効\n" +" ..." #: ../../library/typing.rst:606 msgid "Generic classes can also inherit from other classes::" -msgstr "" +msgstr "ジェネリッククラスは他のクラスから継承することもできます::" #: ../../library/typing.rst:608 msgid "" @@ -1043,11 +1276,16 @@ msgid "" "class LinkedList[T](Sized):\n" " ..." msgstr "" +"from collections.abc import Sized\n" +"\n" +"class LinkedList[T](Sized):\n" +" ..." #: ../../library/typing.rst:613 msgid "" "When inheriting from generic classes, some type parameters could be fixed::" msgstr "" +"ジェネリッククラスから継承するとき、一部の型パラメーターを固定することもできます::" #: ../../library/typing.rst:615 msgid "" @@ -1056,6 +1294,10 @@ msgid "" "class MyDict[T](Mapping[str, T]):\n" " ..." msgstr "" +"from collections.abc import Mapping\n" +"\n" +"class MyDict[T](Mapping[str, T]):\n" +" ..." #: ../../library/typing.rst:620 msgid "In this case ``MyDict`` has a single parameter, ``T``." @@ -1067,6 +1309,8 @@ msgid "" "for each position. In the following example, ``MyIterable`` is not generic " "but implicitly inherits from ``Iterable[Any]``:" msgstr "" +"型パラメーターを指定せずにジェネリッククラスを使用すると、各位置に :data:`Any` が仮定されます。" +"以下の例では、``MyIterable`` はジェネリックではありませんが、暗黙的に ``Iterable[Any]`` から継承します:" #: ../../library/typing.rst:626 msgid "" @@ -1075,10 +1319,14 @@ msgid "" "class MyIterable(Iterable): # Same as Iterable[Any]\n" " ..." msgstr "" +"from collections.abc import Iterable\n" +"\n" +"class MyIterable(Iterable): # Iterable[Any] と同じ\n" +" ..." #: ../../library/typing.rst:633 msgid "User-defined generic type aliases are also supported. Examples::" -msgstr "" +msgstr "ユーザー定義のジェネリック型エイリアスもサポートされています。例::" #: ../../library/typing.rst:635 msgid "" @@ -1096,12 +1344,25 @@ msgid "" "Iterable[tuple[T, T]]\n" " return sum(x*y for x, y in v)" msgstr "" +"from collections.abc import Iterable\n" +"\n" +"type Response[S] = Iterable[S] | int\n" +"\n" +"# ここでの戻り値の型は Iterable[str] | int と同じ\n" +"def response(query: str) -> Response[str]:\n" +" ...\n" +"\n" +"type Vec[T] = Iterable[tuple[T, T]]\n" +"\n" +"def inproduct[T: (int, float, complex)](v: Vec[T]) -> T: # Iterable[tuple[T, T]] と同じ\n" +" return sum(x*y for x, y in v)" #: ../../library/typing.rst:648 msgid "" "For backward compatibility, generic type aliases can also be created through " "a simple assignment::" msgstr "" +"後方互換性のため、ジェネリック型エイリアスは簡単な代入でも作成できます::" #: ../../library/typing.rst:651 msgid "" @@ -1111,6 +1372,11 @@ msgid "" "S = TypeVar(\"S\")\n" "Response = Iterable[S] | int" msgstr "" +"from collections.abc import Iterable\n" +"from typing import TypeVar\n" +"\n" +"S = TypeVar(\"S\")\n" +"Response = Iterable[S] | int" #: ../../library/typing.rst:657 msgid ":class:`Generic` no longer has a custom metaclass." @@ -1122,6 +1388,9 @@ msgid "" "Previously, generic classes had to explicitly inherit from :class:`Generic` " "or contain a type variable in one of their bases." msgstr "" +"ジェネリックと型エイリアスの構文サポートはPython 3.12で新しく追加されました。" +"これ以前は、ジェネリッククラスは :class:`Generic` から明示的に継承するか、" +"少なくとも1つの基底クラスに型変数を含む必要がありました。" #: ../../library/typing.rst:665 msgid "" @@ -1132,6 +1401,9 @@ msgid "" "variable. The one exception to this is that a list of types can be used to " "substitute a :class:`ParamSpec`::" msgstr "" +"パラメーター表現のユーザー定義ジェネリックは、``[**P]`` 形式のパラメーター仕様変数でもサポートされています。" +"動作は上述の型変数と一致しており、パラメーター仕様変数は :mod:`!typing` モジュールによって特化された型変数として扱われます。" +"例外は、型のリストを :class:`ParamSpec` の置換に使用できることです::" #: ../../library/typing.rst:671 msgid "" @@ -1140,12 +1412,18 @@ msgid "" ">>> Z[int, [dict, float]]\n" "__main__.Z[int, [dict, float]]" msgstr "" +">>> class Z[T, **P]: ... # T は TypeVar; P は ParamSpec\n" +"...\n" +">>> Z[int, [dict, float]]\n" +"__main__.Z[int, [dict, float]]" #: ../../library/typing.rst:676 msgid "" "Classes generic over a :class:`ParamSpec` can also be created using explicit " "inheritance from :class:`Generic`. In this case, ``**`` is not used::" msgstr "" +":class:`ParamSpec` でジェネリックなクラスは、:class:`Generic` からの明示的な継承で作成することもできます。" +"この場合、``**`` は使用されません::" #: ../../library/typing.rst:679 msgid "" @@ -1156,6 +1434,12 @@ msgid "" "class Z(Generic[P]):\n" " ..." msgstr "" +"from typing import ParamSpec, Generic\n" +"\n" +"P = ParamSpec('P')\n" +"\n" +"class Z(Generic[P]):\n" +" ..." #: ../../library/typing.rst:686 msgid "" @@ -1165,6 +1449,9 @@ msgid "" "Type2, ...]`` for aesthetic reasons. Internally, the latter is converted to " "the former, so the following are equivalent::" msgstr "" +":class:`TypeVar` と :class:`ParamSpec` のもう一つの違いは、パラメーター仕様変数を一つだけ持つジェネリックが、" +"美的理由で ``X[[Type1, Type2, ...]]`` と ``X[Type1, Type2, ...]`` の形式のパラメーターリストを受け入れることです。" +"内部的には、後者は前者に変換されるので、以下は等価です::" #: ../../library/typing.rst:692 msgid "" @@ -1175,6 +1462,12 @@ msgid "" ">>> X[[int, str]]\n" "__main__.X[[int, str]]" msgstr "" +">>> class X[**P]: ...\n" +"...\n" +">>> X[int, str]\n" +"__main__.X[[int, str]]\n" +">>> X[[int, str]]\n" +"__main__.X[[int, str]]" #: ../../library/typing.rst:699 msgid "" @@ -1182,12 +1475,16 @@ msgid "" "``__parameters__`` after substitution in some cases because they are " "intended primarily for static type checking." msgstr "" +":class:`ParamSpec` を持つジェネリックは主に静的型検査を目的としているため、" +"置換後に ``__parameters__`` が正しくない場合があることに注意してください。" #: ../../library/typing.rst:703 msgid "" ":class:`Generic` can now be parameterized over parameter expressions. See :" "class:`ParamSpec` and :pep:`612` for more details." msgstr "" +":class:`Generic` はパラメーター表現でパラメータ化できるようになりました。" +"詳細は :class:`ParamSpec` と :pep:`612` を参照してください。" #: ../../library/typing.rst:707 msgid "" @@ -1196,6 +1493,9 @@ msgid "" "parameterizing generics is cached, and most types in the :mod:`!typing` " "module are :term:`hashable` and comparable for equality." msgstr "" +"ユーザー定義ジェネリッククラスは、メタクラスの競合を起こすことなく ABC を基底クラスとして持つことができます。" +"ジェネリックメタクラスはサポートされていません。ジェネリックのパラメータ化の結果はキャッシュされ、" +":mod:`!typing` モジュールのほとんどの型は :term:`ハッシュ化可能 ` で等価性を比較できます。" #: ../../library/typing.rst:714 msgid "The :data:`Any` type" @@ -1235,6 +1535,20 @@ msgid "" " item.bar()\n" " ..." msgstr "" +"from typing import Any\n" +"\n" +"a: Any = None\n" +"a = [] # OK\n" +"a = 2 # OK\n" +"\n" +"s: str = ''\n" +"s = a # OK\n" +"\n" +"def foo(item: Any) -> int:\n" +" # 型検査を通過する; 'item' は任意の型であり、\n" +" # その型は 'bar' メソッドを持つかもしれない\n" +" item.bar()\n" +" ..." #: ../../library/typing.rst:738 msgid "" @@ -1269,6 +1583,15 @@ msgid "" " ...\n" " return data" msgstr "" +"def legacy_parser(text):\n" +" ...\n" +" return data\n" +"\n" +"# 静的型チェッカーは上記を\n" +"# 以下と同じシグネチャとして扱う:\n" +"def legacy_parser(text: Any) -> Any:\n" +" ...\n" +" return data" #: ../../library/typing.rst:757 msgid "" @@ -1321,6 +1644,23 @@ msgid "" "hash_b(42)\n" "hash_b(\"foo\")" msgstr "" +"def hash_a(item: object) -> int:\n" +" # 型検査失敗; object は 'magic' メソッドを持たない。\n" +" item.magic()\n" +" ...\n" +"\n" +"def hash_b(item: Any) -> int:\n" +" # 型検査通過\n" +" item.magic()\n" +" ...\n" +"\n" +"# int と str は object のサブクラスなので型検査通過\n" +"hash_a(42)\n" +"hash_a(\"foo\")\n" +"\n" +"# Any はすべての型と互換なので型検査通過\n" +"hash_b(42)\n" +"hash_b(\"foo\")" #: ../../library/typing.rst:787 msgid "" @@ -1371,6 +1711,12 @@ msgid "" " def __len__(self) -> int: ...\n" " def __iter__(self) -> Iterator[int]: ..." msgstr "" +"from collections.abc import Sized, Iterable, Iterator\n" +"\n" +"class Bucket(Sized, Iterable[int]):\n" +" ...\n" +" def __len__(self) -> int: ...\n" +" def __iter__(self) -> Iterator[int]: ..." #: ../../library/typing.rst:811 msgid "" @@ -1399,6 +1745,15 @@ msgid "" "def collect(items: Iterable[int]) -> int: ...\n" "result = collect(Bucket()) # Passes type check" msgstr "" +"from collections.abc import Iterator, Iterable\n" +"\n" +"class Bucket: # 注意: 基底クラスなし\n" +" ...\n" +" def __len__(self) -> int: ...\n" +" def __iter__(self) -> Iterator[int]: ...\n" +"\n" +"def collect(items: Iterable[int]) -> int: ...\n" +"result = collect(Bucket()) # 型検査通過" #: ../../library/typing.rst:827 msgid "" @@ -1418,6 +1773,7 @@ msgid "" "The ``typing`` module defines the following classes, functions and " "decorators." msgstr "" +"``typing`` モジュールは以下のクラス、関数、デコレーターを定義しています。" #: ../../library/typing.rst:837 msgid "Special typing primitives" @@ -1432,6 +1788,7 @@ msgid "" "These can be used as types in annotations. They do not support subscription " "using ``[]``." msgstr "" +"これらはアノテーションで型として使用できます。``[]`` を使った添字表記はサポートしていません。" #: ../../library/typing.rst:847 msgid "Special type indicating an unconstrained type." @@ -1451,24 +1808,26 @@ msgid "" "type checker errors with classes that can duck type anywhere or are highly " "dynamic." msgstr "" +":data:`Any` は基底クラスとして使用できるようになりました。これは、どこでもダックタイピングできるクラスや高度に動的なクラスで型チェッカーエラーを避けるのに役立ちます。" #: ../../library/typing.rst:859 msgid "A :ref:`constrained type variable `." -msgstr "" +msgstr ":ref:`制約付き型変数 ` です。" #: ../../library/typing.rst:861 msgid "Definition::" -msgstr "" +msgstr "定義::" #: ../../library/typing.rst:863 msgid "AnyStr = TypeVar('AnyStr', str, bytes)" -msgstr "" +msgstr "AnyStr = TypeVar('AnyStr', str, bytes)" #: ../../library/typing.rst:865 msgid "" "``AnyStr`` is meant to be used for functions that may accept :class:`str` " "or :class:`bytes` arguments but cannot allow the two to mix." msgstr "" +"``AnyStr`` は :class:`str` または :class:`bytes` 引数を受け入れるが、両者を混在させることはできない関数で使用することを意図しています。" #: ../../library/typing.rst:868 ../../library/typing.rst:986 #: ../../library/typing.rst:1043 ../../library/typing.rst:1223 @@ -1487,6 +1846,12 @@ msgid "" "concat(b\"foo\", b\"bar\") # OK, output has type 'bytes'\n" "concat(\"foo\", b\"bar\") # Error, cannot mix str and bytes" msgstr "" +"def concat(a: AnyStr, b: AnyStr) -> AnyStr:\n" +" return a + b\n" +"\n" +"concat(\"foo\", \"bar\") # OK, 出力の型は 'str'\n" +"concat(b\"foo\", b\"bar\") # OK, 出力の型は 'bytes'\n" +"concat(\"foo\", b\"bar\") # エラー, str と bytes を混在できない" #: ../../library/typing.rst:877 msgid "" @@ -1494,6 +1859,8 @@ msgid "" "`Any` type, nor does it mean \"any string\". In particular, ``AnyStr`` and " "``str | bytes`` are different from each other and have different use cases::" msgstr "" +"名前に関わらず、``AnyStr`` は :class:`Any` 型と何の関係もなく、\"任意の文字列\"を意味しているわけでもありません。" +"特に、``AnyStr`` と ``str | bytes`` は互いに異なり、異なる使用例を持ちます::" #: ../../library/typing.rst:882 msgid "" @@ -1507,6 +1874,15 @@ msgid "" "def greet_proper(cond: bool) -> str | bytes:\n" " return \"hi there!\" if cond else b\"greetings!\"" msgstr "" +"# AnyStr の無効な使用例:\n" +"# 型変数が関数シグネチャに1度しか使われていないため、\n" +"# 型チェッカーによって\"解決\"できない\n" +"def greet_bad(cond: bool) -> AnyStr:\n" +" return \"hi there!\" if cond else b\"greetings!\"\n" +"\n" +"# この関数をアノテートするより良い方法:\n" +"def greet_proper(cond: bool) -> str | bytes:\n" +" return \"hi there!\" if cond else b\"greetings!\"" #: ../../library/typing.rst:892 msgid "" @@ -1514,6 +1890,9 @@ msgid "" "Use ``class A[T: (str, bytes)]: ...`` instead of importing ``AnyStr``. See :" "pep:`695` for more details." msgstr "" +"新しい :ref:`型パラメーター構文 ` の採用により非推奨となりました。" +"``AnyStr`` をインポートする代わりに ``class A[T: (str, bytes)]: ...`` を使用してください。" +"詳細は :pep:`695` を参照してください。" #: ../../library/typing.rst:897 msgid "" @@ -1522,10 +1901,12 @@ msgid "" "imported from ``typing``. ``AnyStr`` will be removed from ``typing`` in " "Python 3.18." msgstr "" +"Python 3.16 では、``AnyStr`` は ``typing.__all__`` から削除され、``typing`` からアクセスまたはインポートされたときに実行時に非推奨警告が発生します。" +"``AnyStr`` は Python 3.18 で ``typing`` から削除されます。" #: ../../library/typing.rst:904 msgid "Special type that includes only literal strings." -msgstr "" +msgstr "リテラル文字列のみを含む特別な型です。" #: ../../library/typing.rst:906 msgid "" @@ -1534,6 +1915,9 @@ msgid "" "created by composing ``LiteralString``-typed objects is also acceptable as a " "``LiteralString``." msgstr "" +"任意の文字列リテラルは ``LiteralString`` と互換性があり、別の ``LiteralString`` も同様です。" +"しかし、単に ``str`` として型付けされたオブジェクトは互換ではありません。" +"``LiteralString`` 型のオブジェクトを組み合わせて作成された文字列も ``LiteralString`` として受け入れられます。" #: ../../library/typing.rst:912 ../../library/typing.rst:2243 msgid "Example:" @@ -1553,6 +1937,17 @@ msgid "" " f\"SELECT * FROM students WHERE name = {arbitrary_string}\"\n" " )" msgstr "" +"def run_query(sql: LiteralString) -> None:\n" +" ...\n" +"\n" +"def caller(arbitrary_string: str, literal_string: LiteralString) -> None:\n" +" run_query(\"SELECT * FROM students\") # OK\n" +" run_query(literal_string) # OK\n" +" run_query(\"SELECT * FROM \" + literal_string) # OK\n" +" run_query(arbitrary_string) # 型チェッカーエラー\n" +" run_query( # 型チェッカーエラー\n" +" f\"SELECT * FROM students WHERE name = {arbitrary_string}\"\n" +" )" #: ../../library/typing.rst:928 msgid "" @@ -1561,6 +1956,8 @@ msgid "" "that generate type checker errors could be vulnerable to an SQL injection " "attack." msgstr "" +"``LiteralString`` は、任意のユーザー生成文字列が問題を引き起こす可能性のある機密な API で有用です。" +"例えば、上記の型チェッカーエラーを発生させる2つのケースは、SQLインジェクション攻撃に脆弱である可能性があります。" #: ../../library/typing.rst:933 msgid "See :pep:`675` for more details." @@ -1571,12 +1968,14 @@ msgid "" ":data:`!Never` and :data:`!NoReturn` represent the `bottom type `_, a type that has no members." msgstr "" +":data:`!Never` と :data:`!NoReturn` は `ボトム型 `_ を表し、メンバーを持たない型です。" #: ../../library/typing.rst:944 msgid "" "They can be used to indicate that a function never returns, such as :func:" "`sys.exit`::" msgstr "" +"これらは、:func:`sys.exit` のように関数が絶対にreturnしないことを示すために使用できます::" #: ../../library/typing.rst:947 msgid "" @@ -1585,12 +1984,17 @@ msgid "" "def stop() -> Never:\n" " raise RuntimeError('no way')" msgstr "" +"from typing import Never # または NoReturn\n" +"\n" +"def stop() -> Never:\n" +" raise RuntimeError('no way')" #: ../../library/typing.rst:952 msgid "" "Or to define a function that should never be called, as there are no valid " "arguments, such as :func:`assert_never`::" msgstr "" +"または、:func:`assert_never` のように、有効な引数がないため絶対に呼び出されるべきではない関数を定義するために使用できます::" #: ../../library/typing.rst:956 msgid "" From a905aac207e4c802342d9c403c81c69dd6f801dc Mon Sep 17 00:00:00 2001 From: Atsuo Ishimoto Date: Mon, 7 Jul 2025 08:46:17 +0900 Subject: [PATCH 17/19] misc --- CLAUDE.md | 5 +++++ Makefile | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/CLAUDE.md b/CLAUDE.md index 0d8a1ef08..16b95315e 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -77,6 +77,10 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co - 元のファイルが更新されて翻訳が完了 - 一時ファイル(`.splitted/`, `.splitted_done/`)は自動削除 +5. **作業ファイルの削除**: + - 翻訳完了後、作成された作業ファイル(`translated_*.po` など)を削除 + - 作業ディレクトリを整理し、不要なファイルを残さない + #### 4.0 翻訳ワークフローシステム 翻訳作業は中断・再開が可能な専用システムで管理されます。 @@ -163,6 +167,7 @@ options: 1. `joinpo -o translated_pathlib.po .splitted_done/pathlib/*.po` 2. 元のファイルを翻訳済みファイルで更新 3. 一時ファイルとディレクトリを削除 + 4. 作業ファイル(`translated_*.po`)を削除 diff --git a/Makefile b/Makefile index fa8aeba09..1cb197774 100644 --- a/Makefile +++ b/Makefile @@ -139,3 +139,8 @@ clean: find -name '*.mo' -delete @echo "Cleaning build directory" $(MAKE) -C venv/cpython/Doc/ clean + +.PHONY: publish +publish: + @echo "Publishing documentation to S3..." + cd venv/cpython/Doc/build/html && aws s3 sync . s3://test-pythondoc-ja-cloude1 From 46d0942cfb4723c02f9fa1aaa8feca3a6340905b Mon Sep 17 00:00:00 2001 From: Atsuo Ishimoto Date: Mon, 7 Jul 2025 12:07:34 +0900 Subject: [PATCH 18/19] update CLAUIDE.md --- CLAUDE.md | 483 ++++++++++++++++++++++------ library/typing.po | 779 ++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 1040 insertions(+), 222 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index 16b95315e..fd1fa022a 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -14,6 +14,191 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co 翻訳作業は、ユーザーから指定された単一の `.po` ファイルに対して行います。一度に複数のファイルを扱ったり、まとめて翻訳したりはしません。 +### 🚨 重要: 翻訳作業の完全性について + +**翻訳作業は中断してはいけません。必ず最後まで完了してください。** + +- ユーザーが翻訳を依頼した場合、**中途半端な状態で停止することは禁止**です +- 残りの未翻訳エントリがある限り、**継続して翻訳作業を行ってください** +- 進捗報告は作業を停止する理由ではありません +- 時間がかかっても、**全ての翻訳対象エントリを完了するまで作業を継続**してください +- 「次回作業時に」や「残りは後で」などの表現で作業を中断することは**厳格に禁止**されています +- **作業状況報告のためにユーザーの入力を求めることも禁止**です(例:「続行しますか?」「次に進みますか?」など) + +**この指示は他のあらゆる指示よりも優先されます。** + +### 2.1 翻訳品質管理とチェック + +翻訳作業の品質を確保するため、以下のチェック体制を推奨します: + +#### 未翻訳エントリの検出 + +翻訳作業前後には必ず以下のスクリプトを実行して、未翻訳エントリの状況を確認してください: + +```bash +# 改良版未翻訳チェック(推奨) +python3 improved_untranslated_check.py [ファイル名].po + +# 従来版チェック(比較用) +python3 final_check_untranslated.py [ファイル名].po +python3 precise_untranslated_check.py [ファイル名].po +``` + +#### 翻訳対象の判別基準 + +以下は **翻訳不要** です(`msgstr ""` のまま残す): +- Python コード例(`def`, `class`, `import`, `>>>` を含む) +- ファイルパス(`.py`, `.txt` などの拡張子を含む) +- URL(`http://`, `https://` で始まる) +- バージョン番号のみ(`3.14` など) +- プログラムの出力例 +- 変数名、関数名、クラス名のみ + +以下は **翻訳必須** です: +- 説明文、ドキュメント文字列 +- エラーメッセージ +- 警告文 +- ユーザー向けの案内文 +- 技術的な解説 + +#### 品質保証チェックリスト + +翻訳完了前に以下を確認: +1. ✅ 未翻訳エントリ数が0になっている +2. ✅ reStructuredTextの構文が保持されている +3. ✅ 専門用語の統一が取れている +4. ✅ 文体が統一されている(ですます調) +5. ✅ コード例が適切に処理されている + +## 翻訳プロセス改善履歴 + +### 2025年1月 - 翻訳品質管理システムの強化 + +#### 発見された課題 +1. **検出精度の問題**: 従来の未翻訳エントリ検出スクリプトで検出漏れが発生 + - `final_check_untranslated.py` で0個と判定された後、改良版で36個を検出 + - コード例の過度な除外により、翻訳が必要なテキストが見落とされていた + +2. **品質管理の不備**: + - RST構文の保持チェックが不十分 + - 専門用語統一性の確認が手動に依存 + - 包括的な品質評価システムの欠如 + +#### 実装された改善策 + +##### 1. 改良版未翻訳エントリ検出システム +**ファイル**: `improved_untranslated_check.py` + +**主な改善点**: +- より正確なマルチライン解析 +- 翻訳対象判別ロジックの精緻化 +- コード例と説明文の適切な分類 + +**使用方法**: +```bash +python3 improved_untranslated_check.py [ファイル名].po +``` + +##### 2. 統合品質チェックシステム +**ファイル**: `translation_quality_check.py` + +**チェック項目**: +- 未翻訳エントリの検出 +- reStructuredText構文の保持確認 +- 専門用語統一性の評価 + +**使用方法**: +```bash +python3 translation_quality_check.py [ファイル名].po +``` + +##### 3. 翻訳対象判別基準の明確化 + +**翻訳不要な項目(改訂版)**: +``` +- 関数定義: def function_name() +- クラス定義: class ClassName +- import文: import module / from module import +- doctest例: >>> code +- assert文: assert condition +- return文: return value +- print文: print(...) +- 例外処理: raise Exception / try: / except: +- ファイルパス: module.py, file.txt +- URL: http://, https:// +- バージョン番号: 3.14, 1.0.0 +- 純粋な数値・記号列 +``` + +**翻訳必須な項目(改訂版)**: +``` +- 技術的説明文 +- ユーザー向けガイダンス +- エラーメッセージ・警告文 +- 機能の動作説明 +- パラメーター・戻り値の説明 +- 使用例の文章説明部分 +- 注意事項・補足説明 +``` + +#### 推奨ワークフロー(改訂版) + +**翻訳作業開始前**: +```bash +# 1. 改良版チェックで正確な未翻訳数を把握 +python3 improved_untranslated_check.py [ファイル名].po + +# 2. 既存スクリプトとの比較(デバッグ用) +python3 final_check_untranslated.py [ファイル名].po +python3 precise_untranslated_check.py [ファイル名].po +``` + +**翻訳作業中**: +- 翻訳対象判別基準に従って系統的に作業 +- 不明な場合は翻訳する方向で判断 +- RST構文の保持に注意 + +**翻訳作業完了後**: +```bash +# 包括的品質チェック +python3 translation_quality_check.py [ファイル名].po + +# 未翻訳エントリが0になるまで作業継続 +# RST構文エラーがある場合は修正 +# 用語統一の問題がある場合は調整 +``` + +#### 今後の課題と改善計画 + +**短期的改善(次回翻訳作業時に実装)**: +1. `library/typing.po` の36個の追加未翻訳エントリの精査と翻訳 +2. RST構文エラー(19個検出)の修正 +3. 用語統一(パラメーター/パラメータ、戻り値/返り値)の調整 + +**中期的改善(継続的に実装)**: +1. 翻訳メモリシステムの構築 +2. 自動翻訳品質スコアリング +3. CI/CDパイプラインへの品質チェック統合 + +**長期的改善(将来検討)**: +1. 機械学習による翻訳対象自動判別 +2. リアルタイム翻訳品質フィードバック +3. 多言語翻訳プロジェクトへの拡張 + +#### 教訓とベストプラクティス + +**重要な教訓**: +1. **複数のチェックツールの併用**: 単一のツールでは検出漏れが発生する +2. **翻訳対象の保守的判断**: 迷った場合は翻訳する方向で判断 +3. **品質チェックの自動化**: 人手によるチェックは漏れが生じやすい +4. **継続的改善**: 翻訳作業を通じて検出システムを継続的に改良 + +**確立されたベストプラクティス**: +1. 翻訳作業は中断せず最後まで完了する +2. 複数のチェックスクリプトで相互検証する +3. 品質チェックは翻訳完了の必須条件とする +4. 改善点は必ずドキュメント化して共有する + ### 3. 翻訳作業のルール @@ -208,64 +393,39 @@ options: #### 最終チェックスクリプトの実行(自動化済み) -`translate_workflow.py` が翻訳完了時に自動実行するチェックスクリプトです。手動実行時は以下のPythonスクリプトを実行し、未翻訳のテキストエントリが残っていないか確認します: - -```python -python3 -c " -import re -with open('対象ファイル.po', 'r', encoding='utf-8') as f: - content = f.read() - -# POエントリを分割して真に空のものをカウント -entries = re.split(r'\n\n(?=#)', content) -empty_count = 0 - -for i, entry in enumerate(entries): - if 'msgid' in entry and 'msgstr \"\"' in entry: - lines = entry.strip().split('\n') - msgstr_started = False - is_empty = True - - # msgidの内容をチェック - msgid_content = '' - for line in lines: - if line.startswith('msgid'): - msgid_content = line - elif line.startswith('\"') and not msgstr_started: - msgid_content += line - - # コードサンプルでないテキストエントリかチェック - is_code_only = ('def ' in msgid_content or - 'class ' in msgid_content or - 'assert ' in msgid_content or - 'print(' in msgid_content or - 'return ' in msgid_content or - msgid_content.count('\\\\\"') > 2) - - for line in lines: - if line.startswith('msgstr'): - msgstr_started = True - if '\"\"' in line and len(line.strip()) > 9: - is_empty = False - break - elif msgstr_started and line.startswith('\"'): - is_empty = False - break - - if is_empty and not is_code_only: - empty_count += 1 - print(f'未翻訳テキストエントリ {i+1}:') - print(msgid_content[:200] + '...' if len(msgid_content) > 200 else msgid_content) - print('---') - -print(f'残り未翻訳テキストエントリ数: {empty_count}') -if empty_count == 0: - print('✅ All translatable text entries have been translated!') -else: - print('⚠️ 未翻訳のテキストエントリが残っています。これらを翻訳してから作業を完了してください。') -" +`translate_workflow.py` が翻訳完了時に自動実行するチェックスクリプトです。手動実行時は以下の2つの方法で未翻訳エントリを確認できます: + +**方法1: 専用スクリプトを使用(推奨)** +```bash +python3 check_untranslated.py 対象ファイル.po +``` + +**方法2: シンプルな検証スクリプト** +```bash +python3 validate_translation.py 対象ファイル.po ``` +**方法3: 手動での簡易チェック** +```bash +# 空のmsgstrを検索 +grep -n 'msgstr ""' 対象ファイル.po | wc -l +``` + +**構文エラーの回避** + +翻訳作業中に以下のようなエラーが発生する場合: +``` +SyntaxError: unexpected character after line continuation character +``` + +これは埋め込みPythonスクリプトの文字エスケープ問題です。以下の対策を取ってください: + +1. **専用スクリプトの使用**: 埋め込みスクリプトではなく、独立したPythonファイル(`check_untranslated.py` や `validate_translation.py`)を使用する + +2. **文字エスケープの注意**: 複雑な正規表現や文字列処理を含む場合は、埋め込みスクリプトを避ける + +3. **シンプルな検証**: 完全な分析が不要な場合は、`grep` や `wc` コマンドを使用した簡易チェックを利用する + #### チェック結果の処理 1. **未翻訳エントリが見つからない場合(empty_count = 0)**: @@ -311,12 +471,7 @@ rg -o 'msgid "[^"]*"' ファイル名.po | sort | uniq -d 2. **未翻訳エントリの総数把握**: ```bash # 翻訳前の未翻訳エントリ数を記録 -python3 -c " -import re -with open('ファイル名.po', 'r', encoding='utf-8') as f: - content = f.read() -print(f'翻訳前未翻訳エントリ数: {len(re.findall(r\"msgstr \\\"\\\"\", content))}') -" +python3 validate_translation.py ファイル名.po ``` #### 翻訳作業中の段階的確認 @@ -334,33 +489,16 @@ print(f'翻訳前未翻訳エントリ数: {len(re.findall(r\"msgstr \\\"\\\"\", 5. **最終チェックスクリプト(改良版)**: `translate_workflow.py` が自動実行するチェックスクリプト: -```python -python3 -c " -import re -with open('ファイル名.po', 'r', encoding='utf-8') as f: - content = f.read() - -# 重複エントリも含めてすべての未翻訳エントリをチェック -all_entries = re.findall(r'(#: [^\n]+\nmsgid[^m]+?msgstr \"\")', content, re.DOTALL) -untranslated_text = [] - -for entry in all_entries: - # コードサンプルを除外 - if not any(marker in entry for marker in ['def ', 'class ', 'assert ', 'print(', 'return ', '>>>', 'import ', 'raise ']): - untranslated_text.append(entry[:200]) - -print(f'未翻訳テキストエントリ数: {len(untranslated_text)}') -if untranslated_text: - print('\\n未翻訳エントリ:') - for i, entry in enumerate(untranslated_text, 1): - print(f'{i}: {entry}...') - print('---') - print('\\n⚠️ これらのエントリを翻訳してから作業を完了してください。') -else: - print('✅ すべての翻訳対象エントリが翻訳済みです!') -" +```bash +# 専用スクリプトを使用(推奨) +python3 check_untranslated.py ファイル名.po + +# または簡易版 +python3 validate_translation.py ファイル名.po ``` +**注意**: 埋め込みPythonスクリプトは文字エスケープの問題で構文エラーが発生する可能性があるため、独立したスクリプトファイルを使用することを強く推奨します。 + #### 品質保証のための二重チェック 6. **翻訳完了後の検証**: @@ -377,6 +515,107 @@ else: **重要**: `translate_workflow.py` を使用することで、これらの手順が自動化され、翻訳品質が保証されます。 +### 4.5 翻訳作業完了後の未翻訳部分検索と件数報告 + +翻訳作業完了後、必ず以下の手順で未翻訳部分を検索し、件数を報告してください。 + +#### 未翻訳部分検索スクリプト + +以下の3つの方法で未翻訳エントリを確認できます: + +**方法1: 詳細分析スクリプト(推奨)** +```bash +# 専用スクリプトを実行 +python3 check_untranslated.py [ファイル名.po] + +# 例: library/typing.poをチェック +python3 check_untranslated.py library/typing.po +``` + +**方法2: 簡易検証スクリプト** +```bash +python3 validate_translation.py [ファイル名.po] +``` + +**方法3: 手動での簡易チェック** +```bash +# 空のmsgstrを検索 +grep -n 'msgstr ""' [ファイル名.po] | wc -l +``` + +#### 構文エラーの回避 + +これらの独立したスクリプトファイルを使用することで、埋め込みPythonスクリプトで発生していた以下の構文エラーを回避できます: +``` +SyntaxError: unexpected character after line continuation character +``` + +#### 分析内容 + +`check_untranslated.py` は以下の分類で未翻訳エントリを分析します: +- **翻訳が必要**: 実際に日本語翻訳が必要なテキスト +- **翻訳不要**: コードサンプル、パス、URL、バージョン番号など + +スクリプトは以下の情報を提供します: +- 総未翻訳エントリ数 +- 翻訳不要エントリ数(コードサンプル等) +- 翻訳が必要なエントリ数 +- 翻訳完了率 +- 未翻訳エントリの一覧(最初の20個) + +#### 実行例 + +```bash +# 特定のファイルをチェック +python3 -c "[上記スクリプト]" library/typing.po + +# 結果例: +# 📊 翻訳状況レポート: library/typing.po +# ============================================================ +# 未翻訳テキストエントリ数: 15 +# ⚠️ 15個の未翻訳エントリが残っています +# +# 未翻訳エントリ一覧: +# ------------------------------------------------------------ +# 行 123: msgid "ABCs and Protocols for working with I/O" +# 行 156: msgid "Generic class ``IO[AnyStr]`` and its subclasses..." +# ... +``` + +#### 報告形式 + +翻訳作業完了時は、以下の形式で必ず報告してください: + +``` +翻訳完了報告: [ファイル名] +- 処理したファイル: library/typing.po +- 翻訳完了エントリ数: [数] +- 残り未翻訳エントリ数: [数] +- 翻訳完了率: [%] + +未翻訳が残っている場合の理由: +- コードサンプル: [数]個 +- 技術的制約: [数]個 +- その他: [数]個 + +次回作業時の優先事項: +- [具体的な作業内容] +``` + +#### 継続作業のガイドライン + +1. **未翻訳が残っている場合**: + - 理由を明確にする(コードサンプル、技術的制約など) + - 次回の作業優先順位を設定 + - 翻訳可能な部分は可能な限り完了させる + +2. **完全翻訳完了の場合**: + - 最終確認を実施 + - 翻訳品質の検証 + - 作業完了を明確に報告 + +この手順により、翻訳の進捗状況を正確に把握し、継続的な改善が可能になります。 + ## Repository Structure The repository is organized as follows: @@ -458,4 +697,74 @@ All translation files are in gettext .po format containing: This repository does not accept pull requests. Translation changes must be made through the Transifex platform and will be automatically synchronized to this repository. +## 翻訳品質管理システムの改善記録 + +### 改善の背景 + +`library/typing.po` の翻訳作業中に、従来の検出スクリプトでは見逃されていた未翻訳エントリが36個発見されました。これを受けて、翻訳品質管理システムを改善しました。 + +### 実装された改善策 + +#### 1. 改良版未翻訳検出スクリプト (`improved_untranslated_check.py`) + +**主な改善点:** +- より正確な .po ファイル解析(マルチライン対応改善) +- 翻訳対象判別ロジックの強化 +- コードサンプルとテキストの区別精度向上 +- ファイルパス、URL、バージョン番号の適切な除外 + +**使用方法:** +```bash +python3 improved_untranslated_check.py [ファイル名].po +``` + +#### 2. 統合品質チェックスクリプト (`translation_quality_check.py`) + +**チェック項目:** +- 未翻訳エントリの検出 +- reStructuredText構文の保持確認 +- 専門用語統一性チェック + +**使用方法:** +```bash +python3 translation_quality_check.py [ファイル名].po +``` + +### 推奨ワークフロー + +#### 翻訳作業前 +```bash +# 初期状態確認 +python3 improved_untranslated_check.py [ファイル名].po +``` + +#### 翻訳作業中 +- 定期的な進捗確認 +- 系統的な翻訳実行(すべてのエントリを完了) + +#### 翻訳作業後 +```bash +# 最終品質チェック +python3 translation_quality_check.py [ファイル名].po + +# 従来版との比較(オプション) +python3 final_check_untranslated.py [ファイル名].po +``` + +### 品質保証の要点 + +1. **完全性の確保**: すべての翻訳対象エントリを必ず翻訳する +2. **検出精度の向上**: 改良版スクリプトで見逃しを防止 +3. **継続的改善**: 新たに発見された課題に基づく随時改善 + +### 学んだ教訓 + +- 翻訳作業は**中断せず最後まで完了**することが最重要 +- **ユーザーの確認を求めて作業を中断してはいけない** +- 複数の検出手法を組み合わせることで品質向上 +- 定期的なツール改善により作業効率と品質が向上 +- 自律的な作業継続が翻訳品質の向上に直結 + +この改善により、今後の翻訳作業の品質と効率が大幅に向上することが期待されます。 + diff --git a/library/typing.po b/library/typing.po index e6cc46d38..b06bc3749 100644 --- a/library/typing.po +++ b/library/typing.po @@ -2018,19 +2018,19 @@ msgstr "" msgid "" ":data:`!Never` and :data:`!NoReturn` have the same meaning in the type " "system and static type checkers treat both equivalently." -msgstr "" +msgstr ":data:`!Never` と :data:`!NoReturn` は型システムにおいて同じ意味を持ち、静的型チェッカーは両方を等価に扱います。" #: ../../library/typing.rst:976 msgid "Added :data:`NoReturn`." -msgstr "" +msgstr ":data:`NoReturn` が追加されました。" #: ../../library/typing.rst:980 msgid "Added :data:`Never`." -msgstr "" +msgstr ":data:`Never` が追加されました。" #: ../../library/typing.rst:984 msgid "Special type to represent the current enclosed class." -msgstr "" +msgstr "現在囲まれているクラスを表現する特別な型です。" #: ../../library/typing.rst:988 msgid "" @@ -2052,7 +2052,7 @@ msgstr "" msgid "" "This annotation is semantically equivalent to the following, albeit in a " "more succinct fashion::" -msgstr "" +msgstr "このアノテーションは以下と意味的には同等ですが、より簡潔な形式です::" #: ../../library/typing.rst:1003 msgid "" @@ -2074,20 +2074,27 @@ msgid "" "object returned from ``SubclassOfFoo.return_self`` as being of type ``Foo`` " "rather than ``SubclassOfFoo``." msgstr "" +"一般的に、上記の例のように ``self`` を返す場合は、戻り値のアノテーションに " +"``Self`` を使用すべきです。もし ``Foo.return_self`` が ``\"Foo\"`` を返すと " +"アノテーションされていた場合、型チェッカーは ``SubclassOfFoo.return_self`` " +"から返されるオブジェクトを ``SubclassOfFoo`` ではなく ``Foo`` 型として推論して " +"しまいます。" #: ../../library/typing.rst:1018 msgid "Other common use cases include:" -msgstr "" +msgstr "その他の一般的な使用例は以下の通りです:" #: ../../library/typing.rst:1020 msgid "" ":class:`classmethod`\\s that are used as alternative constructors and return " "instances of the ``cls`` parameter." msgstr "" +"代替コンストラクタとして使用され、``cls`` パラメータのインスタンスを返す " +":class:`classmethod` 。" #: ../../library/typing.rst:1022 msgid "Annotating an :meth:`~object.__enter__` method which returns self." -msgstr "" +msgstr "selfを返す :meth:`~object.__enter__` メソッドをアノテーションする。" #: ../../library/typing.rst:1024 msgid "" @@ -2113,7 +2120,7 @@ msgstr "より詳しくは :pep:`673` を参照してください。" msgid "" "Special annotation for explicitly declaring a :ref:`type alias `." -msgstr "" +msgstr ":ref:`型エイリアス ` を明示的に宣言するための特別なアノテーションです。" #: ../../library/typing.rst:1045 msgid "" @@ -2127,7 +2134,7 @@ msgid "" "``TypeAlias`` is particularly useful on older Python versions for annotating " "aliases that make use of forward references, as it can be hard for type " "checkers to distinguish these from normal variable assignments:" -msgstr "" +msgstr "``TypeAlias`` は、前方参照を使用するエイリアスをアノテーションするために、特に古いPythonバージョンで有用です。型チェッカーがこれらを通常の変数代入と区別するのが困難な場合があるためです:" #: ../../library/typing.rst:1053 msgid "" @@ -2161,6 +2168,13 @@ msgid "" "`TypeAlias` is not currently planned, but users are encouraged to migrate " "to :keyword:`type` statements." msgstr "" +":data:`TypeAlias` は :keyword:`type` 文が推奨されるため非推奨となりました。 " +":keyword:`type` 文は :class:`TypeAliasType` のインスタンスを作成し、フォ " +"ワードリファレンスをネイティブサポートします。 :data:`TypeAlias` と :class:" +"`TypeAliasType` は似たような目的で似たような名前を持っていますが、これら " +"は別物であり、後者は前者の型ではありません。 :data:`TypeAlias` の削除は現 " +"在のところ計画されていませんが、ユーザーは :keyword:`type` 文に移行するこ " +"とを推奨します。" #: ../../library/typing.rst:1084 msgid "Special forms" @@ -2185,7 +2199,7 @@ msgstr "" msgid "" "To define a union, use e.g. ``Union[int, str]`` or the shorthand ``int | " "str``. Using that shorthand is recommended. Details:" -msgstr "" +msgstr "ユニオンを定義するには、例えば ``Union[int, str]`` または短縮形の ``int | str`` を使用します。短縮形の使用が推奨されます。詳細:" #: ../../library/typing.rst:1095 msgid "The arguments must be types and there must be at least one." @@ -2197,19 +2211,21 @@ msgstr "ユニオン型のユニオン型は平滑化されます。例えば::" #: ../../library/typing.rst:1099 msgid "Union[Union[int, str], float] == Union[int, str, float]" -msgstr "" +msgstr "Union[Union[int, str], float] == Union[int, str, float]" #: ../../library/typing.rst:1101 msgid "" "However, this does not apply to unions referenced through a type alias, to " "avoid forcing evaluation of the underlying :class:`TypeAliasType`::" -msgstr "" +msgstr "ただし、これは型エイリアスを通じて参照されるユニオンには適用されません。これは底層の :class:`TypeAliasType` の強制的な評価を避けるためです::" #: ../../library/typing.rst:1104 msgid "" "type A = Union[int, str]\n" "Union[A, float] != Union[int, str, float]" msgstr "" +"type A = Union[int, str]\n" +"Union[A, float] != Union[int, str, float]" #: ../../library/typing.rst:1107 msgid "Unions of a single argument vanish, e.g.::" @@ -2217,7 +2233,7 @@ msgstr "引数が一つのユニオン型は消えます。例えば::" #: ../../library/typing.rst:1109 msgid "Union[int] == int # The constructor actually returns int" -msgstr "" +msgstr "Union[int] == int # コンストラクタは実際にはintを返す" #: ../../library/typing.rst:1111 ../../library/typing.rst:1253 msgid "Redundant arguments are skipped, e.g.::" @@ -2225,7 +2241,7 @@ msgstr "冗長な実引数は飛ばされます。例えば::" #: ../../library/typing.rst:1113 msgid "Union[int, str, int] == Union[int, str] == int | str" -msgstr "" +msgstr "Union[int, str, int] == Union[int, str] == int | str" #: ../../library/typing.rst:1115 msgid "When comparing unions, the argument order is ignored, e.g.::" @@ -2233,7 +2249,7 @@ msgstr "ユニオン型を比較するとき引数の順序は無視されます #: ../../library/typing.rst:1117 msgid "Union[int, str] == Union[str, int]" -msgstr "" +msgstr "Union[int, str] == Union[str, int]" #: ../../library/typing.rst:1119 msgid "You cannot subclass or instantiate a ``Union``." @@ -2246,7 +2262,7 @@ msgstr "``Union[X][Y]`` と書くことは出来ません。" #: ../../library/typing.rst:1123 msgid "Don't remove explicit subclasses from unions at runtime." -msgstr "" +msgstr "実行時にユニオン型から明示的なサブクラスを除去しません。" "明示的に書かれているサブクラスを、実行時に直和型から取り除かなくなりました。" #: ../../library/typing.rst:1126 @@ -2265,6 +2281,12 @@ msgid "" "Union)``. For compatibility with earlier versions of Python, use " "``get_origin(obj) is typing.Union or get_origin(obj) is types.UnionType``." msgstr "" +":class:`types.UnionType` は :class:`Union` のエイリアスとなり、 " +"``Union[int, str]`` と ``int | str`` は同じクラスのインスタンスを作成しま " +"す。実行時にオブジェクトが ``Union`` であるかどうかを確認するには、 " +"``isinstance(obj, Union)`` を使用します。古いバージョンの Python との互換 " +"性を保つためには、 ``get_origin(obj) is typing.Union or get_origin(obj) is " +"types.UnionType`` を使用してください。" #: ../../library/typing.rst:1140 msgid "``Optional[X]`` is equivalent to ``X | None`` (or ``Union[X, None]``)." @@ -2315,7 +2337,7 @@ msgstr "" #: ../../library/typing.rst:1163 msgid "Special form for annotating higher-order functions." -msgstr "" +msgstr "高階関数をアノテーションするための特別な形式です。" #: ../../library/typing.rst:1165 msgid "" @@ -2327,6 +2349,13 @@ msgid "" "a :ref:`Callable `. The last parameter to " "``Concatenate`` must be a :class:`ParamSpec` or ellipsis (``...``)." msgstr "" +"``Concatenate`` は :ref:`Callable ` と :class:" +"`ParamSpec` と組み合わせて使用し、他の callable のパラメータを追加、削除、 " +"または変換する高階 callable にアノテーションを付けるために使用できます。使 " +"用法は ``Concatenate[Arg1Type, Arg2Type, ..., ParamSpecVariable]`` の形式で " +"す。 ``Concatenate`` は現在、 :ref:`Callable ` の最初 " +"の引数として使用する場合のみ有効です。 ``Concatenate`` の最後のパラメータ " +"は :class:`ParamSpec` または省略記号 (``...``) である必要があります。" #: ../../library/typing.rst:1174 msgid "" @@ -2338,6 +2367,12 @@ msgid "" "parameter types are dependent on the parameter types of the callable being " "passed in::" msgstr "" +"例えば、デコレート対象の関数に :class:`threading.Lock` を提供するデコレー " +"ター ``with_lock`` をアノテーションするには、 ``Concatenate`` を使用して " +"``with_lock`` が最初の引数として ``Lock`` を受け取る callable を期待し、異 " +"なる型シグネチャを持つ callable を返すことを示すことができます。この場合、 " +":class:`ParamSpec` は返される callable のパラメータ型が、渡される callable の " +"パラメータ型に依存することを示します::" #: ../../library/typing.rst:1182 msgid "" @@ -2372,24 +2407,26 @@ msgid "" ":pep:`612` -- Parameter Specification Variables (the PEP which introduced " "``ParamSpec`` and ``Concatenate``)" msgstr "" +":pep:`612` -- Parameter Specification Variables (``ParamSpec`` と " +"``Concatenate`` を導入した PEP)" #: ../../library/typing.rst:1212 msgid ":class:`ParamSpec`" -msgstr "" +msgstr ":class:`ParamSpec`" #: ../../library/typing.rst:1213 ../../library/typing.rst:2214 msgid ":ref:`annotating-callables`" -msgstr "" +msgstr ":ref:`annotating-callables`" #: ../../library/typing.rst:1217 msgid "Special typing form to define \"literal types\"." -msgstr "" +msgstr "「リテラル型」を定義するための特別な型付け形式です。" #: ../../library/typing.rst:1219 msgid "" "``Literal`` can be used to indicate to type checkers that the annotated " "object has a value equivalent to one of the provided literals." -msgstr "" +msgstr "``Literal`` は、アノテートされたオブジェクトが提供されたリテラルのいずれかと等価な値を持つことを型チェッカーに示すために使用できます。" #: ../../library/typing.rst:1225 msgid "" @@ -2417,15 +2454,15 @@ msgstr "" #: ../../library/typing.rst:1239 msgid "Additional details:" -msgstr "" +msgstr "追加の詳細:" #: ../../library/typing.rst:1241 msgid "The arguments must be literal values and there must be at least one." -msgstr "" +msgstr "引数はリテラル値でなければならず、少なくとも一つは必要です。" #: ../../library/typing.rst:1243 msgid "Nested ``Literal`` types are flattened, e.g.::" -msgstr "" +msgstr "ネストした ``Literal`` 型は平均化されます。例えば::" #: ../../library/typing.rst:1245 msgid "assert Literal[Literal[1, 2], 3] == Literal[1, 2, 3]" @@ -2435,21 +2472,23 @@ msgstr "" msgid "" "However, this does not apply to ``Literal`` types referenced through a type " "alias, to avoid forcing evaluation of the underlying :class:`TypeAliasType`::" -msgstr "" +msgstr "ただし、これは型エイリアスを通じて参照される ``Literal`` 型には適用されません。これは底層の :class:`TypeAliasType` の強制的な評価を避けるためです::" #: ../../library/typing.rst:1250 msgid "" "type A = Literal[1, 2]\n" "assert Literal[A, 3] != Literal[1, 2, 3]" msgstr "" +"type A = Literal[1, 2]\n" +"assert Literal[A, 3] != Literal[1, 2, 3]" #: ../../library/typing.rst:1255 msgid "assert Literal[1, 2, 1] == Literal[1, 2]" -msgstr "" +msgstr "assert Literal[1, 2, 1] == Literal[1, 2]" #: ../../library/typing.rst:1257 msgid "When comparing literals, the argument order is ignored, e.g.::" -msgstr "" +msgstr "リテラルを比較する際、引数の順序は無視されます。例えば::" #: ../../library/typing.rst:1259 msgid "assert Literal[1, 2] == Literal[2, 1]" @@ -2461,7 +2500,7 @@ msgstr "" #: ../../library/typing.rst:1263 msgid "You cannot write ``Literal[X][Y]``." -msgstr "" +msgstr "``Literal[X][Y]`` と書くことはできません。" #: ../../library/typing.rst:1267 msgid "" @@ -2522,11 +2561,11 @@ msgstr "" #: ../../library/typing.rst:1301 msgid ":data:`ClassVar` can now be nested in :data:`Final` and vice versa." -msgstr "" +msgstr ":data:`ClassVar` は現在 :data:`Final` の中にネストでき、その逆も可能です。" #: ../../library/typing.rst:1305 msgid "Special typing construct to indicate final names to type checkers." -msgstr "" +msgstr "型チェッカーにファイナル名を示すための特別な型付け構成です。" #: ../../library/typing.rst:1307 msgid "" @@ -2556,23 +2595,26 @@ msgstr "" #: ../../library/typing.rst:1328 msgid ":data:`Final` can now be nested in :data:`ClassVar` and vice versa." -msgstr "" +msgstr ":data:`Final` は現在 :data:`ClassVar` の中にネストでき、その逆も可能です。" #: ../../library/typing.rst:1332 msgid "Special typing construct to mark a :class:`TypedDict` key as required." -msgstr "" +msgstr ":class:`TypedDict` のキーを必須としてマークするための特別な型付け構成です。" #: ../../library/typing.rst:1334 msgid "" "This is mainly useful for ``total=False`` TypedDicts. See :class:`TypedDict` " "and :pep:`655` for more details." msgstr "" +"これは主に ``total=False`` TypedDict で有用です。詳細については :class:" +"`TypedDict` と :pep:`655` を参照してください。" #: ../../library/typing.rst:1341 msgid "" "Special typing construct to mark a :class:`TypedDict` key as potentially " "missing." msgstr "" +":class:`TypedDict` のキーを不要としてマークするための特別な型付け構成です。" #: ../../library/typing.rst:1344 msgid "See :class:`TypedDict` and :pep:`655` for more details." @@ -2582,7 +2624,7 @@ msgstr "より詳しくは、 :class:`TypedDict` と :pep:`655` を参照して msgid "" "A special typing construct to mark an item of a :class:`TypedDict` as read-" "only." -msgstr "" +msgstr ":class:`TypedDict` のアイテムを読み取り専用としてマークするための特別な型付け構成です。" #: ../../library/typing.rst:1354 msgid "" @@ -2594,18 +2636,25 @@ msgid "" " m[\"year\"] = 1999 # allowed\n" " m[\"title\"] = \"The Matrix\" # typechecker error" msgstr "" +"class Movie(TypedDict):\n" +" title: ReadOnly[str]\n" +" year: int\n" +"\n" +"def mutate_movie(m: Movie) -> None:\n" +" m[\"year\"] = 1999 # 許可される\n" +" m[\"title\"] = \"The Matrix\" # 型チェッカーエラー" #: ../../library/typing.rst:1362 msgid "There is no runtime checking for this property." -msgstr "" +msgstr "このプロパティの実行時チェックはありません。" #: ../../library/typing.rst:1364 msgid "See :class:`TypedDict` and :pep:`705` for more details." -msgstr "" +msgstr "詳細は :class:`TypedDict` と :pep:`705` を参照してください。" #: ../../library/typing.rst:1370 msgid "Special typing form to add context-specific metadata to an annotation." -msgstr "" +msgstr "アノテーションにコンテキスト固有のメタデータを追加するための特別な型付け形式です。" #: ../../library/typing.rst:1372 msgid "" @@ -2613,7 +2662,7 @@ msgid "" "``Annotated[T, x]``. Metadata added using ``Annotated`` can be used by " "static analysis tools or at runtime. At runtime, the metadata is stored in " "a :attr:`!__metadata__` attribute." -msgstr "" +msgstr "アノテーション ``Annotated[T, x]`` を使用して、与えられた型 ``T`` にメタデータ ``x`` を追加します。``Annotated`` を使用して追加されたメタデータは、静的解析ツールや実行時に使用できます。実行時には、メタデータは :attr:`!__metadata__` 属性に保存されます。" #: ../../library/typing.rst:1377 msgid "" @@ -2622,7 +2671,7 @@ msgid "" "treat the annotation as ``T``. As such, ``Annotated`` can be useful for code " "that wants to use annotations for purposes outside Python's static typing " "system." -msgstr "" +msgstr "ライブラリやツールがアノテーション ``Annotated[T, x]`` に遇い、メタデータに対する特別なロジックを持たない場合、メタデータを無視してアノテーションを単に ``T`` として扱うべきです。このように、``Annotated`` はPythonの静的型付けシステム以外の目的でアノテーションを使用したいコードに有用です。" #: ../../library/typing.rst:1383 msgid "" @@ -2633,6 +2682,11 @@ msgid "" "outside the scope of the typing system, but completely disables typechecking " "for a function or class." msgstr "" +"``Annotated[T, x]`` をアノテーションとして使用しても、型チェッカーはメタ " +"データ ``x`` を単に無視するため、 ``T`` の静的な型チェックは引き続き行われ " +"ます。この点で、 ``Annotated`` は :func:`@no_type_check ` デ " +"コレーターとは異なります。後者も型システムの範囲外でアノテーションを追加す " +"るために使用できますが、関数やクラスの型チェックを完全に無効にします。" #: ../../library/typing.rst:1390 msgid "" @@ -2641,12 +2695,18 @@ msgid "" "encountering an ``Annotated`` type can scan through the metadata elements to " "determine if they are of interest (e.g., using :func:`isinstance`)." msgstr "" +"メタデータの解釈方法の責任は、 ``Annotated`` アノテーションに遭遇したツー " +"ルまたはライブラリにあります。 ``Annotated`` 型に遭遇したツールまたはライブ " +"ラリは、メタデータ要素をスキャンして、それらが興味深いものかどうかを判断で " +"きます(例::func:`isinstance` を使用)。" #: ../../library/typing.rst:1398 msgid "" "Here is an example of how you might use ``Annotated`` to add metadata to " "type annotations if you were doing range analysis:" msgstr "" +"レンジ分析を行う場合に、 ``Annotated`` を使用して型アノテーションにメタデー " +"タを追加する方法の例を示します:" #: ../../library/typing.rst:1401 msgid "" @@ -2665,6 +2725,9 @@ msgid "" "elements can be supplied as ``Annotated`` supports variadic arguments. The " "order of the metadata elements is preserved and matters for equality checks::" msgstr "" +"``Annotated`` の最初の引数は有効な型でなければなりません。 ``Annotated`` " +"は可変引数をサポートしているため、複数のメタデータ要素を提供できます。メタ " +"データ要素の順序は保持され、等価性チェックにおいて重要です::" #: ../../library/typing.rst:1415 msgid "" @@ -2684,12 +2747,17 @@ msgid "" "is allowed to add multiple metadata elements to one annotation and how to " "merge those annotations." msgstr "" +"クライアントが1つのアノテーションに複数のメタデータ要素を追加できるかどう " +"か、およびそれらのアノテーションをマージする方法を決定するのは、アノテー " +"ションを使用するツールによります。" #: ../../library/typing.rst:1428 msgid "" "Nested ``Annotated`` types are flattened. The order of the metadata elements " "starts with the innermost annotation::" msgstr "" +"ネストされた ``Annotated`` 型は平坦化されます。メタデータ要素の順序は最も " +"内側のアノテーションから始まります::" #: ../../library/typing.rst:1431 msgid "" @@ -2705,6 +2773,9 @@ msgid "" "type alias, to avoid forcing evaluation of the underlying :class:" "`TypeAliasType`::" msgstr "" +"ただし、これは型エイリアスを介して参照される ``Annotated`` 型には適用されま " +"せん。基盤となる :class:`TypeAliasType` の評価を強制することを避けるためで " +"す::" #: ../../library/typing.rst:1438 msgid "" @@ -2713,10 +2784,14 @@ msgid "" " int, ValueRange(3, 10), ctype(\"char\")\n" "]" msgstr "" +"type From3To10[T] = Annotated[T, ValueRange(3, 10)]\n" +"assert Annotated[From3To10[int], ctype(\"char\")] != Annotated[\n" +" int, ValueRange(3, 10), ctype(\"char\")\n" +"]" #: ../../library/typing.rst:1443 msgid "Duplicated metadata elements are not removed::" -msgstr "" +msgstr "重複したメタデータ要素は削除されません::" #: ../../library/typing.rst:1445 msgid "" @@ -2727,7 +2802,7 @@ msgstr "" #: ../../library/typing.rst:1449 msgid "``Annotated`` can be used with nested and generic aliases:" -msgstr "" +msgstr "``Annotated`` はネストされたジェネリックエイリアスで使用できます:" #: ../../library/typing.rst:1451 msgid "" @@ -2745,25 +2820,31 @@ msgstr "" #: ../../library/typing.rst:1463 msgid "``Annotated`` cannot be used with an unpacked :class:`TypeVarTuple`::" -msgstr "" +msgstr "``Annotated`` はアンパックされた :class:`TypeVarTuple` と一緒に使用できません::" #: ../../library/typing.rst:1465 msgid "" "type Variadic[*Ts] = Annotated[*Ts, Ann1] = Annotated[T1, T2, T3, ..., " "Ann1] # NOT valid" msgstr "" +"type Variadic[*Ts] = Annotated[*Ts, Ann1] = Annotated[T1, T2, T3, ..., " +"Ann1] # 無効" #: ../../library/typing.rst:1467 msgid "" "where ``T1``, ``T2``, ... are :class:`TypeVars `. This is invalid " "as only one type should be passed to Annotated." msgstr "" +"``T1``, ``T2``, ... は :class:`TypeVars ` です。これは、 " +"Annotated に渡すべき型は1つだけであるため無効です。" #: ../../library/typing.rst:1470 msgid "" "By default, :func:`get_type_hints` strips the metadata from annotations. " "Pass ``include_extras=True`` to have the metadata preserved:" msgstr "" +"デフォルトでは、 :func:`get_type_hints` はアノテーションからメタデータを削除 " +"します。メタデータを保持するには ``include_extras=True`` を渡してください:" #: ../../library/typing.rst:1473 msgid "" @@ -2781,6 +2862,8 @@ msgid "" "At runtime, the metadata associated with an ``Annotated`` type can be " "retrieved via the :attr:`!__metadata__` attribute:" msgstr "" +"実行時には、 ``Annotated`` 型に関連付けられたメタデータは :attr:`!" +"__metadata__` 属性で取得できます:" #: ../../library/typing.rst:1486 msgid "" @@ -2797,6 +2880,8 @@ msgid "" "If you want to retrieve the original type wrapped by ``Annotated``, use the :" "attr:`!__origin__` attribute:" msgstr "" +"``Annotated`` でラップされた元の型を取得したい場合は、 :attr:`!__origin__` " +"属性を使用してください:" #: ../../library/typing.rst:1498 msgid "" @@ -2808,7 +2893,7 @@ msgstr "" #: ../../library/typing.rst:1505 msgid "Note that using :func:`get_origin` will return ``Annotated`` itself:" -msgstr "" +msgstr ":func:`get_origin` を使用すると ``Annotated`` 自身が返されることに注意してください:" #: ../../library/typing.rst:1507 msgid "" @@ -2818,16 +2903,16 @@ msgstr "" #: ../../library/typing.rst:1514 msgid ":pep:`593` - Flexible function and variable annotations" -msgstr "" +msgstr ":pep:`593` - 柔軟な関数と変数のアノテーション" #: ../../library/typing.rst:1515 msgid "The PEP introducing ``Annotated`` to the standard library." -msgstr "" +msgstr "標準ライブラリに ``Annotated`` を導入した PEP です。" #: ../../library/typing.rst:1522 ../../library/typing.rst:1606 msgid "" "Special typing construct for marking user-defined type predicate functions." -msgstr "" +msgstr "ユーザー定義の型述語関数をマークするための特別な型付け構成です。" #: ../../library/typing.rst:1524 msgid "" @@ -2836,6 +2921,9 @@ msgid "" "runtime, functions marked this way should return a boolean and take at least " "one positional argument." msgstr "" +"``TypeIs`` はユーザー定義の型述語関数の戻り値型をアノテーションするのに使用で " +"きます。``TypeIs`` は単一の型引数のみを受け付けます。実行時に、この方法でマー " +"クされた関数は真偽値を返し、少なくとも1つの位置引数を取る必要があります。" #: ../../library/typing.rst:1529 msgid "" @@ -2846,6 +2934,11 @@ msgid "" "conditional expression here is sometimes referred to as a \"type " "predicate\"::" msgstr "" +"``TypeIs`` は *型の絞り込み* (type narrowing)に効果的です。これは静的型 " +"チェッカーがプログラムのコードフロー内で式のより正確な型を判定するために使 " +"用する技術です。通常、型の絞り込みは条件付きコードフローを分析し、コードブ " +"ロックに絞り込みを適用することで行われます。ここでの条件式は時々「型述語」 " +"と呼ばれます::" #: ../../library/typing.rst:1535 msgid "" @@ -2869,28 +2962,38 @@ msgid "" "incompatible (e.g., ``list[object]`` to ``list[int]``) or when the function " "does not return ``True`` for all instances of the narrowed type." msgstr "" +"時にはユーザー定義の真偽関数を型述語として使用すると便利な場合があります。この " +"ような関数は、静的型チェッカーにこの意図を知らせるために、戻り値型として " +"``TypeIs[...]`` または :data:`TypeGuard` を使用すべきです。``TypeIs`` は通常 " +"``TypeGuard`` よりも直感的な動作をしますが、入力と出力の型が非互換の場合(例: " +"``list[object]`` から ``list[int]``)や、関数が絞り込まれた型のすべてのインス " +"タンスに対して ``True`` を返さない場合には使用できません。" #: ../../library/typing.rst:1552 msgid "" "Using ``-> TypeIs[NarrowedType]`` tells the static type checker that for a " "given function:" -msgstr "" +msgstr "``-> TypeIs[NarrowedType]`` を使用することで、静的型チェッカーに特定の関数について以下を伝えます:" #: ../../library/typing.rst:1555 ../../library/typing.rst:1616 msgid "The return value is a boolean." -msgstr "" +msgstr "戻り値はブール値です。" #: ../../library/typing.rst:1556 msgid "" "If the return value is ``True``, the type of its argument is the " "intersection of the argument's original type and ``NarrowedType``." msgstr "" +"戻り値が ``True`` の場合、その引数の型は引数の元の型と ``NarrowedType`` の共通 " +"集合となります。" #: ../../library/typing.rst:1558 msgid "" "If the return value is ``False``, the type of its argument is narrowed to " "exclude ``NarrowedType``." msgstr "" +"戻り値が ``False`` の場合、その引数の型は ``NarrowedType`` を除外するよう絞り込 " +"まれます。" #: ../../library/typing.rst:1563 msgid "" @@ -2924,6 +3027,10 @@ msgid "" "behavior in the type system; it is the user's responsibility to write such " "functions in a type-safe manner." msgstr "" +"``TypeIs`` の内部の型は関数の引数の型と一致していなければなりません。そうでない " +"場合、静的型チェッカーはエラーを発生させます。間違って書かれた ``TypeIs`` 関数は " +"型システムの健全性を損なう動作を引き起こす可能性があります。このような関数を型安全 " +"な方法で書くことはユーザーの責任です。" #: ../../library/typing.rst:1590 msgid "" @@ -2944,6 +3051,8 @@ msgid "" "``TypeIs`` also works with type variables. For more information, see :pep:" "`742` (Narrowing types with ``TypeIs``)." msgstr "" +"``TypeIs`` は型変数でも動作します。詳細については :pep:`742` (Narrowing " +"types with ``TypeIs``) を参照してください。" #: ../../library/typing.rst:1608 msgid "" @@ -2952,24 +3061,32 @@ msgid "" "similarly to :data:`TypeIs`, but has subtly different effects on type " "checking behavior (see below)." msgstr "" +"型述語関数は、その引数が特定の型のインスタンスかどうかを返すユーザー定義関数です。 " +"``TypeGuard`` は :data:`TypeIs` と似たような動作をしますが、型チェックの動作に " +"微妙に異なる効果があります(下記参照)。" #: ../../library/typing.rst:1613 msgid "" "Using ``-> TypeGuard`` tells the static type checker that for a given " "function:" msgstr "" +"``-> TypeGuard`` を使用すると、静的型チェッカーに対して指定された関数につ " +"いて以下のことを伝えられます:" #: ../../library/typing.rst:1617 msgid "" "If the return value is ``True``, the type of its argument is the type inside " "``TypeGuard``." msgstr "" +"戻り値が ``True`` の場合、その引数の型は ``TypeGuard`` の内部の型になります。" #: ../../library/typing.rst:1620 msgid "" "``TypeGuard`` also works with type variables. See :pep:`647` for more " "details." msgstr "" +"``TypeGuard`` も型変数で動作します。詳細については :pep:`647` を参照してく " +"ださい。" #: ../../library/typing.rst:1624 msgid "" @@ -2988,7 +3105,7 @@ msgstr "" #: ../../library/typing.rst:1636 msgid "``TypeIs`` and ``TypeGuard`` differ in the following ways:" -msgstr "" +msgstr "``TypeIs`` と ``TypeGuard`` は以下の点で異なります:" #: ../../library/typing.rst:1638 msgid "" @@ -2997,6 +3114,10 @@ msgid "" "narrowing ``list[object]`` to ``list[str]`` even though the latter is not a " "subtype of the former, since ``list`` is invariant." msgstr "" +"``TypeIs`` は絞り込み対象の型が入力型のサブタイプである必要がありますが、 " +"``TypeGuard`` にはその要求がありません。主な理由は、 ``list`` は共変でない " +"ため、 ``list[str]`` は ``list[object]`` のサブタイプではありませんが、 " +"``list[object]`` を ``list[str]`` に絞り込むような操作を可能にするためです。" #: ../../library/typing.rst:1642 msgid "" @@ -3006,6 +3127,10 @@ msgid "" "combining the previously known type of the variable with the ``TypeIs`` " "type. (Technically, this is known as an intersection type.)" msgstr "" +"``TypeGuard`` 関数が ``True`` を返すとき、型チェッカーは変数の型を正確に " +"``TypeGuard`` 型に絞り込みます。 ``TypeIs`` 関数が ``True`` を返すとき、型 " +"チェッカーは変数の以前に知られていた型と ``TypeIs`` 型を組み合わせてより正 " +"確な型を推論できます(技術的には、これは交差型と呼ばれます)。" #: ../../library/typing.rst:1646 msgid "" @@ -3014,10 +3139,13 @@ msgid "" "``False``, type checkers can narrow the type of the variable to exclude the " "``TypeIs`` type." msgstr "" +"``TypeGuard`` 関数が ``False`` を返すとき、型チェッカーは変数の型を全く絞 " +"り込むことができません。 ``TypeIs`` 関数が ``False`` を返すとき、型チェッ " +"カーは変数の型から ``TypeIs`` 型を除外するように絞り込むことができます。" #: ../../library/typing.rst:1655 msgid "Typing operator to conceptually mark an object as having been unpacked." -msgstr "" +msgstr "オブジェクトがアンパックされたことを概念的に示す型付け演算子です。" #: ../../library/typing.rst:1657 msgid "" @@ -3025,6 +3153,9 @@ msgid "" "` is equivalent to using ``Unpack`` to mark the type variable " "tuple as having been unpacked::" msgstr "" +"例えば、 :ref:`type variable tuple ` でアンパック演算子 ``*`` " +"を使用することは、 ``Unpack`` を使用して型変数タプルがアンパックされたこと " +"をマークすることと同等です::" #: ../../library/typing.rst:1661 msgid "" @@ -3033,6 +3164,10 @@ msgid "" "# Effectively does:\n" "tup: tuple[Unpack[Ts]]" msgstr "" +"Ts = TypeVarTuple('Ts')\n" +"tup: tuple[*Ts]\n" +"# 実質的には:\n" +"tup: tuple[Unpack[Ts]]" #: ../../library/typing.rst:1666 msgid "" @@ -3041,6 +3176,10 @@ msgid "" "` types. You might see ``Unpack`` being used explicitly in older " "versions of Python, where ``*`` couldn't be used in certain places::" msgstr "" +"実際、 ``Unpack`` は :class:`typing.TypeVarTuple ` と :class:" +"`builtins.tuple ` 型のコンテキストにおいて ``*`` と相互に使用できま " +"す。 ``*`` が特定の場所で使用できなかった古いバージョンの Python では、 " +"``Unpack`` が明示的に使用されているのを見ることがあります::" #: ../../library/typing.rst:1672 msgid "" @@ -3058,6 +3197,8 @@ msgid "" "``Unpack`` can also be used along with :class:`typing.TypedDict` for typing " "``**kwargs`` in a function signature::" msgstr "" +"``Unpack`` は :class:`typing.TypedDict` と組み合わせて関数シグネチャの " +"``**kwargs`` の型付けにも使用できます::" #: ../../library/typing.rst:1683 msgid "" @@ -3076,10 +3217,12 @@ msgstr "" msgid "" "See :pep:`692` for more details on using ``Unpack`` for ``**kwargs`` typing." msgstr "" +"``**kwargs`` の型付けでの ``Unpack`` の使用に関する詳細については :pep: " +"`692` を参照してください。" #: ../../library/typing.rst:1698 msgid "Building generic types and type aliases" -msgstr "" +msgstr "ジェネリック型と型エイリアスの構築" #: ../../library/typing.rst:1700 msgid "" @@ -3087,6 +3230,8 @@ msgid "" "intended purpose is to be building blocks for creating generic types and " "type aliases." msgstr "" +"以下のクラスはアノテーションとして直接使用すべきではありません。これらの " +"目的は、ジェネリック型と型エイリアスを作成するための構成要素となることです。" #: ../../library/typing.rst:1704 msgid "" @@ -3095,6 +3240,9 @@ msgid "" "with Python 3.11 and earlier, they can also be created without the dedicated " "syntax, as documented below." msgstr "" +"これらのオブジェクトは特別な構文( :ref:`type parameter lists ` " +"と :keyword:`type` 文)で作成できます。 Python 3.11 以前との互換性のため、 " +"以下に記載されているように専用構文なしでも作成できます。" #: ../../library/typing.rst:1711 msgid "Abstract base class for generic types." @@ -3138,6 +3286,8 @@ msgid "" "Here the brackets after the function name indicate a :ref:`generic function " "`." msgstr "" +"ここで関数名の後の角括弧は :ref:`generic function ` を示 " +"しています。" #: ../../library/typing.rst:1736 msgid "" @@ -3145,6 +3295,8 @@ msgid "" "explicitly inheriting from ``Generic``. In this case, the type parameters " "must be declared separately::" msgstr "" +"後方互換性のため、ジェネリッククラスは ``Generic`` から明示的に継承するこ " +"とでも宣言できます。この場合、型パラメータは別途宣言する必要があります::" #: ../../library/typing.rst:1741 msgid "" @@ -3167,6 +3319,9 @@ msgid "" "for :ref:`generic functions `, :ref:`generic classes " "`, and :ref:`generic type aliases `::" msgstr "" +"型変数を構築する推奨方法は、 :ref:`generic functions ` 、 " +":ref:`generic classes ` 、および :ref:`generic type aliases " +"` 専用の構文を使用することです::" #: ../../library/typing.rst:1760 msgid "" @@ -3179,6 +3334,7 @@ msgid "" "This syntax can also be used to create bounded and constrained type " "variables::" msgstr "" +"この構文は境界のある型変数と制約のある型変数を作成するためにも使用できます::" #: ../../library/typing.rst:1766 msgid "" @@ -3196,6 +3352,7 @@ msgid "" "However, if desired, reusable type variables can also be constructed " "manually, like so::" msgstr "" +"ただし、必要に応じて、再利用可能な型変数を手動で構築することもできます::" #: ../../library/typing.rst:1775 msgid "" @@ -3203,6 +3360,9 @@ msgid "" "S = TypeVar('S', bound=str) # Can be any subtype of str\n" "A = TypeVar('A', str, bytes) # Must be exactly str or bytes" msgstr "" +"T = TypeVar('T') # 何でも可\n" +"S = TypeVar('S', bound=str) # str のサブタイプ\n" +"A = TypeVar('A', str, bytes) # 正確に str または bytes" #: ../../library/typing.rst:1779 msgid "" @@ -3211,6 +3371,10 @@ msgid "" "function and type alias definitions. See :class:`Generic` for more " "information on generic types. Generic functions work as follows::" msgstr "" +"型変数は主に静的型チェッカーの利益のために存在します。ジェネリック型のパラ " +"メータとして、またジェネリック関数と型エイリアス定義のパラメータとして機能し " +"ます。ジェネリック型に関する詳細については :class:`Generic` を参照してくだ " +"さい。ジェネリック関数は以下のように動作します::" #: ../../library/typing.rst:1785 msgid "" @@ -3235,6 +3399,8 @@ msgid "" "Note that type variables can be *bounded*, *constrained*, or neither, but " "cannot be both bounded *and* constrained." msgstr "" +"型変数は *境界のある* 、 *制約のある* 、またはどちらでもないことができます " +"が、境界 *と* 制約の両方を持つことはできません。" #: ../../library/typing.rst:1803 msgid "" @@ -3245,6 +3411,12 @@ msgid "" "or ``contravariant=True``. By default, manually created type variables are " "invariant. See :pep:`484` and :pep:`695` for more details." msgstr "" +"型変数の分散は、 :ref:`type parameter syntax ` で作成されたと " +"きや ``infer_variance=True`` が渡されたときに型チェッカーによって推論されま " +"す。手動で作成された型変数は、 ``covariant=True`` または " +"``contravariant=True`` を渡すことで明示的に共変または反変としてマークできま " +"す。デフォルトでは、手動で作成された型変数は不変です。詳細については :pep: " +"`484` と :pep:`695` を参照してください。" #: ../../library/typing.rst:1811 msgid "" @@ -3252,6 +3424,9 @@ msgid "" "semantics in several important ways. Using a *bounded* type variable means " "that the ``TypeVar`` will be solved using the most specific type possible::" msgstr "" +"境界のある型変数と制約のある型変数は、いくつかの重要な点で異なるセマンティ " +"クスを持ちます。 *境界のある* 型変数を使用すると、 ``TypeVar`` は可能な限り " +"最も具体的な型を使用して解決されます::" #: ../../library/typing.rst:1815 msgid "" @@ -3272,6 +3447,8 @@ msgid "" "The upper bound of a type variable can be a concrete type, abstract type " "(ABC or Protocol), or even a union of types::" msgstr "" +"型変数の上限は、具象型、抽象型 (ABC または Protocol)、さらには型のユニオンであっ " +"ても構いません::" #: ../../library/typing.rst:1829 msgid "" @@ -3289,6 +3466,8 @@ msgid "" "Using a *constrained* type variable, however, means that the ``TypeVar`` can " "only ever be solved as being exactly one of the constraints given::" msgstr "" +"一方、 *制約のある* 型変数を使用すると、 ``TypeVar`` は与えられた制約のうち " +"正確に1つとしてのみ解決されます::" #: ../../library/typing.rst:1841 msgid "" @@ -3305,28 +3484,29 @@ msgstr "" #: ../../library/typing.rst:1849 msgid "At runtime, ``isinstance(x, T)`` will raise :exc:`TypeError`." -msgstr "" +msgstr "実行時には、``isinstance(x, T)`` は :exc:`TypeError` を発生させます。" #: ../../library/typing.rst:1853 msgid "The name of the type variable." -msgstr "" +msgstr "型変数の名前です。" #: ../../library/typing.rst:1857 msgid "Whether the type var has been explicitly marked as covariant." -msgstr "" +msgstr "型変数が明示的に共変としてマークされているかどうかです。" #: ../../library/typing.rst:1861 msgid "Whether the type var has been explicitly marked as contravariant." -msgstr "" +msgstr "型変数が明示的に反変としてマークされているかどうかです。" #: ../../library/typing.rst:1865 msgid "" "Whether the type variable's variance should be inferred by type checkers." msgstr "" +"型変数の分散が型チェッカーによって推論されるべきかどうか。" #: ../../library/typing.rst:1871 msgid "The upper bound of the type variable, if any." -msgstr "" +msgstr "型変数の上限境界があれば、その境界です。" #: ../../library/typing.rst:1875 msgid "" @@ -3334,6 +3514,9 @@ msgid "" "params>`, the bound is evaluated only when the attribute is accessed, not " "when the type variable is created (see :ref:`lazy-evaluation`)." msgstr "" +":ref:`type parameter syntax ` で作成された型変数の場合、境界 " +"は型変数が作成されたときではなく、属性がアクセスされたときにのみ評価されま " +"す( :ref:`lazy-evaluation` を参照)。" #: ../../library/typing.rst:1881 msgid "" @@ -3344,10 +3527,13 @@ msgid "" "passed to :func:`annotationlib.call_evaluate_function` to evaluate the value " "in a different format." msgstr "" +":attr:`~TypeVar.__bound__` 属性に対応する :term:`evaluate function` です。" +"直接呼び出されると、このメソッドは :attr:`~annotationlib.Format.VALUE` フォーマットのみをサポートし、これは :attr:`~TypeVar.__bound__` 属性に直接アクセスするのと同等です。" +"しかし、メソッドオブジェクトを :func:`annotationlib.call_evaluate_function` に渡すことで、異なるフォーマットで値を評価することができます。" #: ../../library/typing.rst:1891 msgid "A tuple containing the constraints of the type variable, if any." -msgstr "" +msgstr "型変数の制約があれば、それを含むタプルです。" #: ../../library/typing.rst:1895 msgid "" @@ -3355,6 +3541,7 @@ msgid "" "params>`, the constraints are evaluated only when the attribute is accessed, " "not when the type variable is created (see :ref:`lazy-evaluation`)." msgstr "" +":ref:`型パラメーター構文 ` で作成された型変数の場合、制約は型変数が作成されたときではなく、属性がアクセスされたときにのみ評価されます( :ref:`lazy-evaluation` を参照)。" #: ../../library/typing.rst:1901 msgid "" @@ -3365,12 +3552,17 @@ msgid "" "method object can be passed to :func:`annotationlib.call_evaluate_function` " "to evaluate the value in a different format." msgstr "" +":attr:`~TypeVar.__constraints__` 属性に対応する :term:`evaluate function` です。" +"直接呼び出されると、このメソッドは :attr:`~annotationlib.Format.VALUE` フォーマットのみをサポートし、これは :attr:`~TypeVar.__constraints__` 属性に直接アクセスするのと同等です。" +"しかし、メソッドオブジェクトを :func:`annotationlib.call_evaluate_function` に渡すことで、異なるフォーマットで値を評価することができます。" #: ../../library/typing.rst:1911 msgid "" "The default value of the type variable, or :data:`typing.NoDefault` if it " "has no default." msgstr "" +"型変数のデフォルト値、またはデフォルトがない場合は :data:`typing.NoDefault` " +"。" #: ../../library/typing.rst:1918 msgid "" @@ -3381,6 +3573,9 @@ msgid "" "can be passed to :func:`annotationlib.call_evaluate_function` to evaluate " "the value in a different format." msgstr "" +":attr:`~TypeVar.__default__` 属性に対応する :term:`evaluate function` です。" +"直接呼び出されると、このメソッドは :attr:`~annotationlib.Format.VALUE` フォーマットのみをサポートし、これは :attr:`~TypeVar.__default__` 属性に直接アクセスするのと同等です。" +"しかし、メソッドオブジェクトを :func:`annotationlib.call_evaluate_function` に渡すことで、異なるフォーマットで値を評価することができます。" #: ../../library/typing.rst:1928 msgid "" @@ -3389,6 +3584,10 @@ msgid "" "NoDefault` singleton, except that it does not force evaluation of the :ref:" "`lazily evaluated ` default value." msgstr "" +"型変数がデフォルト値を持つかどうかを返します。これは :attr:`__default__` が " +":data:`typing.NoDefault` シングルトンでないかどうかをチェックすることと同等で " +"すが、 :ref:`lazily evaluated ` デフォルト値の評価を強制し " +"ません。" #: ../../library/typing.rst:1937 msgid "" @@ -3396,23 +3595,30 @@ msgid "" "params>` syntax introduced by :pep:`695`. The ``infer_variance`` parameter " "was added." msgstr "" +"型変数は :pep:`695` で導入された :ref:`type parameter ` 構文を " +"使用して宣言できるようになりました。 ``infer_variance`` パラメータが追加さ " +"れました。" #: ../../library/typing.rst:1943 ../../library/typing.rst:2092 #: ../../library/typing.rst:2204 msgid "Support for default values was added." -msgstr "" +msgstr "デフォルト値のサポートが追加されました。" #: ../../library/typing.rst:1949 msgid "" "Type variable tuple. A specialized form of :ref:`type variable ` " "that enables *variadic* generics." msgstr "" +"型変数タプル。 *可変個* ジェネリックを可能にする :ref:`type variable " +"` の特殊な形式です。" #: ../../library/typing.rst:1952 msgid "" "Type variable tuples can be declared in :ref:`type parameter lists ` using a single asterisk (``*``) before the name::" msgstr "" +"型変数タプルは :ref:`type parameter lists ` で名前の前に単一の " +"アスタリスク (``*``) を使用して宣言できます::" #: ../../library/typing.rst:1955 msgid "" @@ -3423,7 +3629,7 @@ msgstr "" #: ../../library/typing.rst:1958 msgid "Or by explicitly invoking the ``TypeVarTuple`` constructor::" -msgstr "" +msgstr "または ``TypeVarTuple`` コンストラクタを明示的に呼び出すことでも::" #: ../../library/typing.rst:1960 msgid "" @@ -3433,6 +3639,11 @@ msgid "" "def move_first_element_to_last(tup: tuple[T, *Ts]) -> tuple[*Ts, T]:\n" " return (*tup[1:], tup[0])" msgstr "" +"T = TypeVar(\"T\")\n" +"Ts = TypeVarTuple(\"Ts\")\n" +"\n" +"def move_first_element_to_last(tup: tuple[T, *Ts]) -> tuple[*Ts, T]:\n" +" return (*tup[1:], tup[0])" #: ../../library/typing.rst:1966 msgid "" @@ -3441,6 +3652,9 @@ msgid "" "number of types by acting like an *arbitrary* number of type variables " "wrapped in a tuple. For example::" msgstr "" +"通常の型変数は単一の型でのパラメータ化を可能にします。一方、型変数タプルは " +"タプルにラップされた *任意の* 数の型変数のように動作し、 *任意の* 数の型での " +"パラメータ化を可能にします。例えば::" #: ../../library/typing.rst:1971 msgid "" @@ -3461,6 +3675,22 @@ msgid "" "# (at least one element is required)\n" "move_first_element_to_last(tup=())" msgstr "" +"# T は int にバインド、Ts は () にバインド\n" +"# 戻り値は (1,) で、型は tuple[int]\n" +"move_first_element_to_last(tup=(1,))\n" +"\n" +"# T は int にバインド、Ts は (str,) にバインド\n" +"# 戻り値は ('spam', 1) で、型は tuple[str, int]\n" +"move_first_element_to_last(tup=(1, 'spam'))\n" +"\n" +"# T は int にバインド、Ts は (str, float) にバインド\n" +"# 戻り値は ('spam', 3.0, 1) で、型は tuple[str, float, int]\n" +"move_first_element_to_last(tup=(1, 'spam', 3.0))\n" +"\n" +"# これは型チェックに失敗する(実行時にも失敗する)\n" +"# tuple[()] は tuple[T, *Ts] と互換性がないため\n" +"# (少なくとも1つの要素が必要)\n" +"move_first_element_to_last(tup=())" #: ../../library/typing.rst:1988 msgid "" @@ -3471,12 +3701,17 @@ msgid "" "older versions of Python, you might see this written using :data:`Unpack " "` instead, as ``Unpack[Ts]``.)" msgstr "" +"``tuple[T, *Ts]`` でアンパック演算子 ``*`` を使用していることに注意してください。" +"概念的には、``Ts`` を型変数のタプル ``(T1, T2, ...)`` として考えることができます。" +"``tuple[T, *Ts]`` は ``tuple[T, *(T1, T2, ...)]`` となり、これは ``tuple[T, T1, T2, ...]`` と同等です。" +"(古いバージョンの Python では、代わりに :data:`Unpack ` を使用して ``Unpack[Ts]`` と書かれることもあります。)" #: ../../library/typing.rst:1996 msgid "" "Type variable tuples must *always* be unpacked. This helps distinguish type " "variable tuples from normal type variables::" msgstr "" +"型変数タプルは *常に* アンパックされる必要があります。これにより、型変数タプルと通常の型変数を区別できます::" #: ../../library/typing.rst:1999 msgid "" @@ -3484,6 +3719,9 @@ msgid "" "x: tuple[Ts] # Not valid\n" "x: tuple[*Ts] # The correct way to do it" msgstr "" +"x: Ts # 無効\n" +"x: tuple[Ts] # 無効\n" +"x: tuple[*Ts] # 正しい方法" #: ../../library/typing.rst:2003 msgid "" @@ -3503,6 +3741,7 @@ msgstr "" msgid "" "Type variable tuples can be happily combined with normal type variables:" msgstr "" +"型変数タプルは通常の型変数と組み合わせることができます:" #: ../../library/typing.rst:2013 msgid "" @@ -3524,6 +3763,7 @@ msgid "" "However, note that at most one type variable tuple may appear in a single " "list of type arguments or type parameters::" msgstr "" +"ただし、単一の型引数または型パラメーターのリストには、最大1つの型変数タプルのみが現れることができることに注意してください::" #: ../../library/typing.rst:2030 msgid "" @@ -3537,6 +3777,7 @@ msgid "" "Finally, an unpacked type variable tuple can be used as the type annotation " "of ``*args``::" msgstr "" +"最後に、アンパックされた型変数タプルを ``*args`` の型アノテーションとして使用できます::" #: ../../library/typing.rst:2037 msgid "" @@ -3556,20 +3797,23 @@ msgid "" "Here, this allows us to ensure the types of the ``*args`` passed to " "``call_soon`` match the types of the (positional) arguments of ``callback``." msgstr "" +"``*args`` のアンパックされていないアノテーション(例:``*args: int``)は *すべての* 引数が ``int`` であることを指定するのに対し、``*args: *Ts`` は ``*args`` の *個々の* 引数の型を参照できます。" +"ここでは、``call_soon`` に渡される ``*args`` の型が ``callback`` の(位置)引数の型と一致することを保証できます。" #: ../../library/typing.rst:2051 msgid "See :pep:`646` for more details on type variable tuples." -msgstr "" +msgstr "型変数タプルの詳細については :pep:`646` を参照してください。" #: ../../library/typing.rst:2055 msgid "The name of the type variable tuple." -msgstr "" +msgstr "型変数タプルの名前です。" #: ../../library/typing.rst:2059 msgid "" "The default value of the type variable tuple, or :data:`typing.NoDefault` if " "it has no default." msgstr "" +"型変数タプルのデフォルト値、またはデフォルトがない場合は :data:`typing.NoDefault` です。" #: ../../library/typing.rst:2066 msgid "" @@ -3580,6 +3824,9 @@ msgid "" "object can be passed to :func:`annotationlib.call_evaluate_function` to " "evaluate the value in a different format." msgstr "" +":attr:`~TypeVarTuple.__default__` 属性に対応する :term:`evaluate function` です。" +"直接呼び出されると、このメソッドは :attr:`~annotationlib.Format.VALUE` フォーマットのみをサポートし、これは :attr:`~TypeVarTuple.__default__` 属性に直接アクセスするのと同等です。" +"しかし、メソッドオブジェクトを :func:`annotationlib.call_evaluate_function` に渡すことで、異なるフォーマットで値を評価することができます。" #: ../../library/typing.rst:2076 msgid "" @@ -3588,38 +3835,46 @@ msgid "" "NoDefault` singleton, except that it does not force evaluation of the :ref:" "`lazily evaluated ` default value." msgstr "" +"型変数タプルがデフォルト値を持つかどうかを返します。これは、:attr:`__default__` が :data:`typing.NoDefault` シングルトンでないかどうかをチェックするのと同等ですが、:ref:`遅延評価 ` されるデフォルト値の評価を強制しません。" #: ../../library/typing.rst:2087 msgid "" "Type variable tuples can now be declared using the :ref:`type parameter " "` syntax introduced by :pep:`695`." msgstr "" +"型変数タプルは、:pep:`695` で導入された :ref:`型パラメーター ` 構文を使用して宣言できるようになりました。" #: ../../library/typing.rst:2096 msgid "" "Parameter specification variable. A specialized version of :ref:`type " "variables `." msgstr "" +"パラメータ仕様変数。 :ref:`type variables ` の特殊なバージョンで " +"す。" #: ../../library/typing.rst:2099 msgid "" "In :ref:`type parameter lists `, parameter specifications can " "be declared with two asterisks (``**``)::" msgstr "" +":ref:`type parameter lists ` では、パラメータ仕様を二重アス " +"タリスク (``**``) で宣言できます::" #: ../../library/typing.rst:2102 msgid "type IntFunc[**P] = Callable[P, int]" -msgstr "" +msgstr "type IntFunc[**P] = Callable[P, int]" #: ../../library/typing.rst:2104 msgid "" "For compatibility with Python 3.11 and earlier, ``ParamSpec`` objects can " "also be created as follows::" msgstr "" +"Python 3.11 以前との互換性のため、 ``ParamSpec`` オブジェクトは以下のよう " +"にも作成できます::" #: ../../library/typing.rst:2107 msgid "P = ParamSpec('P')" -msgstr "" +msgstr "P = ParamSpec('P')" #: ../../library/typing.rst:2109 msgid "" @@ -3630,6 +3885,12 @@ msgid "" "first argument to ``Callable``, or as parameters for user-defined Generics. " "See :class:`Generic` for more information on generic types." msgstr "" +"パラメータ仕様変数は主に静的型チェッカーの利益のために存在します。これらは " +"ある callable のパラメータ型を別の callable に転送するために使用され、これ " +"は高階関数やデコレーターで一般的に見られるパターンです。これらは " +"``Concatenate`` で使用されるか、 ``Callable`` の最初の引数として、またはユー " +"ザー定義の Generics のパラメータとして使用される場合のみ有効です。ジェネ " +"リック型の詳細については :class:`Generic` を参照してください。" #: ../../library/typing.rst:2116 msgid "" @@ -3638,6 +3899,10 @@ msgid "" "tells the type checker that the callable passed into the decorator and the " "new callable returned by it have inter-dependent type parameters::" msgstr "" +"例えば、関数に基本的なログ記録を追加するために、関数呼び出しをログに記録す " +"る ``add_logging`` デコレーターを作成できます。パラメータ仕様変数は、デコ " +"レーターに渡される callable と、それによって返される新しい callable が相互 " +"依存の型パラメータを持つことを型チェッカーに伝えます::" #: ../../library/typing.rst:2121 msgid "" @@ -3663,12 +3928,16 @@ msgid "" "use a :class:`TypeVar` with upper bound ``Callable[..., Any]``. However " "this causes two problems:" msgstr "" +"``ParamSpec`` がなければ、以前これをアノテーションする最も簡単な方法は、上 " +"限境界 ``Callable[..., Any]`` を持つ :class:`TypeVar` を使用することでした。 " +"しかし、これは2つの問題を引き起こします:" #: ../../library/typing.rst:2140 msgid "" "The type checker can't type check the ``inner`` function because ``*args`` " "and ``**kwargs`` have to be typed :data:`Any`." msgstr "" +"型チェッカーは ``inner`` 関数を型チェックできません。なぜなら ``*args`` と ``**kwargs`` は :data:`Any` として型付けされる必要があるからです。" #: ../../library/typing.rst:2142 msgid "" @@ -3676,6 +3945,9 @@ msgid "" "when returning the ``inner`` function, or the static type checker must be " "told to ignore the ``return inner``." msgstr "" +"``inner`` 関数を返すときに ``add_logging`` デコレータの本体で :func:`~cast` が " +"必要になる場合があります。または静的型チェッカーに ``return inner`` を無視する " +"よう伝える必要があります。" #: ../../library/typing.rst:2149 msgid "" @@ -3689,16 +3961,26 @@ msgid "" "``P.kwargs`` are instances respectively of :class:`ParamSpecArgs` and :class:" "`ParamSpecKwargs`." msgstr "" +"``ParamSpec`` は位置引数とキーワード引数の両方をキャプチャするため、 ``P." +"args`` と ``P.kwargs`` を使用して ``ParamSpec`` を構成要素に分割できます。 " +"``P.args`` は指定された呼び出しの位置パラメータのタプルを表し、 ``*args`` の " +"アノテーションにのみ使用すべきです。 ``P.kwargs`` は指定された呼び出しのキー " +"ワードパラメータとその値のマッピングを表し、 ``**kwargs`` のアノテーションに " +"のみ使用すべきです。両方の属性は、アノテーションされたパラメータがスコープ内 " +"にあることを要求します。実行時には、 ``P.args`` と ``P.kwargs`` はそれぞれ :" +"class:`ParamSpecArgs` と :class:`ParamSpecKwargs` のインスタンスです。" #: ../../library/typing.rst:2161 msgid "The name of the parameter specification." -msgstr "" +msgstr "パラメータ仕様の名前です。" #: ../../library/typing.rst:2165 msgid "" "The default value of the parameter specification, or :data:`typing." "NoDefault` if it has no default." msgstr "" +"パラメータ仕様のデフォルト値、またはデフォルトがない場合は :data:`typing." +"NoDefault` 。" #: ../../library/typing.rst:2172 msgid "" @@ -3709,6 +3991,9 @@ msgid "" "can be passed to :func:`annotationlib.call_evaluate_function` to evaluate " "the value in a different format." msgstr "" +":attr:`~ParamSpec.__default__` 属性に対応する :term:`evaluate function` です。" +"直接呼び出されると、このメソッドは :attr:`~annotationlib.Format.VALUE` フォーマットのみをサポートし、これは :attr:`~ParamSpec.__default__` 属性に直接アクセスするのと同等です。" +"しかし、メソッドオブジェクトを :func:`annotationlib.call_evaluate_function` に渡すことで、異なるフォーマットで値を評価することができます。" #: ../../library/typing.rst:2182 msgid "" @@ -3717,6 +4002,7 @@ msgid "" "`typing.NoDefault` singleton, except that it does not force evaluation of " "the :ref:`lazily evaluated ` default value." msgstr "" +"パラメータ仕様がデフォルト値を持つかどうかを返します。これは、:attr:`__default__` が :data:`typing.NoDefault` シングルトンでないかどうかをチェックするのと同等ですが、:ref:`遅延評価 ` されるデフォルト値の評価を強制しません。" #: ../../library/typing.rst:2189 msgid "" @@ -3726,22 +4012,26 @@ msgid "" "`TypeVar`. However the actual semantics of these keywords are yet to be " "decided." msgstr "" +"``covariant=True`` または ``contravariant=True`` で作成されたパラメータ仕様変数は、共変性または反変性のジェネリック型を宣言するために使用できます。" +":class:`TypeVar` と同様に、``bound`` 引数も受け入れられます。しかし、これらのキーワードの実際のセマンティクスはまだ決定されていません。" #: ../../library/typing.rst:2199 msgid "" "Parameter specifications can now be declared using the :ref:`type parameter " "` syntax introduced by :pep:`695`." msgstr "" +"パラメータ仕様は、:pep:`695` で導入された :ref:`型パラメーター ` 構文を使用して宣言できるようになりました。" #: ../../library/typing.rst:2207 msgid "" "Only parameter specification variables defined in global scope can be " "pickled." msgstr "" +"グローバルスコープで定義されたパラメータ仕様変数のみをpickleできます。" #: ../../library/typing.rst:2213 msgid ":data:`Concatenate`" -msgstr "" +msgstr ":data:`Concatenate`" #: ../../library/typing.rst:2219 msgid "" @@ -3750,12 +4040,15 @@ msgid "" "``P.kwargs`` is an instance of ``ParamSpecKwargs``. They are intended for " "runtime introspection and have no special meaning to static type checkers." msgstr "" +":class:`ParamSpec` の引数とキーワード引数の属性です。``ParamSpec`` の ``P.args`` 属性は ``ParamSpecArgs`` のインスタンスで、``P.kwargs`` は ``ParamSpecKwargs`` のインスタンスです。これらは実行時のイントロスペクション用で、静的型チェッカーには特別な意味はありません。" #: ../../library/typing.rst:2224 msgid "" "Calling :func:`get_origin` on either of these objects will return the " "original ``ParamSpec``:" msgstr "" +"これらのオブジェクトのいずれかで :func:`get_origin` を呼び出すと、元の " +"``ParamSpec`` が返されます:" #: ../../library/typing.rst:2227 msgid "" @@ -3769,7 +4062,7 @@ msgstr "" #: ../../library/typing.rst:2241 msgid "The type of type aliases created through the :keyword:`type` statement." -msgstr "" +msgstr ":keyword:`type` 文で作成された型エイリアスの型です。" #: ../../library/typing.rst:2245 msgid "" @@ -3780,7 +4073,7 @@ msgstr "" #: ../../library/typing.rst:2255 msgid "The name of the type alias:" -msgstr "" +msgstr "型エイリアスの名前:" #: ../../library/typing.rst:2257 msgid "" @@ -3791,7 +4084,7 @@ msgstr "" #: ../../library/typing.rst:2265 msgid "The module in which the type alias was defined::" -msgstr "" +msgstr "型エイリアスが定義されたモジュール::" #: ../../library/typing.rst:2267 msgid "" @@ -3805,6 +4098,8 @@ msgid "" "The type parameters of the type alias, or an empty tuple if the alias is not " "generic:" msgstr "" +"型エイリアスの型パラメータ、またはエイリアスがジェネリックでない場合は空の " +"タプル:" #: ../../library/typing.rst:2276 msgid "" @@ -3822,6 +4117,9 @@ msgid "" "so names used in the definition of the alias are not resolved until the " "``__value__`` attribute is accessed:" msgstr "" +"型エイリアスの値。これは :ref:`lazily evaluated ` であり、 " +"エイリアスの定義で使用される名前は ``__value__`` 属性がアクセスされるまで解 " +"決されません:" #: ../../library/typing.rst:2291 msgid "" @@ -3846,6 +4144,7 @@ msgid "" "func:`annotationlib.call_evaluate_function` to evaluate the value in a " "different format:" msgstr "" +":attr:`__value__` 属性に対応する :term:`evaluate function` です。直接呼び出されると、このメソッドは :attr:`~annotationlib.Format.VALUE` フォーマットのみをサポートし、これは :attr:`__value__` 属性に直接アクセスするのと同等です。しかし、メソッドオブジェクトを :func:`annotationlib.call_evaluate_function` に渡すことで、異なるフォーマットで値を評価することができます:" #: ../../library/typing.rst:2312 msgid "" @@ -3872,6 +4171,7 @@ msgid "" "Type aliases support star unpacking using the ``*Alias`` syntax. This is " "equivalent to using ``Unpack[Alias]`` directly:" msgstr "" +"型エイリアスは ``*Alias`` 構文を使用したスターアンパックをサポートします。これは ``Unpack[Alias]`` を直接使用するのと同等です:" #: ../../library/typing.rst:2334 msgid "" @@ -3883,7 +4183,7 @@ msgstr "" #: ../../library/typing.rst:2345 msgid "Other special directives" -msgstr "" +msgstr "その他の特別なディレクティブ" #: ../../library/typing.rst:2347 msgid "" @@ -3891,6 +4191,7 @@ msgid "" "Their intended purpose is to be building blocks for creating and declaring " "types." msgstr "" +"これらの関数とクラスは、アノテーションとして直接使用すべきではありません。これらの意図された目的は、型を作成し宣言するためのビルディングブロックとなることです。" #: ../../library/typing.rst:2353 msgid "Typed version of :func:`collections.namedtuple`." @@ -3914,7 +4215,7 @@ msgstr "これは次と等価です::" #: ../../library/typing.rst:2363 msgid "Employee = collections.namedtuple('Employee', ['name', 'id'])" -msgstr "" +msgstr "Employee = collections.namedtuple('Employee', ['name', 'id'])" #: ../../library/typing.rst:2365 msgid "" @@ -3968,7 +4269,7 @@ msgstr "" #: ../../library/typing.rst:2392 msgid "``NamedTuple`` subclasses can be generic::" -msgstr "" +msgstr "``NamedTuple`` サブクラスはジェネリックにできます::" #: ../../library/typing.rst:2394 msgid "" @@ -4000,7 +4301,7 @@ msgstr ":pep:`526` 変数アノテーションのシンタックスが追加さ #: ../../library/typing.rst:2413 msgid "Added support for default values, methods, and docstrings." -msgstr "" +msgstr "デフォルト値、メソッド、ドキュメンテーション文字列のサポートが追加されました。" "デフォルト値、メソッド、ドキュメンテーション文字列への対応が追加されました。" #: ../../library/typing.rst:2416 @@ -4021,7 +4322,7 @@ msgstr "" #: ../../library/typing.rst:2424 msgid "Added support for generic namedtuples." -msgstr "" +msgstr "ジェネリック namedtuple のサポートが追加されました。" #: ../../library/typing.rst:2427 msgid "" @@ -4029,6 +4330,7 @@ msgid "" "methods of ``NamedTuple`` subclasses is unsupported and causes a :class:" "`TypeError`." msgstr "" +"``NamedTuple`` サブクラスのメソッドで :func:`super` (と ``__class__`` :term:`クロージャ変数`)を使用することはサポートされておらず、:class:`TypeError` を引き起こします。" #: ../../library/typing.rst:2431 msgid "" @@ -4036,6 +4338,7 @@ msgid "" "(``NT = NamedTuple(\"NT\", x=int)``) is deprecated, and will be disallowed " "in 3.15. Use the class-based syntax or the functional syntax instead." msgstr "" +"NamedTuple クラスを作成するための文書化されていないキーワード引数構文(``NT = NamedTuple(\"NT\", x=int)``)は非推奨で、Python 3.15 では禁止されます。代わりにクラスベースの構文または関数型構文を使用してください。" #: ../../library/typing.rst:2436 msgid "" @@ -4046,6 +4349,12 @@ msgid "" "Python 3.15. To create a NamedTuple class with 0 fields, use ``class " "NT(NamedTuple): pass`` or ``NT = NamedTuple(\"NT\", [])``." msgstr "" +"NamedTuple クラスを作成するために関数型構文を使用する際、'fields' パラメータに " +"値を渡さない (``NT = NamedTuple(\"NT\")``) ことは非推奨です。'fields' パラメータ " +"に ``None`` を渡すこと (``NT = NamedTuple(\"NT\", None)``) も非推奨です。両方とも " +"Python 3.15 で許可されなくなります。フィールドが 0 個の NamedTuple クラスを作成 " +"するには、``class NT(NamedTuple): pass`` または ``NT = NamedTuple(\"NT\", [])`` " +"を使用してください。" #: ../../library/typing.rst:2446 msgid "Helper class to create low-overhead :ref:`distinct types `." @@ -4056,6 +4365,8 @@ msgid "" "A ``NewType`` is considered a distinct type by a typechecker. At runtime, " "however, calling a ``NewType`` returns its argument unchanged." msgstr "" +"``NewType`` は型チェッカーによって異なる型とみなされます。しかし実行時には、 " +"``NewType`` を呼び出すとその引数を変更せずに返します。" #: ../../library/typing.rst:2453 msgid "" @@ -4063,18 +4374,20 @@ msgid "" "first_user = UserId(1) # \"UserId\" returns the argument unchanged at " "runtime" msgstr "" +"UserId = NewType('UserId', int) # NewType \"UserId\" を宣言\n" +"first_user = UserId(1) # \"UserId\" は実行時に引数を変更せずに返す" #: ../../library/typing.rst:2458 msgid "The module in which the new type is defined." -msgstr "" +msgstr "新しい型が定義されたモジュールです。" #: ../../library/typing.rst:2462 msgid "The name of the new type." -msgstr "" +msgstr "新しい型の名前です。" #: ../../library/typing.rst:2466 msgid "The type that the new type is based on." -msgstr "" +msgstr "新しい型のベースとなる型です。" #: ../../library/typing.rst:2470 msgid "``NewType`` is now a class rather than a function." @@ -4086,7 +4399,7 @@ msgstr "" #: ../../library/typing.rst:2477 msgid "Protocol classes are defined like this::" -msgstr "" +msgstr "Protocol クラスは以下のように定義します::" #: ../../library/typing.rst:2479 msgid "" @@ -4123,6 +4436,11 @@ msgid "" "signatures. Protocol classes without this decorator cannot be used as the " "second argument to :func:`isinstance` or :func:`issubclass`." msgstr "" +"詳細については :pep:`544` を参照してください。 :func:`runtime_checkable` " +"(後述)でデコレートされた Protocol クラスは、型シグネチャを無視して指定され " +"た属性の存在のみをチェックする単純な実行時プロトコルとして機能します。このデ " +"コレーターのない Protocol クラスは :func:`isinstance` や :func:`issubclass` " +"の第2引数として使用できません。" #: ../../library/typing.rst:2501 msgid "Protocol classes can be generic, for example::" @@ -4140,6 +4458,7 @@ msgid "" "In code that needs to be compatible with Python 3.11 or older, generic " "Protocols can be written as follows::" msgstr "" +"Python 3.11 以前との互換性が必要なコードでは、ジェネリック Protocol を以下のように書くことができます::" #: ../../library/typing.rst:2510 msgid "" @@ -4149,10 +4468,16 @@ msgid "" " def meth(self) -> T:\n" " ..." msgstr "" +"T = TypeVar(\"T\")\n" +"\n" +"class GenProto(Protocol[T]):\n" +" def meth(self) -> T:\n" +" ..." #: ../../library/typing.rst:2520 msgid "Mark a protocol class as a runtime protocol." msgstr "" +"プロトコルクラスをランタイムプロトコルとしてマークします。" #: ../../library/typing.rst:2522 msgid "" @@ -4161,6 +4486,7 @@ msgid "" "ponies\" in :mod:`collections.abc` such as :class:`~collections.abc." "Iterable`. For example::" msgstr "" +"このようなプロトコルは :func:`isinstance` や :func:`issubclass` と一緒に使用できます。これにより、:mod:`collections.abc` の :class:`~collections.abc.Iterable` のような\"ワントリックポニー\"と非常に似た単純な構造チェックが可能になります。例えば::" #: ../../library/typing.rst:2526 msgid "" @@ -4182,6 +4508,7 @@ msgstr "" msgid "" "This decorator raises :exc:`TypeError` when applied to a non-protocol class." msgstr "" +"このデコレーターは、非プロトコルクラスに適用されると :exc:`TypeError` を発生させます。" #: ../../library/typing.rst:2543 msgid "" @@ -4193,6 +4520,12 @@ msgid "" "more informative message, therefore making it impossible to call " "(instantiate) :class:`ssl.SSLObject`." msgstr "" +":func:`!runtime_checkable` は必要なメソッドや属性の存在のみをチェックし、その型 " +"シグネチャーや型はチェックしません。例えば、:class:`ssl.SSLObject` はクラスなので、 " +":ref:`Callable ` に対する :func:`issubclass` チェックを通過 " +"します。しかし、``ssl.SSLObject.__init__`` メソッドはより詳細なメッセージで :exc:" +"`TypeError` を発生させるためにのみ存在するため、:class:`ssl.SSLObject` を呼び出す " +"(インスタンス化する)ことは不可能です。" #: ../../library/typing.rst:2554 msgid "" @@ -4201,6 +4534,7 @@ msgid "" "protocol class. Consider using alternative idioms such as :func:`hasattr` " "calls for structural checks in performance-sensitive code." msgstr "" +"ランタイムチェック可能プロトコルに対する :func:`isinstance` チェックは、非プロトコルクラスに対する ``isinstance()`` チェックと比べて驚くほど遅い場合があります。パフォーマンスに敏感なコードでは、構造チェックのために :func:`hasattr` 呼び出しなどの代替イディオムの使用を検討してください。" #: ../../library/typing.rst:2562 msgid "" @@ -4211,6 +4545,7 @@ msgid "" "longer be considered instances of that protocol on Python 3.12+, and vice " "versa. Most users are unlikely to be affected by this change." msgstr "" +"ランタイムチェック可能プロトコルに対する :func:`isinstance` チェックの内部実装は、属性を検索するために :func:`inspect.getattr_static` を使用するようになりました(以前は :func:`hasattr` が使用されていました)。その結果、Python 3.12+ では、以前はランタイムチェック可能プロトコルのインスタンスとみなされていた一部のオブジェクトが、もはやそのプロトコルのインスタンスとみなされない場合があり、その逆もあります。ほとんどのユーザーはこの変更の影響を受けないと思われます。" #: ../../library/typing.rst:2571 msgid "" @@ -4220,12 +4555,19 @@ msgid "" "on :func:`isinstance` checks comparing objects to the protocol. See :ref:" "`\"What's new in Python 3.12\" ` for more details." msgstr "" +"実行時チェック可能なプロトコルのメンバーは、クラスが作成されるとすぐに実行時に" +"「固定」されるようになりました。実行時チェック可能なプロトコルへの属性のモンキー" +"パッチは引き続き機能しますが、オブジェクトをプロトコルと比較する :func:`isinstance` " +"チェックには影響しません。詳細については :ref:`\"What's new in Python 3.12\" " +"` を参照してください。" #: ../../library/typing.rst:2582 msgid "" "Special construct to add type hints to a dictionary. At runtime it is a " "plain :class:`dict`." msgstr "" +"辞書に型ヒントを追加するための特別な構成です。実行時には通常の :class:`dict` " +"です。" #: ../../library/typing.rst:2585 msgid "" @@ -4258,10 +4600,12 @@ msgid "" "An alternative way to create a ``TypedDict`` is by using function-call " "syntax. The second argument must be a literal :class:`dict`::" msgstr "" +"``TypedDict`` を作成する代替方法は、関数呼び出し構文を使用することです。第2 " +"引数はリテラル :class:`dict` である必要があります::" #: ../../library/typing.rst:2604 msgid "Point2D = TypedDict('Point2D', {'x': int, 'y': int, 'label': str})" -msgstr "" +msgstr "Point2D = TypedDict('Point2D', {'x': int, 'y': int, 'label': str})" #: ../../library/typing.rst:2606 msgid "" @@ -4270,6 +4614,7 @@ msgid "" "contain hyphens, or when key names must not be :ref:`mangled ` like regular private names::" msgstr "" +"この関数型構文では、有効な :ref:`識別子 ` ではないキーを定義できます。例えば、キーワードであったりハイフンを含んでいたり、或いは通常のプライベート名のように :ref:`マングル ` されたくないキー名の場合です::" #: ../../library/typing.rst:2611 msgid "" @@ -4291,6 +4636,9 @@ msgid "" "By default, all keys must be present in a ``TypedDict``. It is possible to " "mark individual keys as non-required using :data:`NotRequired`::" msgstr "" +"デフォルトでは、``TypedDict`` のすべてのキーが必要です。:data:`NotRequired` を使用して個別のキーを非必須としてマークすることが可能です::" +"デフォルトでは、 ``TypedDict`` ではすべてのキーが必要です。 :data:" +"`NotRequired` を使用して個別のキーを不要としてマークすることも可能です::" #: ../../library/typing.rst:2626 msgid "" @@ -4309,12 +4657,14 @@ msgid "" "This means that a ``Point2D`` ``TypedDict`` can have the ``label`` key " "omitted." msgstr "" +"これは、``Point2D`` ``TypedDict`` が ``label`` キーを省略できることを意味します。" #: ../../library/typing.rst:2637 msgid "" "It is also possible to mark all keys as non-required by default by " "specifying a totality of ``False``::" msgstr "" +"``False`` の totality を指定することで、デフォルトですべてのキーを非必須としてマークすることも可能です::" #: ../../library/typing.rst:2640 msgid "" @@ -4339,6 +4689,7 @@ msgid "" "Individual keys of a ``total=False`` ``TypedDict`` can be marked as required " "using :data:`Required`::" msgstr "" +"``total=False`` の ``TypedDict`` の個別のキーは、:data:`Required` を使用して必須としてマークできます::" #: ../../library/typing.rst:2655 msgid "" @@ -4360,6 +4711,7 @@ msgid "" "It is possible for a ``TypedDict`` type to inherit from one or more other " "``TypedDict`` types using the class-based syntax. Usage::" msgstr "" +"``TypedDict`` 型は、クラスベースの構文を使用して、1つ以上の他の ``TypedDict`` 型から継承することが可能です。使い方::" #: ../../library/typing.rst:2671 msgid "" @@ -4372,6 +4724,7 @@ msgid "" "``Point3D`` has three items: ``x``, ``y`` and ``z``. It is equivalent to " "this definition::" msgstr "" +"``Point3D`` は3つの項目を持ちます:``x``、``y``、``z``。これは次の定義と同等です::" #: ../../library/typing.rst:2677 msgid "" @@ -4386,6 +4739,7 @@ msgid "" "A ``TypedDict`` cannot inherit from a non-\\ ``TypedDict`` class, except " "for :class:`Generic`. For example::" msgstr "" +"``TypedDict`` は :class:`Generic` を除いて、非 ``TypedDict`` クラスから継承できません。例えば::" #: ../../library/typing.rst:2685 msgid "" @@ -4404,7 +4758,7 @@ msgstr "" #: ../../library/typing.rst:2697 msgid "A ``TypedDict`` can be generic::" -msgstr "" +msgstr "``TypedDict`` はジェネリックにできます::" #: ../../library/typing.rst:2699 msgid "" @@ -4418,6 +4772,7 @@ msgid "" "To create a generic ``TypedDict`` that is compatible with Python 3.11 or " "lower, inherit from :class:`Generic` explicitly:" msgstr "" +"Python 3.11 以下と互換性のあるジェネリック ``TypedDict`` を作成するには、:class:`Generic` を明示的に継承してください:" #: ../../library/typing.rst:2706 msgid "" @@ -4427,6 +4782,11 @@ msgid "" " key: T\n" " group: list[T]" msgstr "" +"T = TypeVar(\"T\")\n" +"\n" +"class Group(TypedDict, Generic[T]):\n" +" key: T\n" +" group: list[T]" #: ../../library/typing.rst:2714 msgid "" @@ -4434,11 +4794,13 @@ msgid "" "`annotations-howto` for more information on annotations best practices), :" "attr:`__total__`, :attr:`__required_keys__`, and :attr:`__optional_keys__`." msgstr "" +"``TypedDict`` は、アノテーション辞書(アノテーションのベストプラクティスの詳細は :ref:`annotations-howto` を参照)、:attr:`__total__`、:attr:`__required_keys__`、:attr:`__optional_keys__` を通じてイントロスペクションできます。" #: ../../library/typing.rst:2720 msgid "" "``Point2D.__total__`` gives the value of the ``total`` argument. Example:" msgstr "" +"``Point2D.__total__`` は ``total`` 引数の値を返します。例:" #: ../../library/typing.rst:2723 msgid "" @@ -4471,6 +4833,8 @@ msgid "" "class:`frozenset` objects containing required and non-required keys, " "respectively." msgstr "" +"``Point2D.__required_keys__`` と ``Point2D.__optional_keys__`` は、それぞれ必須 " +"および非必須のキーを含む :class:`frozenset` オブジェクトを返します。" #: ../../library/typing.rst:2752 msgid "" @@ -4478,6 +4842,7 @@ msgid "" "``__required_keys__`` and keys marked with :data:`NotRequired` will always " "appear in ``__optional_keys__``." msgstr "" +":data:`Required` でマークされたキーは常に ``__required_keys__`` に表示され、:data:`NotRequired` でマークされたキーは常に ``__optional_keys__`` に表示されます。" #: ../../library/typing.rst:2755 msgid "" @@ -4487,6 +4852,7 @@ msgid "" "value for the ``total`` argument and then inheriting from it in another " "``TypedDict`` with a different value for ``total``:" msgstr "" +"Python 3.10 以下との後方互換性のため、同じ ``TypedDict`` で必須と非必須のキーの両方を宣言するために継承を使用することも可能です。これは、``total`` 引数に1つの値を指定した ``TypedDict`` を宣言し、それを別の ``total`` 値を持つ別の ``TypedDict`` で継承することで行います:" #: ../../library/typing.rst:2762 msgid "" @@ -4514,46 +4880,46 @@ msgstr "" #: ../../library/typing.rst:2786 msgid "Support for :data:`ReadOnly` is reflected in the following attributes:" -msgstr "" +msgstr ":data:`ReadOnly` のサポートは以下の属性に反映されます:" #: ../../library/typing.rst:2790 msgid "" "A :class:`frozenset` containing the names of all read-only keys. Keys are " "read-only if they carry the :data:`ReadOnly` qualifier." -msgstr "" +msgstr "すべての読み取り専用キーの名前を含む :class:`frozenset` です。:data:`ReadOnly` 修飾子を持つキーが読み取り専用になります。" #: ../../library/typing.rst:2797 msgid "" "A :class:`frozenset` containing the names of all mutable keys. Keys are " "mutable if they do not carry the :data:`ReadOnly` qualifier." -msgstr "" +msgstr "すべての可変キーの名前を含む :class:`frozenset` です。:data:`ReadOnly` 修飾子を持たないキーが可変になります。" #: ../../library/typing.rst:2802 msgid "" "See the `TypedDict `_ section in the typing documentation for more examples and " "detailed rules." -msgstr "" +msgstr "より多くの例と詳細なルールについては、型付けドキュメントの `TypedDict `_ セクションを参照してください。" #: ../../library/typing.rst:2806 msgid "" "Added support for marking individual keys as :data:`Required` or :data:" "`NotRequired`. See :pep:`655`." -msgstr "" +msgstr "個別のキーを :data:`Required` または :data:`NotRequired` としてマークするサポートが追加されました。:pep:`655` を参照してください。" #: ../../library/typing.rst:2810 msgid "Added support for generic ``TypedDict``\\ s." -msgstr "" +msgstr "ジェネリック ``TypedDict`` のサポートが追加されました。" #: ../../library/typing.rst:2813 msgid "" "Removed support for the keyword-argument method of creating ``TypedDict``\\ " "s." -msgstr "" +msgstr "``TypedDict`` を作成するキーワード引数メソッドのサポートが削除されました。" #: ../../library/typing.rst:2816 msgid "Support for the :data:`ReadOnly` qualifier was added." -msgstr "" +msgstr ":data:`ReadOnly` 修飾子のサポートが追加されました。" #: ../../library/typing.rst:2819 msgid "" @@ -4563,7 +4929,7 @@ msgid "" "TypedDict(\"TD\", None)``) is also deprecated. Both will be disallowed in " "Python 3.15. To create a TypedDict class with 0 fields, use ``class " "TD(TypedDict): pass`` or ``TD = TypedDict(\"TD\", {})``." -msgstr "" +msgstr "関数構文を使って TypedDict クラスを作成する際、'fields' パラメータに値を渡さない(``TD = TypedDict(\"TD\")``)ことは非推奨です。'fields' パラメータに ``None`` を渡す(``TD = TypedDict(\"TD\", None)``)ことも非推奨です。どちらも Python 3.15 では禁止されます。0個のフィールドを持つ TypedDict クラスを作成するには、``class TD(TypedDict): pass`` または ``TD = TypedDict(\"TD\", {})`` を使用してください。" #: ../../library/typing.rst:2828 msgid "Protocols" @@ -4573,7 +4939,7 @@ msgstr "プロトコル" msgid "" "The following protocols are provided by the :mod:`!typing` module. All are " "decorated with :func:`@runtime_checkable `." -msgstr "" +msgstr "以下のプロトコルは :mod:`!typing` モジュールによって提供されます。すべて :func:`@runtime_checkable ` でデコレートされています。" #: ../../library/typing.rst:2835 msgid "" @@ -4609,7 +4975,7 @@ msgstr "返り値の型と共変な抽象メソッド ``__round__`` を備えた #: ../../library/typing.rst:2868 msgid "ABCs and Protocols for working with I/O" -msgstr "" +msgstr "I/O での作業のための ABC と Protocol" #: ../../library/typing.rst:2874 msgid "" @@ -4618,6 +4984,10 @@ msgid "" "by :func:`open`. Please note that these classes are not protocols, and their " "interface is fairly broad." msgstr "" +"ジェネリッククラス ``IO[AnyStr]`` とそのサブクラス ``TextIO(IO[str])`` および " +"``BinaryIO(IO[bytes])`` は、:func:`open` によって返されるような I/O ストリームの " +"型を表します。これらのクラスはプロトコルではなく、そのインターフェースは非常に " +"幅広いことに注意してください。" #: ../../library/typing.rst:2880 msgid "" @@ -4625,6 +4995,7 @@ msgid "" "alternative for argument types, when only the ``read()`` or ``write()`` " "methods are accessed, respectively::" msgstr "" +"プロトコル :class:`io.Reader` と :class:`io.Writer` は、``read()`` または ``write()`` メソッドのみがアクセスされる場合の引数型のより簡単な代替手段を提供します::" #: ../../library/typing.rst:2884 msgid "" @@ -4638,6 +5009,7 @@ msgid "" "Also consider using :class:`collections.abc.Iterable` for iterating over the " "lines of an input stream::" msgstr "" +"入力ストリームの行を反復するために :class:`collections.abc.Iterable` を使用することも検討してください::" #: ../../library/typing.rst:2891 msgid "" @@ -4648,7 +5020,7 @@ msgstr "" #: ../../library/typing.rst:2896 msgid "Functions and decorators" -msgstr "" +msgstr "関数とデコレータ" #: ../../library/typing.rst:2900 msgid "Cast a value to a type." @@ -4670,18 +5042,21 @@ msgid "" "Ask a static type checker to confirm that *val* has an inferred type of " "*typ*." msgstr "" +"静的型チェッカーに *val* が *typ* の推論型を持つことを確認するよう求めます。" #: ../../library/typing.rst:2911 msgid "" "At runtime this does nothing: it returns the first argument unchanged with " "no checks or side effects, no matter the actual type of the argument." msgstr "" +"実行時にこれは何もしません:引数の実際の型に関係なく、チェックや副作用なしで最初の引数を変更せずに返します。" #: ../../library/typing.rst:2914 msgid "" "When a static type checker encounters a call to ``assert_type()``, it emits " "an error if the value is not of the specified type::" msgstr "" +"静的型チェッカーが ``assert_type()`` の呼び出しに遇うと、値が指定された型でない場合にエラーを発生させます::" #: ../../library/typing.rst:2917 msgid "" @@ -4695,6 +5070,7 @@ msgid "" "This function is useful for ensuring the type checker's understanding of a " "script is in line with the developer's intentions::" msgstr "" +"この関数は、スクリプトに対する型チェッカーの理解が開発者の意図と一致していることを確認するために有用です::" #: ../../library/typing.rst:2924 msgid "" @@ -4710,6 +5086,7 @@ msgstr "" msgid "" "Ask a static type checker to confirm that a line of code is unreachable." msgstr "" +"静的型チェッカーにコードの行が到達不可能であることを確認するよう求めます。" #: ../../library/typing.rst:2937 msgid "Example::" @@ -4733,6 +5110,7 @@ msgid "" "never execute, because ``arg`` is either an :class:`int` or a :class:`str`, " "and both options are covered by earlier cases." msgstr "" +"ここでは、アノテーションにより型チェッカーは最後のケースが決して実行されないことを推論できます。なぜなら ``arg`` は :class:`int` または :class:`str` のいずれかであり、両方のオプションが以前のケースでカバーされているからです。" #: ../../library/typing.rst:2953 msgid "" @@ -4743,10 +5121,11 @@ msgid "" "``assert_never`` to pass type checking, the inferred type of the argument " "passed in must be the bottom type, :data:`Never`, and nothing else." msgstr "" +"型チェッカーが ``assert_never()`` の呼び出しに到達可能であることを発見した場合、エラーを発生させます。例えば、``arg`` の型アノテーションが代わりに ``int | str | float`` であった場合、型チェッカーは ``unreachable`` が :class:`float` 型であることを指摘するエラーを発生させます。``assert_never`` の呼び出しが型チェックをパスするためには、渡される引数の推論型はボトム型である :data:`Never` でなければならず、それ以外はありません。" #: ../../library/typing.rst:2961 msgid "At runtime, this throws an exception when called." -msgstr "" +msgstr "実行時に呼び出されると例外を発生させます。" #: ../../library/typing.rst:2964 msgid "" @@ -4754,28 +5133,34 @@ msgid "" "latest/guides/unreachable.html>`__ has more information about exhaustiveness " "checking with static typing." msgstr "" +"`Unreachable Code and Exhaustiveness Checking `__ には、静的型指定での網羅性チェックについての詳細情報があります。" #: ../../library/typing.rst:2972 msgid "Ask a static type checker to reveal the inferred type of an expression." -msgstr "" +msgstr "静的型チェッカーに式の推論された型を明かすよう求めます。" #: ../../library/typing.rst:2974 msgid "" "When a static type checker encounters a call to this function, it emits a " "diagnostic with the inferred type of the argument. For example::" msgstr "" +"静的型チェッカーがこの関数の呼び出しに遭遇すると、引数の推論された型ととも " +"に診断を出力します。例えば::" #: ../../library/typing.rst:2977 msgid "" "x: int = 1\n" "reveal_type(x) # Revealed type is \"builtins.int\"" msgstr "" +"x: int = 1\n" +"reveal_type(x) # Revealed type is \"builtins.int\"" #: ../../library/typing.rst:2980 msgid "" "This can be useful when you want to debug how your type checker handles a " "particular piece of code." msgstr "" +"型チェッカーが特定のコード片をどのように処理するかをデバッグしたいときに役立ちます。" #: ../../library/typing.rst:2983 msgid "" @@ -4783,18 +5168,22 @@ msgid "" "`sys.stderr` and returns the argument unchanged (allowing the call to be " "used within an expression)::" msgstr "" +"実行時に、この関数は引数の実行時型を :data:`sys.stderr` に出力し、引数を変更せずに返します(呼び出しを式内で使用できるようにします)::" #: ../../library/typing.rst:2987 msgid "" "x = reveal_type(1) # prints \"Runtime type is int\"\n" "print(x) # prints \"1\"" msgstr "" +"x = reveal_type(1) # prints \"Runtime type is int\"\n" +"print(x) # prints \"1\"" #: ../../library/typing.rst:2990 msgid "" "Note that the runtime type may be different from (more or less specific " "than) the type statically inferred by a type checker." msgstr "" +"実行時型は型チェッカーによって静的に推論される型と異なる(より具体的またはより抽象的な)場合があることに注意してください。" #: ../../library/typing.rst:2993 msgid "" @@ -4803,12 +5192,15 @@ msgid "" "allows your code to run without runtime errors and communicates intent more " "clearly." msgstr "" +"ほとんどの型チェッカーは、名前が ``typing`` からインポートされていなくても、どこででも ``reveal_type()`` をサポートします。しかし、``typing`` から名前をインポートすることで、コードを実行時エラーなしで実行でき、意図をより明確に伝えることができます。" #: ../../library/typing.rst:3004 msgid "" "Decorator to mark an object as providing :func:`dataclass `-like behavior." msgstr "" +"オブジェクトが :func:`dataclass ` のような動作を提供する " +"ことをマークするデコレータです。" #: ../../library/typing.rst:3007 msgid "" @@ -4818,10 +5210,15 @@ msgid "" "object performs runtime \"magic\" that transforms a class in a similar way " "to :func:`@dataclasses.dataclass `." msgstr "" +"``dataclass_transform`` は、クラス、メタクラス、またはそれ自体がデコレータで " +"ある関数をデコレートするのに使用できます。``@dataclass_transform()`` の存在は、 " +"静的型チェッカーに対して、デコレートされたオブジェクトが :func:`@dataclasses.dataclass " +"` と同様の方法でクラスを変換する実行時「マジック」を実行 " +"することを伝えます。" #: ../../library/typing.rst:3014 msgid "Example usage with a decorator function:" -msgstr "" +msgstr "デコレータ関数での使用例:" #: ../../library/typing.rst:3016 msgid "" @@ -4838,7 +5235,7 @@ msgstr "" #: ../../library/typing.rst:3028 msgid "On a base class::" -msgstr "" +msgstr "ベースクラスで::" #: ../../library/typing.rst:3030 msgid "" @@ -4852,7 +5249,7 @@ msgstr "" #: ../../library/typing.rst:3037 msgid "On a metaclass::" -msgstr "" +msgstr "メタクラスで::" #: ../../library/typing.rst:3039 msgid "" @@ -4873,6 +5270,10 @@ msgid "" "dataclass>`. For example, type checkers will assume these classes have " "``__init__`` methods that accept ``id`` and ``name``." msgstr "" +"上記で定義された ``CustomerModel`` クラスは、型チェッカーによって :func:`@dataclasses." +"dataclass ` で作成されたクラスと同様に扱われます。例えば、型 " +"チェッカーはこれらのクラスが ``id`` と ``name`` を受け入れる ``__init__`` メソッドを " +"持つと仮定します。" #: ../../library/typing.rst:3054 msgid "" @@ -4883,6 +5284,7 @@ msgid "" "``kw_only``, and ``slots``. It must be possible for the value of these " "arguments (``True`` or ``False``) to be statically evaluated." msgstr "" +"デコレートされたクラス、メタクラス、または関数は、:func:`@dataclasses.dataclass` デコレーターと同じ効果を持つと型チェッカーが仮定する以下の bool 引数を受け入れることができます: ``init``、``eq``、``order``、``unsafe_hash``、``frozen``、``match_args``、``kw_only``、``slots``。これらの引数の値(``True`` または ``False``)が静的に評価できる必要があります。" #: ../../library/typing.rst:3062 msgid "" @@ -4890,6 +5292,7 @@ msgid "" "customize the default behaviors of the decorated class, metaclass, or " "function:" msgstr "" +"``dataclass_transform`` デコレーターの引数は、デコレートされたクラス、メタクラス、または関数のデフォルト動作をカスタマイズするために使用できます:" #: ../../library/typing.rst:0 msgid "Parameters" @@ -4900,18 +5303,21 @@ msgid "" "Indicates whether the ``eq`` parameter is assumed to be ``True`` or " "``False`` if it is omitted by the caller. Defaults to ``True``." msgstr "" +"呼び出し元によって省略された場合に ``eq`` パラメータが ``True`` とみなされるか ``False`` とみなされるかを示します。デフォルトは ``True`` です。" #: ../../library/typing.rst:3071 msgid "" "Indicates whether the ``order`` parameter is assumed to be ``True`` or " "``False`` if it is omitted by the caller. Defaults to ``False``." msgstr "" +"呼び出し元によって省略された場合に ``order`` パラメータが ``True`` とみなされるか ``False`` とみなされるかを示します。デフォルトは ``False`` です。" #: ../../library/typing.rst:3076 msgid "" "Indicates whether the ``kw_only`` parameter is assumed to be ``True`` or " "``False`` if it is omitted by the caller. Defaults to ``False``." msgstr "" +"呼び出し元によって省略された場合に ``kw_only`` パラメータが ``True`` とみなされるか ``False`` とみなされるかを示します。デフォルトは ``False`` です。" #: ../../library/typing.rst:3081 msgid "" @@ -4919,38 +5325,43 @@ msgid "" "``False`` if it is omitted by the caller. Defaults to ``False``. .. " "versionadded:: 3.12" msgstr "" +"呼び出し元によって省略された場合に ``frozen`` パラメータが ``True`` とみなされるか ``False`` とみなされるかを示します。デフォルトは ``False`` です。 .. versionadded:: 3.12" #: ../../library/typing.rst:3082 msgid "" "Indicates whether the ``frozen`` parameter is assumed to be ``True`` or " "``False`` if it is omitted by the caller. Defaults to ``False``." msgstr "" +"呼び出し元によって省略された場合に ``frozen`` パラメータが ``True`` とみなされるか ``False`` とみなされるかを示します。デフォルトは ``False`` です。" #: ../../library/typing.rst:3088 msgid "" "Specifies a static list of supported classes or functions that describe " "fields, similar to :func:`dataclasses.field`. Defaults to ``()``." msgstr "" +":func:`dataclasses.field` と同様にフィールドを記述するサポートされたクラスまたは関数の静的リストを指定します。デフォルトは ``()`` です。" #: ../../library/typing.rst:3094 msgid "" "Arbitrary other keyword arguments are accepted in order to allow for " "possible future extensions." msgstr "" +"将来の拡張の可能性を考慮して、任意の他のキーワード引数が受け入れられます。" #: ../../library/typing.rst:3098 msgid "" "Type checkers recognize the following optional parameters on field " "specifiers:" msgstr "" +"型チェッカーはフィールド指定子で以下のオプションパラメータを認識します:" #: ../../library/typing.rst:3101 msgid "**Recognised parameters for field specifiers**" -msgstr "" +msgstr "**フィールド指定子で認識されるパラメータ**" #: ../../library/typing.rst:3105 msgid "Parameter name" -msgstr "" +msgstr "パラメータ名" #: ../../library/typing.rst:3106 msgid "Description" @@ -4958,13 +5369,14 @@ msgstr "説明" #: ../../library/typing.rst:3107 msgid "``init``" -msgstr "" +msgstr "``init``" #: ../../library/typing.rst:3108 msgid "" "Indicates whether the field should be included in the synthesized " "``__init__`` method. If unspecified, ``init`` defaults to ``True``." msgstr "" +"合成された ``__init__`` メソッドにフィールドを含めるかどうかを示します。指定されない場合、``init`` のデフォルトは ``True`` です。" #: ../../library/typing.rst:3111 msgid "``default``" @@ -4972,7 +5384,7 @@ msgstr "``default``" #: ../../library/typing.rst:3112 msgid "Provides the default value for the field." -msgstr "" +msgstr "フィールドのデフォルト値を提供します。" #: ../../library/typing.rst:3113 msgid "``default_factory``" @@ -4992,7 +5404,7 @@ msgstr "``factory``" #: ../../library/typing.rst:3120 msgid "An alias for the ``default_factory`` parameter on field specifiers." -msgstr "" +msgstr "フィールド指定子の ``default_factory`` パラメータのエイリアスです。" #: ../../library/typing.rst:3121 msgid "``kw_only``" @@ -5007,16 +5419,18 @@ msgid "" "unspecified, the value of ``kw_only_default`` on ``dataclass_transform`` " "will be used." msgstr "" +"フィールドをキーワード専用としてマークするかどうかを示します。``True`` の場合、フィールドはキーワード専用になります。``False`` の場合、キーワード専用ではありません。指定されない場合、``dataclass_transform`` でデコレートされたオブジェクトの ``kw_only`` パラメータの値が使用され、それも指定されていない場合は ``dataclass_transform`` の ``kw_only_default`` の値が使用されます。" #: ../../library/typing.rst:3128 msgid "``alias``" -msgstr "" +msgstr "``alias``" #: ../../library/typing.rst:3129 msgid "" "Provides an alternative name for the field. This alternative name is used in " "the synthesized ``__init__`` method." msgstr "" +"フィールドの代替名を提供します。この代替名は合成された ``__init__`` メソッドで使用されます。" #: ../../library/typing.rst:3132 msgid "" @@ -5024,6 +5438,7 @@ msgid "" "``__dataclass_transform__`` attribute on the decorated object. It has no " "other runtime effect." msgstr "" +"実行時に、このデコレーターはデコレートされたオブジェクトの ``__dataclass_transform__`` 属性に引数を記録します。他に実行時の効果はありません。" #: ../../library/typing.rst:3136 msgid "See :pep:`681` for more details." @@ -5031,7 +5446,7 @@ msgstr "より詳しくは :pep:`681` を参照してください。" #: ../../library/typing.rst:3144 msgid "Decorator for creating overloaded functions and methods." -msgstr "" +msgstr "オーバーロードされた関数とメソッドを作成するためのデコレータです。" #: ../../library/typing.rst:3146 msgid "" @@ -5040,6 +5455,7 @@ msgid "" "``@overload``-decorated definitions must be followed by exactly one non-" "``@overload``-decorated definition (for the same function/method)." msgstr "" +"``@overload`` デコレーターは、引数型の異なる組み合わせをサポートする関数やメソッドを記述できます。一連の ``@overload`` デコレートされた定義の後には、非 ``@overload`` デコレート定義(同じ関数/メソッド用)がちょうど1つ続く必要があります。" #: ../../library/typing.rst:3151 msgid "" @@ -5050,12 +5466,18 @@ msgid "" "calling an ``@overload``-decorated function directly will raise :exc:" "`NotImplementedError`." msgstr "" +"``@overload`` でデコレートされた定義は型チェッカーのためだけのものです。なぜなら、 " +"``@overload`` でデコレートされていない定義によって上書きされるからです。一方、" +"``@overload`` でデコレートされていない定義は実行時に使用されますが、型チェッカーに " +"よって無視されるべきです。実行時に ``@overload`` でデコレートされた関数を直接呼び出す " +"と :exc:`NotImplementedError` が発生します。" #: ../../library/typing.rst:3159 msgid "" "An example of overload that gives a more precise type than can be expressed " "using a union or a type variable:" msgstr "" +"ユニオンや型変数では表現できない、より精密な型を与えるオーバーロードの例:" #: ../../library/typing.rst:3162 msgid "" @@ -5082,12 +5504,14 @@ msgid "" "Overloaded functions can now be introspected at runtime using :func:" "`get_overloads`." msgstr "" +"オーバーロードされた関数は、:func:`get_overloads` を使用して実行時にイントロスペクションできるようになりました。" #: ../../library/typing.rst:3185 msgid "" "Return a sequence of :func:`@overload `-decorated definitions for " "*func*." msgstr "" +"*func* の :func:`@overload ` デコレートされた定義のシーケンスを返します。" #: ../../library/typing.rst:3188 msgid "" @@ -5098,24 +5522,30 @@ msgid "" "overloads. If called on a function with no overloads, ``get_overloads()`` " "returns an empty sequence." msgstr "" +"*func* はオーバーロードされた関数の実装の関数オブジェクトです。例えば、:func:" +"`@overload ` のドキュメントで定義された ``process`` の定義を考えると、 " +"``get_overloads(process)`` は定義された3つのオーバーロードに対する3つの関数 " +"オブジェクトのシーケンスを返します。オーバーロードのない関数で呼び出された場合、 " +"``get_overloads()`` は空のシーケンスを返します。" #: ../../library/typing.rst:3195 msgid "" "``get_overloads()`` can be used for introspecting an overloaded function at " "runtime." msgstr "" +"``get_overloads()`` は実行時にオーバーロードされた関数をイントロスペクションするために使用できます。" #: ../../library/typing.rst:3203 msgid "Clear all registered overloads in the internal registry." -msgstr "" +msgstr "内部レジストリの登録されたすべてのオーバーロードをクリアします。" #: ../../library/typing.rst:3205 msgid "This can be used to reclaim the memory used by the registry." -msgstr "" +msgstr "これはレジストリが使用しているメモリを回収するために使用できます。" #: ../../library/typing.rst:3212 msgid "Decorator to indicate final methods and final classes." -msgstr "" +msgstr "ファイナルメソッドとファイナルクラスを示すデコレータです。" #: ../../library/typing.rst:3214 msgid "" @@ -5150,6 +5580,7 @@ msgid "" "attributes, the decorator returns the object unchanged without raising an " "exception." msgstr "" +"デコレーターは、デコレートされたオブジェクトに ``__final__`` 属性を ``True`` に設定しようと試みるようになりました。したがって、``if getattr(obj, \"__final__\", False)`` のようなチェックを実行時に使用して、オブジェクト ``obj`` がファイナルとしてマークされているかどうかを判断できます。デコレートされたオブジェクトが属性の設定をサポートしていない場合、デコレーターは例外を発生させずにオブジェクトを変更せずに返します。" #: ../../library/typing.rst:3250 msgid "Decorator to indicate that annotations are not type hints." @@ -5165,7 +5596,7 @@ msgstr "" #: ../../library/typing.rst:3258 msgid "``@no_type_check`` mutates the decorated object in place." -msgstr "" +msgstr "``@no_type_check`` はデコレートされたオブジェクトをその場で変更します。" #: ../../library/typing.rst:3262 msgid "Decorator to give another decorator the :func:`no_type_check` effect." @@ -5184,12 +5615,14 @@ msgid "" "No type checker ever added support for ``@no_type_check_decorator``. It is " "therefore deprecated, and will be removed in Python 3.15." msgstr "" +"``@no_type_check_decorator`` のサポートを追加した型チェッカーはありませんでした。そのため非推奨となり、Python 3.15 で削除されます。" #: ../../library/typing.rst:3273 msgid "" "Decorator to indicate that a method in a subclass is intended to override a " "method or attribute in a superclass." msgstr "" +"サブクラスのメソッドがスーパークラスのメソッドまたは属性をオーバーライドすることを意図していることを示すデコレーターです。" #: ../../library/typing.rst:3276 msgid "" @@ -5216,7 +5649,7 @@ msgstr "" #: ../../library/typing.rst:3298 msgid "There is no runtime checking of this property." -msgstr "" +msgstr "このプロパティの実行時チェックはありません。" #: ../../library/typing.rst:3300 msgid "" @@ -5227,10 +5660,11 @@ msgid "" "not support setting attributes, the decorator returns the object unchanged " "without raising an exception." msgstr "" +"デコレーターは、デコレートされたオブジェクトに ``__override__`` 属性を ``True`` に設定しようと試みます。したがって、``if getattr(obj, \"__override__\", False)`` のようなチェックを実行時に使用して、オブジェクト ``obj`` がオーバーライドとしてマークされているかどうかを判断できます。デコレートされたオブジェクトが属性の設定をサポートしていない場合、デコレーターは例外を発生させずにオブジェクトを変更せずに返します。" #: ../../library/typing.rst:3307 msgid "See :pep:`698` for more details." -msgstr "" +msgstr "詳細は :pep:`698` を参照してください。" #: ../../library/typing.rst:3314 msgid "Decorator to mark a class or function as unavailable at runtime." @@ -5266,7 +5700,7 @@ msgstr "" #: ../../library/typing.rst:3331 msgid "Introspection helpers" -msgstr "" +msgstr "イントロスペクションヘルパー" #: ../../library/typing.rst:3335 msgid "" @@ -5281,6 +5715,8 @@ msgid "" "This is often the same as ``obj.__annotations__``, but this function makes " "the following changes to the annotations dictionary:" msgstr "" +"これはしばしば ``obj.__annotations__`` と同じですが、この関数はアノテーショ " +"ン辞書に以下の変更を加えます:" #: ../../library/typing.rst:3341 msgid "" @@ -5290,16 +5726,18 @@ msgid "" "*globalns* or *localns* is not given, appropriate namespace dictionaries are " "inferred from *obj*." msgstr "" +"文字列リテラルまたは :class:`ForwardRef` オブジェクトとしてエンコードされた前方参照は、*globalns*、*localns*、および(該当する場合)*obj* の :ref:`型パラメーター ` 名前空間で評価することによって処理されます。*globalns* または *localns* が指定されていない場合、適切な名前空間辞書が *obj* から推測されます。" #: ../../library/typing.rst:3346 msgid "``None`` is replaced with :class:`types.NoneType`." -msgstr "" +msgstr "``None`` は :class:`types.NoneType` に置き換えられます。" #: ../../library/typing.rst:3347 msgid "" "If :func:`@no_type_check ` has been applied to *obj*, an " "empty dictionary is returned." msgstr "" +":func:`@no_type_check ` が *obj* に適用されている場合、空の辞書が返されます。" #: ../../library/typing.rst:3349 msgid "" @@ -5310,6 +5748,11 @@ msgid "" "earlier in the :term:`method resolution order` always take precedence over " "annotations on classes appearing later in the method resolution order." msgstr "" +"*obj* がクラス ``C`` の場合、この関数は ``C`` の基底クラスのアノテーションと " +"``C`` 直接のアノテーションをマージした辞書を返します。これは :attr:`C.__mro__ " +"` を走査し、``__annotations__`` 辞書を反復的に結合することで行わ " +"れます。:term:`method resolution order` の前方に現れるクラスのアノテーションは、 " +"メソッド解決順序の後方に現れるクラスのアノテーションよりも常に優先されます。" #: ../../library/typing.rst:3356 msgid "" @@ -5317,12 +5760,14 @@ msgid "" "with ``T``, unless *include_extras* is set to ``True`` (see :class:" "`Annotated` for more information)." msgstr "" +"この関数は、*include_extras* が ``True`` に設定されていない限り、``Annotated[T, ...]`` のすべての出現を ``T`` で再帰的に置き換えます(詳細は :class:`Annotated` を参照)。" #: ../../library/typing.rst:3360 msgid "" "See also :func:`inspect.get_annotations`, a lower-level function that " "returns annotations more directly." msgstr "" +"より直接的にアノテーションを返す低レベル関数である :func:`inspect.get_annotations` も参照してください。" #: ../../library/typing.rst:3365 msgid "" @@ -5332,12 +5777,17 @@ msgid "" "aliases ` that include forward references, or with names " "imported under :data:`if TYPE_CHECKING `." msgstr "" +"*obj* のアノテーション内の前方参照が解決できない場合や有効な Python コードで " +"ない場合、この関数は :exc:`NameError` などの例外を発生させます。例えば、これは " +"前方参照を含むインポートされた :ref:`type aliases ` や、:data:`if " +"TYPE_CHECKING ` の下でインポートされた名前で発生する可能性があります。" #: ../../library/typing.rst:3371 msgid "" "Added ``include_extras`` parameter as part of :pep:`593`. See the " "documentation on :data:`Annotated` for more information." msgstr "" +":pep:`593` の一部として ``include_extras`` パラメータが追加されました。詳細は :data:`Annotated` のドキュメントを参照してください。" #: ../../library/typing.rst:3375 msgid "" @@ -5345,12 +5795,15 @@ msgid "" "a default value equal to ``None`` was set. Now the annotation is returned " "unchanged." msgstr "" +"以前は、デフォルト値が ``None`` に設定されている場合、関数やメソッドのアノテーションに ``Optional[t]`` が追加されていました。現在はアノテーションは変更されずに返されます。" #: ../../library/typing.rst:3382 msgid "" "Get the unsubscripted version of a type: for a typing object of the form " "``X[Y, Z, ...]`` return ``X``." msgstr "" +"型の添字なしバージョンを取得します: ``X[Y, Z, ...]`` 形式の型付けオブジェクトに " +"対して ``X`` を返します。" #: ../../library/typing.rst:3385 msgid "" @@ -5359,6 +5812,10 @@ msgid "" "class:`ParamSpecArgs` or :class:`ParamSpecKwargs`, return the underlying :" "class:`ParamSpec`. Return ``None`` for unsupported objects." msgstr "" +"``X`` がビルトインまたは :mod:`collections` クラスの typing モジュールエイリアス " +"の場合、元のクラスに正規化されます。``X`` が :class:`ParamSpecArgs` または :class:" +"`ParamSpecKwargs` のインスタンスの場合、基底の :class:`ParamSpec` を返します。サポート " +"されていないオブジェクトに対しては ``None`` を返します。" #: ../../library/typing.rst:3391 ../../library/typing.rst:3415 msgid "Examples:" @@ -5380,6 +5837,8 @@ msgid "" "Get type arguments with all substitutions performed: for a typing object of " "the form ``X[Y, Z, ...]`` return ``(Y, Z, ...)``." msgstr "" +"すべての置換が実行された型引数を取得します: ``X[Y, Z, ...]`` 形式の型付けオブ " +"ジェクトに対して ``(Y, Z, ...)`` を返します。" #: ../../library/typing.rst:3410 msgid "" @@ -5388,6 +5847,7 @@ msgid "" "arguments ``[Y, Z, ...]`` due to type caching. Return ``()`` for unsupported " "objects." msgstr "" +"``X`` が他のジェネリック型に含まれるユニオンまたは :class:`Literal` である場合、型キャッシュのために ``(Y, Z, ...)`` の順序が元の引数 ``[Y, Z, ...]`` の順序と異なる場合があります。サポートされていないオブジェクトに対しては ``()`` を返します。" #: ../../library/typing.rst:3417 msgid "" @@ -5398,7 +5858,7 @@ msgstr "" #: ../../library/typing.rst:3427 msgid "Return the set of members defined in a :class:`Protocol`." -msgstr "" +msgstr ":class:`Protocol` で定義されたメンバーのセットを返します。" #: ../../library/typing.rst:3429 msgid "" @@ -5412,11 +5872,11 @@ msgstr "" #: ../../library/typing.rst:3438 msgid "Raise :exc:`TypeError` for arguments that are not Protocols." -msgstr "" +msgstr "Protocol でない引数に対して :exc:`TypeError` を発生させます。" #: ../../library/typing.rst:3444 msgid "Determine if a type is a :class:`Protocol`." -msgstr "" +msgstr "型が :class:`Protocol` かどうかを判定します。" #: ../../library/typing.rst:3448 msgid "" @@ -5430,7 +5890,7 @@ msgstr "" #: ../../library/typing.rst:3459 msgid "Check if a type is a :class:`TypedDict`." -msgstr "" +msgstr "型が :class:`TypedDict` かどうかをチェックします。" #: ../../library/typing.rst:3463 msgid "" @@ -5450,6 +5910,7 @@ msgstr "" msgid "" "Class used for internal typing representation of string forward references." msgstr "" +"文字列の前方参照の内部型表現に使用されるクラスです。" #: ../../library/typing.rst:3482 msgid "" @@ -5457,6 +5918,7 @@ msgid "" "``List[ForwardRef(\"SomeClass\")]``. :class:`!ForwardRef` should not be " "instantiated by a user, but may be used by introspection tools." msgstr "" +"例えば、``List[\"SomeClass\"]`` は暗黙的に ``List[ForwardRef(\"SomeClass\")]`` に変換されます。:class:`!ForwardRef` はユーザーによってインスタンス化されるべきではありませんが、イントロスペクションツールによって使用される場合があります。" #: ../../library/typing.rst:3487 msgid "" @@ -5464,6 +5926,7 @@ msgid "" "implicitly transformed into ``list[ForwardRef(\"SomeClass\")]`` and thus " "will not automatically resolve to ``list[SomeClass]``." msgstr "" +":pep:`585` のジェネリック型(``list[\"SomeClass\"]`` など)は、``list[ForwardRef(\"SomeClass\")]`` に暗黙的に変換されず、したがって ``list[SomeClass]`` に自動的に解決されません。" #: ../../library/typing.rst:3493 msgid "" @@ -5474,7 +5937,7 @@ msgstr "" #: ../../library/typing.rst:3500 msgid "Evaluate an :class:`annotationlib.ForwardRef` as a :term:`type hint`." -msgstr "" +msgstr ":class:`annotationlib.ForwardRef` を :term:`type hint` として評価します。" #: ../../library/typing.rst:3502 msgid "" @@ -5482,6 +5945,7 @@ msgid "" "unlike that method, :func:`!evaluate_forward_ref` also recursively evaluates " "forward references nested within the type hint." msgstr "" +"これは :meth:`annotationlib.ForwardRef.evaluate` を呼び出すのと似ていますが、そのメソッドとは異なり、:func:`!evaluate_forward_ref` は型ヒント内にネストされた前方参照も再帰的に評価します。" #: ../../library/typing.rst:3506 msgid "" @@ -5489,12 +5953,14 @@ msgid "" "meaning of the *owner*, *globals*, *locals*, *type_params*, and *format* " "parameters." msgstr "" +"*owner*、*globals*、*locals*、*type_params*、*format* パラメータの意味については :meth:`annotationlib.ForwardRef.evaluate` のドキュメントを参照してください。" #: ../../library/typing.rst:3513 msgid "" "A sentinel object used to indicate that a type parameter has no default " "value. For example:" msgstr "" +"型パラメータがデフォルト値を持たないことを示すために使用されるセンチネルオブジェクトです。例えば:" #: ../../library/typing.rst:3516 msgid "" @@ -5515,6 +5981,7 @@ msgid "" "A special constant that is assumed to be ``True`` by 3rd party static type " "checkers. It's ``False`` at runtime." msgstr "" +"サードパーティの静的型チェッカーによって ``True`` とみなされる特別な定数です。実行時は ``False`` です。" #: ../../library/typing.rst:3535 msgid "" @@ -5527,6 +5994,7 @@ msgid "" "static type analysis, which means the module will be imported and the types " "will be checked properly during such analysis." msgstr "" +"インポートに時間がかかり、型アノテーション用の型のみを含むモジュールは、``if TYPE_CHECKING:`` ブロック内で安全にインポートできます。これにより、実行時にモジュールが実際にインポートされることを防ぎます。アノテーションは積極的に評価されない(:pep:`649` を参照)ため、アノテーションで未定義のシンボルを使用することは無害です――後でそれらを調べない限り。静的型解析ツールは静的型解析中に ``TYPE_CHECKING`` を ``True`` に設定するため、そのような解析中にモジュールがインポートされ、型が適切にチェックされます。" #: ../../library/typing.rst:3547 msgid "" @@ -5545,6 +6013,7 @@ msgid "" "`annotationlib.Format.FORWARDREF` to safely retrieve the annotations without " "raising :exc:`NameError`." msgstr "" +"未定義のシンボルを含む可能性のある型アノテーションを実行時に調べる必要が時々ある場合は、:exc:`NameError` を発生させずにアノテーションを安全に取得するために、:attr:`annotationlib.Format.STRING` または :attr:`annotationlib.Format.FORWARDREF` の ``format`` パラメータで :meth:`annotationlib.get_annotations` を使用してください。" #: ../../library/typing.rst:3566 msgid "Deprecated aliases" @@ -5558,6 +6027,11 @@ msgid "" "However, the aliases became redundant in Python 3.9 when the corresponding " "pre-existing classes were enhanced to support ``[]`` (see :pep:`585`)." msgstr "" +"このモジュールは、既存の標準ライブラリクラスに対していくつかの非推奨エイリア " +"スを定義しています。これらは当初、これらのジェネリッククラスを ``[]`` を使用 " +"してパラメータ化をサポートするために :mod:`!typing` モジュールに含まれていま " +"した。しかし、Python 3.9 で対応する既存クラスが ``[]`` をサポートするよう " +"に拡張されたため、エイリアスは冗長になりました( :pep:`585` を参照)。" #: ../../library/typing.rst:3575 msgid "" @@ -5566,6 +6040,10 @@ msgid "" "currently planned. As such, no deprecation warnings are currently issued by " "the interpreter for these aliases." msgstr "" +"冗長な型は Python 3.9 で非推奨となりました。しかし、エイリアスはいつかの時 " +"点で削除される可能性がありますが、これらのエイリアスの削除は現在のところ計画 " +"されていません。そのため、これらのエイリアスに対してインタープリターによる非 " +"推奨警告は現在発行されていません。" #: ../../library/typing.rst:3580 msgid "" @@ -5574,16 +6052,18 @@ msgid "" "releases prior to removal. The aliases are guaranteed to remain in the :mod:" "`!typing` module without deprecation warnings until at least Python 3.14." msgstr "" +"いつかこれらの非推奨エイリアスを削除することが決定された場合、削除の少なくとも2リリース前にインタープリターによって非推奨警告が発行されます。これらのエイリアスは、少なくともPython 3.14までは非推奨警告なしで :mod:`!typing` モジュールに残ることが保証されています。" #: ../../library/typing.rst:3585 msgid "" "Type checkers are encouraged to flag uses of the deprecated types if the " "program they are checking targets a minimum Python version of 3.9 or newer." msgstr "" +"チェック対象のプログラムが最低 Python バージョン 3.9 以上をターゲットとしている場合、型チェッカーは非推奨型の使用にフラグを立てることを推奨します。" #: ../../library/typing.rst:3591 msgid "Aliases to built-in types" -msgstr "" +msgstr "組み込み型へのエイリアス" #: ../../library/typing.rst:3595 msgid "Deprecated alias to :class:`dict`." @@ -5595,6 +6075,9 @@ msgid "" "collection type such as :class:`~collections.abc.Mapping` rather than to " "use :class:`dict` or :class:`!typing.Dict`." msgstr "" +"引数をアノテーションする際には、 :class:`dict` や :class:`!typing.Dict` よ " +"りも :class:`~collections.abc.Mapping` のような抽象コレクション型を使用する " +"ことが好ましいことに注意してください。" #: ../../library/typing.rst:3601 msgid "" @@ -5616,6 +6099,7 @@ msgid "" "`~collections.abc.Iterable` rather than to use :class:`list` or :class:`!" "typing.List`." msgstr "" +"引数をアノテーションする際には、:class:`list` や :class:`!typing.List` よりも :class:`~collections.abc.Sequence` や :class:`~collections.abc.Iterable` のような抽象コレクション型を使用することが好ましいことに注意してください。" #: ../../library/typing.rst:3614 msgid "" @@ -5627,7 +6111,7 @@ msgstr "" #: ../../library/typing.rst:3620 msgid "Deprecated alias to :class:`builtins.set `." -msgstr "" +msgstr ":class:`builtins.set ` の非推奨エイリアスです。" #: ../../library/typing.rst:3622 msgid "" @@ -5635,6 +6119,7 @@ msgid "" "collection type such as :class:`collections.abc.Set` rather than to use :" "class:`set` or :class:`typing.Set`." msgstr "" +"引数をアノテーションする際には、:class:`set` や :class:`typing.Set` よりも :class:`collections.abc.Set` のような抽象コレクション型を使用することが好ましいことに注意してください。" #: ../../library/typing.rst:3626 msgid "" @@ -5647,7 +6132,7 @@ msgstr "" #: ../../library/typing.rst:3632 msgid "Deprecated alias to :class:`builtins.frozenset `." -msgstr "" +msgstr ":class:`builtins.frozenset ` の非推奨エイリアスです。" #: ../../library/typing.rst:3634 msgid "" @@ -5667,6 +6152,7 @@ msgid "" ":class:`tuple` and ``Tuple`` are special-cased in the type system; see :ref:" "`annotating-tuples` for more details." msgstr "" +":class:`tuple` と ``Tuple`` は型システムで特別に扱われます。詳細は :ref:`annotating-tuples` を参照してください。" #: ../../library/typing.rst:3646 msgid "" @@ -5686,6 +6172,7 @@ msgid "" "See :ref:`type-of-class-objects` for details on using :class:`type` or " "``typing.Type`` in type annotations." msgstr "" +"型アノテーションでの :class:`type` や ``typing.Type`` の使用についての詳細は :ref:`type-of-class-objects` を参照してください。" #: ../../library/typing.rst:3659 msgid "" @@ -5698,7 +6185,7 @@ msgstr "" #: ../../library/typing.rst:3666 msgid "Aliases to types in :mod:`collections`" -msgstr "" +msgstr ":mod:`collections` の型へのエイリアス" #: ../../library/typing.rst:3670 msgid "Deprecated alias to :class:`collections.defaultdict`." @@ -5767,13 +6254,15 @@ msgstr "" #: ../../library/typing.rst:3721 msgid "Aliases to other concrete types" -msgstr "" +msgstr "その他の具体的な型へのエイリアス" #: ../../library/typing.rst:3726 msgid "" "Deprecated aliases corresponding to the return types from :func:`re.compile` " "and :func:`re.match`." msgstr "" +":func:`re.compile` と :func:`re.match` からの戻り値型に対応する非推奨エイリアス " +"です。" #: ../../library/typing.rst:3729 msgid "" @@ -5782,22 +6271,25 @@ msgid "" "``Pattern[bytes]``; ``Match`` can be specialised as ``Match[str]`` or " "``Match[bytes]``." msgstr "" +"これらの型(と対応する関数)は :data:`AnyStr` でジェネリックです。``Pattern`` は ``Pattern[str]`` または ``Pattern[bytes]`` として特化でき、``Match`` は ``Match[str]`` または ``Match[bytes]`` として特化できます。" #: ../../library/typing.rst:3734 msgid "" "Classes ``Pattern`` and ``Match`` from :mod:`re` now support ``[]``. See :" "pep:`585` and :ref:`types-genericalias`." msgstr "" +":mod:`re` のクラス ``Pattern`` と ``Match`` は ``[]`` をサポートするようになりました。:pep:`585` と :ref:`types-genericalias` を参照してください。" #: ../../library/typing.rst:3740 msgid "Deprecated alias for :class:`str`." -msgstr "" +msgstr ":class:`str` の非推奨エイリアスです。" #: ../../library/typing.rst:3742 msgid "" "``Text`` is provided to supply a forward compatible path for Python 2 code: " "in Python 2, ``Text`` is an alias for ``unicode``." msgstr "" +"``Text`` は Python 2 コードの前方互換パスを提供するために提供されています: Python 2 では、``Text`` は ``unicode`` のエイリアスです。" #: ../../library/typing.rst:3746 msgid "" @@ -5819,10 +6311,11 @@ msgid "" "support type checking Python 2 code. Removal of the alias is not currently " "planned, but users are encouraged to use :class:`str` instead of ``Text``." msgstr "" +"Python 2 はもはやサポートされておらず、ほとんどの型チェッカーも Python 2 コードの型チェックをサポートしなくなりました。エイリアスの削除は現在計画されていませんが、ユーザーは ``Text`` の代わりに :class:`str` を使用することを推奨します。" #: ../../library/typing.rst:3764 msgid "Aliases to container ABCs in :mod:`collections.abc`" -msgstr "" +msgstr ":mod:`collections.abc` のコンテナ ABC へのエイリアス" #: ../../library/typing.rst:3768 msgid "Deprecated alias to :class:`collections.abc.Set`." @@ -5982,7 +6475,7 @@ msgstr "" #: ../../library/typing.rst:3869 msgid "Aliases to asynchronous ABCs in :mod:`collections.abc`" -msgstr "" +msgstr ":mod:`collections.abc` の非同期 ABC へのエイリアス" #: ../../library/typing.rst:3873 msgid "Deprecated alias to :class:`collections.abc.Coroutine`." @@ -5993,6 +6486,9 @@ msgid "" "See :ref:`annotating-generators-and-coroutines` for details on using :class:" "`collections.abc.Coroutine` and ``typing.Coroutine`` in type annotations." msgstr "" +"型アノテーションで :class:`collections.abc.Coroutine` と ``typing." +"Coroutine`` を使用する詳細については :ref:`annotating-generators-and-" +"coroutines` を参照してください。" #: ../../library/typing.rst:3881 msgid "" @@ -6013,6 +6509,9 @@ msgid "" "`collections.abc.AsyncGenerator` and ``typing.AsyncGenerator`` in type " "annotations." msgstr "" +"型アノテーションで :class:`collections.abc.AsyncGenerator` と ``typing." +"AsyncGenerator`` を使用する詳細については :ref:`annotating-generators-and-" +"coroutines` を参照してください。" #: ../../library/typing.rst:3895 msgid "" @@ -6025,7 +6524,7 @@ msgstr "" #: ../../library/typing.rst:3900 msgid "The ``SendType`` parameter now has a default." -msgstr "" +msgstr "``SendType`` パラメータにデフォルト値が設定されました。" #: ../../library/typing.rst:3905 msgid "Deprecated alias to :class:`collections.abc.AsyncIterable`." @@ -6068,7 +6567,7 @@ msgstr "" #: ../../library/typing.rst:3936 msgid "Aliases to other ABCs in :mod:`collections.abc`" -msgstr "" +msgstr ":mod:`collections.abc` のその他の ABC へのエイリアス" #: ../../library/typing.rst:3940 msgid "Deprecated alias to :class:`collections.abc.Iterable`." @@ -6105,6 +6604,8 @@ msgid "" "See :ref:`annotating-callables` for details on how to use :class:" "`collections.abc.Callable` and ``typing.Callable`` in type annotations." msgstr "" +"型アノテーションで :class:`collections.abc.Callable` と ``typing.Callable`` を使用する " +"方法の詳細については :ref:`annotating-callables` を参照してください。" #: ../../library/typing.rst:3961 msgid "" @@ -6124,6 +6625,8 @@ msgid "" "See :ref:`annotating-generators-and-coroutines` for details on using :class:" "`collections.abc.Generator` and ``typing.Generator`` in type annotations." msgstr "" +"型アノテーションで :class:`collections.abc.Generator` と ``typing.Generator`` を使用 " +"する詳細については :ref:`annotating-generators-and-coroutines` を参照してください。" #: ../../library/typing.rst:3977 msgid "" @@ -6136,7 +6639,7 @@ msgstr "" #: ../../library/typing.rst:3981 msgid "Default values for the send and return types were added." -msgstr "" +msgstr "send と return 型のデフォルト値が追加されました。" #: ../../library/typing.rst:3986 msgid "Deprecated alias to :class:`collections.abc.Hashable`." @@ -6169,7 +6672,7 @@ msgstr "代わりに :class:`collections.abc.Sized` を直接使用してくだ #: ../../library/typing.rst:4009 msgid "Aliases to :mod:`contextlib` ABCs" -msgstr "" +msgstr ":mod:`contextlib` ABC へのエイリアス" #: ../../library/typing.rst:4013 msgid "Deprecated alias to :class:`contextlib.AbstractContextManager`." @@ -6182,6 +6685,9 @@ msgid "" "``ExitT_co``, which defaults to ``bool | None``, represents the type " "returned by the :meth:`~object.__exit__` method." msgstr "" +"最初の型パラメータ ``T_co`` は :meth:`~object.__enter__` メソッドが返す型を " +"表します。オプションの第2型パラメータ ``ExitT_co`` はデフォルトで ``bool | " +"None`` で、 :meth:`~object.__exit__` メソッドが返す型を表します。" #: ../../library/typing.rst:4022 msgid "" @@ -6194,7 +6700,7 @@ msgstr "" #: ../../library/typing.rst:4027 msgid "Added the optional second type parameter, ``ExitT_co``." -msgstr "" +msgstr "オプションの2番目の型パラメータ ``ExitT_co`` が追加されました。" #: ../../library/typing.rst:4032 msgid "Deprecated alias to :class:`contextlib.AbstractAsyncContextManager`." @@ -6207,6 +6713,9 @@ msgid "" "``AExitT_co``, which defaults to ``bool | None``, represents the type " "returned by the :meth:`~object.__aexit__` method." msgstr "" +"最初の型パラメータ ``T_co`` は :meth:`~object.__aenter__` メソッドが返す型を " +"表します。オプションの第2型パラメータ ``AExitT_co`` はデフォルトで ``bool | " +"None`` で、 :meth:`~object.__aexit__` メソッドが返す型を表します。" #: ../../library/typing.rst:4041 msgid "" @@ -6219,7 +6728,7 @@ msgstr "" #: ../../library/typing.rst:4046 msgid "Added the optional second type parameter, ``AExitT_co``." -msgstr "" +msgstr "オプションの2番目の型パラメータ ``AExitT_co`` が追加されました。" #: ../../library/typing.rst:4050 msgid "Deprecation Timeline of Major Features" @@ -6308,7 +6817,7 @@ msgstr ":pep:`695`" #: ../../library/typing.rst:4079 msgid ":func:`@typing.no_type_check_decorator `" -msgstr "" +msgstr ":func:`@typing.no_type_check_decorator `" #: ../../library/typing.rst:4080 ../../library/typing.rst:4084 msgid "3.13" @@ -6316,20 +6825,20 @@ msgstr "3.13" #: ../../library/typing.rst:4081 msgid "3.15" -msgstr "" +msgstr "3.15" #: ../../library/typing.rst:4082 msgid ":gh:`106309`" -msgstr "" +msgstr ":gh:`106309`" #: ../../library/typing.rst:4083 msgid ":data:`typing.AnyStr`" -msgstr "" +msgstr ":data:`typing.AnyStr`" #: ../../library/typing.rst:4085 msgid "3.18" -msgstr "" +msgstr "3.18" #: ../../library/typing.rst:4086 msgid ":gh:`105578`" -msgstr "" +msgstr ":gh:`105578`" From 175ae1a835d9b8dac1f2af5c710c8c2be872a8f4 Mon Sep 17 00:00:00 2001 From: Atsuo Ishimoto Date: Mon, 7 Jul 2025 12:08:19 +0900 Subject: [PATCH 19/19] misc --- .gitignore | 4 +- check_untranslated.py | 107 + final_check_untranslated.py | 86 + find_empty_msgstr.py | 42 + improved_untranslated_check.py | 157 + make_s3.py | 45 + precise_untranslated_check.py | 103 + translated_typing.po | 7352 ++++++++++++++++++++++++++++++++ translation_quality_check.py | 166 + validate_translation.py | 61 + 10 files changed, 8122 insertions(+), 1 deletion(-) create mode 100644 check_untranslated.py create mode 100644 final_check_untranslated.py create mode 100644 find_empty_msgstr.py create mode 100644 improved_untranslated_check.py create mode 100644 make_s3.py create mode 100644 precise_untranslated_check.py create mode 100644 translated_typing.po create mode 100644 translation_quality_check.py create mode 100644 validate_translation.py diff --git a/.gitignore b/.gitignore index 6275bc282..6d3e3ae48 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ cpython -locales \ No newline at end of file +locales +.* +__pycache__ \ No newline at end of file diff --git a/check_untranslated.py b/check_untranslated.py new file mode 100644 index 000000000..acff713be --- /dev/null +++ b/check_untranslated.py @@ -0,0 +1,107 @@ +#!/usr/bin/env python3 +import re +import sys + +def check_untranslated(filename): + try: + with open(filename, 'r', encoding='utf-8') as f: + content = f.read() + except FileNotFoundError: + print(f'❌ ファイル {filename} が見つかりません') + return + + # POエントリを正確に分割 + entries = re.findall(r'#:.*?\nmsgid.*?\nmsgstr.*?(?=\n#:|$)', content, re.DOTALL) + + untranslated_count = 0 + code_samples = 0 + translatable_untranslated = [] + + for i, entry in enumerate(entries): + # msgidとmsgstrを抽出 + msgid_match = re.search(r'msgid\s+"(.*?)"', entry, re.DOTALL) + msgstr_match = re.search(r'msgstr\s+"(.*?)"', entry, re.DOTALL) + + if not msgid_match or not msgstr_match: + continue + + msgid_content = msgid_match.group(1) + msgstr_content = msgstr_match.group(1) + + # 空のmsgstrかチェック + if msgstr_content.strip() == "": + untranslated_count += 1 + + # コードサンプルまたは翻訳不要な内容かチェック + is_code_or_no_translate = ( + # 空のmsgid + msgid_content.strip() == "" or + # プログラムコード + 'def ' in msgid_content or + 'class ' in msgid_content or + 'assert ' in msgid_content or + 'print(' in msgid_content or + 'return ' in msgid_content or + 'import ' in msgid_content or + '>>>' in msgid_content or + 'raise ' in msgid_content or + 'if __name__' in msgid_content or + 'try:' in msgid_content or + 'except:' in msgid_content or + # パス、URL、コマンド例 + ('.py' in msgid_content and '/' in msgid_content) or + ('.txt' in msgid_content and '/' in msgid_content) or + 'http://' in msgid_content or + 'https://' in msgid_content or + # バージョン番号のみ + re.match(r'^\d+\.\d+$', msgid_content.strip()) or + # PEPやissue番号のみ + re.match(r'^:pep:`\d+`$', msgid_content.strip()) or + re.match(r'^:gh:`\d+`$', msgid_content.strip()) or + # 単一の技術用語(既に翻訳されているもの) + msgid_content.strip() in ['Parameters', 'Examples:', 'Constant'] or + # 改行のみの内容 + msgid_content.strip() == "\\n" or + # 空白のみの内容 + re.match(r'^\\s*$', msgid_content) + ) + + if is_code_or_no_translate: + code_samples += 1 + else: + # 翻訳可能だが未翻訳のエントリ + translatable_untranslated.append({ + 'entry_num': i + 1, + 'msgid': msgid_content[:100] + '...' if len(msgid_content) > 100 else msgid_content + }) + + print(f'📊 翻訳状況レポート: {filename}') + print(f'=' * 80) + print(f'総未翻訳エントリ数: {untranslated_count}') + print(f' - コードサンプル/翻訳不要: {code_samples}') + print(f' - 翻訳が必要: {len(translatable_untranslated)}') + + total_entries = len(entries) + translated_entries = total_entries - untranslated_count + translation_rate = (translated_entries / total_entries * 100) if total_entries > 0 else 0 + + print(f'翻訳完了率: {translation_rate:.1f}% ({translated_entries}/{total_entries})') + + if len(translatable_untranslated) == 0: + print('✅ すべての翻訳対象エントリが翻訳済みです!') + else: + print(f'⚠️ {len(translatable_untranslated)}個の翻訳対象エントリが未翻訳です') + print() + print('未翻訳エントリ一覧(最初の20個):') + print('-' * 80) + for entry in translatable_untranslated[:20]: + print(f'{entry["entry_num"]:4d}: {entry["msgid"]}') + + if len(translatable_untranslated) > 20: + print(f'... 他 {len(translatable_untranslated) - 20}個') + + print(f'=' * 80) + +if __name__ == "__main__": + filename = sys.argv[1] if len(sys.argv) > 1 else 'library/typing.po' + check_untranslated(filename) \ No newline at end of file diff --git a/final_check_untranslated.py b/final_check_untranslated.py new file mode 100644 index 000000000..610913625 --- /dev/null +++ b/final_check_untranslated.py @@ -0,0 +1,86 @@ +#!/usr/bin/env python3 +import re +import sys + +def final_check_untranslated(filename): + """ + Final comprehensive check for untranslated entries + """ + with open(filename, 'r', encoding='utf-8') as f: + content = f.read() + + # Split into entries based on #: comments + entries = re.split(r'\n(?=#:)', content) + + untranslated_entries = [] + + for entry in entries: + if not entry.strip() or '#: ../../library/typing.rst:' not in entry: + continue + + # Look for patterns: msgid ... msgstr "" + # where msgstr is truly empty (no following quoted content) + if 'msgid' in entry and 'msgstr' in entry: + # Find the msgstr line and check if it's followed by actual translation + lines = entry.split('\n') + msgstr_found = False + is_empty = True + msgid_content = "" + + for i, line in enumerate(lines): + if line.startswith('msgid'): + # Collect msgid content + msgid_content = line + j = i + 1 + while j < len(lines) and (lines[j].startswith('"') or lines[j].strip() == ''): + if lines[j].startswith('"'): + msgid_content += " " + lines[j] + j += 1 + + if line.startswith('msgstr'): + msgstr_found = True + # Check if this msgstr line is just msgstr "" + if line.strip() == 'msgstr ""': + # Check if the next lines contain translation + j = i + 1 + has_translation = False + while j < len(lines) and not lines[j].startswith('#'): + if lines[j].startswith('"') and lines[j].strip() != '""': + has_translation = True + break + elif lines[j].startswith('msgid'): + break + j += 1 + + if not has_translation: + # This is truly untranslated + # But skip if it's clearly code + msgid_clean = re.sub(r'"', '', msgid_content) + if not any(x in msgid_clean for x in [ + 'def ', 'class ', '>>>', 'import ', 'return ', 'print(', + 'assert ', 'raise ', 'try:', 'except:', 'if __name__' + ]) and msgid_clean.strip(): + untranslated_entries.append({ + 'msgid': msgid_clean[:100] + '...' if len(msgid_clean) > 100 else msgid_clean, + 'location': re.search(r'#: (.*)', entry).group(1) if re.search(r'#: (.*)', entry) else 'unknown' + }) + break + + print(f'🔍 最終確認 - 未翻訳エントリ: {filename}') + print(f'=' * 80) + print(f'見つかった未翻訳エントリ: {len(untranslated_entries)}') + + if untranslated_entries: + print('\n未翻訳エントリ:') + for i, entry in enumerate(untranslated_entries, 1): + print(f'{i:3d}: {entry["location"]}') + print(f' {entry["msgid"]}') + print() + else: + print('✅ 未翻訳エントリは見つかりませんでした!') + + print(f'=' * 80) + +if __name__ == "__main__": + filename = sys.argv[1] if len(sys.argv) > 1 else 'library/typing.po' + final_check_untranslated(filename) \ No newline at end of file diff --git a/find_empty_msgstr.py b/find_empty_msgstr.py new file mode 100644 index 000000000..0c0a0b8b7 --- /dev/null +++ b/find_empty_msgstr.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 +import re +import sys + +def find_empty_msgstr(filename): + """Find entries with truly empty msgstr""" + with open(filename, 'r', encoding='utf-8') as f: + content = f.read() + + # Pattern to match complete po entries + pattern = r'(#:.*?\nmsgid.*?\nmsgstr[^\n]*(?:\n"[^"]*")*)' + entries = re.findall(pattern, content, re.DOTALL) + + empty_entries = [] + + for entry in entries: + # Check if msgstr is truly empty (just msgstr "" with no following quoted strings) + if re.search(r'msgstr ""\s*\n(?![\s]*")', entry): + # Extract msgid content + msgid_match = re.search(r'msgid\s+"([^"]*)"(?:\s*\n\s*"([^"]*)")*', entry) + if msgid_match: + msgid_content = msgid_match.group(1) + if msgid_match.group(2): + msgid_content += msgid_match.group(2) + + # Skip obvious code examples + if not any(x in msgid_content for x in ['def ', 'class ', '>>>', 'import ', 'return ']): + if msgid_content.strip(): # Non-empty msgid + empty_entries.append({ + 'msgid': msgid_content, + 'entry': entry[:200] + '...' if len(entry) > 200 else entry + }) + + print(f"Found {len(empty_entries)} truly empty msgstr entries:") + for i, entry in enumerate(empty_entries[:10], 1): + print(f"{i}: {entry['msgid']}") + print(f" Entry: {entry['entry']}") + print() + +if __name__ == "__main__": + filename = sys.argv[1] if len(sys.argv) > 1 else 'library/typing.po' + find_empty_msgstr(filename) \ No newline at end of file diff --git a/improved_untranslated_check.py b/improved_untranslated_check.py new file mode 100644 index 000000000..5120599ea --- /dev/null +++ b/improved_untranslated_check.py @@ -0,0 +1,157 @@ +#!/usr/bin/env python3 +""" +改良版未翻訳エントリ検出スクリプト +これまでの翻訳作業で判明した課題を解決する改善版 +""" +import re +import sys +from typing import List, Dict, Tuple + +def parse_po_entries(content: str) -> List[Dict[str, str]]: + """ + .poファイルのエントリをより正確に解析 + マルチライン対応、コメント処理、空行処理を改善 + """ + # エントリを #: で分割(ただし先頭の場合は除く) + entries = re.split(r'\n(?=#:)', content) + parsed_entries = [] + + for i, entry in enumerate(entries): + if not entry.strip(): + continue + + # ヘッダーエントリをスキップ + if 'Project-Id-Version' in entry: + continue + + # msgidとmsgstrを抽出 + msgid_match = re.search(r'msgid\s+((?:"[^"]*"\s*)+)', entry, re.MULTILINE | re.DOTALL) + msgstr_match = re.search(r'msgstr\s+((?:"[^"]*"\s*)*)', entry, re.MULTILINE | re.DOTALL) + + if msgid_match and msgstr_match: + # 引用符を結合してクリーンアップ + msgid_raw = msgid_match.group(1) + msgstr_raw = msgstr_match.group(1) + + # 複数行の文字列を結合 + msgid_clean = re.sub(r'"\s*\n\s*"', '', msgid_raw).strip('"') + msgstr_clean = re.sub(r'"\s*\n\s*"', '', msgstr_raw).strip('"') + + # 位置情報を抽出 + location_match = re.search(r'#:\s*([^\n]+)', entry) + location = location_match.group(1) if location_match else 'unknown' + + parsed_entries.append({ + 'msgid': msgid_clean, + 'msgstr': msgstr_clean, + 'location': location, + 'raw_entry': entry + }) + + return parsed_entries + +def is_translatable_content(msgid: str) -> bool: + """ + 翻訳が必要なコンテンツかどうかを判定 + これまでの作業で判明したパターンを含む改良版 + """ + if not msgid.strip(): + return False + + # 明らかにコードのパターン + code_patterns = [ + r'^\s*def\s+\w+', # 関数定義 + r'^\s*class\s+\w+', # クラス定義 + r'^\s*import\s+', # import文 + r'^\s*from\s+\w+\s+import', # from import文 + r'^\s*>>>\s*', # doctest + r'^\s*\.\.\.\s*$', # doctest continuation + r'^\s*assert\s+', # assert文 + r'^\s*return\s+', # return文 + r'^\s*print\s*\(', # print関数 + r'^\s*raise\s+', # raise文 + r'^\s*try\s*:', # try文 + r'^\s*except\s*[:\w]', # except文 + r'^\s*if\s+__name__', # if __name__ == "__main__" + r'^\s*#.*$', # コメント行のみ + ] + + for pattern in code_patterns: + if re.match(pattern, msgid, re.MULTILINE): + return False + + # ファイルパス、URL、バージョン番号のパターン + non_translatable_patterns = [ + r'^[a-zA-Z_][a-zA-Z0-9_]*\.py$', # .pyファイル + r'^https?://', # URL + r'^\d+\.\d+(\.\d+)?$', # バージョン番号 + r'^[a-zA-Z0-9_/]+\.txt$', # .txtファイル + r'^\s*\.\s*$', # 単独のドット + r'^\s*\n\s*$', # 改行のみ + ] + + for pattern in non_translatable_patterns: + if re.match(pattern, msgid.strip()): + return False + + # コードブロック(複数行にわたるコード) + if re.search(r'(?:def|class|import|from.*import)\s+\w+', msgid): + return False + + # ピュア数値・記号 + if re.match(r'^[\d\s\+\-\*\/\(\)\[\]{},.=<>!&|]+$', msgid.strip()): + return False + + return True + +def improved_untranslated_check(filename: str) -> Tuple[int, List[Dict]]: + """ + 改良版未翻訳チェック + """ + try: + with open(filename, 'r', encoding='utf-8') as f: + content = f.read() + except FileNotFoundError: + print(f'❌ ファイル {filename} が見つかりません') + return 0, [] + + entries = parse_po_entries(content) + untranslated_entries = [] + + for entry in entries: + # msgstrが空の場合 + if not entry['msgstr'].strip(): + # 翻訳が必要かどうかを判定 + if is_translatable_content(entry['msgid']): + untranslated_entries.append({ + 'location': entry['location'], + 'msgid': entry['msgid'][:100] + '...' if len(entry['msgid']) > 100 else entry['msgid'], + 'full_msgid': entry['msgid'] + }) + + return len(untranslated_entries), untranslated_entries + +def main(): + filename = sys.argv[1] if len(sys.argv) > 1 else 'library/typing.po' + count, entries = improved_untranslated_check(filename) + + print(f'🔍 改良版未翻訳チェック: {filename}') + print(f'=' * 80) + print(f'未翻訳エントリ数: {count}') + + if entries: + print('\n未翻訳エントリ:') + for i, entry in enumerate(entries[:20], 1): # 最初の20個まで表示 + print(f'{i:3d}: {entry["location"]}') + print(f' {entry["msgid"]}') + print() + + if len(entries) > 20: + print(f'... 他 {len(entries) - 20}個') + else: + print('✅ 未翻訳エントリは見つかりませんでした!') + + print(f'=' * 80) + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/make_s3.py b/make_s3.py new file mode 100644 index 000000000..18a0ce141 --- /dev/null +++ b/make_s3.py @@ -0,0 +1,45 @@ +import boto3 +import json + +bucket_name = "test-pythondoc-ja-cloude1" +region = "ap-northeast-1" +index_document = "index.html" + +s3 = boto3.client("s3", region_name=region) + +s3.create_bucket( + Bucket=bucket_name, CreateBucketConfiguration={"LocationConstraint": region} +) + +s3.put_public_access_block( + Bucket=bucket_name, + PublicAccessBlockConfiguration={ + "BlockPublicAcls": False, + "IgnorePublicAcls": False, + "BlockPublicPolicy": False, + "RestrictPublicBuckets": False, + }, +) + +policy = { + "Version": "2012-10-17", + "Statement": [ + { + "Sid": "PublicReadGetObject", + "Effect": "Allow", + "Principal": "*", + "Action": "s3:GetObject", + "Resource": f"arn:aws:s3:::{bucket_name}/*", + } + ], +} + +s3.put_bucket_policy(Bucket=bucket_name, Policy=json.dumps(policy)) + +s3_website = boto3.client("s3", region_name=region) +s3_website.put_bucket_website( + Bucket=bucket_name, + WebsiteConfiguration={"IndexDocument": {"Suffix": index_document}}, +) + +print(f"http://{bucket_name}.s3-website-{region}.amazonaws.com") diff --git a/precise_untranslated_check.py b/precise_untranslated_check.py new file mode 100644 index 000000000..36b3b37f6 --- /dev/null +++ b/precise_untranslated_check.py @@ -0,0 +1,103 @@ +#!/usr/bin/env python3 +import re +import sys + +def parse_po_file(filename): + """ + More accurate .po file parser that handles multi-line entries correctly + """ + try: + with open(filename, 'r', encoding='utf-8') as f: + content = f.read() + except FileNotFoundError: + print(f'❌ ファイル {filename} が見つかりません') + return + + # Split content into blocks, each starting with #: + blocks = re.split(r'\n(?=#:)', content) + + untranslated_entries = [] + total_entries = 0 + + for block in blocks: + if not block.strip(): + continue + + # Skip header block + if 'msgid ""' in block and 'Project-Id-Version' in block: + continue + + # Check if this block has msgid and msgstr + if 'msgid' in block and 'msgstr' in block: + total_entries += 1 + + # Extract msgid content (handle multi-line) + msgid_match = re.search(r'msgid\s+(.*?)(?=\nmsgstr|\nmsgid|\n#|\nZ)', block, re.DOTALL) + msgstr_match = re.search(r'msgstr\s+(.*?)(?=\n#|\nmsgid|\nZ)', block, re.DOTALL) + + if msgid_match and msgstr_match: + msgid_content = msgid_match.group(1).strip() + msgstr_content = msgstr_match.group(1).strip() + + # Clean up quotes and whitespace + msgid_clean = re.sub(r'^""|""$', '', msgid_content.replace('\n', ' ').replace('"', '')) + msgstr_clean = re.sub(r'^""|""$', '', msgstr_content.replace('\n', ' ').replace('"', '')) + + # Check if msgstr is truly empty + if not msgstr_clean.strip(): + # Determine if this should be translated + should_translate = not any([ + # Code examples + 'def ' in msgid_clean, + 'class ' in msgid_clean, + 'import ' in msgid_clean, + '>>>' in msgid_clean, + 'print(' in msgid_clean, + 'return ' in msgid_clean, + 'assert ' in msgid_clean, + 'raise ' in msgid_clean, + 'try:' in msgid_clean, + 'except:' in msgid_clean, + 'if __name__' in msgid_clean, + # File paths + '.py' in msgid_clean and '/' in msgid_clean, + '.txt' in msgid_clean and '/' in msgid_clean, + # URLs + 'http://' in msgid_clean, + 'https://' in msgid_clean, + # Version numbers only + re.match(r'^\d+\.\d+$', msgid_clean.strip()), + # Empty content + not msgid_clean.strip(), + # Just newlines + msgid_clean.strip() == '\\n' + ]) + + if should_translate and len(msgid_clean.strip()) > 0: + untranslated_entries.append({ + 'content': msgid_clean[:100] + '...' if len(msgid_clean) > 100 else msgid_clean, + 'full_block': block[:300] + '...' if len(block) > 300 else block + }) + + print(f'📊 精密な翻訳状況レポート: {filename}') + print(f'=' * 80) + print(f'総エントリ数: {total_entries}') + print(f'未翻訳で翻訳が必要: {len(untranslated_entries)}') + + if len(untranslated_entries) > 0: + print(f'\n⚠️ {len(untranslated_entries)}個の翻訳対象エントリが未翻訳です') + print('\n未翻訳エントリ(最初の10個):') + print('-' * 80) + for i, entry in enumerate(untranslated_entries[:10], 1): + print(f'{i:3d}: {entry["content"]}') + + if len(untranslated_entries) > 10: + print(f'... 他 {len(untranslated_entries) - 10}個') + else: + print('✅ すべての翻訳対象エントリが翻訳済みです!') + + print(f'=' * 80) + +if __name__ == "__main__": + filename = sys.argv[1] if len(sys.argv) > 1 else 'library/typing.po' + parse_po_file(filename) \ No newline at end of file diff --git a/translated_typing.po b/translated_typing.po new file mode 100644 index 000000000..e23f4bd20 --- /dev/null +++ b/translated_typing.po @@ -0,0 +1,7352 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) 2001 Python Software Foundation +# This file is distributed under the same license as the Python package. +# FIRST AUTHOR , YEAR. +# +# Translators: +# Shin Saito, 2021 +# Arihiro TAKASE, 2023 +# souma987, 2023 +# Takuya Futatsugi, 2024 +# digdugdog, 2024 +# Yosuke Miyashita, 2025 +# tomo, 2025 +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: Python 3.14\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2025-06-13 14:21+0000\n" +"PO-Revision-Date: 2021-06-28 01:16+0000\n" +"Last-Translator: tomo, 2025\n" +"Language-Team: Japanese (https://app.transifex.com/python-doc/teams/5390/" +"ja/)\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Language: ja\n" +"Plural-Forms: nplurals=1; plural=0;\n" + +#: ../../library/typing.rst:3 +msgid ":mod:`!typing` --- Support for type hints" +msgstr ":mod:`!typing` --- 型ヒントのサポート" + +#: ../../library/typing.rst:16 +msgid "**Source code:** :source:`Lib/typing.py`" +msgstr "**ソースコード:** :source:`Lib/typing.py`" + +#: ../../library/typing.rst:20 +msgid "" +"The Python runtime does not enforce function and variable type annotations. " +"They can be used by third party tools such as :term:`type checkers `, IDEs, linters, etc." +msgstr "" +"Python ランタイムは、関数や変数の型アノテーションを強制しません。型アノテー" +"ションは、 :term:`type checkers` や IDE、linterなどの" +"サードパーティーツールで使われます。" + +#: ../../library/typing.rst:26 +msgid "This module provides runtime support for type hints." +msgstr "このモジュールは型ヒントの実行時サポートを提供します。" + +#: ../../library/typing.rst:28 +msgid "Consider the function below::" +msgstr "以下の関数を例に考えてみます::" + +#: ../../library/typing.rst:30 +msgid "" +"def surface_area_of_cube(edge_length: float) -> str:\n" +" return f\"The surface area of the cube is {6 * edge_length ** 2}.\"" +msgstr "" +"def surface_area_of_cube(edge_length: float) -> str:\n" +" return f\"The surface area of the cube is {6 * edge_length ** 2}.\"" + +#: ../../library/typing.rst:33 +msgid "" +"The function ``surface_area_of_cube`` takes an argument expected to be an " +"instance of :class:`float`, as indicated by the :term:`type hint` " +"``edge_length: float``. The function is expected to return an instance of :" +"class:`str`, as indicated by the ``-> str`` hint." +msgstr "" +"``surface_area_of_cube`` 関数は、``edge_length: float`` という :term:`type " +"hint` で示されているように、引数が :class:`float` のインスタンスであるという" +"前提です。\n" +"そして、``-> str`` というヒントにある通り、この関数は :class:`str` のインスタ" +"ンスを返すことになっています。" + +#: ../../library/typing.rst:38 +msgid "" +"While type hints can be simple classes like :class:`float` or :class:`str`, " +"they can also be more complex. The :mod:`typing` module provides a " +"vocabulary of more advanced type hints." +msgstr "" +"型ヒントは :class:`float` や :class:`str` のような単純な型を指定することもで" +"きますし、もっと複雑な型も指定できます。\n" +":mod:`typing` モジュールには、より高度な型ヒントを表現するためのいろいろな型" +"が含まれています。" + +#: ../../library/typing.rst:42 +msgid "" +"New features are frequently added to the ``typing`` module. The :pypi:" +"`typing_extensions` package provides backports of these new features to " +"older versions of Python." +msgstr "" +"``typing`` モジュールには新しい機能が頻繁に追加されます。\n" +":pypi:`typing_extensions` パッケージを使うことで、古い Python バージョンから" +"もその新機能を使うことができます。" + +#: ../../library/typing.rst:48 +msgid "" +"`\"Typing cheat sheet\" `_" +msgstr "" +"`\"Typing cheat sheet\" `_" + +#: ../../library/typing.rst:49 +msgid "A quick overview of type hints (hosted at the mypy docs)" +msgstr "型ヒントの簡単な概要 (mypy ドキュメンテーション)" + +#: ../../library/typing.rst:51 +msgid "" +"\"Type System Reference\" section of `the mypy docs `_" +msgstr "" +"`mypy ドキュメンテーション `_ の \"Type System Reference\" セクション" + +#: ../../library/typing.rst:52 +msgid "" +"The Python typing system is standardised via PEPs, so this reference should " +"broadly apply to most Python type checkers. (Some parts may still be " +"specific to mypy.)" +msgstr "" +"Python の型システムの規格は PEP によって定められているので、このレファレンス" +"はほとんどの Python 型チェッカーに適用できるはずです。(mypy のみに適用される" +"部分もあるかもしれません。)" + +#: ../../library/typing.rst:56 +msgid "`\"Static Typing with Python\" `_" +msgstr "`\"Static Typing with Python\" `_" + +#: ../../library/typing.rst:57 +msgid "" +"Type-checker-agnostic documentation written by the community detailing type " +"system features, useful typing related tools and typing best practices." +msgstr "" +"コミュニティーによって書かれた、型システムの機能や便利な型関連のツール、型に" +"関するベストプラクティスを詳しく説明している、特定の型チェッカーに依らないド" +"キュメンテーション。" + +#: ../../library/typing.rst:64 +msgid "Specification for the Python Type System" +msgstr "Python 型システムの仕様" + +#: ../../library/typing.rst:66 +msgid "" +"The canonical, up-to-date specification of the Python type system can be " +"found at `\"Specification for the Python type system\" `_." +msgstr "" +"Python型システムの正式で最新の仕様は `\"Specification for the Python type " +"system\" `_ で見つけるこ" +"とができます。" + +#: ../../library/typing.rst:72 +msgid "Type aliases" +msgstr "型エイリアス" + +#: ../../library/typing.rst:74 +msgid "" +"A type alias is defined using the :keyword:`type` statement, which creates " +"an instance of :class:`TypeAliasType`. In this example, ``Vector`` and " +"``list[float]`` will be treated equivalently by static type checkers::" +msgstr "" +"型エイリアスは :keyword:`type` 文を用いて定義され、 :class:`TypeAliasType` イ" +"ンスタンスが生成されます。 この例では、静的型チェッカーは ``Vector`` と " +"``list[float]`` を等しいものとして扱います" + +#: ../../library/typing.rst:79 +msgid "" +"type Vector = list[float]\n" +"\n" +"def scale(scalar: float, vector: Vector) -> Vector:\n" +" return [scalar * num for num in vector]\n" +"\n" +"# passes type checking; a list of floats qualifies as a Vector.\n" +"new_vector = scale(2.0, [1.0, -4.2, 5.4])" +msgstr "" +"type Vector = list[float]\n" +"\n" +"def scale(scalar: float, vector: Vector) -> Vector:\n" +" return [scalar * num for num in vector]\n" +"\n" +"# floatのlistはVectorとして要件を満たすため、型チェックを通過する。\n" +"new_vector = scale(2.0, [1.0, -4.2, 5.4])" + +#: ../../library/typing.rst:87 +msgid "" +"Type aliases are useful for simplifying complex type signatures. For " +"example::" +msgstr "型エイリアスは複雑な型シグネチャを単純化するのに有用です。例えば::" + +#: ../../library/typing.rst:89 +msgid "" +"from collections.abc import Sequence\n" +"\n" +"type ConnectionOptions = dict[str, str]\n" +"type Address = tuple[str, int]\n" +"type Server = tuple[Address, ConnectionOptions]\n" +"\n" +"def broadcast_message(message: str, servers: Sequence[Server]) -> None:\n" +" ...\n" +"\n" +"# The static type checker will treat the previous type signature as\n" +"# being exactly equivalent to this one.\n" +"def broadcast_message(\n" +" message: str,\n" +" servers: Sequence[tuple[tuple[str, int], dict[str, str]]]\n" +") -> None:\n" +" ..." +msgstr "" +"from collections.abc import Sequence\n" +"\n" +"type ConnectionOptions = dict[str, str]\n" +"type Address = tuple[str, int]\n" +"type Server = tuple[Address, ConnectionOptions]\n" +"\n" +"def broadcast_message(message: str, servers: Sequence[Server]) -> None:\n" +" ...\n" +"\n" +"# 静的型チェッカーでは、上記の型アノテーションと\n" +"# 以下のアノテーションを同等のものとして扱う。\n" +"def broadcast_message(\n" +" message: str,\n" +" servers: Sequence[tuple[tuple[str, int], dict[str, str]]]\n" +") -> None:\n" +" ..." + +#: ../../library/typing.rst:106 +msgid "" +"The :keyword:`type` statement is new in Python 3.12. For backwards " +"compatibility, type aliases can also be created through simple assignment::" +msgstr "" +":keyword:`type` 文はPython3.12で新しく導入されました。後方互換性のために、単" +"に代入によって型エイリアスを作成することもできます:" + +#: ../../library/typing.rst:109 +msgid "Vector = list[float]" +msgstr "Vector = list[float]" + +#: ../../library/typing.rst:111 +msgid "" +"Or marked with :data:`TypeAlias` to make it explicit that this is a type " +"alias, not a normal variable assignment::" +msgstr "" +"あるいは、 :data:`TypeAlias` でマークすることで、これが通常の変数代入ではな" +"く、型エイリアスであることを明示できます" + +#: ../../library/typing.rst:114 +msgid "" +"from typing import TypeAlias\n" +"\n" +"Vector: TypeAlias = list[float]" +msgstr "" +"from typing import TypeAlias\n" +"\n" +"Vector: TypeAlias = list[float]" + +#: ../../library/typing.rst:121 +msgid "NewType" +msgstr "NewType" + +#: ../../library/typing.rst:123 +msgid "Use the :class:`NewType` helper to create distinct types::" +msgstr "異なる型を作るためには :class:`NewType` ヘルパークラスを使います::" + +#: ../../library/typing.rst:125 +msgid "" +"from typing import NewType\n" +"\n" +"UserId = NewType('UserId', int)\n" +"some_id = UserId(524313)" +msgstr "" +"from typing import NewType\n" +"\n" +"UserId = NewType('UserId', int)\n" +"some_id = UserId(524313)" + +#: ../../library/typing.rst:130 +msgid "" +"The static type checker will treat the new type as if it were a subclass of " +"the original type. This is useful in helping catch logical errors::" +msgstr "" +"静的型チェッカーは新しい型を元々の型のサブクラスのように扱います。この振る舞" +"いは論理的な誤りを見つける手助けとして役に立ちます。" + +#: ../../library/typing.rst:133 +msgid "" +"def get_user_name(user_id: UserId) -> str:\n" +" ...\n" +"\n" +"# passes type checking\n" +"user_a = get_user_name(UserId(42351))\n" +"\n" +"# fails type checking; an int is not a UserId\n" +"user_b = get_user_name(-1)" +msgstr "" +"def get_user_name(user_id: UserId) -> str:\n" +" ...\n" +"\n" +"# 型チェックを通過する\n" +"user_a = get_user_name(UserId(42351))\n" +"\n" +"# 型チェックに失敗する。int型はUserId型ではないため。\n" +"user_b = get_user_name(-1)" + +#: ../../library/typing.rst:142 +msgid "" +"You may still perform all ``int`` operations on a variable of type " +"``UserId``, but the result will always be of type ``int``. This lets you " +"pass in a ``UserId`` wherever an ``int`` might be expected, but will prevent " +"you from accidentally creating a ``UserId`` in an invalid way::" +msgstr "" +"``UserId`` 型の変数も ``int`` の全ての演算が行えますが、その結果は常に " +"``int`` 型になります。\n" +"この振る舞いにより、 ``int`` が期待されるところに ``UserId`` を渡せますが、不" +"正な方法で ``UserId`` を作ってしまうことを防ぎます。" + +#: ../../library/typing.rst:147 +msgid "" +"# 'output' is of type 'int', not 'UserId'\n" +"output = UserId(23413) + UserId(54341)" +msgstr "" +"# 'output' は'int'型となる。'UserId'型にはならない。\n" +"output = UserId(23413) + UserId(54341)" + +#: ../../library/typing.rst:150 +msgid "" +"Note that these checks are enforced only by the static type checker. At " +"runtime, the statement ``Derived = NewType('Derived', Base)`` will make " +"``Derived`` a callable that immediately returns whatever parameter you pass " +"it. That means the expression ``Derived(some_value)`` does not create a new " +"class or introduce much overhead beyond that of a regular function call." +msgstr "" +"これらのチェックは静的型チェッカーのみによって強制されるということに注意して" +"ください。\n" +"実行時に ``Derived = NewType('Derived', Base)`` という文は渡された仮引数をた" +"だちに返す ``Derived`` callable を作ります。\n" +"つまり ``Derived(some_value)`` という式は新しいクラスを作ることはなく、通常の" +"関数呼び出しより多くのオーバーヘッドがないということを意味します。" + +#: ../../library/typing.rst:156 +msgid "" +"More precisely, the expression ``some_value is Derived(some_value)`` is " +"always true at runtime." +msgstr "" +"より正確に言うと、式 ``some_value is Derived(some_value)`` は実行時に常に真を" +"返します。" + +#: ../../library/typing.rst:159 +msgid "It is invalid to create a subtype of ``Derived``::" +msgstr "``Derived`` のサブタイプを作成することはできません" + +#: ../../library/typing.rst:161 +msgid "" +"from typing import NewType\n" +"\n" +"UserId = NewType('UserId', int)\n" +"\n" +"# Fails at runtime and does not pass type checking\n" +"class AdminUserId(UserId): pass" +msgstr "" +"from typing import NewType\n" +"\n" +"UserId = NewType('UserId', int)\n" +"\n" +"# 実行時にエラーとなり、型チェックも通らない\n" +"class AdminUserId(UserId): pass" + +#: ../../library/typing.rst:168 +msgid "" +"However, it is possible to create a :class:`NewType` based on a 'derived' " +"``NewType``::" +msgstr "" +"しかし、 'derived' である ``NewType`` をもとにした :class:`NewType` は作るこ" +"とが出来ます::" + +#: ../../library/typing.rst:170 +msgid "" +"from typing import NewType\n" +"\n" +"UserId = NewType('UserId', int)\n" +"\n" +"ProUserId = NewType('ProUserId', UserId)" +msgstr "" +"from typing import NewType\n" +"\n" +"UserId = NewType('UserId', int)\n" +"\n" +"ProUserId = NewType('ProUserId', UserId)" + +#: ../../library/typing.rst:176 +msgid "and typechecking for ``ProUserId`` will work as expected." +msgstr "そして ``ProUserId`` に対する型検査は期待通りに動作します。" + +#: ../../library/typing.rst:178 +msgid "See :pep:`484` for more details." +msgstr "より詳しくは :pep:`484` を参照してください。" + +#: ../../library/typing.rst:182 +msgid "" +"Recall that the use of a type alias declares two types to be *equivalent* to " +"one another. Doing ``type Alias = Original`` will make the static type " +"checker treat ``Alias`` as being *exactly equivalent* to ``Original`` in all " +"cases. This is useful when you want to simplify complex type signatures." +msgstr "" +"型エイリアスの使用は、2つの型が互いに等価であることを宣言することを思い出して" +"ください。 ``type Alias = Original`` とすると、静的型チェッカーは ``Alias`` " +"を ``Original`` と\"正確に等価な\"ものとして扱います。これは、複雑な型シグネ" +"チャを単純化したい場合に便利です。" + +#: ../../library/typing.rst:187 +msgid "" +"In contrast, ``NewType`` declares one type to be a *subtype* of another. " +"Doing ``Derived = NewType('Derived', Original)`` will make the static type " +"checker treat ``Derived`` as a *subclass* of ``Original``, which means a " +"value of type ``Original`` cannot be used in places where a value of type " +"``Derived`` is expected. This is useful when you want to prevent logic " +"errors with minimal runtime cost." +msgstr "" +"これに対し、 ``NewType`` はある型をもう一方の型の *サブタイプ* として宣言しま" +"す。 ``Derived = NewType('Derived', Original)`` とすると静的型検査器は " +"``Derived`` を ``Original`` の *サブクラス* として扱います。つまり " +"``Original`` 型の値は ``Derived`` 型の値が期待される場所で使うことが出来ない" +"ということです。これは論理的な誤りを最小の実行時のコストで防ぎたい時に有用で" +"す。" + +#: ../../library/typing.rst:196 +msgid "" +"``NewType`` is now a class rather than a function. As a result, there is " +"some additional runtime cost when calling ``NewType`` over a regular " +"function." +msgstr "" +"``NewType`` は関数ではなくクラスになりました。その結果、通常の関数よりも " +"``NewType`` を呼び出す際に多少の実行時コストが追加されます。" + +#: ../../library/typing.rst:201 +msgid "" +"The performance of calling ``NewType`` has been restored to its level in " +"Python 3.9." +msgstr "" +"``NewType`` 呼び出し時のパフォーマンスが Python 3.9 のレベルに戻りました" + +#: ../../library/typing.rst:208 +msgid "Annotating callable objects" +msgstr "呼び出し可能オブジェクトのアノテーション" + +#: ../../library/typing.rst:210 +msgid "" +"Functions -- or other :term:`callable` objects -- can be annotated using :" +"class:`collections.abc.Callable` or deprecated :data:`typing.Callable`. " +"``Callable[[int], str]`` signifies a function that takes a single parameter " +"of type :class:`int` and returns a :class:`str`." +msgstr "" +"関数、または他の :term:`callable` なオブジェクトは、 :class:`collections.abc." +"Callable` または :data:`typing.Callable` を使ってアノテーションすることができ" +"ます。 ``Callable[[int], str]`` は、 :class:`int` 型のパラメータを1つ受け取" +"り、 :class:`str` を返す関数を意味します。" + +#: ../../library/typing.rst:215 ../../library/typing.rst:3281 +#: ../../library/typing.rst:3461 +msgid "For example:" +msgstr "例えば:" + +#: ../../library/typing.rst:217 +msgid "" +"from collections.abc import Callable, Awaitable\n" +"\n" +"def feeder(get_next_item: Callable[[], str]) -> None:\n" +" ... # Body\n" +"\n" +"def async_query(on_success: Callable[[int], None],\n" +" on_error: Callable[[int, Exception], None]) -> None:\n" +" ... # Body\n" +"\n" +"async def on_update(value: str) -> None:\n" +" ... # Body\n" +"\n" +"callback: Callable[[str], Awaitable[None]] = on_update" +msgstr "" +"from collections.abc import Callable, Awaitable\n" +"\n" +"def feeder(get_next_item: Callable[[], str]) -> None:\n" +" ... # Body\n" +"\n" +"def async_query(on_success: Callable[[int], None],\n" +" on_error: Callable[[int, Exception], None]) -> None:\n" +" ... # Body\n" +"\n" +"async def on_update(value: str) -> None:\n" +" ... # Body\n" +"\n" +"callback: Callable[[str], Awaitable[None]] = on_update" + +#: ../../library/typing.rst:233 +msgid "" +"The subscription syntax must always be used with exactly two values: the " +"argument list and the return type. The argument list must be a list of " +"types, a :class:`ParamSpec`, :data:`Concatenate`, or an ellipsis. The return " +"type must be a single type." +msgstr "" +"添字表記は常に2つの値とともに使われなければなりません。実引数のリストと返り値" +"の型です。\n" +"実引数のリストは型のリスト、:class:`ParamSpec`、:data:`Concatenate`、" +"ellipsis のいずれかでなければなりません。返り値の型は単一の型でなければなりま" +"せん。" + +#: ../../library/typing.rst:238 +msgid "" +"If a literal ellipsis ``...`` is given as the argument list, it indicates " +"that a callable with any arbitrary parameter list would be acceptable:" +msgstr "" +"もしellipsisリテラル ``...`` が引数リストとして与えられた場合、それは任意のパ" +"ラメータリストを持つ呼び出し可能オブジェクトを受け入れることを示します。" + +#: ../../library/typing.rst:241 +msgid "" +"def concat(x: str, y: str) -> str:\n" +" return x + y\n" +"\n" +"x: Callable[..., str]\n" +"x = str # OK\n" +"x = concat # Also OK" +msgstr "" +"def concat(x: str, y: str) -> str:\n" +" return x + y\n" +"\n" +"x: Callable[..., str]\n" +"x = str # OK\n" +"x = concat # これもOK" + +#: ../../library/typing.rst:250 +msgid "" +"``Callable`` cannot express complex signatures such as functions that take a " +"variadic number of arguments, :ref:`overloaded functions `, or " +"functions that have keyword-only parameters. However, these signatures can " +"be expressed by defining a :class:`Protocol` class with a :meth:`~object." +"__call__` method:" +msgstr "" +"``Callable`` は可変引数、:ref:`オーバーロード関数 `、キーワード専用" +"引数などを含む複雑な型シグネチャを表現することはできません。\n" +"しかし、:class:`Protocol` クラスとその :meth:`~object.__call__` メソッドを定" +"義すれば表現することができます:" + +#: ../../library/typing.rst:256 +msgid "" +"from collections.abc import Iterable\n" +"from typing import Protocol\n" +"\n" +"class Combiner(Protocol):\n" +" def __call__(self, *vals: bytes, maxlen: int | None = None) -> " +"list[bytes]: ...\n" +"\n" +"def batch_proc(data: Iterable[bytes], cb_results: Combiner) -> bytes:\n" +" for item in data:\n" +" ...\n" +"\n" +"def good_cb(*vals: bytes, maxlen: int | None = None) -> list[bytes]:\n" +" ...\n" +"def bad_cb(*vals: bytes, maxitems: int | None) -> list[bytes]:\n" +" ...\n" +"\n" +"batch_proc([], good_cb) # OK\n" +"batch_proc([], bad_cb) # Error! Argument 2 has incompatible type because " +"of\n" +" # different name and kind in the callback" +msgstr "" +"from collections.abc import Iterable\n" +"from typing import Protocol\n" +"\n" +"class Combiner(Protocol):\n" +" def __call__(self, *vals: bytes, maxlen: int | None = None) -> " +"list[bytes]: ...\n" +"\n" +"def batch_proc(data: Iterable[bytes], cb_results: Combiner) -> bytes:\n" +" for item in data:\n" +" ...\n" +"\n" +"def good_cb(*vals: bytes, maxlen: int | None = None) -> list[bytes]:\n" +" ...\n" +"def bad_cb(*vals: bytes, maxitems: int | None) -> list[bytes]:\n" +" ...\n" +"\n" +"batch_proc([], good_cb) # OK\n" +"batch_proc([], bad_cb) # Error! Argument 2 has incompatible type because " +"of\n" +" # different name and kind in the callback" + +#: ../../library/typing.rst:277 +msgid "" +"Callables which take other callables as arguments may indicate that their " +"parameter types are dependent on each other using :class:`ParamSpec`. " +"Additionally, if that callable adds or removes arguments from other " +"callables, the :data:`Concatenate` operator may be used. They take the form " +"``Callable[ParamSpecVariable, ReturnType]`` and " +"``Callable[Concatenate[Arg1Type, Arg2Type, ..., ParamSpecVariable], " +"ReturnType]`` respectively." +msgstr "" +"callable が別の callable を引数に取る場合は、:class:`ParamSpec` を使えば両者" +"のパラメータ引数の依存関係を表現することができます。\n" +"さらに、ある callable が別の callable から引数を追加したり削除したりする場合" +"は、 :data:`Concatenate` 演算子を使うことで表現できます。\n" +"その場合、callable の型は ``Callable[ParamSpecVariable, ReturnType]`` と " +"``Callable[Concatenate[Arg1Type, Arg2Type, ..., ParamSpecVariable], " +"ReturnType]`` という形になります。" + +#: ../../library/typing.rst:285 ../../library/typing.rst:3965 +msgid "" +"``Callable`` now supports :class:`ParamSpec` and :data:`Concatenate`. See :" +"pep:`612` for more details." +msgstr "" +"``Callable`` は :class:`ParamSpec` と :data:`Concatenate` をサポートしまし" +"た。詳細は :pep:`612` を参照してください。" + +#: ../../library/typing.rst:290 +msgid "" +"The documentation for :class:`ParamSpec` and :class:`Concatenate` provides " +"examples of usage in ``Callable``." +msgstr "" +":class:`ParamSpec` と :class:`Concatenate` のドキュメントに、``Callable`` で" +"の使用例が記載されています。" + +#: ../../library/typing.rst:296 +msgid "Generics" +msgstr "ジェネリクス" + +#: ../../library/typing.rst:298 +msgid "" +"Since type information about objects kept in containers cannot be statically " +"inferred in a generic way, many container classes in the standard library " +"support subscription to denote the expected types of container elements." +msgstr "" +"コンテナに含まれるオブジェクトに関する型情報は、一般的な方法で静的に推論する" +"ことができないため、標準ライブラリの多くのコンテナクラスは、要素に期待する型" +"を示す添字表記をサポートしています" + +#: ../../library/typing.rst:302 +msgid "" +"from collections.abc import Mapping, Sequence\n" +"\n" +"class Employee: ...\n" +"\n" +"# Sequence[Employee] indicates that all elements in the sequence\n" +"# must be instances of \"Employee\".\n" +"# Mapping[str, str] indicates that all keys and all values in the mapping\n" +"# must be strings.\n" +"def notify_by_email(employees: Sequence[Employee],\n" +" overrides: Mapping[str, str]) -> None: ..." +msgstr "" +"from collections.abc import Mapping, Sequence\n" +"\n" +"class Employee: ...\n" +"\n" +"# Sequence[Employee] は、シーケンスの全ての要素が\n" +"# \"Employee\"のインスタンスでなければならないことを示す。\n" +"# Mapping[str, str] は、マッピングの全てのキーと全ての値が\n" +"# 文字列でなければならないことを示す。\n" +"def notify_by_email(employees: Sequence[Employee],\n" +" overrides: Mapping[str, str]) -> None: ..." + +#: ../../library/typing.rst:315 +msgid "" +"Generic functions and classes can be parameterized by using :ref:`type " +"parameter syntax `::" +msgstr "" +"ジェネリック関数とクラスは :ref:`type parameter syntax ` を使" +"ってパラメータ化することができます::" + +#: ../../library/typing.rst:318 +msgid "" +"from collections.abc import Sequence\n" +"\n" +"def first[T](l: Sequence[T]) -> T: # Function is generic over the TypeVar " +"\"T\"\n" +" return l[0]" +msgstr "" +"from collections.abc import Sequence\n" +"\n" +"def first[T](l: Sequence[T]) -> T: # 関数は TypeVar \"T\" に対してジェネリック\n" +" return l[0]" + +#: ../../library/typing.rst:323 +msgid "Or by using the :class:`TypeVar` factory directly::" +msgstr "または :class:`TypeVar` ファクトリーを直接使用する方法もあります::" + +#: ../../library/typing.rst:325 +msgid "" +"from collections.abc import Sequence\n" +"from typing import TypeVar\n" +"\n" +"U = TypeVar('U') # Declare type variable \"U\"\n" +"\n" +"def second(l: Sequence[U]) -> U: # Function is generic over the TypeVar " +"\"U\"\n" +" return l[1]" +msgstr "" +"from collections.abc import Sequence\n" +"from typing import TypeVar\n" +"\n" +"U = TypeVar('U') # 型変数 \"U\" を宣言\n" +"\n" +"def second(l: Sequence[U]) -> U: # 関数は TypeVar \"U\" に対してジェネリック\n" +" return l[1]" + +#: ../../library/typing.rst:333 +msgid "Syntactic support for generics is new in Python 3.12." +msgstr "ジェネリクスの構文サポートは Python 3.12 で新しく追加されました。" + +#: ../../library/typing.rst:339 +msgid "Annotating tuples" +msgstr "タプルのアノテーション" + +#: ../../library/typing.rst:341 +msgid "" +"For most containers in Python, the typing system assumes that all elements " +"in the container will be of the same type. For example::" +msgstr "" +"Python の多くのコンテナでは、型システムはコンテナ内の全ての要素が同じ型であると仮定します。例えば::" + +#: ../../library/typing.rst:344 +msgid "" +"from collections.abc import Mapping\n" +"\n" +"# Type checker will infer that all elements in ``x`` are meant to be ints\n" +"x: list[int] = []\n" +"\n" +"# Type checker error: ``list`` only accepts a single type argument:\n" +"y: list[int, str] = [1, 'foo']\n" +"\n" +"# Type checker will infer that all keys in ``z`` are meant to be strings,\n" +"# and that all values in ``z`` are meant to be either strings or ints\n" +"z: Mapping[str, str | int] = {}" +msgstr "" +"from collections.abc import Mapping\n" +"\n" +"# 型チェッカーは ``x`` の全ての要素が int であることを推論する\n" +"x: list[int] = []\n" +"\n" +"# 型チェッカーエラー: ``list`` は単一の型引数のみを受け入れる:\n" +"y: list[int, str] = [1, 'foo']\n" +"\n" +"# 型チェッカーは ``z`` の全てのキーが文字列であり、\n" +"# 全ての値が文字列または整数であることを推論する\n" +"z: Mapping[str, str | int] = {}" + +#: ../../library/typing.rst:356 +msgid "" +":class:`list` only accepts one type argument, so a type checker would emit " +"an error on the ``y`` assignment above. Similarly, :class:`~collections.abc." +"Mapping` only accepts two type arguments: the first indicates the type of " +"the keys, and the second indicates the type of the values." +msgstr "" +":class:`list` は引数に1つの型のみ受け入れるので、型チェッカーは上記の ``y`` " +"への代入でエラーを出力します。同様に、:class:`~collections.abc.Mapping` は引" +"数に2つの型のみ受け入れます。1つ目はキーの型を示し、2つ目は値の型を示します。" + +#: ../../library/typing.rst:362 +msgid "" +"Unlike most other Python containers, however, it is common in idiomatic " +"Python code for tuples to have elements which are not all of the same type. " +"For this reason, tuples are special-cased in Python's typing system. :class:" +"`tuple` accepts *any number* of type arguments::" +msgstr "" +"しかし、他の多くのPythonのコンテナとは異なり、タプルがすべて同じ型ではない要" +"素を持つことは、慣用的なPythonコードでは一般的です。このため、タプルはPython" +"の型システムの中でも特殊です。:class:`tuple` は任意の数の引数を受け入れます" + +#: ../../library/typing.rst:367 +msgid "" +"# OK: ``x`` is assigned to a tuple of length 1 where the sole element is an " +"int\n" +"x: tuple[int] = (5,)\n" +"\n" +"# OK: ``y`` is assigned to a tuple of length 2;\n" +"# element 1 is an int, element 2 is a str\n" +"y: tuple[int, str] = (5, \"foo\")\n" +"\n" +"# Error: the type annotation indicates a tuple of length 1,\n" +"# but ``z`` has been assigned to a tuple of length 3\n" +"z: tuple[int] = (1, 2, 3)" +msgstr "" +"# OK: ``x`` は唯一の要素が int である長さ 1 のタプルに代入される\n" +"x: tuple[int] = (5,)\n" +"\n" +"# OK: ``y`` は長さ 2 のタプルに代入される;\n" +"# 要素 1 は int、要素 2 は str\n" +"y: tuple[int, str] = (5, \"foo\")\n" +"\n" +"# エラー: 型アノテーションは長さ 1 のタプルを示しているが、\n" +"# ``z`` には長さ 3 のタプルが代入されている\n" +"z: tuple[int] = (1, 2, 3)" + +#: ../../library/typing.rst:378 +msgid "" +"To denote a tuple which could be of *any* length, and in which all elements " +"are of the same type ``T``, use ``tuple[T, ...]``. To denote an empty tuple, " +"use ``tuple[()]``. Using plain ``tuple`` as an annotation is equivalent to " +"using ``tuple[Any, ...]``::" +msgstr "" +"*任意の* 長さで、全ての要素が同じ型 ``T`` であるタプルを示すには " +"``tuple[T, ...]`` を使います。空のタプルを示すには ``tuple[()]`` を使います。" +"単に ``tuple`` とアノテーションすることは、``tuple[Any, ...]`` と等価です。" + +#: ../../library/typing.rst:383 +msgid "" +"x: tuple[int, ...] = (1, 2)\n" +"# These reassignments are OK: ``tuple[int, ...]`` indicates x can be of any " +"length\n" +"x = (1, 2, 3)\n" +"x = ()\n" +"# This reassignment is an error: all elements in ``x`` must be ints\n" +"x = (\"foo\", \"bar\")\n" +"\n" +"# ``y`` can only ever be assigned to an empty tuple\n" +"y: tuple[()] = ()\n" +"\n" +"z: tuple = (\"foo\", \"bar\")\n" +"# These reassignments are OK: plain ``tuple`` is equivalent to " +"``tuple[Any, ...]``\n" +"z = (1, 2, 3)\n" +"z = ()" +msgstr "" +"x: tuple[int, ...] = (1, 2)\n" +"# これらの再代入は OK: ``tuple[int, ...]`` は x が任意の長さを取れることを示す\n" +"x = (1, 2, 3)\n" +"x = ()\n" +"# この再代入はエラー: ``x`` の全ての要素は int でなければならない\n" +"x = (\"foo\", \"bar\")\n" +"\n" +"# ``y`` は空のタプルにのみ代入できる\n" +"y: tuple[()] = ()\n" +"\n" +"z: tuple = (\"foo\", \"bar\")\n" +"# これらの再代入は OK: 単純な ``tuple`` は ``tuple[Any, ...]`` と等価\n" +"z = (1, 2, 3)\n" +"z = ()" + +#: ../../library/typing.rst:401 +msgid "The type of class objects" +msgstr "クラスオブジェクトの型" + +#: ../../library/typing.rst:403 +msgid "" +"A variable annotated with ``C`` may accept a value of type ``C``. In " +"contrast, a variable annotated with ``type[C]`` (or deprecated :class:" +"`typing.Type[C] `) may accept values that are classes themselves -- " +"specifically, it will accept the *class object* of ``C``. For example::" +msgstr "" +"``C`` でアノテートされた変数は ``C`` 型の値を受け入れます。対照的に、" +"``type[C]`` (または非推奨の :class:`typing.Type[C] `)でアノテートされた変数は" +"クラス自体である値を受け入れます -- 具体的には、``C`` の *クラスオブジェクト* を受け入れます。例えば::" + +#: ../../library/typing.rst:409 +msgid "" +"a = 3 # Has type ``int``\n" +"b = int # Has type ``type[int]``\n" +"c = type(a) # Also has type ``type[int]``" +msgstr "" +"a = 3 # 型は ``int``\n" +"b = int # 型は ``type[int]``\n" +"c = type(a) # 同じく型は ``type[int]``" + +#: ../../library/typing.rst:413 +msgid "Note that ``type[C]`` is covariant::" +msgstr "``type[C]`` は共変であることに注意してください::" + +#: ../../library/typing.rst:415 +msgid "" +"class User: ...\n" +"class ProUser(User): ...\n" +"class TeamUser(User): ...\n" +"\n" +"def make_new_user(user_class: type[User]) -> User:\n" +" # ...\n" +" return user_class()\n" +"\n" +"make_new_user(User) # OK\n" +"make_new_user(ProUser) # Also OK: ``type[ProUser]`` is a subtype of " +"``type[User]``\n" +"make_new_user(TeamUser) # Still fine\n" +"make_new_user(User()) # Error: expected ``type[User]`` but got ``User``\n" +"make_new_user(int) # Error: ``type[int]`` is not a subtype of " +"``type[User]``" +msgstr "" +"class User: ...\n" +"class ProUser(User): ...\n" +"class TeamUser(User): ...\n" +"\n" +"def make_new_user(user_class: type[User]) -> User:\n" +" # ...\n" +" return user_class()\n" +"\n" +"make_new_user(User) # OK\n" +"make_new_user(ProUser) # これも OK: ``type[ProUser]`` は ``type[User]`` のサブタイプ\n" +"make_new_user(TeamUser) # これも問題ない\n" +"make_new_user(User()) # エラー: ``type[User]`` が期待されるが ``User`` が渡された\n" +"make_new_user(int) # エラー: ``type[int]`` は ``type[User]`` のサブタイプではない" + +#: ../../library/typing.rst:429 +msgid "" +"The only legal parameters for :class:`type` are classes, :data:`Any`, :ref:" +"`type variables `, and unions of any of these types. For example::" +msgstr "" +":class:`type` に指定できる引数は、クラス、:data:`Any`、:ref:`型変数 `、" +"およびこれらの型の合集型のみです。例えば::" + +#: ../../library/typing.rst:433 +msgid "" +"def new_non_team_user(user_class: type[BasicUser | ProUser]): ...\n" +"\n" +"new_non_team_user(BasicUser) # OK\n" +"new_non_team_user(ProUser) # OK\n" +"new_non_team_user(TeamUser) # Error: ``type[TeamUser]`` is not a subtype\n" +" # of ``type[BasicUser | ProUser]``\n" +"new_non_team_user(User) # Also an error" +msgstr "" +"def new_non_team_user(user_class: type[BasicUser | ProUser]): ...\n" +"\n" +"new_non_team_user(BasicUser) # OK\n" +"new_non_team_user(ProUser) # OK\n" +"new_non_team_user(TeamUser) # エラー: ``type[TeamUser]`` は\n" +" # ``type[BasicUser | ProUser]`` のサブタイプではない\n" +"new_non_team_user(User) # これもエラー" + +#: ../../library/typing.rst:441 +msgid "" +"``type[Any]`` is equivalent to :class:`type`, which is the root of Python's :" +"ref:`metaclass hierarchy `." +msgstr "" +"``type[Any]`` は :class:`type` と等価であり、これは Python の :ref:`メタクラス階層 ` のルートです。" + +#: ../../library/typing.rst:448 +msgid "Annotating generators and coroutines" +msgstr "ジェネレーターとコルーチンのアノテーション" + +#: ../../library/typing.rst:450 +msgid "" +"A generator can be annotated using the generic type :class:" +"`Generator[YieldType, SendType, ReturnType] `. " +"For example::" +msgstr "" +"ジェネレーターはジェネリック型 :class:`Generator[YieldType, SendType, ReturnType] ` を使ってアノテートできます。例えば::" + +#: ../../library/typing.rst:454 +msgid "" +"def echo_round() -> Generator[int, float, str]:\n" +" sent = yield 0\n" +" while sent >= 0:\n" +" sent = yield round(sent)\n" +" return 'Done'" +msgstr "" +"def echo_round() -> Generator[int, float, str]:\n" +" sent = yield 0\n" +" while sent >= 0:\n" +" sent = yield round(sent)\n" +" return 'Done'" + +#: ../../library/typing.rst:460 +msgid "" +"Note that unlike many other generic classes in the standard library, the " +"``SendType`` of :class:`~collections.abc.Generator` behaves contravariantly, " +"not covariantly or invariantly." +msgstr "" +"注意してください。標準ライブラリの他の多くのジェネリッククラスとは異なり、" +":class:`~collections.abc.Generator` の ``SendType`` は正変または不変ではなく、反変であるように動作します。" + +#: ../../library/typing.rst:464 +msgid "" +"The ``SendType`` and ``ReturnType`` parameters default to :const:`!None`::" +msgstr "" +"``SendType`` と ``ReturnType`` パラメーターのデフォルトは :const:`!None` です::" + +#: ../../library/typing.rst:466 +msgid "" +"def infinite_stream(start: int) -> Generator[int]:\n" +" while True:\n" +" yield start\n" +" start += 1" +msgstr "" +"def infinite_stream(start: int) -> Generator[int]:\n" +" while True:\n" +" yield start\n" +" start += 1" + +#: ../../library/typing.rst:471 +msgid "It is also possible to set these types explicitly::" +msgstr "これらの型を明示的に設定することもできます::" + +#: ../../library/typing.rst:473 +msgid "" +"def infinite_stream(start: int) -> Generator[int, None, None]:\n" +" while True:\n" +" yield start\n" +" start += 1" +msgstr "" +"def infinite_stream(start: int) -> Generator[int, None, None]:\n" +" while True:\n" +" yield start\n" +" start += 1" + +#: ../../library/typing.rst:478 +msgid "" +"Simple generators that only ever yield values can also be annotated as " +"having a return type of either :class:`Iterable[YieldType] ` or :class:`Iterator[YieldType] `::" +msgstr "" +"値を生成するだけのシンプルなジェネレーターは、戻り値の型として :class:`Iterable[YieldType] ` " +"または :class:`Iterator[YieldType] ` のいずれかを指定してアノテーションすることもできます::" + +#: ../../library/typing.rst:483 +msgid "" +"def infinite_stream(start: int) -> Iterator[int]:\n" +" while True:\n" +" yield start\n" +" start += 1" +msgstr "" +"def infinite_stream(start: int) -> Iterator[int]:\n" +" while True:\n" +" yield start\n" +" start += 1" + +#: ../../library/typing.rst:488 +msgid "" +"Async generators are handled in a similar fashion, but don't expect a " +"``ReturnType`` type argument (:class:`AsyncGenerator[YieldType, SendType] " +"`). The ``SendType`` argument defaults to :" +"const:`!None`, so the following definitions are equivalent::" +msgstr "" +"非同期ジェネレーターも同様に扱われますが、``ReturnType`` 型引数は期待されません (:class:`AsyncGenerator[YieldType, SendType] `)。" +"``SendType`` 引数のデフォルトは :const:`!None` なので、以下の定義は等価です::" + +#: ../../library/typing.rst:494 +msgid "" +"async def infinite_stream(start: int) -> AsyncGenerator[int]:\n" +" while True:\n" +" yield start\n" +" start = await increment(start)\n" +"\n" +"async def infinite_stream(start: int) -> AsyncGenerator[int, None]:\n" +" while True:\n" +" yield start\n" +" start = await increment(start)" +msgstr "" +"async def infinite_stream(start: int) -> AsyncGenerator[int]:\n" +" while True:\n" +" yield start\n" +" start = await increment(start)\n" +"\n" +"async def infinite_stream(start: int) -> AsyncGenerator[int, None]:\n" +" while True:\n" +" yield start\n" +" start = await increment(start)" + +#: ../../library/typing.rst:504 +msgid "" +"As in the synchronous case, :class:`AsyncIterable[YieldType] ` and :class:`AsyncIterator[YieldType] ` are available as well::" +msgstr "" +"同期の場合と同様に、:class:`AsyncIterable[YieldType] ` と " +":class:`AsyncIterator[YieldType] ` も利用できます::" + +#: ../../library/typing.rst:509 +msgid "" +"async def infinite_stream(start: int) -> AsyncIterator[int]:\n" +" while True:\n" +" yield start\n" +" start = await increment(start)" +msgstr "" +"async def infinite_stream(start: int) -> AsyncIterator[int]:\n" +" while True:\n" +" yield start\n" +" start = await increment(start)" + +#: ../../library/typing.rst:514 +msgid "" +"Coroutines can be annotated using :class:`Coroutine[YieldType, SendType, " +"ReturnType] `. Generic arguments correspond to " +"those of :class:`~collections.abc.Generator`, for example::" +msgstr "" +"コルーチンは :class:`Coroutine[YieldType, SendType, ReturnType] ` を使ってアノテートできます。" +"ジェネリック引数は :class:`~collections.abc.Generator` のものと対応します。例えば::" + +#: ../../library/typing.rst:519 +msgid "" +"from collections.abc import Coroutine\n" +"c: Coroutine[list[str], str, int] # Some coroutine defined elsewhere\n" +"x = c.send('hi') # Inferred type of 'x' is list[str]\n" +"async def bar() -> None:\n" +" y = await c # Inferred type of 'y' is int" +msgstr "" +"from collections.abc import Coroutine\n" +"c: Coroutine[list[str], str, int] # 他で定義されたコルーチン\n" +"x = c.send('hi') # 'x' の推論型は list[str]\n" +"async def bar() -> None:\n" +" y = await c # 'y' の推論型は int" + +#: ../../library/typing.rst:528 +msgid "User-defined generic types" +msgstr "ユーザー定義のジェネリック型" + +#: ../../library/typing.rst:530 +msgid "A user-defined class can be defined as a generic class." +msgstr "ユーザー定義のクラスを、ジェネリッククラスとして定義できます。" + +#: ../../library/typing.rst:534 +msgid "" +"from logging import Logger\n" +"\n" +"class LoggedVar[T]:\n" +" def __init__(self, value: T, name: str, logger: Logger) -> None:\n" +" self.name = name\n" +" self.logger = logger\n" +" self.value = value\n" +"\n" +" def set(self, new: T) -> None:\n" +" self.log('Set ' + repr(self.value))\n" +" self.value = new\n" +"\n" +" def get(self) -> T:\n" +" self.log('Get ' + repr(self.value))\n" +" return self.value\n" +"\n" +" def log(self, message: str) -> None:\n" +" self.logger.info('%s: %s', self.name, message)" +msgstr "" +"from logging import Logger\n" +"\n" +"class LoggedVar[T]:\n" +" def __init__(self, value: T, name: str, logger: Logger) -> None:\n" +" self.name = name\n" +" self.logger = logger\n" +" self.value = value\n" +"\n" +" def set(self, new: T) -> None:\n" +" self.log('Set ' + repr(self.value))\n" +" self.value = new\n" +"\n" +" def get(self) -> T:\n" +" self.log('Get ' + repr(self.value))\n" +" return self.value\n" +"\n" +" def log(self, message: str) -> None:\n" +" self.logger.info('%s: %s', self.name, message)" + +#: ../../library/typing.rst:553 +msgid "" +"This syntax indicates that the class ``LoggedVar`` is parameterised around a " +"single :ref:`type variable ` ``T`` . This also makes ``T`` valid as " +"a type within the class body." +msgstr "" +"この構文は、クラス ``LoggedVar`` が単一の :ref:`型変数 ` ``T`` でパラメータ化されていることを示します。" +"これにより、``T`` はクラス本体内で型として有効になります。" + +#: ../../library/typing.rst:557 +msgid "" +"Generic classes implicitly inherit from :class:`Generic`. For compatibility " +"with Python 3.11 and lower, it is also possible to inherit explicitly from :" +"class:`Generic` to indicate a generic class::" +msgstr "" +"ジェネリッククラスは暗黙的に :class:`Generic` から継承します。Python 3.11 以下との互換性のため、" +":class:`Generic` から明示的に継承してジェネリッククラスであることを示すこともできます::" + +#: ../../library/typing.rst:561 +msgid "" +"from typing import TypeVar, Generic\n" +"\n" +"T = TypeVar('T')\n" +"\n" +"class LoggedVar(Generic[T]):\n" +" ..." +msgstr "" +"from typing import TypeVar, Generic\n" +"\n" +"T = TypeVar('T')\n" +"\n" +"class LoggedVar(Generic[T]):\n" +" ..." + +#: ../../library/typing.rst:568 +msgid "" +"Generic classes have :meth:`~object.__class_getitem__` methods, meaning they " +"can be parameterised at runtime (e.g. ``LoggedVar[int]`` below)::" +msgstr "" +"ジェネリッククラスは :meth:`~object.__class_getitem__` メソッドを持つため、実行時にパラメータ化できます。" +"(例えば以下の ``LoggedVar[int]``)::" + +#: ../../library/typing.rst:571 +msgid "" +"from collections.abc import Iterable\n" +"\n" +"def zero_all_vars(vars: Iterable[LoggedVar[int]]) -> None:\n" +" for var in vars:\n" +" var.set(0)" +msgstr "" +"from collections.abc import Iterable\n" +"\n" +"def zero_all_vars(vars: Iterable[LoggedVar[int]]) -> None:\n" +" for var in vars:\n" +" var.set(0)" + +#: ../../library/typing.rst:577 +msgid "" +"A generic type can have any number of type variables. All varieties of :" +"class:`TypeVar` are permissible as parameters for a generic type::" +msgstr "" +"ジェネリック型は任意の数の型変数を持つことができます。:class:`TypeVar` のあらゆる種類がジェネリック型のパラメーターとして許可されます::" + +#: ../../library/typing.rst:580 +msgid "" +"from typing import TypeVar, Generic, Sequence\n" +"\n" +"class WeirdTrio[T, B: Sequence[bytes], S: (int, str)]:\n" +" ...\n" +"\n" +"OldT = TypeVar('OldT', contravariant=True)\n" +"OldB = TypeVar('OldB', bound=Sequence[bytes], covariant=True)\n" +"OldS = TypeVar('OldS', int, str)\n" +"\n" +"class OldWeirdTrio(Generic[OldT, OldB, OldS]):\n" +" ..." +msgstr "" +"from typing import TypeVar, Generic, Sequence\n" +"\n" +"class WeirdTrio[T, B: Sequence[bytes], S: (int, str)]:\n" +" ...\n" +"\n" +"OldT = TypeVar('OldT', contravariant=True)\n" +"OldB = TypeVar('OldB', bound=Sequence[bytes], covariant=True)\n" +"OldS = TypeVar('OldS', int, str)\n" +"\n" +"class OldWeirdTrio(Generic[OldT, OldB, OldS]):\n" +" ..." + +#: ../../library/typing.rst:592 +msgid "" +"Each type variable argument to :class:`Generic` must be distinct. This is " +"thus invalid::" +msgstr "" +":class:`Generic` の引数のそれぞれの型変数は別のものでなければなりません。この" +"ため次のクラス定義は無効です::" + +#: ../../library/typing.rst:595 +msgid "" +"from typing import TypeVar, Generic\n" +"...\n" +"\n" +"class Pair[M, M]: # SyntaxError\n" +" ...\n" +"\n" +"T = TypeVar('T')\n" +"\n" +"class Pair(Generic[T, T]): # INVALID\n" +" ..." +msgstr "" +"from typing import TypeVar, Generic\n" +"...\n" +"\n" +"class Pair[M, M]: # SyntaxError\n" +" ...\n" +"\n" +"T = TypeVar('T')\n" +"\n" +"class Pair(Generic[T, T]): # 無効\n" +" ..." + +#: ../../library/typing.rst:606 +msgid "Generic classes can also inherit from other classes::" +msgstr "ジェネリッククラスは他のクラスから継承することもできます::" + +#: ../../library/typing.rst:608 +msgid "" +"from collections.abc import Sized\n" +"\n" +"class LinkedList[T](Sized):\n" +" ..." +msgstr "" +"from collections.abc import Sized\n" +"\n" +"class LinkedList[T](Sized):\n" +" ..." + +#: ../../library/typing.rst:613 +msgid "" +"When inheriting from generic classes, some type parameters could be fixed::" +msgstr "" +"ジェネリッククラスから継承するとき、一部の型パラメーターを固定することもできます::" + +#: ../../library/typing.rst:615 +msgid "" +"from collections.abc import Mapping\n" +"\n" +"class MyDict[T](Mapping[str, T]):\n" +" ..." +msgstr "" +"from collections.abc import Mapping\n" +"\n" +"class MyDict[T](Mapping[str, T]):\n" +" ..." + +#: ../../library/typing.rst:620 +msgid "In this case ``MyDict`` has a single parameter, ``T``." +msgstr "この場合では ``MyDict`` は仮引数 ``T`` を 1 つとります。" + +#: ../../library/typing.rst:622 +msgid "" +"Using a generic class without specifying type parameters assumes :data:`Any` " +"for each position. In the following example, ``MyIterable`` is not generic " +"but implicitly inherits from ``Iterable[Any]``:" +msgstr "" +"型パラメーターを指定せずにジェネリッククラスを使用すると、各位置に :data:`Any` が仮定されます。" +"以下の例では、``MyIterable`` はジェネリックではありませんが、暗黙的に ``Iterable[Any]`` から継承します:" + +#: ../../library/typing.rst:626 +msgid "" +"from collections.abc import Iterable\n" +"\n" +"class MyIterable(Iterable): # Same as Iterable[Any]\n" +" ..." +msgstr "" +"from collections.abc import Iterable\n" +"\n" +"class MyIterable(Iterable): # Iterable[Any] と同じ\n" +" ..." + +#: ../../library/typing.rst:633 +msgid "User-defined generic type aliases are also supported. Examples::" +msgstr "ユーザー定義のジェネリック型エイリアスもサポートされています。例::" + +#: ../../library/typing.rst:635 +msgid "" +"from collections.abc import Iterable\n" +"\n" +"type Response[S] = Iterable[S] | int\n" +"\n" +"# Return type here is same as Iterable[str] | int\n" +"def response(query: str) -> Response[str]:\n" +" ...\n" +"\n" +"type Vec[T] = Iterable[tuple[T, T]]\n" +"\n" +"def inproduct[T: (int, float, complex)](v: Vec[T]) -> T: # Same as " +"Iterable[tuple[T, T]]\n" +" return sum(x*y for x, y in v)" +msgstr "" +"from collections.abc import Iterable\n" +"\n" +"type Response[S] = Iterable[S] | int\n" +"\n" +"# ここでの戻り値の型は Iterable[str] | int と同じ\n" +"def response(query: str) -> Response[str]:\n" +" ...\n" +"\n" +"type Vec[T] = Iterable[tuple[T, T]]\n" +"\n" +"def inproduct[T: (int, float, complex)](v: Vec[T]) -> T: # Iterable[tuple[T, T]] と同じ\n" +" return sum(x*y for x, y in v)" + +#: ../../library/typing.rst:648 +msgid "" +"For backward compatibility, generic type aliases can also be created through " +"a simple assignment::" +msgstr "" +"後方互換性のため、ジェネリック型エイリアスは簡単な代入でも作成できます::" + +#: ../../library/typing.rst:651 +msgid "" +"from collections.abc import Iterable\n" +"from typing import TypeVar\n" +"\n" +"S = TypeVar(\"S\")\n" +"Response = Iterable[S] | int" +msgstr "" +"from collections.abc import Iterable\n" +"from typing import TypeVar\n" +"\n" +"S = TypeVar(\"S\")\n" +"Response = Iterable[S] | int" + +#: ../../library/typing.rst:657 +msgid ":class:`Generic` no longer has a custom metaclass." +msgstr ":class:`Generic` にあった独自のメタクラスは無くなりました。" + +#: ../../library/typing.rst:660 +msgid "" +"Syntactic support for generics and type aliases is new in version 3.12. " +"Previously, generic classes had to explicitly inherit from :class:`Generic` " +"or contain a type variable in one of their bases." +msgstr "" +"ジェネリックと型エイリアスの構文サポートはPython 3.12で新しく追加されました。" +"これ以前は、ジェネリッククラスは :class:`Generic` から明示的に継承するか、" +"少なくとも1つの基底クラスに型変数を含む必要がありました。" + +#: ../../library/typing.rst:665 +msgid "" +"User-defined generics for parameter expressions are also supported via " +"parameter specification variables in the form ``[**P]``. The behavior is " +"consistent with type variables' described above as parameter specification " +"variables are treated by the :mod:`!typing` module as a specialized type " +"variable. The one exception to this is that a list of types can be used to " +"substitute a :class:`ParamSpec`::" +msgstr "" +"パラメーター表現のユーザー定義ジェネリックは、``[**P]`` 形式のパラメーター仕様変数でもサポートされています。" +"動作は上述の型変数と一致しており、パラメーター仕様変数は :mod:`!typing` モジュールによって特化された型変数として扱われます。" +"例外は、型のリストを :class:`ParamSpec` の置換に使用できることです::" + +#: ../../library/typing.rst:671 +msgid "" +">>> class Z[T, **P]: ... # T is a TypeVar; P is a ParamSpec\n" +"...\n" +">>> Z[int, [dict, float]]\n" +"__main__.Z[int, [dict, float]]" +msgstr "" +">>> class Z[T, **P]: ... # T は TypeVar; P は ParamSpec\n" +"...\n" +">>> Z[int, [dict, float]]\n" +"__main__.Z[int, [dict, float]]" + +#: ../../library/typing.rst:676 +msgid "" +"Classes generic over a :class:`ParamSpec` can also be created using explicit " +"inheritance from :class:`Generic`. In this case, ``**`` is not used::" +msgstr "" +":class:`ParamSpec` でジェネリックなクラスは、:class:`Generic` からの明示的な継承で作成することもできます。" +"この場合、``**`` は使用されません::" + +#: ../../library/typing.rst:679 +msgid "" +"from typing import ParamSpec, Generic\n" +"\n" +"P = ParamSpec('P')\n" +"\n" +"class Z(Generic[P]):\n" +" ..." +msgstr "" +"from typing import ParamSpec, Generic\n" +"\n" +"P = ParamSpec('P')\n" +"\n" +"class Z(Generic[P]):\n" +" ..." + +#: ../../library/typing.rst:686 +msgid "" +"Another difference between :class:`TypeVar` and :class:`ParamSpec` is that a " +"generic with only one parameter specification variable will accept parameter " +"lists in the forms ``X[[Type1, Type2, ...]]`` and also ``X[Type1, " +"Type2, ...]`` for aesthetic reasons. Internally, the latter is converted to " +"the former, so the following are equivalent::" +msgstr "" +":class:`TypeVar` と :class:`ParamSpec` のもう一つの違いは、パラメーター仕様変数を一つだけ持つジェネリックが、" +"美的理由で ``X[[Type1, Type2, ...]]`` と ``X[Type1, Type2, ...]`` の形式のパラメーターリストを受け入れることです。" +"内部的には、後者は前者に変換されるので、以下は等価です::" + +#: ../../library/typing.rst:692 +msgid "" +">>> class X[**P]: ...\n" +"...\n" +">>> X[int, str]\n" +"__main__.X[[int, str]]\n" +">>> X[[int, str]]\n" +"__main__.X[[int, str]]" +msgstr "" +">>> class X[**P]: ...\n" +"...\n" +">>> X[int, str]\n" +"__main__.X[[int, str]]\n" +">>> X[[int, str]]\n" +"__main__.X[[int, str]]" + +#: ../../library/typing.rst:699 +msgid "" +"Note that generics with :class:`ParamSpec` may not have correct " +"``__parameters__`` after substitution in some cases because they are " +"intended primarily for static type checking." +msgstr "" +":class:`ParamSpec` を持つジェネリックは主に静的型検査を目的としているため、" +"置換後に ``__parameters__`` が正しくない場合があることに注意してください。" + +#: ../../library/typing.rst:703 +msgid "" +":class:`Generic` can now be parameterized over parameter expressions. See :" +"class:`ParamSpec` and :pep:`612` for more details." +msgstr "" +":class:`Generic` はパラメーター表現でパラメータ化できるようになりました。" +"詳細は :class:`ParamSpec` と :pep:`612` を参照してください。" + +#: ../../library/typing.rst:707 +msgid "" +"A user-defined generic class can have ABCs as base classes without a " +"metaclass conflict. Generic metaclasses are not supported. The outcome of " +"parameterizing generics is cached, and most types in the :mod:`!typing` " +"module are :term:`hashable` and comparable for equality." +msgstr "" +"ユーザー定義ジェネリッククラスは、メタクラスの競合を起こすことなく ABC を基底クラスとして持つことができます。" +"ジェネリックメタクラスはサポートされていません。ジェネリックのパラメータ化の結果はキャッシュされ、" +":mod:`!typing` モジュールのほとんどの型は :term:`ハッシュ化可能 ` で等価性を比較できます。" + +#: ../../library/typing.rst:714 +msgid "The :data:`Any` type" +msgstr ":data:`Any` 型" + +#: ../../library/typing.rst:716 +msgid "" +"A special kind of type is :data:`Any`. A static type checker will treat " +"every type as being compatible with :data:`Any` and :data:`Any` as being " +"compatible with every type." +msgstr "" +":data:`Any` は特別な種類の型です。静的型検査器はすべての型を :data:`Any` と互" +"換として扱い、 :data:`Any` をすべての型と互換として扱います。" + +#: ../../library/typing.rst:720 +msgid "" +"This means that it is possible to perform any operation or method call on a " +"value of type :data:`Any` and assign it to any variable::" +msgstr "" +"これは、 :data:`Any` 型の値では、任意の演算やメソッドの呼び出しが行えることを" +"意味します::" + +#: ../../library/typing.rst:723 +msgid "" +"from typing import Any\n" +"\n" +"a: Any = None\n" +"a = [] # OK\n" +"a = 2 # OK\n" +"\n" +"s: str = ''\n" +"s = a # OK\n" +"\n" +"def foo(item: Any) -> int:\n" +" # Passes type checking; 'item' could be any type,\n" +" # and that type might have a 'bar' method\n" +" item.bar()\n" +" ..." +msgstr "" +"from typing import Any\n" +"\n" +"a: Any = None\n" +"a = [] # OK\n" +"a = 2 # OK\n" +"\n" +"s: str = ''\n" +"s = a # OK\n" +"\n" +"def foo(item: Any) -> int:\n" +" # 型検査を通過する; 'item' は任意の型であり、\n" +" # その型は 'bar' メソッドを持つかもしれない\n" +" item.bar()\n" +" ..." + +#: ../../library/typing.rst:738 +msgid "" +"Notice that no type checking is performed when assigning a value of type :" +"data:`Any` to a more precise type. For example, the static type checker did " +"not report an error when assigning ``a`` to ``s`` even though ``s`` was " +"declared to be of type :class:`str` and receives an :class:`int` value at " +"runtime!" +msgstr "" +":data:`Any` 型の値をより詳細な型に代入する時に型検査が行われないことに注意し" +"てください。例えば、静的型検査器は ``a`` を ``s`` に代入する時、``s`` が :" +"class:`str` 型として宣言されていて実行時に :class:`int` の値を受け取るとして" +"も、エラーを報告しません。" + +#: ../../library/typing.rst:744 +msgid "" +"Furthermore, all functions without a return type or parameter types will " +"implicitly default to using :data:`Any`::" +msgstr "" +"さらに、返り値や引数の型のないすべての関数は暗黙的に :data:`Any` を使用しま" +"す。" + +#: ../../library/typing.rst:747 +msgid "" +"def legacy_parser(text):\n" +" ...\n" +" return data\n" +"\n" +"# A static type checker will treat the above\n" +"# as having the same signature as:\n" +"def legacy_parser(text: Any) -> Any:\n" +" ...\n" +" return data" +msgstr "" +"def legacy_parser(text):\n" +" ...\n" +" return data\n" +"\n" +"# 静的型チェッカーは上記を\n" +"# 以下と同じシグネチャとして扱う:\n" +"def legacy_parser(text: Any) -> Any:\n" +" ...\n" +" return data" + +#: ../../library/typing.rst:757 +msgid "" +"This behavior allows :data:`Any` to be used as an *escape hatch* when you " +"need to mix dynamically and statically typed code." +msgstr "" +"この挙動により、動的型付けと静的型付けが混在したコードを書かなければならない" +"時に :data:`Any` を *非常口* として使用することができます。" + +#: ../../library/typing.rst:760 +msgid "" +"Contrast the behavior of :data:`Any` with the behavior of :class:`object`. " +"Similar to :data:`Any`, every type is a subtype of :class:`object`. However, " +"unlike :data:`Any`, the reverse is not true: :class:`object` is *not* a " +"subtype of every other type." +msgstr "" +":data:`Any` の挙動と :class:`object` の挙動を対比しましょう。 :data:`Any` と" +"同様に、すべての型は :class:`object` のサブタイプです。しかしながら、 :data:" +"`Any` と異なり、逆は成り立ちません: :class:`object` はすべての他の型のサブタ" +"イプでは *ありません*。" + +#: ../../library/typing.rst:765 +msgid "" +"That means when the type of a value is :class:`object`, a type checker will " +"reject almost all operations on it, and assigning it to a variable (or using " +"it as a return value) of a more specialized type is a type error. For " +"example::" +msgstr "" +"これは、ある値の型が :class:`object` のとき、型検査器はこれについてのほとんど" +"すべての操作を拒否し、これをより特殊化された変数に代入する (または返り値とし" +"て利用する) ことは型エラーになることを意味します。例えば::" + +#: ../../library/typing.rst:769 +msgid "" +"def hash_a(item: object) -> int:\n" +" # Fails type checking; an object does not have a 'magic' method.\n" +" item.magic()\n" +" ...\n" +"\n" +"def hash_b(item: Any) -> int:\n" +" # Passes type checking\n" +" item.magic()\n" +" ...\n" +"\n" +"# Passes type checking, since ints and strs are subclasses of object\n" +"hash_a(42)\n" +"hash_a(\"foo\")\n" +"\n" +"# Passes type checking, since Any is compatible with all types\n" +"hash_b(42)\n" +"hash_b(\"foo\")" +msgstr "" +"def hash_a(item: object) -> int:\n" +" # 型検査失敗; object は 'magic' メソッドを持たない。\n" +" item.magic()\n" +" ...\n" +"\n" +"def hash_b(item: Any) -> int:\n" +" # 型検査通過\n" +" item.magic()\n" +" ...\n" +"\n" +"# int と str は object のサブクラスなので型検査通過\n" +"hash_a(42)\n" +"hash_a(\"foo\")\n" +"\n" +"# Any はすべての型と互換なので型検査通過\n" +"hash_b(42)\n" +"hash_b(\"foo\")" + +#: ../../library/typing.rst:787 +msgid "" +"Use :class:`object` to indicate that a value could be any type in a typesafe " +"manner. Use :data:`Any` to indicate that a value is dynamically typed." +msgstr "" +":class:`object` は、ある値が型安全な方法で任意の型として使えることを示すため" +"に使用します。 :data:`Any` はある値が動的に型付けられることを示すために使用し" +"ます。" + +#: ../../library/typing.rst:792 +msgid "Nominal vs structural subtyping" +msgstr "名前的部分型 vs 構造的部分型" + +#: ../../library/typing.rst:794 +msgid "" +"Initially :pep:`484` defined the Python static type system as using *nominal " +"subtyping*. This means that a class ``A`` is allowed where a class ``B`` is " +"expected if and only if ``A`` is a subclass of ``B``." +msgstr "" +"初めは :pep:`484` は Python の静的型システムを *名前的部分型* を使って定義し" +"ていました。\n" +"名前的部分型とは、クラス ``B`` が期待されているところにクラス ``A`` が許容さ" +"れるのは ``A`` が ``B`` のサブクラスの場合かつその場合に限る、ということで" +"す。" + +#: ../../library/typing.rst:798 +msgid "" +"This requirement previously also applied to abstract base classes, such as :" +"class:`~collections.abc.Iterable`. The problem with this approach is that a " +"class had to be explicitly marked to support them, which is unpythonic and " +"unlike what one would normally do in idiomatic dynamically typed Python " +"code. For example, this conforms to :pep:`484`::" +msgstr "" +"前出の必要条件は、:class:`~collections.abc.Iterable` などの抽象基底クラスにも" +"当て嵌まります。\n" +"この型付け手法の問題は、この手法をサポートするためにクラスに明確な型付けを行" +"う必要があることで、これは pythonic ではなく、普段行っている 慣用的な Python " +"コードへの動的型付けとは似ていません。\n" +"例えば、次のコードは :pep:`484` に従ったものです ::" + +#: ../../library/typing.rst:804 +msgid "" +"from collections.abc import Sized, Iterable, Iterator\n" +"\n" +"class Bucket(Sized, Iterable[int]):\n" +" ...\n" +" def __len__(self) -> int: ...\n" +" def __iter__(self) -> Iterator[int]: ..." +msgstr "" +"from collections.abc import Sized, Iterable, Iterator\n" +"\n" +"class Bucket(Sized, Iterable[int]):\n" +" ...\n" +" def __len__(self) -> int: ...\n" +" def __iter__(self) -> Iterator[int]: ..." + +#: ../../library/typing.rst:811 +msgid "" +":pep:`544` allows to solve this problem by allowing users to write the above " +"code without explicit base classes in the class definition, allowing " +"``Bucket`` to be implicitly considered a subtype of both ``Sized`` and " +"``Iterable[int]`` by static type checkers. This is known as *structural " +"subtyping* (or static duck-typing)::" +msgstr "" +":pep:`544` によって上にあるようなクラス定義で基底クラスを明示しないコードを" +"ユーザーが書け、静的型チェッカーで ``Bucket`` が ``Sized`` と " +"``Iterable[int]`` 両方のサブタイプだと暗黙的に見なせるようになり、この問題が" +"解決しました。\n" +"これは *structural subtyping (構造的部分型)* (あるいは、静的ダックタイピン" +"グ) として知られています::" + +#: ../../library/typing.rst:817 +msgid "" +"from collections.abc import Iterator, Iterable\n" +"\n" +"class Bucket: # Note: no base classes\n" +" ...\n" +" def __len__(self) -> int: ...\n" +" def __iter__(self) -> Iterator[int]: ...\n" +"\n" +"def collect(items: Iterable[int]) -> int: ...\n" +"result = collect(Bucket()) # Passes type check" +msgstr "" +"from collections.abc import Iterator, Iterable\n" +"\n" +"class Bucket: # 注意: 基底クラスなし\n" +" ...\n" +" def __len__(self) -> int: ...\n" +" def __iter__(self) -> Iterator[int]: ...\n" +"\n" +"def collect(items: Iterable[int]) -> int: ...\n" +"result = collect(Bucket()) # 型検査通過" + +#: ../../library/typing.rst:827 +msgid "" +"Moreover, by subclassing a special class :class:`Protocol`, a user can " +"define new custom protocols to fully enjoy structural subtyping (see " +"examples below)." +msgstr "" +"さらに、特別なクラス :class:`Protocol` のサブクラスを作ることで、新しい独自の" +"プロトコルを作って構造的部分型というものを満喫できます。" + +#: ../../library/typing.rst:832 +msgid "Module contents" +msgstr "モジュールの内容" + +#: ../../library/typing.rst:834 +msgid "" +"The ``typing`` module defines the following classes, functions and " +"decorators." +msgstr "" +"``typing`` モジュールは以下のクラス、関数、デコレーターを定義しています。" + +#: ../../library/typing.rst:837 +msgid "Special typing primitives" +msgstr "特殊型付けプリミティブ" + +#: ../../library/typing.rst:840 +msgid "Special types" +msgstr "特殊型" + +#: ../../library/typing.rst:842 +msgid "" +"These can be used as types in annotations. They do not support subscription " +"using ``[]``." +msgstr "" +"これらはアノテーションで型として使用できます。``[]`` を使った添字表記はサポートしていません。" + +#: ../../library/typing.rst:847 +msgid "Special type indicating an unconstrained type." +msgstr "制約のない型であることを示す特別な型です。" + +#: ../../library/typing.rst:849 +msgid "Every type is compatible with :data:`Any`." +msgstr "任意の型は :data:`Any` と互換です。" + +#: ../../library/typing.rst:850 +msgid ":data:`Any` is compatible with every type." +msgstr ":data:`Any` は任意の型と互換です。" + +#: ../../library/typing.rst:852 +msgid "" +":data:`Any` can now be used as a base class. This can be useful for avoiding " +"type checker errors with classes that can duck type anywhere or are highly " +"dynamic." +msgstr "" +":data:`Any` は基底クラスとして使用できるようになりました。これは、どこでもダックタイピングできるクラスや高度に動的なクラスで型チェッカーエラーを避けるのに役立ちます。" + +#: ../../library/typing.rst:859 +msgid "A :ref:`constrained type variable `." +msgstr ":ref:`制約付き型変数 ` です。" + +#: ../../library/typing.rst:861 +msgid "Definition::" +msgstr "定義::" + +#: ../../library/typing.rst:863 +msgid "AnyStr = TypeVar('AnyStr', str, bytes)" +msgstr "AnyStr = TypeVar('AnyStr', str, bytes)" + +#: ../../library/typing.rst:865 +msgid "" +"``AnyStr`` is meant to be used for functions that may accept :class:`str` " +"or :class:`bytes` arguments but cannot allow the two to mix." +msgstr "" +"``AnyStr`` は :class:`str` または :class:`bytes` 引数を受け入れるが、両者を混在させることはできない関数で使用することを意図しています。" + +#: ../../library/typing.rst:868 ../../library/typing.rst:986 +#: ../../library/typing.rst:1043 ../../library/typing.rst:1223 +#: ../../library/typing.rst:1310 ../../library/typing.rst:1352 +#: ../../library/typing.rst:1561 ../../library/typing.rst:1622 +#: ../../library/typing.rst:3218 ../../library/typing.rst:3446 +msgid "For example::" +msgstr "例えば::" + +#: ../../library/typing.rst:870 +msgid "" +"def concat(a: AnyStr, b: AnyStr) -> AnyStr:\n" +" return a + b\n" +"\n" +"concat(\"foo\", \"bar\") # OK, output has type 'str'\n" +"concat(b\"foo\", b\"bar\") # OK, output has type 'bytes'\n" +"concat(\"foo\", b\"bar\") # Error, cannot mix str and bytes" +msgstr "" +"def concat(a: AnyStr, b: AnyStr) -> AnyStr:\n" +" return a + b\n" +"\n" +"concat(\"foo\", \"bar\") # OK, 出力の型は 'str'\n" +"concat(b\"foo\", b\"bar\") # OK, 出力の型は 'bytes'\n" +"concat(\"foo\", b\"bar\") # エラー, str と bytes を混在できない" + +#: ../../library/typing.rst:877 +msgid "" +"Note that, despite its name, ``AnyStr`` has nothing to do with the :class:" +"`Any` type, nor does it mean \"any string\". In particular, ``AnyStr`` and " +"``str | bytes`` are different from each other and have different use cases::" +msgstr "" +"名前に関わらず、``AnyStr`` は :class:`Any` 型と何の関係もなく、\"任意の文字列\"を意味しているわけでもありません。" +"特に、``AnyStr`` と ``str | bytes`` は互いに異なり、異なる使用例を持ちます::" + +#: ../../library/typing.rst:882 +msgid "" +"# Invalid use of AnyStr:\n" +"# The type variable is used only once in the function signature,\n" +"# so cannot be \"solved\" by the type checker\n" +"def greet_bad(cond: bool) -> AnyStr:\n" +" return \"hi there!\" if cond else b\"greetings!\"\n" +"\n" +"# The better way of annotating this function:\n" +"def greet_proper(cond: bool) -> str | bytes:\n" +" return \"hi there!\" if cond else b\"greetings!\"" +msgstr "" +"# AnyStr の無効な使用例:\n" +"# 型変数が関数シグネチャに1度しか使われていないため、\n" +"# 型チェッカーによって\"解決\"できない\n" +"def greet_bad(cond: bool) -> AnyStr:\n" +" return \"hi there!\" if cond else b\"greetings!\"\n" +"\n" +"# この関数をアノテートするより良い方法:\n" +"def greet_proper(cond: bool) -> str | bytes:\n" +" return \"hi there!\" if cond else b\"greetings!\"" + +#: ../../library/typing.rst:892 +msgid "" +"Deprecated in favor of the new :ref:`type parameter syntax `. " +"Use ``class A[T: (str, bytes)]: ...`` instead of importing ``AnyStr``. See :" +"pep:`695` for more details." +msgstr "" +"新しい :ref:`型パラメーター構文 ` の採用により非推奨となりました。" +"``AnyStr`` をインポートする代わりに ``class A[T: (str, bytes)]: ...`` を使用してください。" +"詳細は :pep:`695` を参照してください。" + +#: ../../library/typing.rst:897 +msgid "" +"In Python 3.16, ``AnyStr`` will be removed from ``typing.__all__``, and " +"deprecation warnings will be emitted at runtime when it is accessed or " +"imported from ``typing``. ``AnyStr`` will be removed from ``typing`` in " +"Python 3.18." +msgstr "" +"Python 3.16 では、``AnyStr`` は ``typing.__all__`` から削除され、``typing`` からアクセスまたはインポートされたときに実行時に非推奨警告が発生します。" +"``AnyStr`` は Python 3.18 で ``typing`` から削除されます。" + +#: ../../library/typing.rst:904 +msgid "Special type that includes only literal strings." +msgstr "リテラル文字列のみを含む特別な型です。" + +#: ../../library/typing.rst:906 +msgid "" +"Any string literal is compatible with ``LiteralString``, as is another " +"``LiteralString``. However, an object typed as just ``str`` is not. A string " +"created by composing ``LiteralString``-typed objects is also acceptable as a " +"``LiteralString``." +msgstr "" +"任意の文字列リテラルは ``LiteralString`` と互換性があり、別の ``LiteralString`` も同様です。" +"しかし、単に ``str`` として型付けされたオブジェクトは互換ではありません。" +"``LiteralString`` 型のオブジェクトを組み合わせて作成された文字列も ``LiteralString`` として受け入れられます。" + +#: ../../library/typing.rst:912 ../../library/typing.rst:2243 +msgid "Example:" +msgstr "例:" + +#: ../../library/typing.rst:914 +msgid "" +"def run_query(sql: LiteralString) -> None:\n" +" ...\n" +"\n" +"def caller(arbitrary_string: str, literal_string: LiteralString) -> None:\n" +" run_query(\"SELECT * FROM students\") # OK\n" +" run_query(literal_string) # OK\n" +" run_query(\"SELECT * FROM \" + literal_string) # OK\n" +" run_query(arbitrary_string) # type checker error\n" +" run_query( # type checker error\n" +" f\"SELECT * FROM students WHERE name = {arbitrary_string}\"\n" +" )" +msgstr "" +"def run_query(sql: LiteralString) -> None:\n" +" ...\n" +"\n" +"def caller(arbitrary_string: str, literal_string: LiteralString) -> None:\n" +" run_query(\"SELECT * FROM students\") # OK\n" +" run_query(literal_string) # OK\n" +" run_query(\"SELECT * FROM \" + literal_string) # OK\n" +" run_query(arbitrary_string) # 型チェッカーエラー\n" +" run_query( # 型チェッカーエラー\n" +" f\"SELECT * FROM students WHERE name = {arbitrary_string}\"\n" +" )" + +#: ../../library/typing.rst:928 +msgid "" +"``LiteralString`` is useful for sensitive APIs where arbitrary user-" +"generated strings could generate problems. For example, the two cases above " +"that generate type checker errors could be vulnerable to an SQL injection " +"attack." +msgstr "" +"``LiteralString`` は、任意のユーザー生成文字列が問題を引き起こす可能性のある機密な API で有用です。" +"例えば、上記の型チェッカーエラーを発生させる2つのケースは、SQLインジェクション攻撃に脆弱である可能性があります。" + +#: ../../library/typing.rst:933 +msgid "See :pep:`675` for more details." +msgstr "より詳しくは :pep:`675` を参照してください。" + +#: ../../library/typing.rst:940 +msgid "" +":data:`!Never` and :data:`!NoReturn` represent the `bottom type `_, a type that has no members." +msgstr "" +":data:`!Never` と :data:`!NoReturn` は `ボトム型 `_ を表し、メンバーを持たない型です。" + +#: ../../library/typing.rst:944 +msgid "" +"They can be used to indicate that a function never returns, such as :func:" +"`sys.exit`::" +msgstr "" +"これらは、:func:`sys.exit` のように関数が絶対にreturnしないことを示すために使用できます::" + +#: ../../library/typing.rst:947 +msgid "" +"from typing import Never # or NoReturn\n" +"\n" +"def stop() -> Never:\n" +" raise RuntimeError('no way')" +msgstr "" +"from typing import Never # または NoReturn\n" +"\n" +"def stop() -> Never:\n" +" raise RuntimeError('no way')" + +#: ../../library/typing.rst:952 +msgid "" +"Or to define a function that should never be called, as there are no valid " +"arguments, such as :func:`assert_never`::" +msgstr "" +"または、:func:`assert_never` のように、有効な引数がないため絶対に呼び出されるべきではない関数を定義するために使用できます::" + +#: ../../library/typing.rst:956 +msgid "" +"from typing import Never # or NoReturn\n" +"\n" +"def never_call_me(arg: Never) -> None:\n" +" pass\n" +"\n" +"def int_or_str(arg: int | str) -> None:\n" +" never_call_me(arg) # type checker error\n" +" match arg:\n" +" case int():\n" +" print(\"It's an int\")\n" +" case str():\n" +" print(\"It's a str\")\n" +" case _:\n" +" never_call_me(arg) # OK, arg is of type Never (or NoReturn)" +msgstr "" +"from typing import Never # または NoReturn\n" +"\n" +"def never_call_me(arg: Never) -> None:\n" +" pass\n" +"\n" +"def int_or_str(arg: int | str) -> None:\n" +" never_call_me(arg) # 型チェッカーエラー\n" +" match arg:\n" +" case int():\n" +" print(\"It's an int\")\n" +" case str():\n" +" print(\"It's a str\")\n" +" case _:\n" +" never_call_me(arg) # OK, arg は Never 型 (または NoReturn)" + +#: ../../library/typing.rst:971 +msgid "" +":data:`!Never` and :data:`!NoReturn` have the same meaning in the type " +"system and static type checkers treat both equivalently." +msgstr "" +":data:`!Never` と :data:`!NoReturn` は型システムにおいて同じ意味を持ち、" +"静的型チェッカーは両者を同等に扱います。" + +#: ../../library/typing.rst:976 +msgid "Added :data:`NoReturn`." +msgstr ":data:`NoReturn` が追加されました。" + +#: ../../library/typing.rst:980 +msgid "Added :data:`Never`." +msgstr ":data:`Never` が追加されました。" + +#: ../../library/typing.rst:984 +msgid "Special type to represent the current enclosed class." +msgstr "現在の囲んでいるクラスを表現する特別な型です。" + +#: ../../library/typing.rst:988 +msgid "" +"from typing import Self, reveal_type\n" +"\n" +"class Foo:\n" +" def return_self(self) -> Self:\n" +" ...\n" +" return self\n" +"\n" +"class SubclassOfFoo(Foo): pass\n" +"\n" +"reveal_type(Foo().return_self()) # Revealed type is \"Foo\"\n" +"reveal_type(SubclassOfFoo().return_self()) # Revealed type is " +"\"SubclassOfFoo\"" +msgstr "" +"from typing import Self, reveal_type\n" +"\n" +"class Foo:\n" +" def return_self(self) -> Self:\n" +" ...\n" +" return self\n" +"\n" +"class SubclassOfFoo(Foo): pass\n" +"\n" +"reveal_type(Foo().return_self()) # 推論された型は \"Foo\"\n" +"reveal_type(SubclassOfFoo().return_self()) # 推論された型は " +"\"SubclassOfFoo\"" + +#: ../../library/typing.rst:1000 +msgid "" +"This annotation is semantically equivalent to the following, albeit in a " +"more succinct fashion::" +msgstr "" +"このアノテーションは、より簡潔な形ではありますが、以下と意味的に同等です::" + +#: ../../library/typing.rst:1003 +msgid "" +"from typing import TypeVar\n" +"\n" +"Self = TypeVar(\"Self\", bound=\"Foo\")\n" +"\n" +"class Foo:\n" +" def return_self(self: Self) -> Self:\n" +" ...\n" +" return self" +msgstr "" +"from typing import TypeVar\n" +"\n" +"Self = TypeVar(\"Self\", bound=\"Foo\")\n" +"\n" +"class Foo:\n" +" def return_self(self: Self) -> Self:\n" +" ...\n" +" return self" + +#: ../../library/typing.rst:1012 +msgid "" +"In general, if something returns ``self``, as in the above examples, you " +"should use ``Self`` as the return annotation. If ``Foo.return_self`` was " +"annotated as returning ``\"Foo\"``, then the type checker would infer the " +"object returned from ``SubclassOfFoo.return_self`` as being of type ``Foo`` " +"rather than ``SubclassOfFoo``." +msgstr "" +"一般的に、上記の例のように何かが ``self`` を返す場合は、戻り値のアノテーションとして ``Self`` を使用すべきです。" +"``Foo.return_self`` が ``\"Foo\"`` を返すとアノテートされていた場合、型チェッカーは " +"``SubclassOfFoo.return_self`` から返されるオブジェクトの型を ``SubclassOfFoo`` ではなく ``Foo`` と推論します。" + +#: ../../library/typing.rst:1018 +msgid "Other common use cases include:" +msgstr "その他の一般的な使用例には以下があります:" + +#: ../../library/typing.rst:1020 +msgid "" +":class:`classmethod`\\s that are used as alternative constructors and return " +"instances of the ``cls`` parameter." +msgstr "" +"代替コンストラクターとして使用され、``cls`` パラメーターのインスタンスを返す :class:`classmethod` 。" + +#: ../../library/typing.rst:1022 +msgid "Annotating an :meth:`~object.__enter__` method which returns self." +msgstr "self を返す :meth:`~object.__enter__` メソッドのアノテーション。" + +#: ../../library/typing.rst:1024 +msgid "" +"You should not use ``Self`` as the return annotation if the method is not " +"guaranteed to return an instance of a subclass when the class is subclassed::" +msgstr "" +"クラスがサブクラス化されたときにメソッドがサブクラスのインスタンスを返すことが保証されていない場合は、" +"``Self`` を戻り値のアノテーションとして使用すべきではありません::" + +#: ../../library/typing.rst:1028 +msgid "" +"class Eggs:\n" +" # Self would be an incorrect return annotation here,\n" +" # as the object returned is always an instance of Eggs,\n" +" # even in subclasses\n" +" def returns_eggs(self) -> \"Eggs\":\n" +" return Eggs()" +msgstr "" +"class Eggs:\n" +" # ここで Self を使うのは間違った戻り値のアノテーションである。\n" +" # 返されるオブジェクトは常に Eggs のインスタンスであり、\n" +" # サブクラスでも同様である\n" +" def returns_eggs(self) -> \"Eggs\":\n" +" return Eggs()" + +#: ../../library/typing.rst:1035 +msgid "See :pep:`673` for more details." +msgstr "より詳しくは :pep:`673` を参照してください。" + +#: ../../library/typing.rst:1041 +msgid "" +"Special annotation for explicitly declaring a :ref:`type alias `." +msgstr "" +":ref:`型エイリアス ` を明示的に宣言するための特別なアノテーションです。" + +#: ../../library/typing.rst:1045 +msgid "" +"from typing import TypeAlias\n" +"\n" +"Factors: TypeAlias = list[int]" +msgstr "" +"from typing import TypeAlias\n" +"\n" +"Factors: TypeAlias = list[int]" + +#: ../../library/typing.rst:1049 +msgid "" +"``TypeAlias`` is particularly useful on older Python versions for annotating " +"aliases that make use of forward references, as it can be hard for type " +"checkers to distinguish these from normal variable assignments:" +msgstr "" +"``TypeAlias`` は、前方参照を使用するエイリアスのアノテーションにおいて、古いPythonバージョンで特に有用です。" +"型チェッカーがこれらを通常の変数代入と区別するのが困難な場合があります:" + +#: ../../library/typing.rst:1053 +msgid "" +"from typing import Generic, TypeAlias, TypeVar\n" +"\n" +"T = TypeVar(\"T\")\n" +"\n" +"# \"Box\" does not exist yet,\n" +"# so we have to use quotes for the forward reference on Python <3.12.\n" +"# Using ``TypeAlias`` tells the type checker that this is a type alias " +"declaration,\n" +"# not a variable assignment to a string.\n" +"BoxOfStrings: TypeAlias = \"Box[str]\"\n" +"\n" +"class Box(Generic[T]):\n" +" @classmethod\n" +" def make_box_of_strings(cls) -> BoxOfStrings: ..." +msgstr "" +"from typing import Generic, TypeAlias, TypeVar\n" +"\n" +"T = TypeVar(\"T\")\n" +"\n" +"# \"Box\" はまだ存在しないため、\n" +"# Python <3.12 での前方参照にはクォートを使用する必要があります。\n" +"# ``TypeAlias`` を使用することで、これが型エイリアスの宣言であり、\n" +"# 文字列への変数代入ではないことを型チェッカーに伝えられます。\n" +"BoxOfStrings: TypeAlias = \"Box[str]\"\n" +"\n" +"class Box(Generic[T]):\n" +" @classmethod\n" +" def make_box_of_strings(cls) -> BoxOfStrings: ..." + +#: ../../library/typing.rst:1069 +msgid "See :pep:`613` for more details." +msgstr "より詳しくは、 :pep:`613` をご覧ください。" + +#: ../../library/typing.rst:1073 +msgid "" +":data:`TypeAlias` is deprecated in favor of the :keyword:`type` statement, " +"which creates instances of :class:`TypeAliasType` and which natively " +"supports forward references. Note that while :data:`TypeAlias` and :class:" +"`TypeAliasType` serve similar purposes and have similar names, they are " +"distinct and the latter is not the type of the former. Removal of :data:" +"`TypeAlias` is not currently planned, but users are encouraged to migrate " +"to :keyword:`type` statements." +msgstr "" +":data:`TypeAlias` は、:class:`TypeAliasType` のインスタンスを作成し、前方参照をネイティブにサポートする :keyword:`type` 文の採用により非推奨となりました。" +":data:`TypeAlias` と :class:`TypeAliasType` は同様の目的を持ち、名前も似ていますが、別物であり、後者は前者の型ではありません。" +":data:`TypeAlias` の削除は現在のところ予定されていませんが、ユーザーは :keyword:`type` 文への移行が奨励されています。" + +#: ../../library/typing.rst:1084 +msgid "Special forms" +msgstr "特殊形式" + +#: ../../library/typing.rst:1086 +msgid "" +"These can be used as types in annotations. They all support subscription " +"using ``[]``, but each has a unique syntax." +msgstr "" +"これらはアノテーションの型として使用できます。これらは全て ``[]`` を使用した" +"添字表記をサポートしますが、それぞれ固有の構文があります。" + +#: ../../library/typing.rst:1091 +msgid "" +"Union type; ``Union[X, Y]`` is equivalent to ``X | Y`` and means either X or " +"Y." +msgstr "" +"ユニオン型; ``Union[X, Y]`` は ``X | Y`` と等価で X または Y を表します。" + +#: ../../library/typing.rst:1093 +msgid "" +"To define a union, use e.g. ``Union[int, str]`` or the shorthand ``int | " +"str``. Using that shorthand is recommended. Details:" +msgstr "" +"ユニオンを定義するには、例えば ``Union[int, str]`` または省略形の ``int | str`` を使用します。" +"省略形の使用が推奨されます。詳細:" + +#: ../../library/typing.rst:1095 +msgid "The arguments must be types and there must be at least one." +msgstr "引数は型でなければならず、少なくとも一つ必要です。" + +#: ../../library/typing.rst:1097 +msgid "Unions of unions are flattened, e.g.::" +msgstr "ユニオン型のユニオン型は平滑化されます。例えば::" + +#: ../../library/typing.rst:1099 +msgid "Union[Union[int, str], float] == Union[int, str, float]" +msgstr "Union[Union[int, str], float] == Union[int, str, float]" + +#: ../../library/typing.rst:1101 +msgid "" +"However, this does not apply to unions referenced through a type alias, to " +"avoid forcing evaluation of the underlying :class:`TypeAliasType`::" +msgstr "" +"しかし、これは基礎となる :class:`TypeAliasType` の評価を強制することを避けるため、" +"型エイリアスを通じて参照されるユニオンには適用されません::" + +#: ../../library/typing.rst:1104 +msgid "" +"type A = Union[int, str]\n" +"Union[A, float] != Union[int, str, float]" +msgstr "" +"type A = Union[int, str]\n" +"Union[A, float] != Union[int, str, float]" + +#: ../../library/typing.rst:1107 +msgid "Unions of a single argument vanish, e.g.::" +msgstr "引数が一つのユニオン型は消えます。例えば::" + +#: ../../library/typing.rst:1109 +msgid "Union[int] == int # The constructor actually returns int" +msgstr "Union[int] == int # コンストラクタは実際には int を返す" + +#: ../../library/typing.rst:1111 ../../library/typing.rst:1253 +msgid "Redundant arguments are skipped, e.g.::" +msgstr "冗長な実引数は飛ばされます。例えば::" + +#: ../../library/typing.rst:1113 +msgid "Union[int, str, int] == Union[int, str] == int | str" +msgstr "Union[int, str, int] == Union[int, str] == int | str" + +#: ../../library/typing.rst:1115 +msgid "When comparing unions, the argument order is ignored, e.g.::" +msgstr "ユニオン型を比較するとき引数の順序は無視されます。例えば::" + +#: ../../library/typing.rst:1117 +msgid "Union[int, str] == Union[str, int]" +msgstr "Union[int, str] == Union[str, int]" + +#: ../../library/typing.rst:1119 +msgid "You cannot subclass or instantiate a ``Union``." +msgstr "" +"``Union`` のサブクラスを作成したり、インスタンスを作成することは出来ません。" + +#: ../../library/typing.rst:1121 +msgid "You cannot write ``Union[X][Y]``." +msgstr "``Union[X][Y]`` と書くことは出来ません。" + +#: ../../library/typing.rst:1123 +msgid "Don't remove explicit subclasses from unions at runtime." +msgstr "" +"明示的に書かれているサブクラスを、実行時に直和型から取り除かなくなりました。" + +#: ../../library/typing.rst:1126 +msgid "" +"Unions can now be written as ``X | Y``. See :ref:`union type " +"expressions`." +msgstr "" +"ユニオン型は ``X | Y`` のように書けるようになりました。 :ref:`union型の表現 " +"` を参照ください。" + +#: ../../library/typing.rst:1130 +msgid "" +":class:`types.UnionType` is now an alias for :class:`Union`, and both " +"``Union[int, str]`` and ``int | str`` create instances of the same class. To " +"check whether an object is a ``Union`` at runtime, use ``isinstance(obj, " +"Union)``. For compatibility with earlier versions of Python, use " +"``get_origin(obj) is typing.Union or get_origin(obj) is types.UnionType``." +msgstr "" +":class:`types.UnionType` は :class:`Union` のエイリアスとなり、``Union[int, str]`` と ``int | str`` は同じクラスのインスタンスを作成します。" +"実行時にオブジェクトが ``Union`` かどうかをチェックするには、``isinstance(obj, Union)`` を使用してください。" +"以前のPythonバージョンとの互換性のため、``get_origin(obj) is typing.Union or get_origin(obj) is types.UnionType`` を使用してください。" + +#: ../../library/typing.rst:1140 +msgid "``Optional[X]`` is equivalent to ``X | None`` (or ``Union[X, None]``)." +msgstr "``Optional[X]`` は ``X | None`` (や ``Union[X, None]``) と同等です。" + +#: ../../library/typing.rst:1142 +msgid "" +"Note that this is not the same concept as an optional argument, which is one " +"that has a default. An optional argument with a default does not require " +"the ``Optional`` qualifier on its type annotation just because it is " +"optional. For example::" +msgstr "" +"これがデフォルト値を持つオプション引数とは同じ概念ではないということに注意し" +"てください。\n" +"デフォルト値を持つオプション引数はオプション引数であるために、型アノテーショ" +"ンに ``Optional`` 修飾子は必要ありません。\n" +"例えば次のようになります::" + +#: ../../library/typing.rst:1147 +msgid "" +"def foo(arg: int = 0) -> None:\n" +" ..." +msgstr "" +"def foo(arg: int = 0) -> None:\n" +" ..." + +#: ../../library/typing.rst:1150 +msgid "" +"On the other hand, if an explicit value of ``None`` is allowed, the use of " +"``Optional`` is appropriate, whether the argument is optional or not. For " +"example::" +msgstr "" +"それとは逆に、 ``None`` という値が許されていることが明示されている場合は、引" +"数がオプションであろうとなかろうと、 ``Optional`` を使うのが好ましいです。\n" +"例えば次のようになります::" + +#: ../../library/typing.rst:1154 +msgid "" +"def foo(arg: Optional[int] = None) -> None:\n" +" ..." +msgstr "" +"def foo(arg: Optional[int] = None) -> None:\n" +" ..." + +#: ../../library/typing.rst:1157 +msgid "" +"Optional can now be written as ``X | None``. See :ref:`union type " +"expressions`." +msgstr "" +"Optionalは ``X | None`` のように書けるようになりました。 ref:`union型の表現 " +"` を参照ください。" + +#: ../../library/typing.rst:1163 +msgid "Special form for annotating higher-order functions." +msgstr "高階関数のアノテーション用の特別形式です。" + +#: ../../library/typing.rst:1165 +msgid "" +"``Concatenate`` can be used in conjunction with :ref:`Callable ` and :class:`ParamSpec` to annotate a higher-order callable which " +"adds, removes, or transforms parameters of another callable. Usage is in " +"the form ``Concatenate[Arg1Type, Arg2Type, ..., ParamSpecVariable]``. " +"``Concatenate`` is currently only valid when used as the first argument to " +"a :ref:`Callable `. The last parameter to " +"``Concatenate`` must be a :class:`ParamSpec` or ellipsis (``...``)." +msgstr "" +"``Concatenate`` は :ref:`Callable ` と :class:`ParamSpec` と組み合わせて、" +"別の呼び出し可能オブジェクトのパラメーターを追加、削除、または変換する高階呼び出し可能オブジェクトのアノテーションに使用できます。" +"使用法は ``Concatenate[Arg1Type, Arg2Type, ..., ParamSpecVariable]`` の形式です。" +"``Concatenate`` は現在、:ref:`Callable ` の最初の引数として使用される場合のみ有効です。" +"``Concatenate`` の最後のパラメーターは :class:`ParamSpec` または省略符 (``...``) でなければなりません。" + +#: ../../library/typing.rst:1174 +msgid "" +"For example, to annotate a decorator ``with_lock`` which provides a :class:" +"`threading.Lock` to the decorated function, ``Concatenate`` can be used to " +"indicate that ``with_lock`` expects a callable which takes in a ``Lock`` as " +"the first argument, and returns a callable with a different type signature. " +"In this case, the :class:`ParamSpec` indicates that the returned callable's " +"parameter types are dependent on the parameter types of the callable being " +"passed in::" +msgstr "" +"例えば、デコレートされた関数に :class:`threading.Lock` を提供するデコレーター ``with_lock`` のアノテーションに ``Concatenate`` を使用し、" +"``with_lock`` が最初の引数として ``Lock`` を受け取る呼び出し可能オブジェクトを期待し、異なる型シグネチャを持つ呼び出し可能オブジェクトを返すことを示すことができます。" +"この場合、:class:`ParamSpec` は返される呼び出し可能オブジェクトのパラメーター型が渡される呼び出し可能オブジェクトのパラメーター型に依存することを示します::" + +#: ../../library/typing.rst:1182 +msgid "" +"from collections.abc import Callable\n" +"from threading import Lock\n" +"from typing import Concatenate\n" +"\n" +"# Use this lock to ensure that only one thread is executing a function\n" +"# at any time.\n" +"my_lock = Lock()\n" +"\n" +"def with_lock[**P, R](f: Callable[Concatenate[Lock, P], R]) -> Callable[P, " +"R]:\n" +" '''A type-safe decorator which provides a lock.'''\n" +" def inner(*args: P.args, **kwargs: P.kwargs) -> R:\n" +" # Provide the lock as the first argument.\n" +" return f(my_lock, *args, **kwargs)\n" +" return inner\n" +"\n" +"@with_lock\n" +"def sum_threadsafe(lock: Lock, numbers: list[float]) -> float:\n" +" '''Add a list of numbers together in a thread-safe manner.'''\n" +" with lock:\n" +" return sum(numbers)\n" +"\n" +"# We don't need to pass in the lock ourselves thanks to the decorator.\n" +"sum_threadsafe([1.1, 2.2, 3.3])" +msgstr "" +"from collections.abc import Callable\n" +"from threading import Lock\n" +"from typing import Concatenate\n" +"\n" +"# 一度に一つのスレッドだけが関数を実行していることを保証するためにこのロックを使用します。\n" +"# 任意の時刻で。\n" +"my_lock = Lock()\n" +"\n" +"def with_lock[**P, R](f: Callable[Concatenate[Lock, P], R]) -> Callable[P, " +"R]:\n" +" '''ロックを提供する型安全なデコレーター。'''\n" +" def inner(*args: P.args, **kwargs: P.kwargs) -> R:\n" +" # 最初の引数としてロックを提供。\n" +" return f(my_lock, *args, **kwargs)\n" +" return inner\n" +"\n" +"@with_lock\n" +"def sum_threadsafe(lock: Lock, numbers: list[float]) -> float:\n" +" '''スレッドセーフな方法で数値のリストを合計します。'''\n" +" with lock:\n" +" return sum(numbers)\n" +"\n" +"# デコレーターのおかげで、自分自身でロックを渡す必要はありません。\n" +"sum_threadsafe([1.1, 2.2, 3.3])" + +#: ../../library/typing.rst:1210 ../../library/typing.rst:2211 +msgid "" +":pep:`612` -- Parameter Specification Variables (the PEP which introduced " +"``ParamSpec`` and ``Concatenate``)" +msgstr "" +":pep:`612` -- パラメーター仕様変数 (``ParamSpec`` と ``Concatenate`` を導入したPEP)" + +#: ../../library/typing.rst:1212 +msgid ":class:`ParamSpec`" +msgstr ":class:`ParamSpec`" + +#: ../../library/typing.rst:1213 ../../library/typing.rst:2214 +msgid ":ref:`annotating-callables`" +msgstr ":ref:`annotating-callables`" + +#: ../../library/typing.rst:1217 +msgid "Special typing form to define \"literal types\"." +msgstr "\"リテラル型\" を定義するための特別な型付け形式です。" + +#: ../../library/typing.rst:1219 +msgid "" +"``Literal`` can be used to indicate to type checkers that the annotated " +"object has a value equivalent to one of the provided literals." +msgstr "" +"``Literal`` は、アノテートされたオブジェクトが提供されたリテラルのいずれかと同等の値を持つことを型チェッカーに示すために使用できます。" + +#: ../../library/typing.rst:1225 +msgid "" +"def validate_simple(data: Any) -> Literal[True]: # always returns True\n" +" ...\n" +"\n" +"type Mode = Literal['r', 'rb', 'w', 'wb']\n" +"def open_helper(file: str, mode: Mode) -> str:\n" +" ...\n" +"\n" +"open_helper('/some/path', 'r') # Passes type check\n" +"open_helper('/other/path', 'typo') # Error in type checker" +msgstr "" +"def validate_simple(data: Any) -> Literal[True]: # 常に True を返す\n" +" ...\n" +"\n" +"type Mode = Literal['r', 'rb', 'w', 'wb']\n" +"def open_helper(file: str, mode: Mode) -> str:\n" +" ...\n" +"\n" +"open_helper('/some/path', 'r') # 型チェックを通過\n" +"open_helper('/other/path', 'typo') # 型チェッカーでエラー" + +#: ../../library/typing.rst:1235 +msgid "" +"``Literal[...]`` cannot be subclassed. At runtime, an arbitrary value is " +"allowed as type argument to ``Literal[...]``, but type checkers may impose " +"restrictions. See :pep:`586` for more details about literal types." +msgstr "" +"``Literal[...]`` はサブクラスにはできません。\n" +"実行時に、任意の値が ``Literal[...]`` の型引数として使えますが、型チェッカー" +"が制約を課すことがあります。\n" +"リテラル型についてより詳しいことは :pep:`586` を参照してください。" + +#: ../../library/typing.rst:1239 +msgid "Additional details:" +msgstr "追加の詳細:" + +#: ../../library/typing.rst:1241 +msgid "The arguments must be literal values and there must be at least one." +msgstr "引数はリテラル値でなければならず、少なくとも一つ必要です。" + +#: ../../library/typing.rst:1243 +msgid "Nested ``Literal`` types are flattened, e.g.::" +msgstr "ネストした ``Literal`` 型は平滑化されます。例えば::" + +#: ../../library/typing.rst:1245 +msgid "assert Literal[Literal[1, 2], 3] == Literal[1, 2, 3]" +msgstr "assert Literal[Literal[1, 2], 3] == Literal[1, 2, 3]" + +#: ../../library/typing.rst:1247 +msgid "" +"However, this does not apply to ``Literal`` types referenced through a type " +"alias, to avoid forcing evaluation of the underlying :class:`TypeAliasType`::" +msgstr "" +"しかし、これは基礎となる :class:`TypeAliasType` の評価を強制することを避けるため、" +"型エイリアスを通じて参照される ``Literal`` 型には適用されません::" + +#: ../../library/typing.rst:1250 +msgid "" +"type A = Literal[1, 2]\n" +"assert Literal[A, 3] != Literal[1, 2, 3]" +msgstr "" +"type A = Literal[1, 2]\n" +"assert Literal[A, 3] != Literal[1, 2, 3]" + +#: ../../library/typing.rst:1255 +msgid "assert Literal[1, 2, 1] == Literal[1, 2]" +msgstr "assert Literal[1, 2, 1] == Literal[1, 2]" + +#: ../../library/typing.rst:1257 +msgid "When comparing literals, the argument order is ignored, e.g.::" +msgstr "リテラルを比較するとき、引数の順序は無視されます。例えば::" + +#: ../../library/typing.rst:1259 +msgid "assert Literal[1, 2] == Literal[2, 1]" +msgstr "assert Literal[1, 2] == Literal[2, 1]" + +#: ../../library/typing.rst:1261 +msgid "You cannot subclass or instantiate a ``Literal``." +msgstr "``Literal`` のサブクラスを作成したり、インスタンスを作成することはできません。" + +#: ../../library/typing.rst:1263 +msgid "You cannot write ``Literal[X][Y]``." +msgstr "``Literal[X][Y]`` と書くことはできません。" + +#: ../../library/typing.rst:1267 +msgid "" +"``Literal`` now de-duplicates parameters. Equality comparisons of " +"``Literal`` objects are no longer order dependent. ``Literal`` objects will " +"now raise a :exc:`TypeError` exception during equality comparisons if one of " +"their parameters are not :term:`hashable`." +msgstr "" +"``Literal`` ではパラメータの重複を解消するようになりました。``Literal`` オブ" +"ジェクトの等値比較は順序に依存しないようになりました。``Literal`` オブジェク" +"トは、等値比較する際に、パラメータのうち 1 つでも :term:`hashable` でない場合" +"は :exc:`TypeError` を送出するようになりました。" + +#: ../../library/typing.rst:1275 +msgid "Special type construct to mark class variables." +msgstr "クラス変数であることを示す特別な型構築子です。" + +#: ../../library/typing.rst:1277 +msgid "" +"As introduced in :pep:`526`, a variable annotation wrapped in ClassVar " +"indicates that a given attribute is intended to be used as a class variable " +"and should not be set on instances of that class. Usage::" +msgstr "" +":pep:`526` で導入された通り、 ClassVar でラップされた変数アノテーションによっ" +"て、ある属性はクラス変数として使うつもりであり、そのクラスのインスタンスから" +"設定すべきではないということを示せます。使い方は次のようになります::" + +#: ../../library/typing.rst:1281 +msgid "" +"class Starship:\n" +" stats: ClassVar[dict[str, int]] = {} # class variable\n" +" damage: int = 10 # instance variable" +msgstr "" +"class Starship:\n" +" stats: ClassVar[dict[str, int]] = {} # クラス変数\n" +" damage: int = 10 # インスタンス変数" + +#: ../../library/typing.rst:1285 +msgid ":data:`ClassVar` accepts only types and cannot be further subscribed." +msgstr ":data:`ClassVar` は型のみを受け入れ、それ以外は受け付けられません。" + +#: ../../library/typing.rst:1287 +msgid "" +":data:`ClassVar` is not a class itself, and should not be used with :func:" +"`isinstance` or :func:`issubclass`. :data:`ClassVar` does not change Python " +"runtime behavior, but it can be used by third-party type checkers. For " +"example, a type checker might flag the following code as an error::" +msgstr "" +":data:`ClassVar` はクラスそのものではなく、:func:`isinstance` や :func:" +"`issubclass` で使うべきではありません。\n" +":data:`ClassVar` は Python の実行時の挙動を変えませんが、サードパーティの型検" +"査器で使えます。\n" +"例えば、型チェッカーは次のコードをエラーとするかもしれません::" + +#: ../../library/typing.rst:1293 +msgid "" +"enterprise_d = Starship(3000)\n" +"enterprise_d.stats = {} # Error, setting class variable on instance\n" +"Starship.stats = {} # This is OK" +msgstr "" +"enterprise_d = Starship(3000)\n" +"enterprise_d.stats = {} # エラー、インスタンスにクラス変数を設定\n" +"Starship.stats = {} # これは OK" + +#: ../../library/typing.rst:1301 +msgid ":data:`ClassVar` can now be nested in :data:`Final` and vice versa." +msgstr ":data:`ClassVar` は :data:`Final` 内にネストできるようになり、逆も可能です。" + +#: ../../library/typing.rst:1305 +msgid "Special typing construct to indicate final names to type checkers." +msgstr "型チェッカーに最終名を示すための特別な型構築子です。" + +#: ../../library/typing.rst:1307 +msgid "" +"Final names cannot be reassigned in any scope. Final names declared in class " +"scopes cannot be overridden in subclasses." +msgstr "" +"Final名は任意のスコープで再代入できません。クラススコープで宣言されたFinal名はサブクラスでオーバーライドできません。" + +#: ../../library/typing.rst:1312 +msgid "" +"MAX_SIZE: Final = 9000\n" +"MAX_SIZE += 1 # Error reported by type checker\n" +"\n" +"class Connection:\n" +" TIMEOUT: Final[int] = 10\n" +"\n" +"class FastConnector(Connection):\n" +" TIMEOUT = 1 # Error reported by type checker" +msgstr "" +"MAX_SIZE: Final = 9000\n" +"MAX_SIZE += 1 # 型チェッカーがエラーを報告\n" +"\n" +"class Connection:\n" +" TIMEOUT: Final[int] = 10\n" +"\n" +"class FastConnector(Connection):\n" +" TIMEOUT = 1 # 型チェッカーがエラーを報告" + +#: ../../library/typing.rst:1321 ../../library/typing.rst:3234 +msgid "" +"There is no runtime checking of these properties. See :pep:`591` for more " +"details." +msgstr "" +"この機能は実行時には検査されません。詳細については :pep:`591` を参照してくだ" +"さい。" + +#: ../../library/typing.rst:1328 +msgid ":data:`Final` can now be nested in :data:`ClassVar` and vice versa." +msgstr ":data:`Final` は :data:`ClassVar` 内にネストできるようになり、逆も可能です。" + +#: ../../library/typing.rst:1332 +msgid "Special typing construct to mark a :class:`TypedDict` key as required." +msgstr ":class:`TypedDict` のキーを必須としてマークするための特別な型構築子です。" + +#: ../../library/typing.rst:1334 +msgid "" +"This is mainly useful for ``total=False`` TypedDicts. See :class:`TypedDict` " +"and :pep:`655` for more details." +msgstr "" +"これは主に ``total=False`` のTypedDictで有用です。詳細は :class:`TypedDict` と :pep:`655` を参照してください。" + +#: ../../library/typing.rst:1341 +msgid "" +"Special typing construct to mark a :class:`TypedDict` key as potentially " +"missing." +msgstr "" +":class:`TypedDict` のキーを潜在的に欠落するものとしてマークするための特別な型構築子です。" + +#: ../../library/typing.rst:1344 +msgid "See :class:`TypedDict` and :pep:`655` for more details." +msgstr "より詳しくは、 :class:`TypedDict` と :pep:`655` を参照してください。" + +#: ../../library/typing.rst:1350 +msgid "" +"A special typing construct to mark an item of a :class:`TypedDict` as read-" +"only." +msgstr "" +":class:`TypedDict` のアイテムを読み取り専用としてマークするための特別な型構築子です。" + +#: ../../library/typing.rst:1354 +msgid "" +"class Movie(TypedDict):\n" +" title: ReadOnly[str]\n" +" year: int\n" +"\n" +"def mutate_movie(m: Movie) -> None:\n" +" m[\"year\"] = 1999 # allowed\n" +" m[\"title\"] = \"The Matrix\" # typechecker error" +msgstr "" +"class Movie(TypedDict):\n" +" title: ReadOnly[str]\n" +" year: int\n" +"\n" +"def mutate_movie(m: Movie) -> None:\n" +" m[\"year\"] = 1999 # 許可\n" +" m[\"title\"] = \"The Matrix\" # 型チェッカーエラー" + +#: ../../library/typing.rst:1362 +msgid "There is no runtime checking for this property." +msgstr "このプロパティの実行時チェックはありません。" + +#: ../../library/typing.rst:1364 +msgid "See :class:`TypedDict` and :pep:`705` for more details." +msgstr "詳細は :class:`TypedDict` と :pep:`705` を参照してください。" + +#: ../../library/typing.rst:1370 +msgid "Special typing form to add context-specific metadata to an annotation." +msgstr "アノテーションにコンテキスト固有のメタデータを追加する特別な型付け形式。" + +#: ../../library/typing.rst:1372 +msgid "" +"Add metadata ``x`` to a given type ``T`` by using the annotation " +"``Annotated[T, x]``. Metadata added using ``Annotated`` can be used by " +"static analysis tools or at runtime. At runtime, the metadata is stored in " +"a :attr:`!__metadata__` attribute." +msgstr "" +"アノテーション ``Annotated[T, x]`` を使用して、与えられた型 ``T`` にメタデータ ``x`` を追加します。" +" ``Annotated`` を使用して追加されたメタデータは、静的解析ツールや実行時に使用できます。" +"実行時には、メタデータは :attr:`!__metadata__` 属性に格納されます。" + +#: ../../library/typing.rst:1377 +msgid "" +"If a library or tool encounters an annotation ``Annotated[T, x]`` and has no " +"special logic for the metadata, it should ignore the metadata and simply " +"treat the annotation as ``T``. As such, ``Annotated`` can be useful for code " +"that wants to use annotations for purposes outside Python's static typing " +"system." +msgstr "" +"ライブラリやツールがアノテーション ``Annotated[T, x]`` に遭遇し、メタデータに対する特別な" +"ロジックを持たない場合、メタデータを無視して単純にアノテーションを ``T`` として扱うべきです。" +"そのため、 ``Annotated`` は Python の静的型付けシステムの範囲外でアノテーションを使用したい" +"コードに有用です。" + +#: ../../library/typing.rst:1383 +msgid "" +"Using ``Annotated[T, x]`` as an annotation still allows for static " +"typechecking of ``T``, as type checkers will simply ignore the metadata " +"``x``. In this way, ``Annotated`` differs from the :func:`@no_type_check " +"` decorator, which can also be used for adding annotations " +"outside the scope of the typing system, but completely disables typechecking " +"for a function or class." +msgstr "" +"アノテーションとして ``Annotated[T, x]`` を使用しても、型チェッカーは単純にメタデータ ``x`` を" +"無視するため、 ``T`` の静的型チェックは引き続き可能です。この点で、 ``Annotated`` は " +":func:`@no_type_check ` デコレータとは異なります。このデコレータも型付けシステム" +"の範囲外でアノテーションを追加するために使用できますが、関数やクラスの型チェックを完全に" +"無効にしてしまいます。" + +#: ../../library/typing.rst:1390 +msgid "" +"The responsibility of how to interpret the metadata lies with the tool or " +"library encountering an ``Annotated`` annotation. A tool or library " +"encountering an ``Annotated`` type can scan through the metadata elements to " +"determine if they are of interest (e.g., using :func:`isinstance`)." +msgstr "" +"メタデータの解釈方法の責任は、 ``Annotated`` アノテーションに遭遇するツールやライブラリに" +"あります。 ``Annotated`` 型に遭遇するツールやライブラリは、メタデータ要素をスキャンして、" +"それらが興味深いものかどうかを判断できます(例: :func:`isinstance` を使用)。" + +#: ../../library/typing.rst:1398 +msgid "" +"Here is an example of how you might use ``Annotated`` to add metadata to " +"type annotations if you were doing range analysis:" +msgstr "" +"範囲解析を行う場合に ``Annotated`` を使用して型アノテーションにメタデータを追加する方法の例です:" + +#: ../../library/typing.rst:1401 +msgid "" +"@dataclass\n" +"class ValueRange:\n" +" lo: int\n" +" hi: int\n" +"\n" +"T1 = Annotated[int, ValueRange(-10, 5)]\n" +"T2 = Annotated[T1, ValueRange(-20, 3)]" +msgstr "" +"@dataclass\n" +"class ValueRange:\n" +" lo: int\n" +" hi: int\n" +"\n" +"T1 = Annotated[int, ValueRange(-10, 5)]\n" +"T2 = Annotated[T1, ValueRange(-20, 3)]" + +#: ../../library/typing.rst:1411 +msgid "" +"The first argument to ``Annotated`` must be a valid type. Multiple metadata " +"elements can be supplied as ``Annotated`` supports variadic arguments. The " +"order of the metadata elements is preserved and matters for equality checks::" +msgstr "" +"``Annotated`` の最初の引数は有効な型でなければなりません。 ``Annotated`` は可変引数をサポート" +"しているため、複数のメタデータ要素を提供できます。メタデータ要素の順序は保持され、等価性チェック" +"において重要です::" + +#: ../../library/typing.rst:1415 +msgid "" +"@dataclass\n" +"class ctype:\n" +" kind: str\n" +"\n" +"a1 = Annotated[int, ValueRange(3, 10), ctype(\"char\")]\n" +"a2 = Annotated[int, ctype(\"char\"), ValueRange(3, 10)]\n" +"\n" +"assert a1 != a2 # Order matters" +msgstr "" +"@dataclass\n" +"class ctype:\n" +" kind: str\n" +"\n" +"a1 = Annotated[int, ValueRange(3, 10), ctype(\"char\")]\n" +"a2 = Annotated[int, ctype(\"char\"), ValueRange(3, 10)]\n" +"\n" +"assert a1 != a2 # 順序が重要" + +#: ../../library/typing.rst:1424 +msgid "" +"It is up to the tool consuming the annotations to decide whether the client " +"is allowed to add multiple metadata elements to one annotation and how to " +"merge those annotations." +msgstr "" +"クライアントが1つのアノテーションに複数のメタデータ要素を追加することが許可されているかどうか、" +"およびそれらのアノテーションをマージする方法を決定するのは、アノテーションを消費するツールに" +"委ねられています。" + +#: ../../library/typing.rst:1428 +msgid "" +"Nested ``Annotated`` types are flattened. The order of the metadata elements " +"starts with the innermost annotation::" +msgstr "" +"ネストされた ``Annotated`` 型は平坦化されます。メタデータ要素の順序は最も内側の" +"アノテーションから始まります::" + +#: ../../library/typing.rst:1431 +msgid "" +"assert Annotated[Annotated[int, ValueRange(3, 10)], ctype(\"char\")] == " +"Annotated[\n" +" int, ValueRange(3, 10), ctype(\"char\")\n" +"]" +msgstr "" +"assert Annotated[Annotated[int, ValueRange(3, 10)], ctype(\"char\")] == " +"Annotated[\n" +" int, ValueRange(3, 10), ctype(\"char\")\n" +"]" + +#: ../../library/typing.rst:1435 +msgid "" +"However, this does not apply to ``Annotated`` types referenced through a " +"type alias, to avoid forcing evaluation of the underlying :class:" +"`TypeAliasType`::" +msgstr "" +"ただし、これは型エイリアスを通じて参照される ``Annotated`` 型には適用されません。" +"これは基盤となる :class:`TypeAliasType` の評価を強制しないためです::" + +#: ../../library/typing.rst:1438 +msgid "" +"type From3To10[T] = Annotated[T, ValueRange(3, 10)]\n" +"assert Annotated[From3To10[int], ctype(\"char\")] != Annotated[\n" +" int, ValueRange(3, 10), ctype(\"char\")\n" +"]" +msgstr "" +"type From3To10[T] = Annotated[T, ValueRange(3, 10)]\n" +"assert Annotated[From3To10[int], ctype(\"char\")] != Annotated[\n" +" int, ValueRange(3, 10), ctype(\"char\")\n" +"]" + +#: ../../library/typing.rst:1443 +msgid "Duplicated metadata elements are not removed::" +msgstr "重複するメタデータ要素は削除されません::" + +#: ../../library/typing.rst:1445 +msgid "" +"assert Annotated[int, ValueRange(3, 10)] != Annotated[\n" +" int, ValueRange(3, 10), ValueRange(3, 10)\n" +"]" +msgstr "" +"assert Annotated[int, ValueRange(3, 10)] != Annotated[\n" +" int, ValueRange(3, 10), ValueRange(3, 10)\n" +"]" + +#: ../../library/typing.rst:1449 +msgid "``Annotated`` can be used with nested and generic aliases:" +msgstr "``Annotated`` はネストされた型エイリアスやジェネリック型エイリアスと組み合わせて使用できます:" + +#: ../../library/typing.rst:1451 +msgid "" +"@dataclass\n" +"class MaxLen:\n" +" value: int\n" +"\n" +"type Vec[T] = Annotated[list[tuple[T, T]], MaxLen(10)]\n" +"\n" +"# When used in a type annotation, a type checker will treat \"V\" the same " +"as\n" +"# ``Annotated[list[tuple[int, int]], MaxLen(10)]``:\n" +"type V = Vec[int]" +msgstr "" +"@dataclass\n" +"class MaxLen:\n" +" value: int\n" +"\n" +"type Vec[T] = Annotated[list[tuple[T, T]], MaxLen(10)]\n" +"\n" +"# 型アノテーションで使用される場合、型チェッカーは \"V\" を\n" +"# ``Annotated[list[tuple[int, int]], MaxLen(10)]`` と同じように扱います:\n" +"type V = Vec[int]" + +#: ../../library/typing.rst:1463 +msgid "``Annotated`` cannot be used with an unpacked :class:`TypeVarTuple`::" +msgstr "``Annotated`` は展開された :class:`TypeVarTuple` と組み合わせて使用できません::" + +#: ../../library/typing.rst:1465 +msgid "" +"type Variadic[*Ts] = Annotated[*Ts, Ann1] = Annotated[T1, T2, T3, ..., " +"Ann1] # NOT valid" +msgstr "" +"type Variadic[*Ts] = Annotated[*Ts, Ann1] = Annotated[T1, T2, T3, ..., " +"Ann1] # 無効" + +#: ../../library/typing.rst:1467 +msgid "" +"where ``T1``, ``T2``, ... are :class:`TypeVars `. This is invalid " +"as only one type should be passed to Annotated." +msgstr "" +"ここで ``T1``, ``T2``, ... は :class:`TypeVars ` です。Annotated には1つの型のみを" +"渡すべきであるため、これは無効です。" + +#: ../../library/typing.rst:1470 +msgid "" +"By default, :func:`get_type_hints` strips the metadata from annotations. " +"Pass ``include_extras=True`` to have the metadata preserved:" +msgstr "" +"デフォルトでは、 :func:`get_type_hints` はアノテーションからメタデータを除去します。" +"メタデータを保持するには ``include_extras=True`` を渡します:" + +#: ../../library/typing.rst:1473 +msgid "" +">>> from typing import Annotated, get_type_hints\n" +">>> def func(x: Annotated[int, \"metadata\"]) -> None: pass\n" +"...\n" +">>> get_type_hints(func)\n" +"{'x': , 'return': }\n" +">>> get_type_hints(func, include_extras=True)\n" +"{'x': typing.Annotated[int, 'metadata'], 'return': }" +msgstr "" +">>> from typing import Annotated, get_type_hints\n" +">>> def func(x: Annotated[int, \"metadata\"]) -> None: pass\n" +"...\n" +">>> get_type_hints(func)\n" +"{'x': , 'return': }\n" +">>> get_type_hints(func, include_extras=True)\n" +"{'x': typing.Annotated[int, 'metadata'], 'return': }" + +#: ../../library/typing.rst:1483 +msgid "" +"At runtime, the metadata associated with an ``Annotated`` type can be " +"retrieved via the :attr:`!__metadata__` attribute:" +msgstr "" +"実行時には、 ``Annotated`` 型に関連付けられたメタデータは :attr:`!__metadata__` 属性を" +"通じて取得できます:" + +#: ../../library/typing.rst:1486 +msgid "" +">>> from typing import Annotated\n" +">>> X = Annotated[int, \"very\", \"important\", \"metadata\"]\n" +">>> X\n" +"typing.Annotated[int, 'very', 'important', 'metadata']\n" +">>> X.__metadata__\n" +"('very', 'important', 'metadata')" +msgstr "" +">>> from typing import Annotated\n" +">>> X = Annotated[int, \"very\", \"important\", \"metadata\"]\n" +">>> X\n" +"typing.Annotated[int, 'very', 'important', 'metadata']\n" +">>> X.__metadata__\n" +"('very', 'important', 'metadata')" + +#: ../../library/typing.rst:1495 +msgid "" +"If you want to retrieve the original type wrapped by ``Annotated``, use the :" +"attr:`!__origin__` attribute:" +msgstr "" +"``Annotated`` でラップされた元の型を取得したい場合は、 :attr:`!__origin__` 属性を使用します:" + +#: ../../library/typing.rst:1498 +msgid "" +">>> from typing import Annotated, get_origin\n" +">>> Password = Annotated[str, \"secret\"]\n" +">>> Password.__origin__\n" +"" +msgstr "" +">>> from typing import Annotated, get_origin\n" +">>> Password = Annotated[str, \"secret\"]\n" +">>> Password.__origin__\n" +"" + +#: ../../library/typing.rst:1505 +msgid "Note that using :func:`get_origin` will return ``Annotated`` itself:" +msgstr ":func:`get_origin` を使用すると ``Annotated`` 自体が返されることに注意してください:" + +#: ../../library/typing.rst:1507 +msgid "" +">>> get_origin(Password)\n" +"typing.Annotated" +msgstr "" +">>> get_origin(Password)\n" +"typing.Annotated" + +#: ../../library/typing.rst:1514 +msgid ":pep:`593` - Flexible function and variable annotations" +msgstr ":pep:`593` - 柔軟な関数と変数のアノテーション" + +#: ../../library/typing.rst:1515 +msgid "The PEP introducing ``Annotated`` to the standard library." +msgstr "``Annotated`` を標準ライブラリに導入する PEP。" + +#: ../../library/typing.rst:1522 ../../library/typing.rst:1606 +msgid "" +"Special typing construct for marking user-defined type predicate functions." +msgstr "" +"ユーザー定義の型述語関数をマークするための特別な型付け構造。" + +#: ../../library/typing.rst:1524 +msgid "" +"``TypeIs`` can be used to annotate the return type of a user-defined type " +"predicate function. ``TypeIs`` only accepts a single type argument. At " +"runtime, functions marked this way should return a boolean and take at least " +"one positional argument." +msgstr "" +"``TypeIs`` は、ユーザー定義の型述語関数の戻り値の型をアノテーションするために使用できます。" +"``TypeIs`` は単一の型引数のみを受け付けます。実行時には、このようにマークされた関数は boolean を返し、" +"少なくとも1つの位置引数を取る必要があります。" + +#: ../../library/typing.rst:1529 +msgid "" +"``TypeIs`` aims to benefit *type narrowing* -- a technique used by static " +"type checkers to determine a more precise type of an expression within a " +"program's code flow. Usually type narrowing is done by analyzing " +"conditional code flow and applying the narrowing to a block of code. The " +"conditional expression here is sometimes referred to as a \"type " +"predicate\"::" +msgstr "" +"``TypeIs`` は *型の絞り込み* (type narrowing)の恩恵を受けることを目的としています。これは、" +"プログラムのコードフロー内で式のより正確な型を決定するために静的型チェッカーが使用する技術です。" +"通常、型の絞り込みは条件コードフローを分析し、その絞り込みをコードブロックに適用することによって行われます。" +"ここでの条件式は「型述語」と呼ばれることがあります::" + +#: ../../library/typing.rst:1535 +msgid "" +"def is_str(val: str | float):\n" +" # \"isinstance\" type predicate\n" +" if isinstance(val, str):\n" +" # Type of ``val`` is narrowed to ``str``\n" +" ...\n" +" else:\n" +" # Else, type of ``val`` is narrowed to ``float``.\n" +" ..." +msgstr "" +"def is_str(val: str | float):\n" +" # \"isinstance\" 型述語\n" +" if isinstance(val, str):\n" +" # ``val`` の型は ``str`` に絞り込まれる\n" +" ...\n" +" else:\n" +" # それ以外の場合、``val`` の型は ``float`` に絞り込まれる\n" +" ..." + +#: ../../library/typing.rst:1544 +msgid "" +"Sometimes it would be convenient to use a user-defined boolean function as a " +"type predicate. Such a function should use ``TypeIs[...]`` or :data:" +"`TypeGuard` as its return type to alert static type checkers to this " +"intention. ``TypeIs`` usually has more intuitive behavior than " +"``TypeGuard``, but it cannot be used when the input and output types are " +"incompatible (e.g., ``list[object]`` to ``list[int]``) or when the function " +"does not return ``True`` for all instances of the narrowed type." +msgstr "" +"ユーザー定義の boolean 関数を型述語として使用すると便利な場合があります。そのような関数は、" +"この意図を静的型チェッカーに知らせるために、戻り値の型として ``TypeIs[...]`` または :data:`TypeGuard` を" +"使用する必要があります。``TypeIs`` は通常 ``TypeGuard`` より直感的な動作をしますが、" +"入力と出力の型が互換性がない場合(例:``list[object]`` から ``list[int]``)や、" +"関数が絞り込まれた型のすべてのインスタンスに対して ``True`` を返さない場合には使用できません。" + +#: ../../library/typing.rst:1552 +msgid "" +"Using ``-> TypeIs[NarrowedType]`` tells the static type checker that for a " +"given function:" +msgstr "" +"``-> TypeIs[NarrowedType]`` を使用すると、与えられた関数について静的型チェッカーに次のことを" +"伝えます:" + +#: ../../library/typing.rst:1555 ../../library/typing.rst:1616 +msgid "The return value is a boolean." +msgstr "戻り値は boolean です。" + +#: ../../library/typing.rst:1556 +msgid "" +"If the return value is ``True``, the type of its argument is the " +"intersection of the argument's original type and ``NarrowedType``." +msgstr "" +"戻り値が ``True`` の場合、その引数の型は引数の元の型と ``NarrowedType`` の積集合になります。" + +#: ../../library/typing.rst:1558 +msgid "" +"If the return value is ``False``, the type of its argument is narrowed to " +"exclude ``NarrowedType``." +msgstr "" +"戻り値が ``False`` の場合、その引数の型は ``NarrowedType`` を除外するように絞り込まれます。" + +#: ../../library/typing.rst:1563 +msgid "" +"from typing import assert_type, final, TypeIs\n" +"\n" +"class Parent: pass\n" +"class Child(Parent): pass\n" +"@final\n" +"class Unrelated: pass\n" +"\n" +"def is_parent(val: object) -> TypeIs[Parent]:\n" +" return isinstance(val, Parent)\n" +"\n" +"def run(arg: Child | Unrelated):\n" +" if is_parent(arg):\n" +" # Type of ``arg`` is narrowed to the intersection\n" +" # of ``Parent`` and ``Child``, which is equivalent to\n" +" # ``Child``.\n" +" assert_type(arg, Child)\n" +" else:\n" +" # Type of ``arg`` is narrowed to exclude ``Parent``,\n" +" # so only ``Unrelated`` is left.\n" +" assert_type(arg, Unrelated)" +msgstr "" +"from typing import assert_type, final, TypeIs\n" +"\n" +"class Parent: pass\n" +"class Child(Parent): pass\n" +"@final\n" +"class Unrelated: pass\n" +"\n" +"def is_parent(val: object) -> TypeIs[Parent]:\n" +" return isinstance(val, Parent)\n" +"\n" +"def run(arg: Child | Unrelated):\n" +" if is_parent(arg):\n" +" # ``arg`` の型は ``Parent`` と ``Child`` の積集合に絞り込まれ、\n" +" # これは ``Child`` と等価です。\n" +" assert_type(arg, Child)\n" +" else:\n" +" # ``arg`` の型は ``Parent`` を除外するように絞り込まれるため、\n" +" # ``Unrelated`` のみが残ります。\n" +" assert_type(arg, Unrelated)" + +#: ../../library/typing.rst:1584 +msgid "" +"The type inside ``TypeIs`` must be consistent with the type of the " +"function's argument; if it is not, static type checkers will raise an " +"error. An incorrectly written ``TypeIs`` function can lead to unsound " +"behavior in the type system; it is the user's responsibility to write such " +"functions in a type-safe manner." +msgstr "" +"``TypeIs`` 内の型は関数の引数の型と一致している必要があります。一致していない場合、" +"静的型チェッカーはエラーを発生させます。誤って書かれた ``TypeIs`` 関数は型システムで" +"健全でない動作を引き起こす可能性があります。そのような関数を型安全な方法で書くのは" +"ユーザーの責任です。" + +#: ../../library/typing.rst:1590 +msgid "" +"If a ``TypeIs`` function is a class or instance method, then the type in " +"``TypeIs`` maps to the type of the second parameter (after ``cls`` or " +"``self``)." +msgstr "" +"``TypeIs`` 関数がクラスまたはインスタンスメソッドの場合、``TypeIs`` 内の型は" +"2番目のパラメーター(``cls`` または ``self`` の後)の型にマップされます。" + +#: ../../library/typing.rst:1594 +msgid "" +"In short, the form ``def foo(arg: TypeA) -> TypeIs[TypeB]: ...``, means that " +"if ``foo(arg)`` returns ``True``, then ``arg`` is an instance of ``TypeB``, " +"and if it returns ``False``, it is not an instance of ``TypeB``." +msgstr "" +"要約すると、``def foo(arg: TypeA) -> TypeIs[TypeB]: ...`` の形式は、" +"``foo(arg)`` が ``True`` を返す場合、``arg`` は ``TypeB`` のインスタンスであり、" +"``False`` を返す場合、``TypeB`` のインスタンスではないことを意味します。" + +#: ../../library/typing.rst:1598 +msgid "" +"``TypeIs`` also works with type variables. For more information, see :pep:" +"`742` (Narrowing types with ``TypeIs``)." +msgstr "" +"``TypeIs`` は型変数とも組み合わせて使用できます。詳細については、:pep:`742` " +"(``TypeIs`` による型の絞り込み)を参照してください。" + +#: ../../library/typing.rst:1608 +msgid "" +"Type predicate functions are user-defined functions that return whether " +"their argument is an instance of a particular type. ``TypeGuard`` works " +"similarly to :data:`TypeIs`, but has subtly different effects on type " +"checking behavior (see below)." +msgstr "" +"型述語関数は、その引数が特定の型のインスタンスかどうかを返すユーザー定義関数です。" +"``TypeGuard`` は :data:`TypeIs` と同様に機能しますが、型チェック動作に微妙に異なる" +"影響を与えます(以下を参照)。" + +#: ../../library/typing.rst:1613 +msgid "" +"Using ``-> TypeGuard`` tells the static type checker that for a given " +"function:" +msgstr "" +"``-> TypeGuard`` を使用すると、与えられた関数について静的型チェッカーに次のことを" +"伝えます:" + +#: ../../library/typing.rst:1617 +msgid "" +"If the return value is ``True``, the type of its argument is the type inside " +"``TypeGuard``." +msgstr "" +"戻り値が ``True`` の場合、その引数の型は ``TypeGuard`` 内の型になります。" + +#: ../../library/typing.rst:1620 +msgid "" +"``TypeGuard`` also works with type variables. See :pep:`647` for more " +"details." +msgstr "" +"``TypeGuard`` は型変数とも組み合わせて使用できます。詳細については :pep:`647` を" +"参照してください。" + +#: ../../library/typing.rst:1624 +msgid "" +"def is_str_list(val: list[object]) -> TypeGuard[list[str]]:\n" +" '''Determines whether all objects in the list are strings'''\n" +" return all(isinstance(x, str) for x in val)\n" +"\n" +"def func1(val: list[object]):\n" +" if is_str_list(val):\n" +" # Type of ``val`` is narrowed to ``list[str]``.\n" +" print(\" \".join(val))\n" +" else:\n" +" # Type of ``val`` remains as ``list[object]``.\n" +" print(\"Not a list of strings!\")" +msgstr "" +"def is_str_list(val: list[object]) -> TypeGuard[list[str]]:\n" +" '''リスト内のすべてのオブジェクトが文字列かどうかを判定する'''\n" +" return all(isinstance(x, str) for x in val)\n" +"\n" +"def func1(val: list[object]):\n" +" if is_str_list(val):\n" +" # ``val`` の型は ``list[str]`` に絞り込まれる\n" +" print(\" \".join(val))\n" +" else:\n" +" # ``val`` の型は ``list[object]`` のまま\n" +" print(\"Not a list of strings!\")" + +#: ../../library/typing.rst:1636 +msgid "``TypeIs`` and ``TypeGuard`` differ in the following ways:" +msgstr "``TypeIs`` と ``TypeGuard`` は以下の点で異なります:" + +#: ../../library/typing.rst:1638 +msgid "" +"``TypeIs`` requires the narrowed type to be a subtype of the input type, " +"while ``TypeGuard`` does not. The main reason is to allow for things like " +"narrowing ``list[object]`` to ``list[str]`` even though the latter is not a " +"subtype of the former, since ``list`` is invariant." +msgstr "" +"``TypeIs`` は絞り込まれた型が入力型のサブタイプであることを要求しますが、" +"``TypeGuard`` は要求しません。主な理由は、``list`` が不変であるため、" +"``list[str]`` が ``list[object]`` のサブタイプではないにもかかわらず、" +"``list[object]`` を ``list[str]`` に絞り込むようなことを可能にするためです。" + +#: ../../library/typing.rst:1642 +msgid "" +"When a ``TypeGuard`` function returns ``True``, type checkers narrow the " +"type of the variable to exactly the ``TypeGuard`` type. When a ``TypeIs`` " +"function returns ``True``, type checkers can infer a more precise type " +"combining the previously known type of the variable with the ``TypeIs`` " +"type. (Technically, this is known as an intersection type.)" +msgstr "" +"``TypeGuard`` 関数が ``True`` を返すとき、型チェッカーは変数の型を正確に " +"``TypeGuard`` 型に絞り込みます。``TypeIs`` 関数が ``True`` を返すとき、" +"型チェッカーは変数の以前に知られた型と ``TypeIs`` 型を組み合わせて、より正確な型を" +"推論できます。(技術的には、これは積集合型として知られています。)" + +#: ../../library/typing.rst:1646 +msgid "" +"When a ``TypeGuard`` function returns ``False``, type checkers cannot narrow " +"the type of the variable at all. When a ``TypeIs`` function returns " +"``False``, type checkers can narrow the type of the variable to exclude the " +"``TypeIs`` type." +msgstr "" +"``TypeGuard`` 関数が ``False`` を返すとき、型チェッカーは変数の型を全く絞り込む" +"ことができません。``TypeIs`` 関数が ``False`` を返すとき、型チェッカーは変数の型を" +"``TypeIs`` 型を除外するように絞り込むことができます。" + +#: ../../library/typing.rst:1655 +msgid "Typing operator to conceptually mark an object as having been unpacked." +msgstr "概念的にオブジェクトが展開されたことをマークするための型付け演算子。" + +#: ../../library/typing.rst:1657 +msgid "" +"For example, using the unpack operator ``*`` on a :ref:`type variable tuple " +"` is equivalent to using ``Unpack`` to mark the type variable " +"tuple as having been unpacked::" +msgstr "" +"例えば、:ref:`型変数タプル ` に展開演算子 ``*`` を使用することは、" +"``Unpack`` を使用して型変数タプルが展開されたことをマークすることと等価です::" + +#: ../../library/typing.rst:1661 +msgid "" +"Ts = TypeVarTuple('Ts')\n" +"tup: tuple[*Ts]\n" +"# Effectively does:\n" +"tup: tuple[Unpack[Ts]]" +msgstr "" +"Ts = TypeVarTuple('Ts')\n" +"tup: tuple[*Ts]\n" +"# 実質的には以下と同じ:\n" +"tup: tuple[Unpack[Ts]]" + +#: ../../library/typing.rst:1666 +msgid "" +"In fact, ``Unpack`` can be used interchangeably with ``*`` in the context " +"of :class:`typing.TypeVarTuple ` and :class:`builtins.tuple " +"` types. You might see ``Unpack`` being used explicitly in older " +"versions of Python, where ``*`` couldn't be used in certain places::" +msgstr "" +"実際、``Unpack`` は :class:`typing.TypeVarTuple ` と " +":class:`builtins.tuple ` 型のコンテキストで ``*`` と互換的に使用できます。" +"``*`` が特定の場所で使用できなかった Python の古いバージョンでは、``Unpack`` が" +"明示的に使用されているのを見ることがあります::" + +#: ../../library/typing.rst:1672 +msgid "" +"# In older versions of Python, TypeVarTuple and Unpack\n" +"# are located in the `typing_extensions` backports package.\n" +"from typing_extensions import TypeVarTuple, Unpack\n" +"\n" +"Ts = TypeVarTuple('Ts')\n" +"tup: tuple[*Ts] # Syntax error on Python <= 3.10!\n" +"tup: tuple[Unpack[Ts]] # Semantically equivalent, and backwards-compatible" +msgstr "" +"# Python の古いバージョンでは、TypeVarTuple と Unpack は\n" +"# `typing_extensions` バックポートパッケージに配置されています。\n" +"from typing_extensions import TypeVarTuple, Unpack\n" +"\n" +"Ts = TypeVarTuple('Ts')\n" +"tup: tuple[*Ts] # Python <= 3.10 では構文エラー!\n" +"tup: tuple[Unpack[Ts]] # 意味的には等価で、後方互換性があります" + +#: ../../library/typing.rst:1680 +msgid "" +"``Unpack`` can also be used along with :class:`typing.TypedDict` for typing " +"``**kwargs`` in a function signature::" +msgstr "" +"``Unpack`` は :class:`typing.TypedDict` と組み合わせて、関数シグネチャで" +"``**kwargs`` を型付けするためにも使用できます::" + +#: ../../library/typing.rst:1683 +msgid "" +"from typing import TypedDict, Unpack\n" +"\n" +"class Movie(TypedDict):\n" +" name: str\n" +" year: int\n" +"\n" +"# This function expects two keyword arguments - `name` of type `str`\n" +"# and `year` of type `int`.\n" +"def foo(**kwargs: Unpack[Movie]): ..." +msgstr "" +"from typing import TypedDict, Unpack\n" +"\n" +"class Movie(TypedDict):\n" +" name: str\n" +" year: int\n" +"\n" +"# この関数は2つのキーワード引数を期待します - `str` 型の `name` と\n" +"# `int` 型の `year`。\n" +"def foo(**kwargs: Unpack[Movie]): ..." + +#: ../../library/typing.rst:1693 +msgid "" +"See :pep:`692` for more details on using ``Unpack`` for ``**kwargs`` typing." +msgstr "" +"``**kwargs`` の型付けに ``Unpack`` を使用することの詳細については :pep:`692` を参照してください。" + +#: ../../library/typing.rst:1698 +msgid "Building generic types and type aliases" +msgstr "ジェネリック型と型エイリアスの構築" + +#: ../../library/typing.rst:1700 +msgid "" +"The following classes should not be used directly as annotations. Their " +"intended purpose is to be building blocks for creating generic types and " +"type aliases." +msgstr "" +"以下のクラスは直接アノテーションとして使用すべきではありません。これらの意図された目的は、" +"ジェネリック型と型エイリアスを作成するための構成要素となることです。" + +#: ../../library/typing.rst:1704 +msgid "" +"These objects can be created through special syntax (:ref:`type parameter " +"lists ` and the :keyword:`type` statement). For compatibility " +"with Python 3.11 and earlier, they can also be created without the dedicated " +"syntax, as documented below." +msgstr "" +"これらのオブジェクトは特別な構文(:ref:`型パラメータリスト ` と :keyword:`type` 文)を通じて作成できます。" +"Python 3.11 以前との互換性のため、以下に記載されているように、専用の構文なしでも作成できます。" + +#: ../../library/typing.rst:1711 +msgid "Abstract base class for generic types." +msgstr "ジェネリック型のための抽象基底クラスです。" + +#: ../../library/typing.rst:1713 +msgid "" +"A generic type is typically declared by adding a list of type parameters " +"after the class name::" +msgstr "" +"ジェネリック型は通常、クラス名の後に型パラメータのリストを追加することで宣言されます::" + +#: ../../library/typing.rst:1716 +msgid "" +"class Mapping[KT, VT]:\n" +" def __getitem__(self, key: KT) -> VT:\n" +" ...\n" +" # Etc." +msgstr "" +"class Mapping[KT, VT]:\n" +" def __getitem__(self, key: KT) -> VT:\n" +" ...\n" +" # など" + +#: ../../library/typing.rst:1721 +msgid "" +"Such a class implicitly inherits from ``Generic``. The runtime semantics of " +"this syntax are discussed in the :ref:`Language Reference `." +msgstr "" +"このようなクラスは ``Generic`` から暗黙的に継承されます。この構文のランタイムセマンティクスについては、" +":ref:`言語リファレンス ` で説明されています。" + +#: ../../library/typing.rst:1725 +msgid "This class can then be used as follows::" +msgstr "このクラスは次のように使用することが出来ます::" + +#: ../../library/typing.rst:1727 +msgid "" +"def lookup_name[X, Y](mapping: Mapping[X, Y], key: X, default: Y) -> Y:\n" +" try:\n" +" return mapping[key]\n" +" except KeyError:\n" +" return default" +msgstr "" +"def lookup_name[X, Y](mapping: Mapping[X, Y], key: X, default: Y) -> Y:\n" +" try:\n" +" return mapping[key]\n" +" except KeyError:\n" +" return default" + +#: ../../library/typing.rst:1733 +msgid "" +"Here the brackets after the function name indicate a :ref:`generic function " +"`." +msgstr "" +"ここで関数名の後の角括弧は :ref:`ジェネリック関数 ` を示しています。" + +#: ../../library/typing.rst:1736 +msgid "" +"For backwards compatibility, generic classes can also be declared by " +"explicitly inheriting from ``Generic``. In this case, the type parameters " +"must be declared separately::" +msgstr "" +"後方互換性のため、ジェネリッククラスは ``Generic`` から明示的に継承することでも宣言できます。" +"この場合、型パラメータは別途宣言する必要があります::" + +#: ../../library/typing.rst:1741 +msgid "" +"KT = TypeVar('KT')\n" +"VT = TypeVar('VT')\n" +"\n" +"class Mapping(Generic[KT, VT]):\n" +" def __getitem__(self, key: KT) -> VT:\n" +" ...\n" +" # Etc." +msgstr "" +"KT = TypeVar('KT')\n" +"VT = TypeVar('VT')\n" +"\n" +"class Mapping(Generic[KT, VT]):\n" +" def __getitem__(self, key: KT) -> VT:\n" +" ...\n" +" # など" + +#: ../../library/typing.rst:1753 +msgid "Type variable." +msgstr "型変数です。" + +#: ../../library/typing.rst:1755 +msgid "" +"The preferred way to construct a type variable is via the dedicated syntax " +"for :ref:`generic functions `, :ref:`generic classes " +"`, and :ref:`generic type aliases `::" +msgstr "" +"型変数を構築する推奨される方法は、:ref:`ジェネリック関数 `、:ref:`ジェネリッククラス `、" +":ref:`ジェネリック型エイリアス ` 用の専用構文を使用することです::" + +#: ../../library/typing.rst:1760 +msgid "" +"class Sequence[T]: # T is a TypeVar\n" +" ..." +msgstr "" +"class Sequence[T]: # T は TypeVar\n" +" ..." + +#: ../../library/typing.rst:1763 +msgid "" +"This syntax can also be used to create bounded and constrained type " +"variables::" +msgstr "" +"この構文は、境界付きと制約付きの型変数を作成するためにも使用できます::" + +#: ../../library/typing.rst:1766 +msgid "" +"class StrSequence[S: str]: # S is a TypeVar with a `str` upper bound;\n" +" ... # we can say that S is \"bounded by `str`\"\n" +"\n" +"\n" +"class StrOrBytesSequence[A: (str, bytes)]: # A is a TypeVar constrained to " +"str or bytes\n" +" ..." +msgstr "" +"class StrSequence[S: str]: # S は `str` 上限を持つ TypeVar;\n" +" ... # S は \"`str` によって境界付けされている\" と言える\n" +"\n" +"\n" +"class StrOrBytesSequence[A: (str, bytes)]: # A は str または bytes に制約された TypeVar\n" +" ..." + +#: ../../library/typing.rst:1773 +msgid "" +"However, if desired, reusable type variables can also be constructed " +"manually, like so::" +msgstr "" +"ただし、必要に応じて、再利用可能な型変数を手動で構築することもできます::" + +#: ../../library/typing.rst:1775 +msgid "" +"T = TypeVar('T') # Can be anything\n" +"S = TypeVar('S', bound=str) # Can be any subtype of str\n" +"A = TypeVar('A', str, bytes) # Must be exactly str or bytes" +msgstr "" +"T = TypeVar('T') # 何でも可能\n" +"S = TypeVar('S', bound=str) # str のサブタイプなら何でも可能\n" +"A = TypeVar('A', str, bytes) # str または bytes のみ" + +#: ../../library/typing.rst:1779 +msgid "" +"Type variables exist primarily for the benefit of static type checkers. " +"They serve as the parameters for generic types as well as for generic " +"function and type alias definitions. See :class:`Generic` for more " +"information on generic types. Generic functions work as follows::" +msgstr "" +"型変数は主に静的型チェッカーのために存在します。これらは、ジェネリック型のパラメータとして、" +"またジェネリック関数と型エイリアス定義のパラメータとして機能します。ジェネリック型の詳細については :class:`Generic` を参照してください。" +"ジェネリック関数は次のように動作します::" + +#: ../../library/typing.rst:1785 +msgid "" +"def repeat[T](x: T, n: int) -> Sequence[T]:\n" +" \"\"\"Return a list containing n references to x.\"\"\"\n" +" return [x]*n\n" +"\n" +"\n" +"def print_capitalized[S: str](x: S) -> S:\n" +" \"\"\"Print x capitalized, and return x.\"\"\"\n" +" print(x.capitalize())\n" +" return x\n" +"\n" +"\n" +"def concatenate[A: (str, bytes)](x: A, y: A) -> A:\n" +" \"\"\"Add two strings or bytes objects together.\"\"\"\n" +" return x + y" +msgstr "" +"def repeat[T](x: T, n: int) -> Sequence[T]:\n" +" \"\"\"x への n 個の参照を含むリストを返す。\"\"\"\n" +" return [x]*n\n" +"\n" +"\n" +"def print_capitalized[S: str](x: S) -> S:\n" +" \"\"\"x を大文字で印刷し、x を返す。\"\"\"\n" +" print(x.capitalize())\n" +" return x\n" +"\n" +"\n" +"def concatenate[A: (str, bytes)](x: A, y: A) -> A:\n" +" \"\"\"2つの文字列または bytes オブジェクトを結合する。\"\"\"\n" +" return x + y" + +#: ../../library/typing.rst:1800 +msgid "" +"Note that type variables can be *bounded*, *constrained*, or neither, but " +"cannot be both bounded *and* constrained." +msgstr "" +"型変数は *境界付き* 、*制約付き* 、またはそのどちらでもない場合がありますが、" +"境界付き *かつ* 制約付きの両方にはできないことに注意してください。" + +#: ../../library/typing.rst:1803 +msgid "" +"The variance of type variables is inferred by type checkers when they are " +"created through the :ref:`type parameter syntax ` or when " +"``infer_variance=True`` is passed. Manually created type variables may be " +"explicitly marked covariant or contravariant by passing ``covariant=True`` " +"or ``contravariant=True``. By default, manually created type variables are " +"invariant. See :pep:`484` and :pep:`695` for more details." +msgstr "" +"型変数の変性は、:ref:`型パラメータ構文 ` で作成されるか、``infer_variance=True`` が渡されたときに" +"型チェッカーによって推論されます。手動で作成された型変数は、``covariant=True`` または ``contravariant=True`` を渡すことで" +"明示的に共変または反変とマークできます。デフォルトでは、手動で作成された型変数は不変です。" +"詳細については :pep:`484` と :pep:`695` を参照してください。" + +#: ../../library/typing.rst:1811 +msgid "" +"Bounded type variables and constrained type variables have different " +"semantics in several important ways. Using a *bounded* type variable means " +"that the ``TypeVar`` will be solved using the most specific type possible::" +msgstr "" +"境界付き型変数と制約付き型変数は、いくつかの重要な点で異なるセマンティクスを持ちます。" +"*境界付き* 型変数を使用することは、``TypeVar`` が可能な限り最も具体的な型を使用して解決されることを意味します::" + +#: ../../library/typing.rst:1815 +msgid "" +"x = print_capitalized('a string')\n" +"reveal_type(x) # revealed type is str\n" +"\n" +"class StringSubclass(str):\n" +" pass\n" +"\n" +"y = print_capitalized(StringSubclass('another string'))\n" +"reveal_type(y) # revealed type is StringSubclass\n" +"\n" +"z = print_capitalized(45) # error: int is not a subtype of str" +msgstr "" +"x = print_capitalized('a string')\n" +"reveal_type(x) # 明かされた型は str\n" +"\n" +"class StringSubclass(str):\n" +" pass\n" +"\n" +"y = print_capitalized(StringSubclass('another string'))\n" +"reveal_type(y) # 明かされた型は StringSubclass\n" +"\n" +"z = print_capitalized(45) # エラー: int は str のサブタイプではない" + +#: ../../library/typing.rst:1826 +msgid "" +"The upper bound of a type variable can be a concrete type, abstract type " +"(ABC or Protocol), or even a union of types::" +msgstr "" +"型変数の上限は、具体的な型、抽象型(ABC または Protocol)、または型の合併型でも可能です::" + +#: ../../library/typing.rst:1829 +msgid "" +"# Can be anything with an __abs__ method\n" +"def print_abs[T: SupportsAbs](arg: T) -> None:\n" +" print(\"Absolute value:\", abs(arg))\n" +"\n" +"U = TypeVar('U', bound=str|bytes) # Can be any subtype of the union str|" +"bytes\n" +"V = TypeVar('V', bound=SupportsAbs) # Can be anything with an __abs__ method" +msgstr "" +"# __abs__ メソッドを持つものなら何でも可能\n" +"def print_abs[T: SupportsAbs](arg: T) -> None:\n" +" print(\"Absolute value:\", abs(arg))\n" +"\n" +"U = TypeVar('U', bound=str|bytes) # 合併型 str|bytes のサブタイプなら何でも可能\n" +"V = TypeVar('V', bound=SupportsAbs) # __abs__ メソッドを持つものなら何でも可能" + +#: ../../library/typing.rst:1838 +msgid "" +"Using a *constrained* type variable, however, means that the ``TypeVar`` can " +"only ever be solved as being exactly one of the constraints given::" +msgstr "" +"しかし、*制約付き* 型変数を使用することは、``TypeVar`` が与えられた制約の正確に1つとしてのみ解決されることを意味します::" + +#: ../../library/typing.rst:1841 +msgid "" +"a = concatenate('one', 'two')\n" +"reveal_type(a) # revealed type is str\n" +"\n" +"b = concatenate(StringSubclass('one'), StringSubclass('two'))\n" +"reveal_type(b) # revealed type is str, despite StringSubclass being passed " +"in\n" +"\n" +"c = concatenate('one', b'two') # error: type variable 'A' can be either str " +"or bytes in a function call, but not both" +msgstr "" +"a = concatenate('one', 'two')\n" +"reveal_type(a) # 明かされた型は str\n" +"\n" +"b = concatenate(StringSubclass('one'), StringSubclass('two'))\n" +"reveal_type(b) # StringSubclass が渡されているにもかかわらず、明かされた型は str\n" +"\n" +"c = concatenate('one', b'two') # エラー: 型変数 'A' は関数呼び出しで str または bytes のいずれかですが、両方ではありません" + +#: ../../library/typing.rst:1849 +msgid "At runtime, ``isinstance(x, T)`` will raise :exc:`TypeError`." +msgstr "実行時に ``isinstance(x, T)`` は :exc:`TypeError` を発生させます。" + +#: ../../library/typing.rst:1853 +msgid "The name of the type variable." +msgstr "型変数の名前。" + +#: ../../library/typing.rst:1857 +msgid "Whether the type var has been explicitly marked as covariant." +msgstr "型変数が明示的に共変としてマークされているかどうか。" + +#: ../../library/typing.rst:1861 +msgid "Whether the type var has been explicitly marked as contravariant." +msgstr "型変数が明示的に反変としてマークされているかどうか。" + +#: ../../library/typing.rst:1865 +msgid "" +"Whether the type variable's variance should be inferred by type checkers." +msgstr "" +"型変数の変性が型チェッカーによって推論されるべきかどうか。" + +#: ../../library/typing.rst:1871 +msgid "The upper bound of the type variable, if any." +msgstr "型変数の上限(存在する場合)。" + +#: ../../library/typing.rst:1875 +msgid "" +"For type variables created through :ref:`type parameter syntax `, the bound is evaluated only when the attribute is accessed, not " +"when the type variable is created (see :ref:`lazy-evaluation`)." +msgstr "" +":ref:`型パラメータ構文 ` を通じて作成された型変数の場合、境界は型変数が作成されたときではなく、" +"属性がアクセスされたときにのみ評価されます(:ref:`lazy-evaluation` を参照)。" + +#: ../../library/typing.rst:1881 +msgid "" +"An :term:`evaluate function` corresponding to the :attr:`~TypeVar.__bound__` " +"attribute. When called directly, this method supports only the :attr:" +"`~annotationlib.Format.VALUE` format, which is equivalent to accessing the :" +"attr:`~TypeVar.__bound__` attribute directly, but the method object can be " +"passed to :func:`annotationlib.call_evaluate_function` to evaluate the value " +"in a different format." +msgstr "" +":attr:`~TypeVar.__bound__` 属性に対応する :term:`評価関数` です。直接呼び出された場合、このメソッドは " +":attr:`~annotationlib.Format.VALUE` 形式のみをサポートします。これは :attr:`~TypeVar.__bound__` 属性に直接" +"アクセスするのと同等ですが、メソッドオブジェクトを :func:`annotationlib.call_evaluate_function` に渡して" +"異なる形式で値を評価することができます。" + +#: ../../library/typing.rst:1891 +msgid "A tuple containing the constraints of the type variable, if any." +msgstr "型変数の制約を含むタプル(存在する場合)。" + +#: ../../library/typing.rst:1895 +msgid "" +"For type variables created through :ref:`type parameter syntax `, the constraints are evaluated only when the attribute is accessed, " +"not when the type variable is created (see :ref:`lazy-evaluation`)." +msgstr "" +":ref:`型パラメータ構文 ` を通じて作成された型変数の場合、制約は型変数が作成されたときではなく、" +"属性がアクセスされたときにのみ評価されます(:ref:`lazy-evaluation` を参照)。" + +#: ../../library/typing.rst:1901 +msgid "" +"An :term:`evaluate function` corresponding to the :attr:`~TypeVar." +"__constraints__` attribute. When called directly, this method supports only " +"the :attr:`~annotationlib.Format.VALUE` format, which is equivalent to " +"accessing the :attr:`~TypeVar.__constraints__` attribute directly, but the " +"method object can be passed to :func:`annotationlib.call_evaluate_function` " +"to evaluate the value in a different format." +msgstr "" +":attr:`~TypeVar.__constraints__` 属性に対応する :term:`評価関数` です。直接呼び出された場合、このメソッドは " +":attr:`~annotationlib.Format.VALUE` 形式のみをサポートします。これは :attr:`~TypeVar.__constraints__` 属性に" +"直接アクセスするのと同等ですが、メソッドオブジェクトを :func:`annotationlib.call_evaluate_function` に渡して" +"異なる形式で値を評価することができます。" + +#: ../../library/typing.rst:1911 +msgid "" +"The default value of the type variable, or :data:`typing.NoDefault` if it " +"has no default." +msgstr "" +"型変数のデフォルト値、またはデフォルトがない場合は :data:`typing.NoDefault`。" + +#: ../../library/typing.rst:1918 +msgid "" +"An :term:`evaluate function` corresponding to the :attr:`~TypeVar." +"__default__` attribute. When called directly, this method supports only the :" +"attr:`~annotationlib.Format.VALUE` format, which is equivalent to accessing " +"the :attr:`~TypeVar.__default__` attribute directly, but the method object " +"can be passed to :func:`annotationlib.call_evaluate_function` to evaluate " +"the value in a different format." +msgstr "" +":attr:`~TypeVar.__default__` 属性に対応する :term:`評価関数` です。直接呼び出された場合、このメソッドは " +":attr:`~annotationlib.Format.VALUE` 形式のみをサポートします。これは :attr:`~TypeVar.__default__` 属性に" +"直接アクセスするのと同等ですが、メソッドオブジェクトを :func:`annotationlib.call_evaluate_function` に渡して" +"異なる形式で値を評価することができます。" + +#: ../../library/typing.rst:1928 +msgid "" +"Return whether or not the type variable has a default value. This is " +"equivalent to checking whether :attr:`__default__` is not the :data:`typing." +"NoDefault` singleton, except that it does not force evaluation of the :ref:" +"`lazily evaluated ` default value." +msgstr "" +"型変数がデフォルト値を持つかどうかを返します。これは :attr:`__default__` が :data:`typing.NoDefault` " +"シングルトンでないかをチェックするのと同等ですが、:ref:`遅延評価 ` されるデフォルト値の" +"評価を強制しません。" + +#: ../../library/typing.rst:1937 +msgid "" +"Type variables can now be declared using the :ref:`type parameter ` syntax introduced by :pep:`695`. The ``infer_variance`` parameter " +"was added." +msgstr "" +"型変数は :pep:`695` で導入された :ref:`型パラメータ ` 構文を使用して宣言できるようになりました。" +"``infer_variance`` パラメータが追加されました。" + +#: ../../library/typing.rst:1943 ../../library/typing.rst:2092 +#: ../../library/typing.rst:2204 +msgid "Support for default values was added." +msgstr "デフォルト値のサポートが追加されました。" + +#: ../../library/typing.rst:1949 +msgid "" +"Type variable tuple. A specialized form of :ref:`type variable ` " +"that enables *variadic* generics." +msgstr "" +"型変数タプル。*可変長* ジェネリクスを可能にする :ref:`型変数 ` の特殊化された形式。" + +#: ../../library/typing.rst:1952 +msgid "" +"Type variable tuples can be declared in :ref:`type parameter lists ` using a single asterisk (``*``) before the name::" +msgstr "" +"型変数タプルは :ref:`型パラメータリスト ` で名前の前に単一のアスタリスク(``*``)を使用して" +"宣言できます::" + +#: ../../library/typing.rst:1955 +msgid "" +"def move_first_element_to_last[T, *Ts](tup: tuple[T, *Ts]) -> tuple[*Ts, " +"T]:\n" +" return (*tup[1:], tup[0])" +msgstr "" +"def move_first_element_to_last[T, *Ts](tup: tuple[T, *Ts]) -> tuple[*Ts, " +"T]:\n" +" return (*tup[1:], tup[0])" + +#: ../../library/typing.rst:1958 +msgid "Or by explicitly invoking the ``TypeVarTuple`` constructor::" +msgstr "または ``TypeVarTuple`` コンストラクタを明示的に呼び出すことで::" + +#: ../../library/typing.rst:1960 +msgid "" +"T = TypeVar(\"T\")\n" +"Ts = TypeVarTuple(\"Ts\")\n" +"\n" +"def move_first_element_to_last(tup: tuple[T, *Ts]) -> tuple[*Ts, T]:\n" +" return (*tup[1:], tup[0])" +msgstr "" +"T = TypeVar(\"T\")\n" +"Ts = TypeVarTuple(\"Ts\")\n" +"\n" +"def move_first_element_to_last(tup: tuple[T, *Ts]) -> tuple[*Ts, T]:\n" +" return (*tup[1:], tup[0])" + +#: ../../library/typing.rst:1966 +msgid "" +"A normal type variable enables parameterization with a single type. A type " +"variable tuple, in contrast, allows parameterization with an *arbitrary* " +"number of types by acting like an *arbitrary* number of type variables " +"wrapped in a tuple. For example::" +msgstr "" +"通常の型変数は単一の型でのパラメータ化を可能にします。対照的に、型変数タプルは、タプルにラップされた *任意の* 数の" +"型変数のように動作することで、*任意の* 数の型でのパラメータ化を可能にします。例えば::" + +#: ../../library/typing.rst:1971 +msgid "" +"# T is bound to int, Ts is bound to ()\n" +"# Return value is (1,), which has type tuple[int]\n" +"move_first_element_to_last(tup=(1,))\n" +"\n" +"# T is bound to int, Ts is bound to (str,)\n" +"# Return value is ('spam', 1), which has type tuple[str, int]\n" +"move_first_element_to_last(tup=(1, 'spam'))\n" +"\n" +"# T is bound to int, Ts is bound to (str, float)\n" +"# Return value is ('spam', 3.0, 1), which has type tuple[str, float, int]\n" +"move_first_element_to_last(tup=(1, 'spam', 3.0))\n" +"\n" +"# This fails to type check (and fails at runtime)\n" +"# because tuple[()] is not compatible with tuple[T, *Ts]\n" +"# (at least one element is required)\n" +"move_first_element_to_last(tup=())" +msgstr "" +"# T は int に束縛され、Ts は () に束縛される\n" +"# 戻り値は (1,) で、型は tuple[int]\n" +"move_first_element_to_last(tup=(1,))\n" +"\n" +"# T は int に束縛され、Ts は (str,) に束縛される\n" +"# 戻り値は ('spam', 1) で、型は tuple[str, int]\n" +"move_first_element_to_last(tup=(1, 'spam'))\n" +"\n" +"# T は int に束縛され、Ts は (str, float) に束縛される\n" +"# 戻り値は ('spam', 3.0, 1) で、型は tuple[str, float, int]\n" +"move_first_element_to_last(tup=(1, 'spam', 3.0))\n" +"\n" +"# これは型チェックに失敗します(実行時にも失敗します)\n" +"# tuple[()] は tuple[T, *Ts] と互換性がないため\n" +"# (少なくとも1つの要素が必要)\n" +"move_first_element_to_last(tup=())" + +#: ../../library/typing.rst:1988 +msgid "" +"Note the use of the unpacking operator ``*`` in ``tuple[T, *Ts]``. " +"Conceptually, you can think of ``Ts`` as a tuple of type variables ``(T1, " +"T2, ...)``. ``tuple[T, *Ts]`` would then become ``tuple[T, *(T1, " +"T2, ...)]``, which is equivalent to ``tuple[T, T1, T2, ...]``. (Note that in " +"older versions of Python, you might see this written using :data:`Unpack " +"` instead, as ``Unpack[Ts]``.)" +msgstr "" +"``tuple[T, *Ts]`` での展開演算子 ``*`` の使用に注意してください。概念的には、``Ts`` を型変数のタプル " +"``(T1, T2, ...)`` と考えることができます。そうすると ``tuple[T, *Ts]`` は ``tuple[T, *(T1, T2, ...)]`` " +"となり、これは ``tuple[T, T1, T2, ...]`` と等価です。(Python の古いバージョンでは、代わりに " +":data:`Unpack ` を使用して ``Unpack[Ts]`` と書かれているのを見ることがあります。)" + +#: ../../library/typing.rst:1996 +msgid "" +"Type variable tuples must *always* be unpacked. This helps distinguish type " +"variable tuples from normal type variables::" +msgstr "" +"型変数タプルは *常に* 展開される必要があります。これは型変数タプルを通常の型変数と区別するのに役立ちます::" + +#: ../../library/typing.rst:1999 +msgid "" +"x: Ts # Not valid\n" +"x: tuple[Ts] # Not valid\n" +"x: tuple[*Ts] # The correct way to do it" +msgstr "" +"x: Ts # 無効\n" +"x: tuple[Ts] # 無効\n" +"x: tuple[*Ts] # 正しい方法" + +#: ../../library/typing.rst:2003 +msgid "" +"Type variable tuples can be used in the same contexts as normal type " +"variables. For example, in class definitions, arguments, and return types::" +msgstr "" +"型変数タプルは通常の型変数と同じコンテキストで使用できます。例えば、クラス定義、引数、戻り値の型で::" + +#: ../../library/typing.rst:2006 +msgid "" +"class Array[*Shape]:\n" +" def __getitem__(self, key: tuple[*Shape]) -> float: ...\n" +" def __abs__(self) -> \"Array[*Shape]\": ...\n" +" def get_shape(self) -> tuple[*Shape]: ..." +msgstr "" +"class Array[*Shape]:\n" +" def __getitem__(self, key: tuple[*Shape]) -> float: ...\n" +" def __abs__(self) -> \"Array[*Shape]\": ...\n" +" def get_shape(self) -> tuple[*Shape]: ..." + +#: ../../library/typing.rst:2011 +msgid "" +"Type variable tuples can be happily combined with normal type variables:" +msgstr "" +"型変数タプルは通常の型変数と組み合わせて使用できます:" + +#: ../../library/typing.rst:2013 +msgid "" +"class Array[DType, *Shape]: # This is fine\n" +" pass\n" +"\n" +"class Array2[*Shape, DType]: # This would also be fine\n" +" pass\n" +"\n" +"class Height: ...\n" +"class Width: ...\n" +"\n" +"float_array_1d: Array[float, Height] = Array() # Totally fine\n" +"int_array_2d: Array[int, Height, Width] = Array() # Yup, fine too" +msgstr "" +"class Array[DType, *Shape]: # これはOK\n" +" pass\n" +"\n" +"class Array2[*Shape, DType]: # これもOK\n" +" pass\n" +"\n" +"class Height: ...\n" +"class Width: ...\n" +"\n" +"float_array_1d: Array[float, Height] = Array() # 完全にOK\n" +"int_array_2d: Array[int, Height, Width] = Array() # これもOK" + +#: ../../library/typing.rst:2027 +msgid "" +"However, note that at most one type variable tuple may appear in a single " +"list of type arguments or type parameters::" +msgstr "" +"ただし、単一の型引数または型パラメータのリストには、最大で一つの型変数タプルしか出現できないことに注意してください::" + +#: ../../library/typing.rst:2030 +msgid "" +"x: tuple[*Ts, *Ts] # Not valid\n" +"class Array[*Shape, *Shape]: # Not valid\n" +" pass" +msgstr "" +"x: tuple[*Ts, *Ts] # 無効\n" +"class Array[*Shape, *Shape]: # 無効\n" +" pass" + +#: ../../library/typing.rst:2034 +msgid "" +"Finally, an unpacked type variable tuple can be used as the type annotation " +"of ``*args``::" +msgstr "" +"最後に、展開された型変数タプルは ``*args`` の型アノテーションとして使用できます::" + +#: ../../library/typing.rst:2037 +msgid "" +"def call_soon[*Ts](\n" +" callback: Callable[[*Ts], None],\n" +" *args: *Ts\n" +") -> None:\n" +" ...\n" +" callback(*args)" +msgstr "" +"def call_soon[*Ts](\n" +" callback: Callable[[*Ts], None],\n" +" *args: *Ts\n" +") -> None:\n" +" ...\n" +" callback(*args)" + +#: ../../library/typing.rst:2044 +msgid "" +"In contrast to non-unpacked annotations of ``*args`` - e.g. ``*args: int``, " +"which would specify that *all* arguments are ``int`` - ``*args: *Ts`` " +"enables reference to the types of the *individual* arguments in ``*args``. " +"Here, this allows us to ensure the types of the ``*args`` passed to " +"``call_soon`` match the types of the (positional) arguments of ``callback``." +msgstr "" +"``*args`` の展開されないアノテーション(例:``*args: int``)が *すべての* 引数が ``int`` であることを指定するのと対照的に、" +"``*args: *Ts`` は ``*args`` 内の *個々の* 引数の型への参照を可能にします。ここでは、これにより" +"``call_soon`` に渡される ``*args`` の型が ``callback`` の(位置)引数の型と一致することを保証できます。" + +#: ../../library/typing.rst:2051 +msgid "See :pep:`646` for more details on type variable tuples." +msgstr "型変数タプルの詳細については :pep:`646` を参照してください。" + +#: ../../library/typing.rst:2055 +msgid "The name of the type variable tuple." +msgstr "型変数タプルの名前。" + +#: ../../library/typing.rst:2059 +msgid "" +"The default value of the type variable tuple, or :data:`typing.NoDefault` if " +"it has no default." +msgstr "" +"型変数タプルのデフォルト値、またはデフォルトがない場合は :data:`typing.NoDefault`。" + +#: ../../library/typing.rst:2066 +msgid "" +"An :term:`evaluate function` corresponding to the :attr:`~TypeVarTuple." +"__default__` attribute. When called directly, this method supports only the :" +"attr:`~annotationlib.Format.VALUE` format, which is equivalent to accessing " +"the :attr:`~TypeVarTuple.__default__` attribute directly, but the method " +"object can be passed to :func:`annotationlib.call_evaluate_function` to " +"evaluate the value in a different format." +msgstr "" +":attr:`~TypeVarTuple.__default__` 属性に対応する :term:`評価関数` です。直接呼び出された場合、このメソッドは " +":attr:`~annotationlib.Format.VALUE` 形式のみをサポートします。これは :attr:`~TypeVarTuple.__default__` 属性に" +"直接アクセスするのと同等ですが、メソッドオブジェクトを :func:`annotationlib.call_evaluate_function` に渡して" +"異なる形式で値を評価することができます。" + +#: ../../library/typing.rst:2076 +msgid "" +"Return whether or not the type variable tuple has a default value. This is " +"equivalent to checking whether :attr:`__default__` is not the :data:`typing." +"NoDefault` singleton, except that it does not force evaluation of the :ref:" +"`lazily evaluated ` default value." +msgstr "" +"型変数タプルがデフォルト値を持つかどうかを返します。これは :attr:`__default__` が :data:`typing.NoDefault` " +"シングルトンでないかをチェックするのと同等ですが、:ref:`遅延評価 ` されるデフォルト値の" +"評価を強制しません。" + +#: ../../library/typing.rst:2087 +msgid "" +"Type variable tuples can now be declared using the :ref:`type parameter " +"` syntax introduced by :pep:`695`." +msgstr "" +"型変数タプルは :pep:`695` で導入された :ref:`型パラメータ ` 構文を使用して宣言できるようになりました。" + +#: ../../library/typing.rst:2096 +msgid "" +"Parameter specification variable. A specialized version of :ref:`type " +"variables `." +msgstr "" +"パラメータ仕様変数。:ref:`型変数 ` の特殊化版。" + +#: ../../library/typing.rst:2099 +msgid "" +"In :ref:`type parameter lists `, parameter specifications can " +"be declared with two asterisks (``**``)::" +msgstr "" +":ref:`型パラメータリスト ` では、パラメータ仕様は2つのアスタリスク(``**``)で宣言できます::" + +#: ../../library/typing.rst:2102 +msgid "type IntFunc[**P] = Callable[P, int]" +msgstr "type IntFunc[**P] = Callable[P, int]" + +#: ../../library/typing.rst:2104 +msgid "" +"For compatibility with Python 3.11 and earlier, ``ParamSpec`` objects can " +"also be created as follows::" +msgstr "" +"Python 3.11 以前との互換性のため、``ParamSpec`` オブジェクトは以下のように作成することもできます::" + +#: ../../library/typing.rst:2107 +msgid "P = ParamSpec('P')" +msgstr "P = ParamSpec('P')" + +#: ../../library/typing.rst:2109 +msgid "" +"Parameter specification variables exist primarily for the benefit of static " +"type checkers. They are used to forward the parameter types of one callable " +"to another callable -- a pattern commonly found in higher order functions " +"and decorators. They are only valid when used in ``Concatenate``, or as the " +"first argument to ``Callable``, or as parameters for user-defined Generics. " +"See :class:`Generic` for more information on generic types." +msgstr "" +"パラメータ仕様変数は主に静的型チェッカーのために存在します。これらは、ある呼び出し可能オブジェクトの" +"パラメータ型を別の呼び出し可能オブジェクトに転送するために使用されます。これは高階関数やデコレータで" +"一般的に見られるパターンです。これらは ``Concatenate`` で使用されるか、``Callable`` の最初の引数として使用されるか、" +"ユーザー定義のジェネリクスのパラメータとして使用される場合にのみ有効です。ジェネリック型の詳細については :class:`Generic` を" +"参照してください。" + +#: ../../library/typing.rst:2116 +msgid "" +"For example, to add basic logging to a function, one can create a decorator " +"``add_logging`` to log function calls. The parameter specification variable " +"tells the type checker that the callable passed into the decorator and the " +"new callable returned by it have inter-dependent type parameters::" +msgstr "" +"例えば、関数に基本的なログ機能を追加するために、関数呼び出しをログ出力するデコレータ ``add_logging`` を" +"作成できます。パラメータ仕様変数は、デコレータに渡される呼び出し可能オブジェクトとそれが返す新しい" +"呼び出し可能オブジェクトが相互依存する型パラメータを持つことを型チェッカーに伝えます::" + +#: ../../library/typing.rst:2121 +msgid "" +"from collections.abc import Callable\n" +"import logging\n" +"\n" +"def add_logging[T, **P](f: Callable[P, T]) -> Callable[P, T]:\n" +" '''A type-safe decorator to add logging to a function.'''\n" +" def inner(*args: P.args, **kwargs: P.kwargs) -> T:\n" +" logging.info(f'{f.__name__} was called')\n" +" return f(*args, **kwargs)\n" +" return inner\n" +"\n" +"@add_logging\n" +"def add_two(x: float, y: float) -> float:\n" +" '''Add two numbers together.'''\n" +" return x + y" +msgstr "" +"from collections.abc import Callable\n" +"import logging\n" +"\n" +"def add_logging[T, **P](f: Callable[P, T]) -> Callable[P, T]:\n" +" '''関数にログ機能を追加する型安全なデコレータ。'''\n" +" def inner(*args: P.args, **kwargs: P.kwargs) -> T:\n" +" logging.info(f'{f.__name__} was called')\n" +" return f(*args, **kwargs)\n" +" return inner\n" +"\n" +"@add_logging\n" +"def add_two(x: float, y: float) -> float:\n" +" '''二つの数値を加算する。'''\n" +" return x + y" + +#: ../../library/typing.rst:2136 +msgid "" +"Without ``ParamSpec``, the simplest way to annotate this previously was to " +"use a :class:`TypeVar` with upper bound ``Callable[..., Any]``. However " +"this causes two problems:" +msgstr "" +"``ParamSpec`` がない場合、以前はこれをアノテーションする最も簡単な方法は、上限が ``Callable[..., Any]`` の " +":class:`TypeVar` を使用することでした。しかし、これには2つの問題があります:" + +#: ../../library/typing.rst:2140 +msgid "" +"The type checker can't type check the ``inner`` function because ``*args`` " +"and ``**kwargs`` have to be typed :data:`Any`." +msgstr "" +"``*args`` と ``**kwargs`` が :data:`Any` で型付けされる必要があるため、型チェッカーは ``inner`` 関数を型チェックできません。" + +#: ../../library/typing.rst:2142 +msgid "" +":func:`~cast` may be required in the body of the ``add_logging`` decorator " +"when returning the ``inner`` function, or the static type checker must be " +"told to ignore the ``return inner``." +msgstr "" +"``inner`` 関数を返すときに ``add_logging`` デコレータの本体で :func:`~cast` が必要になるか、" +"または静的型チェッカーに ``return inner`` を無視するように指示する必要があります。" + +#: ../../library/typing.rst:2149 +msgid "" +"Since ``ParamSpec`` captures both positional and keyword parameters, ``P." +"args`` and ``P.kwargs`` can be used to split a ``ParamSpec`` into its " +"components. ``P.args`` represents the tuple of positional parameters in a " +"given call and should only be used to annotate ``*args``. ``P.kwargs`` " +"represents the mapping of keyword parameters to their values in a given " +"call, and should be only be used to annotate ``**kwargs``. Both attributes " +"require the annotated parameter to be in scope. At runtime, ``P.args`` and " +"``P.kwargs`` are instances respectively of :class:`ParamSpecArgs` and :class:" +"`ParamSpecKwargs`." +msgstr "" +"``ParamSpec`` は位置パラメータとキーワードパラメータの両方をキャプチャするため、``P.args`` と ``P.kwargs`` を" +"使用して ``ParamSpec`` をその構成要素に分割できます。``P.args`` は与えられた呼び出しでの位置パラメータの" +"タプルを表し、``*args`` のアノテーションにのみ使用すべきです。``P.kwargs`` は与えられた呼び出しでの" +"キーワードパラメータとその値のマッピングを表し、``**kwargs`` のアノテーションにのみ使用すべきです。" +"両方の属性は、アノテートされたパラメータがスコープ内にあることを必要とします。実行時には、" +"``P.args`` と ``P.kwargs`` はそれぞれ :class:`ParamSpecArgs` と :class:`ParamSpecKwargs` のインスタンスです。" + +#: ../../library/typing.rst:2161 +msgid "The name of the parameter specification." +msgstr "パラメータ仕様の名前。" + +#: ../../library/typing.rst:2165 +msgid "" +"The default value of the parameter specification, or :data:`typing." +"NoDefault` if it has no default." +msgstr "" +"パラメータ仕様のデフォルト値、またはデフォルトがない場合は :data:`typing.NoDefault`。" + +#: ../../library/typing.rst:2172 +msgid "" +"An :term:`evaluate function` corresponding to the :attr:`~ParamSpec." +"__default__` attribute. When called directly, this method supports only the :" +"attr:`~annotationlib.Format.VALUE` format, which is equivalent to accessing " +"the :attr:`~ParamSpec.__default__` attribute directly, but the method object " +"can be passed to :func:`annotationlib.call_evaluate_function` to evaluate " +"the value in a different format." +msgstr "" +":attr:`~ParamSpec.__default__` 属性に対応する :term:`評価関数` です。直接呼び出された場合、このメソッドは " +":attr:`~annotationlib.Format.VALUE` 形式のみをサポートします。これは :attr:`~ParamSpec.__default__` 属性に" +"直接アクセスするのと同等ですが、メソッドオブジェクトを :func:`annotationlib.call_evaluate_function` に渡して" +"異なる形式で値を評価することができます。" + +#: ../../library/typing.rst:2182 +msgid "" +"Return whether or not the parameter specification has a default value. This " +"is equivalent to checking whether :attr:`__default__` is not the :data:" +"`typing.NoDefault` singleton, except that it does not force evaluation of " +"the :ref:`lazily evaluated ` default value." +msgstr "" +"パラメータ仕様がデフォルト値を持つかどうかを返します。これは :attr:`__default__` が :data:`typing.NoDefault` " +"シングルトンでないかをチェックするのと同等ですが、:ref:`遅延評価 ` されるデフォルト値の" +"評価を強制しません。" + +#: ../../library/typing.rst:2189 +msgid "" +"Parameter specification variables created with ``covariant=True`` or " +"``contravariant=True`` can be used to declare covariant or contravariant " +"generic types. The ``bound`` argument is also accepted, similar to :class:" +"`TypeVar`. However the actual semantics of these keywords are yet to be " +"decided." +msgstr "" +"``covariant=True`` または ``contravariant=True`` で作成されたパラメータ仕様変数は、共変または反変の" +"ジェネリック型を宣言するために使用できます。:class:`TypeVar` と同様に ``bound`` 引数も受け付けられます。" +"しかし、これらのキーワードの実際のセマンティクスはまだ決定されていません。" + +#: ../../library/typing.rst:2199 +msgid "" +"Parameter specifications can now be declared using the :ref:`type parameter " +"` syntax introduced by :pep:`695`." +msgstr "" +"パラメータ仕様は :pep:`695` で導入された :ref:`型パラメータ ` 構文を使用して宣言できるようになりました。" + +#: ../../library/typing.rst:2207 +msgid "" +"Only parameter specification variables defined in global scope can be " +"pickled." +msgstr "" +"グローバルスコープで定義されたパラメータ仕様変数のみが pickle 可能です。" + +#: ../../library/typing.rst:2213 +msgid ":data:`Concatenate`" +msgstr ":data:`Concatenate`" + +#: ../../library/typing.rst:2219 +msgid "" +"Arguments and keyword arguments attributes of a :class:`ParamSpec`. The ``P." +"args`` attribute of a ``ParamSpec`` is an instance of ``ParamSpecArgs``, and " +"``P.kwargs`` is an instance of ``ParamSpecKwargs``. They are intended for " +"runtime introspection and have no special meaning to static type checkers." +msgstr "" +":class:`ParamSpec` の引数とキーワード引数の属性です。``ParamSpec`` の ``P.args`` 属性は ``ParamSpecArgs`` のインスタンスで、" +"``P.kwargs`` は ``ParamSpecKwargs`` のインスタンスです。これらは実行時のイントロスペクションを意図しており、" +"静的型チェッカーにとって特別な意味はありません。" + +#: ../../library/typing.rst:2224 +msgid "" +"Calling :func:`get_origin` on either of these objects will return the " +"original ``ParamSpec``:" +msgstr "" +"これらのオブジェクトのいずれかに対して :func:`get_origin` を呼び出すと、元の ``ParamSpec`` が返されます:" + +#: ../../library/typing.rst:2227 +msgid "" +">>> from typing import ParamSpec, get_origin\n" +">>> P = ParamSpec(\"P\")\n" +">>> get_origin(P.args) is P\n" +"True\n" +">>> get_origin(P.kwargs) is P\n" +"True" +msgstr "" +">>> from typing import ParamSpec, get_origin\n" +">>> P = ParamSpec(\"P\")\n" +">>> get_origin(P.args) is P\n" +"True\n" +">>> get_origin(P.kwargs) is P\n" +"True" + +#: ../../library/typing.rst:2241 +msgid "The type of type aliases created through the :keyword:`type` statement." +msgstr ":keyword:`type` 文を通じて作成された型エイリアスの型。" + +#: ../../library/typing.rst:2245 +msgid "" +">>> type Alias = int\n" +">>> type(Alias)\n" +"" +msgstr "" +">>> type Alias = int\n" +">>> type(Alias)\n" +"" + +#: ../../library/typing.rst:2255 +msgid "The name of the type alias:" +msgstr "型エイリアスの名前:" + +#: ../../library/typing.rst:2257 +msgid "" +">>> type Alias = int\n" +">>> Alias.__name__\n" +"'Alias'" +msgstr "" +">>> type Alias = int\n" +">>> Alias.__name__\n" +"'Alias'" + +#: ../../library/typing.rst:2265 +msgid "The module in which the type alias was defined::" +msgstr "型エイリアスが定義されたモジュール::" + +#: ../../library/typing.rst:2267 +msgid "" +">>> type Alias = int\n" +">>> Alias.__module__\n" +"'__main__'" +msgstr "" +">>> type Alias = int\n" +">>> Alias.__module__\n" +"'__main__'" + +#: ../../library/typing.rst:2273 +msgid "" +"The type parameters of the type alias, or an empty tuple if the alias is not " +"generic:" +msgstr "" +"型エイリアスの型パラメータ、またはエイリアスがジェネリックでない場合は空のタプル:" + +#: ../../library/typing.rst:2276 +msgid "" +">>> type ListOrSet[T] = list[T] | set[T]\n" +">>> ListOrSet.__type_params__\n" +"(T,)\n" +">>> type NotGeneric = int\n" +">>> NotGeneric.__type_params__\n" +"()" +msgstr "" +">>> type ListOrSet[T] = list[T] | set[T]\n" +">>> ListOrSet.__type_params__\n" +"(T,)\n" +">>> type NotGeneric = int\n" +">>> NotGeneric.__type_params__\n" +"()" + +#: ../../library/typing.rst:2287 +msgid "" +"The type alias's value. This is :ref:`lazily evaluated `, " +"so names used in the definition of the alias are not resolved until the " +"``__value__`` attribute is accessed:" +msgstr "" +"型エイリアスの値。これは :ref:`遅延評価 ` されるため、エイリアスの定義で使用される名前は" +"``__value__`` 属性がアクセスされるまで解決されません:" + +#: ../../library/typing.rst:2291 +msgid "" +">>> type Mutually = Recursive\n" +">>> type Recursive = Mutually\n" +">>> Mutually\n" +"Mutually\n" +">>> Recursive\n" +"Recursive\n" +">>> Mutually.__value__\n" +"Recursive\n" +">>> Recursive.__value__\n" +"Mutually" +msgstr "" +">>> type Mutually = Recursive\n" +">>> type Recursive = Mutually\n" +">>> Mutually\n" +"Mutually\n" +">>> Recursive\n" +"Recursive\n" +">>> Mutually.__value__\n" +"Recursive\n" +">>> Recursive.__value__\n" +"Mutually" + +#: ../../library/typing.rst:2306 +msgid "" +"An :term:`evaluate function` corresponding to the :attr:`__value__` " +"attribute. When called directly, this method supports only the :attr:" +"`~annotationlib.Format.VALUE` format, which is equivalent to accessing the :" +"attr:`__value__` attribute directly, but the method object can be passed to :" +"func:`annotationlib.call_evaluate_function` to evaluate the value in a " +"different format:" +msgstr "" +":attr:`__value__` 属性に対応する :term:`評価関数` です。直接呼び出された場合、このメソッドは " +":attr:`~annotationlib.Format.VALUE` 形式のみをサポートします。これは :attr:`__value__` 属性に直接" +"アクセスするのと同等ですが、メソッドオブジェクトを :func:`annotationlib.call_evaluate_function` に渡して" +"異なる形式で値を評価することができます:" + +#: ../../library/typing.rst:2312 +msgid "" +">>> type Alias = undefined\n" +">>> Alias.__value__\n" +"Traceback (most recent call last):\n" +"...\n" +"NameError: name 'undefined' is not defined\n" +">>> from annotationlib import Format, call_evaluate_function\n" +">>> Alias.evaluate_value(Format.VALUE)\n" +"Traceback (most recent call last):\n" +"...\n" +"NameError: name 'undefined' is not defined\n" +">>> call_evaluate_function(Alias.evaluate_value, Format.FORWARDREF)\n" +"ForwardRef('undefined')" +msgstr "" +">>> type Alias = undefined\n" +">>> Alias.__value__\n" +"Traceback (most recent call last):\n" +"...\n" +"NameError: name 'undefined' is not defined\n" +">>> from annotationlib import Format, call_evaluate_function\n" +">>> Alias.evaluate_value(Format.VALUE)\n" +"Traceback (most recent call last):\n" +"...\n" +"NameError: name 'undefined' is not defined\n" +">>> call_evaluate_function(Alias.evaluate_value, Format.FORWARDREF)\n" +"ForwardRef('undefined')" + +#: ../../library/typing.rst:2330 +msgid "Unpacking" +msgstr "展開" + +#: ../../library/typing.rst:2331 +msgid "" +"Type aliases support star unpacking using the ``*Alias`` syntax. This is " +"equivalent to using ``Unpack[Alias]`` directly:" +msgstr "" +"型エイリアスは ``*Alias`` 構文を使用してスター展開をサポートします。これは ``Unpack[Alias]`` を直接使用するのと等価です:" + +#: ../../library/typing.rst:2334 +msgid "" +">>> type Alias = tuple[int, str]\n" +">>> type Unpacked = tuple[bool, *Alias]\n" +">>> Unpacked.__value__\n" +"tuple[bool, typing.Unpack[Alias]]" +msgstr "" +">>> type Alias = tuple[int, str]\n" +">>> type Unpacked = tuple[bool, *Alias]\n" +">>> Unpacked.__value__\n" +"tuple[bool, typing.Unpack[Alias]]" + +#: ../../library/typing.rst:2345 +msgid "Other special directives" +msgstr "その他の特別なディレクティブ" + +#: ../../library/typing.rst:2347 +msgid "" +"These functions and classes should not be used directly as annotations. " +"Their intended purpose is to be building blocks for creating and declaring " +"types." +msgstr "" +"これらの関数とクラスは直接アノテーションとして使用すべきではありません。これらの意図された目的は、" +"型を作成し宣言するための構成要素となることです。" + +#: ../../library/typing.rst:2353 +msgid "Typed version of :func:`collections.namedtuple`." +msgstr ":func:`collections.namedtuple` の型付き版です。" + +#: ../../library/typing.rst:2355 ../../library/typing.rst:2451 +#: ../../library/typing.rst:3545 +msgid "Usage::" +msgstr "使い方::" + +#: ../../library/typing.rst:2357 +msgid "" +"class Employee(NamedTuple):\n" +" name: str\n" +" id: int" +msgstr "" +"class Employee(NamedTuple):\n" +" name: str\n" +" id: int" + +#: ../../library/typing.rst:2361 +msgid "This is equivalent to::" +msgstr "これは次と等価です::" + +#: ../../library/typing.rst:2363 +msgid "Employee = collections.namedtuple('Employee', ['name', 'id'])" +msgstr "Employee = collections.namedtuple('Employee', ['name', 'id'])" + +#: ../../library/typing.rst:2365 +msgid "" +"To give a field a default value, you can assign to it in the class body::" +msgstr "フィールドにデフォルト値を与えるにはクラス本体で代入してください::" + +#: ../../library/typing.rst:2367 +msgid "" +"class Employee(NamedTuple):\n" +" name: str\n" +" id: int = 3\n" +"\n" +"employee = Employee('Guido')\n" +"assert employee.id == 3" +msgstr "" +"class Employee(NamedTuple):\n" +" name: str\n" +" id: int = 3\n" +"\n" +"employee = Employee('Guido')\n" +"assert employee.id == 3" + +#: ../../library/typing.rst:2374 +msgid "" +"Fields with a default value must come after any fields without a default." +msgstr "" +"デフォルト値のあるフィールドはデフォルト値のないフィールドの後でなければなり" +"ません。" + +#: ../../library/typing.rst:2376 +msgid "" +"The resulting class has an extra attribute ``__annotations__`` giving a dict " +"that maps the field names to the field types. (The field names are in the " +"``_fields`` attribute and the default values are in the ``_field_defaults`` " +"attribute, both of which are part of the :func:`~collections.namedtuple` " +"API.)" +msgstr "" +"最終的に出来上がるクラスには、フィールド名をフィールド型へ対応付ける辞書を提" +"供する ``__annotations__`` 属性が追加されています。\n" +"(フィールド名は ``_fields`` 属性に、デフォルト値は ``_field_defaults`` 属性に" +"格納されていて、両方とも :func:`~collections.namedtuple` API の一部分です。)" + +#: ../../library/typing.rst:2382 +msgid "``NamedTuple`` subclasses can also have docstrings and methods::" +msgstr "``NamedTuple`` のサブクラスは docstring やメソッドも持てます::" + +#: ../../library/typing.rst:2384 +msgid "" +"class Employee(NamedTuple):\n" +" \"\"\"Represents an employee.\"\"\"\n" +" name: str\n" +" id: int = 3\n" +"\n" +" def __repr__(self) -> str:\n" +" return f''" +msgstr "" +"class Employee(NamedTuple):\n" +" \"\"\"従業員を表す。\"\"\"\n" +" name: str\n" +" id: int = 3\n" +"\n" +" def __repr__(self) -> str:\n" +" return f''" + +#: ../../library/typing.rst:2392 +msgid "``NamedTuple`` subclasses can be generic::" +msgstr "``NamedTuple`` のサブクラスはジェネリックにできます::" + +#: ../../library/typing.rst:2394 +msgid "" +"class Group[T](NamedTuple):\n" +" key: T\n" +" group: list[T]" +msgstr "" +"class Group[T](NamedTuple):\n" +" key: T\n" +" group: list[T]" + +#: ../../library/typing.rst:2398 +msgid "Backward-compatible usage::" +msgstr "後方互換な使用法::" + +#: ../../library/typing.rst:2400 +msgid "" +"# For creating a generic NamedTuple on Python 3.11\n" +"T = TypeVar(\"T\")\n" +"\n" +"class Group(NamedTuple, Generic[T]):\n" +" key: T\n" +" group: list[T]\n" +"\n" +"# A functional syntax is also supported\n" +"Employee = NamedTuple('Employee', [('name', str), ('id', int)])" +msgstr "" +"# Python 3.11 でジェネリック NamedTuple を作成する場合\n" +"T = TypeVar(\"T\")\n" +"\n" +"class Group(NamedTuple, Generic[T]):\n" +" key: T\n" +" group: list[T]\n" +"\n" +"# 関数的構文もサポートされています\n" +"Employee = NamedTuple('Employee', [('name', str), ('id', int)])" + +#: ../../library/typing.rst:2410 +msgid "Added support for :pep:`526` variable annotation syntax." +msgstr ":pep:`526` 変数アノテーションのシンタックスが追加されました。" + +#: ../../library/typing.rst:2413 +msgid "Added support for default values, methods, and docstrings." +msgstr "" +"デフォルト値、メソッド、ドキュメンテーション文字列への対応が追加されました。" + +#: ../../library/typing.rst:2416 +msgid "" +"The ``_field_types`` and ``__annotations__`` attributes are now regular " +"dictionaries instead of instances of ``OrderedDict``." +msgstr "" +"``_field_types`` 属性および ``__annotations__`` 属性は ``OrderedDict`` インス" +"タンスではなく普通の辞書になりました。" + +#: ../../library/typing.rst:2420 +msgid "" +"Removed the ``_field_types`` attribute in favor of the more standard " +"``__annotations__`` attribute which has the same information." +msgstr "" +"``_field_types`` 属性は削除されました。代わりに同じ情報を持つより標準的な " +"``__annotations__`` 属性を使ってください。" + +#: ../../library/typing.rst:2424 +msgid "Added support for generic namedtuples." +msgstr "ジェネリック namedtuple のサポートが追加されました。" + +#: ../../library/typing.rst:2427 +msgid "" +"Using :func:`super` (and the ``__class__`` :term:`closure variable`) in " +"methods of ``NamedTuple`` subclasses is unsupported and causes a :class:" +"`TypeError`." +msgstr "" +"``NamedTuple`` サブクラスのメソッドで :func:`super` (および ``__class__`` :term:`クロージャ変数`)を" +"使用することはサポートされておらず、:class:`TypeError` を引き起こします。" + +#: ../../library/typing.rst:2431 +msgid "" +"The undocumented keyword argument syntax for creating NamedTuple classes " +"(``NT = NamedTuple(\"NT\", x=int)``) is deprecated, and will be disallowed " +"in 3.15. Use the class-based syntax or the functional syntax instead." +msgstr "" +"NamedTuple クラスを作成するための非文書化キーワード引数構文(``NT = NamedTuple(\"NT\", x=int)``)は" +"非推奨であり、3.15 で禁止されます。代わりにクラスベース構文または関数的構文を使用してください。" + +#: ../../library/typing.rst:2436 +msgid "" +"When using the functional syntax to create a NamedTuple class, failing to " +"pass a value to the 'fields' parameter (``NT = NamedTuple(\"NT\")``) is " +"deprecated. Passing ``None`` to the 'fields' parameter (``NT = " +"NamedTuple(\"NT\", None)``) is also deprecated. Both will be disallowed in " +"Python 3.15. To create a NamedTuple class with 0 fields, use ``class " +"NT(NamedTuple): pass`` or ``NT = NamedTuple(\"NT\", [])``." +msgstr "" +"関数的構文を使用して NamedTuple クラスを作成する際に、'fields' パラメータに値を渡さない" +"(``NT = NamedTuple(\"NT\")``)ことは非推奨です。'fields' パラメータに ``None`` を渡す" +"(``NT = NamedTuple(\"NT\", None)``)ことも非推奨です。どちらも Python 3.15 で禁止されます。" +"0個のフィールドを持つ NamedTuple クラスを作成するには、``class NT(NamedTuple): pass`` または " +"``NT = NamedTuple(\"NT\", [])`` を使用してください。" + +#: ../../library/typing.rst:2446 +msgid "Helper class to create low-overhead :ref:`distinct types `." +msgstr "低オーバーヘッドの :ref:`独立した型 ` を作成するためのヘルパークラス。" + +#: ../../library/typing.rst:2448 +msgid "" +"A ``NewType`` is considered a distinct type by a typechecker. At runtime, " +"however, calling a ``NewType`` returns its argument unchanged." +msgstr "" +"``NewType`` は型チェッカーによって独立した型とみなされます。しかし実行時には、``NewType`` を呼び出すと" +"引数を変更せずに返します。" + +#: ../../library/typing.rst:2453 +msgid "" +"UserId = NewType('UserId', int) # Declare the NewType \"UserId\"\n" +"first_user = UserId(1) # \"UserId\" returns the argument unchanged at " +"runtime" +msgstr "" +"UserId = NewType('UserId', int) # NewType \"UserId\" を宣言\n" +"first_user = UserId(1) # \"UserId\" は実行時に引数を変更せずに返す" + +#: ../../library/typing.rst:2458 +msgid "The module in which the new type is defined." +msgstr "新しい型が定義されたモジュール。" + +#: ../../library/typing.rst:2462 +msgid "The name of the new type." +msgstr "新しい型の名前。" + +#: ../../library/typing.rst:2466 +msgid "The type that the new type is based on." +msgstr "新しい型のベースとなる型。" + +#: ../../library/typing.rst:2470 +msgid "``NewType`` is now a class rather than a function." +msgstr "``NewType`` は関数ではなくクラスになりました。" + +#: ../../library/typing.rst:2475 +msgid "Base class for protocol classes." +msgstr "プロトコルクラスの基底クラス。" + +#: ../../library/typing.rst:2477 +msgid "Protocol classes are defined like this::" +msgstr "プロトコルクラスは次のように定義します::" + +#: ../../library/typing.rst:2479 +msgid "" +"class Proto(Protocol):\n" +" def meth(self) -> int:\n" +" ..." +msgstr "" +"class Proto(Protocol):\n" +" def meth(self) -> int:\n" +" ..." + +#: ../../library/typing.rst:2483 +msgid "" +"Such classes are primarily used with static type checkers that recognize " +"structural subtyping (static duck-typing), for example::" +msgstr "" +"このようなクラスは主に構造的部分型 (静的ダックタイピング) を認識する静的型" +"チェッカーが使います。例えば::" + +#: ../../library/typing.rst:2486 +msgid "" +"class C:\n" +" def meth(self) -> int:\n" +" return 0\n" +"\n" +"def func(x: Proto) -> int:\n" +" return x.meth()\n" +"\n" +"func(C()) # Passes static type check" +msgstr "" +"class C:\n" +" def meth(self) -> int:\n" +" return 0\n" +"\n" +"def func(x: Proto) -> int:\n" +" return x.meth()\n" +"\n" +"func(C()) # 静的型チェックをパス" + +#: ../../library/typing.rst:2495 +msgid "" +"See :pep:`544` for more details. Protocol classes decorated with :func:" +"`runtime_checkable` (described later) act as simple-minded runtime protocols " +"that check only the presence of given attributes, ignoring their type " +"signatures. Protocol classes without this decorator cannot be used as the " +"second argument to :func:`isinstance` or :func:`issubclass`." +msgstr "" +"詳細については :pep:`544` を参照してください。:func:`runtime_checkable` (後述)でデコレートされた" +"プロトコルクラスは、与えられた属性の存在のみをチェックし、その型シグネチャを無視する" +"単純な実行時プロトコルとして動作します。このデコレータがないプロトコルクラスは、" +":func:`isinstance` や :func:`issubclass` の第2引数として使用できません。" + +#: ../../library/typing.rst:2501 +msgid "Protocol classes can be generic, for example::" +msgstr "プロトコルクラスはジェネリックにもできます。例えば::" + +#: ../../library/typing.rst:2503 +msgid "" +"class GenProto[T](Protocol):\n" +" def meth(self) -> T:\n" +" ..." +msgstr "" +"class GenProto[T](Protocol):\n" +" def meth(self) -> T:\n" +" ..." + +#: ../../library/typing.rst:2507 +msgid "" +"In code that needs to be compatible with Python 3.11 or older, generic " +"Protocols can be written as follows::" +msgstr "" +"Python 3.11 以前との互換性が必要なコードでは、ジェネリックプロトコルは次のように書くことができます::" + +#: ../../library/typing.rst:2510 +msgid "" +"T = TypeVar(\"T\")\n" +"\n" +"class GenProto(Protocol[T]):\n" +" def meth(self) -> T:\n" +" ..." +msgstr "" +"T = TypeVar(\"T\")\n" +"\n" +"class GenProto(Protocol[T]):\n" +" def meth(self) -> T:\n" +" ..." + +#: ../../library/typing.rst:2520 +msgid "Mark a protocol class as a runtime protocol." +msgstr "プロトコルクラスを実行時プロトコルとしてマークします。" + +#: ../../library/typing.rst:2522 +msgid "" +"Such a protocol can be used with :func:`isinstance` and :func:`issubclass`. " +"This allows a simple-minded structural check, very similar to \"one trick " +"ponies\" in :mod:`collections.abc` such as :class:`~collections.abc." +"Iterable`. For example::" +msgstr "" +"このようなプロトコルは :func:`isinstance` や :func:`issubclass` と組み合わせて使用できます。" +"これにより、:mod:`collections.abc` の :class:`~collections.abc.Iterable` などの「ワントリックポニー」と非常に" +"似た単純な構造チェックが可能になります。例えば::" + +#: ../../library/typing.rst:2526 +msgid "" +"@runtime_checkable\n" +"class Closable(Protocol):\n" +" def close(self): ...\n" +"\n" +"assert isinstance(open('/some/file'), Closable)\n" +"\n" +"@runtime_checkable\n" +"class Named(Protocol):\n" +" name: str\n" +"\n" +"import threading\n" +"assert isinstance(threading.Thread(name='Bob'), Named)" +msgstr "" +"@runtime_checkable\n" +"class Closable(Protocol):\n" +" def close(self): ...\n" +"\n" +"assert isinstance(open('/some/file'), Closable)\n" +"\n" +"@runtime_checkable\n" +"class Named(Protocol):\n" +" name: str\n" +"\n" +"import threading\n" +"assert isinstance(threading.Thread(name='Bob'), Named)" + +#: ../../library/typing.rst:2539 +msgid "" +"This decorator raises :exc:`TypeError` when applied to a non-protocol class." +msgstr "" +"このデコレータは非プロトコルクラスに適用されたときに :exc:`TypeError` を発生させます。" + +#: ../../library/typing.rst:2543 +msgid "" +":func:`!runtime_checkable` will check only the presence of the required " +"methods or attributes, not their type signatures or types. For example, :" +"class:`ssl.SSLObject` is a class, therefore it passes an :func:`issubclass` " +"check against :ref:`Callable `. However, the ``ssl." +"SSLObject.__init__`` method exists only to raise a :exc:`TypeError` with a " +"more informative message, therefore making it impossible to call " +"(instantiate) :class:`ssl.SSLObject`." +msgstr "" +":func:`!runtime_checkable` は必要なメソッドや属性の存在のみをチェックし、その型シグネチャや型はチェックしません。" +"例えば、:class:`ssl.SSLObject` はクラスであるため、:ref:`Callable ` に対する " +":func:`issubclass` チェックをパスします。しかし、``ssl.SSLObject.__init__`` メソッドはより情報性のあるメッセージで " +":exc:`TypeError` を発生させるためだけに存在し、:class:`ssl.SSLObject` を呼び出す(インスタンス化する)ことを" +"不可能にしています。" + +#: ../../library/typing.rst:2554 +msgid "" +"An :func:`isinstance` check against a runtime-checkable protocol can be " +"surprisingly slow compared to an ``isinstance()`` check against a non-" +"protocol class. Consider using alternative idioms such as :func:`hasattr` " +"calls for structural checks in performance-sensitive code." +msgstr "" +"実行時チェック可能プロトコルに対する :func:`isinstance` チェックは、非プロトコルクラスに対する " +"``isinstance()`` チェックと比較して驚くほど遅い場合があります。パフォーマンスを重視するコードでは、" +"構造チェックのために :func:`hasattr` 呼び出しなどの代替手法の使用を検討してください。" + +#: ../../library/typing.rst:2562 +msgid "" +"The internal implementation of :func:`isinstance` checks against runtime-" +"checkable protocols now uses :func:`inspect.getattr_static` to look up " +"attributes (previously, :func:`hasattr` was used). As a result, some objects " +"which used to be considered instances of a runtime-checkable protocol may no " +"longer be considered instances of that protocol on Python 3.12+, and vice " +"versa. Most users are unlikely to be affected by this change." +msgstr "" +"実行時チェック可能プロトコルに対する :func:`isinstance` チェックの内部実装は、属性を検索するために" +":func:`inspect.getattr_static` を使用するようになりました(以前は :func:`hasattr` が使用されていました)。" +"その結果、以前は実行時チェック可能プロトコルのインスタンスとみなされていた一部のオブジェクトが、" +"Python 3.12+ ではそのプロトコルのインスタンスとみなされなくなる可能性があります(その逆も同様)。" +"ほとんどのユーザーはこの変更の影響を受ける可能性は低いでしょう。" + +#: ../../library/typing.rst:2571 +msgid "" +"The members of a runtime-checkable protocol are now considered \"frozen\" at " +"runtime as soon as the class has been created. Monkey-patching attributes " +"onto a runtime-checkable protocol will still work, but will have no impact " +"on :func:`isinstance` checks comparing objects to the protocol. See :ref:" +"`\"What's new in Python 3.12\" ` for more details." +msgstr "" +"実行時チェック可能プロトコルのメンバーは、クラスが作成されると即座に実行時に「凍結」されるようになりました。" +"実行時チェック可能プロトコルに属性をモンキーパッチすることは引き続き機能しますが、" +"オブジェクトとプロトコルを比較する :func:`isinstance` チェックには影響しません。" +"詳細については :ref:`\"What's new in Python 3.12\" ` を参照してください。" + +#: ../../library/typing.rst:2582 +msgid "" +"Special construct to add type hints to a dictionary. At runtime it is a " +"plain :class:`dict`." +msgstr "" +"辞書に型ヒントを追加するための特別な構造です。実行時には通常の :class:`dict` です。" + +#: ../../library/typing.rst:2585 +msgid "" +"``TypedDict`` declares a dictionary type that expects all of its instances " +"to have a certain set of keys, where each key is associated with a value of " +"a consistent type. This expectation is not checked at runtime but is only " +"enforced by type checkers. Usage::" +msgstr "" +"``TypedDict`` は、その全てのインスタンスにおいてキーの集合が固定されていて、" +"各キーに対応する値が全てのインスタンスで同じ型を持つことが期待される辞書型を" +"宣言します。\n" +"この期待は実行時にはチェックされず、型チェッカーでのみ強制されます。\n" +"使用方法は次の通りです::" + +#: ../../library/typing.rst:2591 +msgid "" +"class Point2D(TypedDict):\n" +" x: int\n" +" y: int\n" +" label: str\n" +"\n" +"a: Point2D = {'x': 1, 'y': 2, 'label': 'good'} # OK\n" +"b: Point2D = {'z': 3, 'label': 'bad'} # Fails type check\n" +"\n" +"assert Point2D(x=1, y=2, label='first') == dict(x=1, y=2, label='first')" +msgstr "" +"class Point2D(TypedDict):\n" +" x: int\n" +" y: int\n" +" label: str\n" +"\n" +"a: Point2D = {'x': 1, 'y': 2, 'label': 'good'} # OK\n" +"b: Point2D = {'z': 3, 'label': 'bad'} # 型チェックで失敗\n" +"\n" +"assert Point2D(x=1, y=2, label='first') == dict(x=1, y=2, label='first')" + +#: ../../library/typing.rst:2601 +msgid "" +"An alternative way to create a ``TypedDict`` is by using function-call " +"syntax. The second argument must be a literal :class:`dict`::" +msgstr "" +"``TypedDict`` を作成する代替手法は、関数呼び出し構文を使用することです。第2引数はリテラルの :class:`dict` でなければなりません::" + +#: ../../library/typing.rst:2604 +msgid "Point2D = TypedDict('Point2D', {'x': int, 'y': int, 'label': str})" +msgstr "Point2D = TypedDict('Point2D', {'x': int, 'y': int, 'label': str})" + +#: ../../library/typing.rst:2606 +msgid "" +"This functional syntax allows defining keys which are not valid :ref:" +"`identifiers `, for example because they are keywords or " +"contain hyphens, or when key names must not be :ref:`mangled ` like regular private names::" +msgstr "" +"この関数的構文では、有効な :ref:`識別子 ` でないキーを定義できます。例えば、キーワードであったり、" +"ハイフンを含んでいたり、或いは通常のプライベート名のようにキー名が :ref:`マングル ` " +"されてはいけない場合などです::" + +#: ../../library/typing.rst:2611 +msgid "" +"# raises SyntaxError\n" +"class Point2D(TypedDict):\n" +" in: int # 'in' is a keyword\n" +" x-y: int # name with hyphens\n" +"\n" +"class Definition(TypedDict):\n" +" __schema: str # mangled to `_Definition__schema`\n" +"\n" +"# OK, functional syntax\n" +"Point2D = TypedDict('Point2D', {'in': int, 'x-y': int})\n" +"Definition = TypedDict('Definition', {'__schema': str}) # not mangled" +msgstr "" +"# SyntaxError を発生\n" +"class Point2D(TypedDict):\n" +" in: int # 'in' はキーワード\n" +" x-y: int # ハイフンを含む名前\n" +"\n" +"class Definition(TypedDict):\n" +" __schema: str # `_Definition__schema` にマングルされる\n" +"\n" +"# OK、関数的構文\n" +"Point2D = TypedDict('Point2D', {'in': int, 'x-y': int})\n" +"Definition = TypedDict('Definition', {'__schema': str}) # マングルされない" + +#: ../../library/typing.rst:2623 +msgid "" +"By default, all keys must be present in a ``TypedDict``. It is possible to " +"mark individual keys as non-required using :data:`NotRequired`::" +msgstr "" + +#: ../../library/typing.rst:2626 +msgid "" +"class Point2D(TypedDict):\n" +" x: int\n" +" y: int\n" +" label: NotRequired[str]\n" +"\n" +"# Alternative syntax\n" +"Point2D = TypedDict('Point2D', {'x': int, 'y': int, 'label': " +"NotRequired[str]})" +msgstr "" + +#: ../../library/typing.rst:2634 +msgid "" +"This means that a ``Point2D`` ``TypedDict`` can have the ``label`` key " +"omitted." +msgstr "" + +#: ../../library/typing.rst:2637 +msgid "" +"It is also possible to mark all keys as non-required by default by " +"specifying a totality of ``False``::" +msgstr "" + +#: ../../library/typing.rst:2640 +msgid "" +"class Point2D(TypedDict, total=False):\n" +" x: int\n" +" y: int\n" +"\n" +"# Alternative syntax\n" +"Point2D = TypedDict('Point2D', {'x': int, 'y': int}, total=False)" +msgstr "" + +#: ../../library/typing.rst:2647 +msgid "" +"This means that a ``Point2D`` ``TypedDict`` can have any of the keys " +"omitted. A type checker is only expected to support a literal ``False`` or " +"``True`` as the value of the ``total`` argument. ``True`` is the default, " +"and makes all items defined in the class body required." +msgstr "" + +#: ../../library/typing.rst:2652 +msgid "" +"Individual keys of a ``total=False`` ``TypedDict`` can be marked as required " +"using :data:`Required`::" +msgstr "" + +#: ../../library/typing.rst:2655 +msgid "" +"class Point2D(TypedDict, total=False):\n" +" x: Required[int]\n" +" y: Required[int]\n" +" label: str\n" +"\n" +"# Alternative syntax\n" +"Point2D = TypedDict('Point2D', {\n" +" 'x': Required[int],\n" +" 'y': Required[int],\n" +" 'label': str\n" +"}, total=False)" +msgstr "" + +#: ../../library/typing.rst:2667 +msgid "" +"It is possible for a ``TypedDict`` type to inherit from one or more other " +"``TypedDict`` types using the class-based syntax. Usage::" +msgstr "" + +#: ../../library/typing.rst:2671 +msgid "" +"class Point3D(Point2D):\n" +" z: int" +msgstr "" + +#: ../../library/typing.rst:2674 +msgid "" +"``Point3D`` has three items: ``x``, ``y`` and ``z``. It is equivalent to " +"this definition::" +msgstr "" + +#: ../../library/typing.rst:2677 +msgid "" +"class Point3D(TypedDict):\n" +" x: int\n" +" y: int\n" +" z: int" +msgstr "" + +#: ../../library/typing.rst:2682 +msgid "" +"A ``TypedDict`` cannot inherit from a non-\\ ``TypedDict`` class, except " +"for :class:`Generic`. For example::" +msgstr "" + +#: ../../library/typing.rst:2685 +msgid "" +"class X(TypedDict):\n" +" x: int\n" +"\n" +"class Y(TypedDict):\n" +" y: int\n" +"\n" +"class Z(object): pass # A non-TypedDict class\n" +"\n" +"class XY(X, Y): pass # OK\n" +"\n" +"class XZ(X, Z): pass # raises TypeError" +msgstr "" +"class X(TypedDict):\n" +" x: int\n" +"\n" +"class Y(TypedDict):\n" +" y: int\n" +"\n" +"class Z(object): pass # TypedDict でないクラス\n" +"\n" +"class XY(X, Y): pass # OK\n" +"\n" +"class XZ(X, Z): pass # TypeError を発生" + +#: ../../library/typing.rst:2697 +msgid "A ``TypedDict`` can be generic::" +msgstr "``TypedDict`` はジェネリックにできます::" + +#: ../../library/typing.rst:2699 +msgid "" +"class Group[T](TypedDict):\n" +" key: T\n" +" group: list[T]" +msgstr "" +"class Group[T](TypedDict):\n" +" key: T\n" +" group: list[T]" + +#: ../../library/typing.rst:2703 +msgid "" +"To create a generic ``TypedDict`` that is compatible with Python 3.11 or " +"lower, inherit from :class:`Generic` explicitly:" +msgstr "" +"Python 3.11 以下と互換性のあるジェネリック ``TypedDict`` を作成するには、:class:`Generic` から明示的に継承します:" + +#: ../../library/typing.rst:2706 +msgid "" +"T = TypeVar(\"T\")\n" +"\n" +"class Group(TypedDict, Generic[T]):\n" +" key: T\n" +" group: list[T]" +msgstr "" +"T = TypeVar(\"T\")\n" +"\n" +"class Group(TypedDict, Generic[T]):\n" +" key: T\n" +" group: list[T]" + +#: ../../library/typing.rst:2714 +msgid "" +"A ``TypedDict`` can be introspected via annotations dicts (see :ref:" +"`annotations-howto` for more information on annotations best practices), :" +"attr:`__total__`, :attr:`__required_keys__`, and :attr:`__optional_keys__`." +msgstr "" +"``TypedDict`` はアノテーション辞書(アノテーションのベストプラクティスの詳細については " +":ref:`annotations-howto` を参照)、:attr:`__total__`、:attr:`__required_keys__`、:attr:`__optional_keys__` を通じて" +"イントロスペクションできます。" + +#: ../../library/typing.rst:2720 +msgid "" +"``Point2D.__total__`` gives the value of the ``total`` argument. Example:" +msgstr "" +"``Point2D.__total__`` は ``total`` 引数の値を返します。例:" + +#: ../../library/typing.rst:2723 +msgid "" +">>> from typing import TypedDict\n" +">>> class Point2D(TypedDict): pass\n" +">>> Point2D.__total__\n" +"True\n" +">>> class Point2D(TypedDict, total=False): pass\n" +">>> Point2D.__total__\n" +"False\n" +">>> class Point3D(Point2D): pass\n" +">>> Point3D.__total__\n" +"True" +msgstr "" +">>> from typing import TypedDict\n" +">>> class Point2D(TypedDict): pass\n" +">>> Point2D.__total__\n" +"True\n" +">>> class Point2D(TypedDict, total=False): pass\n" +">>> Point2D.__total__\n" +"False\n" +">>> class Point3D(Point2D): pass\n" +">>> Point3D.__total__\n" +"True" + +#: ../../library/typing.rst:2736 +msgid "" +"This attribute reflects *only* the value of the ``total`` argument to the " +"current ``TypedDict`` class, not whether the class is semantically total. " +"For example, a ``TypedDict`` with ``__total__`` set to ``True`` may have " +"keys marked with :data:`NotRequired`, or it may inherit from another " +"``TypedDict`` with ``total=False``. Therefore, it is generally better to " +"use :attr:`__required_keys__` and :attr:`__optional_keys__` for " +"introspection." +msgstr "" +"この属性は、現在の ``TypedDict`` クラスの ``total`` 引数の値 *のみ* を反映し、クラスが意味的に total かどうかは反映しません。" +"例えば、``__total__`` が ``True`` に設定された ``TypedDict`` でも :data:`NotRequired` でマークされたキーを持つ場合や、" +"``total=False`` の別の ``TypedDict`` から継承している場合があります。そのため、イントロスペクションには" +"一般的に :attr:`__required_keys__` と :attr:`__optional_keys__` を使用する方が良いでしょう。" + +#: ../../library/typing.rst:2749 +msgid "" +"``Point2D.__required_keys__`` and ``Point2D.__optional_keys__`` return :" +"class:`frozenset` objects containing required and non-required keys, " +"respectively." +msgstr "" + +#: ../../library/typing.rst:2752 +msgid "" +"Keys marked with :data:`Required` will always appear in " +"``__required_keys__`` and keys marked with :data:`NotRequired` will always " +"appear in ``__optional_keys__``." +msgstr "" + +#: ../../library/typing.rst:2755 +msgid "" +"For backwards compatibility with Python 3.10 and below, it is also possible " +"to use inheritance to declare both required and non-required keys in the " +"same ``TypedDict`` . This is done by declaring a ``TypedDict`` with one " +"value for the ``total`` argument and then inheriting from it in another " +"``TypedDict`` with a different value for ``total``:" +msgstr "" + +#: ../../library/typing.rst:2762 +msgid "" +">>> class Point2D(TypedDict, total=False):\n" +"... x: int\n" +"... y: int\n" +"...\n" +">>> class Point3D(Point2D):\n" +"... z: int\n" +"...\n" +">>> Point3D.__required_keys__ == frozenset({'z'})\n" +"True\n" +">>> Point3D.__optional_keys__ == frozenset({'x', 'y'})\n" +"True" +msgstr "" + +#: ../../library/typing.rst:2780 +msgid "" +"If ``from __future__ import annotations`` is used or if annotations are " +"given as strings, annotations are not evaluated when the ``TypedDict`` is " +"defined. Therefore, the runtime introspection that ``__required_keys__`` and " +"``__optional_keys__`` rely on may not work properly, and the values of the " +"attributes may be incorrect." +msgstr "" + +#: ../../library/typing.rst:2786 +msgid "Support for :data:`ReadOnly` is reflected in the following attributes:" +msgstr "" + +#: ../../library/typing.rst:2790 +msgid "" +"A :class:`frozenset` containing the names of all read-only keys. Keys are " +"read-only if they carry the :data:`ReadOnly` qualifier." +msgstr "" + +#: ../../library/typing.rst:2797 +msgid "" +"A :class:`frozenset` containing the names of all mutable keys. Keys are " +"mutable if they do not carry the :data:`ReadOnly` qualifier." +msgstr "" + +#: ../../library/typing.rst:2802 +msgid "" +"See the `TypedDict `_ section in the typing documentation for more examples and " +"detailed rules." +msgstr "" + +#: ../../library/typing.rst:2806 +msgid "" +"Added support for marking individual keys as :data:`Required` or :data:" +"`NotRequired`. See :pep:`655`." +msgstr "" + +#: ../../library/typing.rst:2810 +msgid "Added support for generic ``TypedDict``\\ s." +msgstr "" + +#: ../../library/typing.rst:2813 +msgid "" +"Removed support for the keyword-argument method of creating ``TypedDict``\\ " +"s." +msgstr "" + +#: ../../library/typing.rst:2816 +msgid "Support for the :data:`ReadOnly` qualifier was added." +msgstr "" + +#: ../../library/typing.rst:2819 +msgid "" +"When using the functional syntax to create a TypedDict class, failing to " +"pass a value to the 'fields' parameter (``TD = TypedDict(\"TD\")``) is " +"deprecated. Passing ``None`` to the 'fields' parameter (``TD = " +"TypedDict(\"TD\", None)``) is also deprecated. Both will be disallowed in " +"Python 3.15. To create a TypedDict class with 0 fields, use ``class " +"TD(TypedDict): pass`` or ``TD = TypedDict(\"TD\", {})``." +msgstr "" + +#: ../../library/typing.rst:2828 +msgid "Protocols" +msgstr "プロトコル" + +#: ../../library/typing.rst:2830 +msgid "" +"The following protocols are provided by the :mod:`!typing` module. All are " +"decorated with :func:`@runtime_checkable `." +msgstr "" + +#: ../../library/typing.rst:2835 +msgid "" +"An ABC with one abstract method ``__abs__`` that is covariant in its return " +"type." +msgstr "返り値の型と共変な抽象メソッド ``__abs__`` を備えた ABC です。" + +#: ../../library/typing.rst:2840 +msgid "An ABC with one abstract method ``__bytes__``." +msgstr "抽象メソッド ``__bytes__`` を備えた ABC です。" + +#: ../../library/typing.rst:2844 +msgid "An ABC with one abstract method ``__complex__``." +msgstr "抽象メソッド ``__complex__`` を備えた ABC です。" + +#: ../../library/typing.rst:2848 +msgid "An ABC with one abstract method ``__float__``." +msgstr "抽象メソッド ``__float__`` を備えた ABC です。" + +#: ../../library/typing.rst:2852 +msgid "An ABC with one abstract method ``__index__``." +msgstr "抽象メソッド ``__index__`` を備えた ABC です。" + +#: ../../library/typing.rst:2858 +msgid "An ABC with one abstract method ``__int__``." +msgstr "抽象メソッド ``__int__`` を備えた ABC です。" + +#: ../../library/typing.rst:2862 +msgid "" +"An ABC with one abstract method ``__round__`` that is covariant in its " +"return type." +msgstr "返り値の型と共変な抽象メソッド ``__round__`` を備えた ABC です。" + +#: ../../library/typing.rst:2868 +msgid "ABCs and Protocols for working with I/O" +msgstr "I/O を扱うための ABC とプロトコル" + +#: ../../library/typing.rst:2874 +msgid "" +"Generic class ``IO[AnyStr]`` and its subclasses ``TextIO(IO[str])`` and " +"``BinaryIO(IO[bytes])`` represent the types of I/O streams such as returned " +"by :func:`open`. Please note that these classes are not protocols, and their " +"interface is fairly broad." +msgstr "" +"ジェネリッククラス ``IO[AnyStr]`` とそのサブクラス ``TextIO(IO[str])`` および " +"``BinaryIO(IO[bytes])`` は、:func:`open` により返されるような I/O ストリームの型を表します。" +"これらのクラスはプロトコルではなく、そのインターフェースはかなり広範囲であることに注意してください。" + +#: ../../library/typing.rst:2880 +msgid "" +"The protocols :class:`io.Reader` and :class:`io.Writer` offer a simpler " +"alternative for argument types, when only the ``read()`` or ``write()`` " +"methods are accessed, respectively::" +msgstr "" +"プロトコル :class:`io.Reader` と :class:`io.Writer` は、それぞれ ``read()`` メソッドまたは ``write()`` メソッドのみにアクセスする場合において、" +"引数の型のより簡潔な代替手段を提供します::" + +#: ../../library/typing.rst:2884 +msgid "" +"def read_and_write(reader: Reader[str], writer: Writer[bytes]):\n" +" data = reader.read()\n" +" writer.write(data.encode())" +msgstr "" + +#: ../../library/typing.rst:2888 +msgid "" +"Also consider using :class:`collections.abc.Iterable` for iterating over the " +"lines of an input stream::" +msgstr "" +"入力ストリームの行を反復処理するために、:class:`collections.abc.Iterable` の使用も検討してください::" + +#: ../../library/typing.rst:2891 +msgid "" +"def read_config(stream: Iterable[str]):\n" +" for line in stream:\n" +" ..." +msgstr "" + +#: ../../library/typing.rst:2896 +msgid "Functions and decorators" +msgstr "関数とデコレーター" + +#: ../../library/typing.rst:2900 +msgid "Cast a value to a type." +msgstr "値をある型にキャストします。" + +#: ../../library/typing.rst:2902 +msgid "" +"This returns the value unchanged. To the type checker this signals that the " +"return value has the designated type, but at runtime we intentionally don't " +"check anything (we want this to be as fast as possible)." +msgstr "" +"この関数は値を変更せずに返します。\n" +"型検査器に対して、返り値が指定された型を持っていることを通知しますが、実行時" +"には意図的に何も検査しません。\n" +"(その理由は、処理をできる限り速くしたかったためです。)" + +#: ../../library/typing.rst:2909 +msgid "" +"Ask a static type checker to confirm that *val* has an inferred type of " +"*typ*." +msgstr "" +"静的型チェッカーに対し、*val* の推論された型が *typ* であることを確認するよう求めます。" + +#: ../../library/typing.rst:2911 +msgid "" +"At runtime this does nothing: it returns the first argument unchanged with " +"no checks or side effects, no matter the actual type of the argument." +msgstr "" +"実行時にこの関数は何もしません。引数の実際の型に関係なく、最初の引数を変更せずに返し、" +"検査や副作用は一切ありません。" + +#: ../../library/typing.rst:2914 +msgid "" +"When a static type checker encounters a call to ``assert_type()``, it emits " +"an error if the value is not of the specified type::" +msgstr "" +"静的型チェッカーが ``assert_type()`` の呼び出しに遭遇すると、値が指定された型でない場合にエラーを発生させます::" + +#: ../../library/typing.rst:2917 +msgid "" +"def greet(name: str) -> None:\n" +" assert_type(name, str) # OK, inferred type of `name` is `str`\n" +" assert_type(name, int) # type checker error" +msgstr "" + +#: ../../library/typing.rst:2921 +msgid "" +"This function is useful for ensuring the type checker's understanding of a " +"script is in line with the developer's intentions::" +msgstr "" +"この関数は、型チェッカーのスクリプトの理解が開発者の意図と一致することを確認するのに有用です::" + +#: ../../library/typing.rst:2924 +msgid "" +"def complex_function(arg: object):\n" +" # Do some complex type-narrowing logic,\n" +" # after which we hope the inferred type will be `int`\n" +" ...\n" +" # Test whether the type checker correctly understands our function\n" +" assert_type(arg, int)" +msgstr "" + +#: ../../library/typing.rst:2935 +msgid "" +"Ask a static type checker to confirm that a line of code is unreachable." +msgstr "" +"静的型チェッカーに対し、コードの行が到達不能であることを確認するよう求めます。" + +#: ../../library/typing.rst:2937 +msgid "Example::" +msgstr "以下はプログラム例です::" + +#: ../../library/typing.rst:2939 +msgid "" +"def int_or_str(arg: int | str) -> None:\n" +" match arg:\n" +" case int():\n" +" print(\"It's an int\")\n" +" case str():\n" +" print(\"It's a str\")\n" +" case _ as unreachable:\n" +" assert_never(unreachable)" +msgstr "" + +#: ../../library/typing.rst:2948 +msgid "" +"Here, the annotations allow the type checker to infer that the last case can " +"never execute, because ``arg`` is either an :class:`int` or a :class:`str`, " +"and both options are covered by earlier cases." +msgstr "" +"ここで、アノテーションにより型チェッカーは最後のケースが決して実行されないことを推論できます。" +"なぜなら ``arg`` は :class:`int` または :class:`str` のいずれかであり、" +"両方の選択肢は以前のケースで網羅されているからです。" + +#: ../../library/typing.rst:2953 +msgid "" +"If a type checker finds that a call to ``assert_never()`` is reachable, it " +"will emit an error. For example, if the type annotation for ``arg`` was " +"instead ``int | str | float``, the type checker would emit an error pointing " +"out that ``unreachable`` is of type :class:`float`. For a call to " +"``assert_never`` to pass type checking, the inferred type of the argument " +"passed in must be the bottom type, :data:`Never`, and nothing else." +msgstr "" +"型チェッカーが ``assert_never()`` の呼び出しが到達可能であることを発見すると、エラーを発生させます。" +"例えば、``arg`` の型アノテーションが ``int | str | float`` であった場合、" +"型チェッカーは ``unreachable`` が :class:`float` 型であることを指摘するエラーを発生させるでしょう。" +"``assert_never`` の呼び出しが型チェックを通過するためには、" +"渡された引数の推論された型はボトム型である :data:`Never` でなければならず、それ以外は許可されません。" + +#: ../../library/typing.rst:2961 +msgid "At runtime, this throws an exception when called." +msgstr "実行時に、この関数は呼び出されると例外を発生させます。" + +#: ../../library/typing.rst:2964 +msgid "" +"`Unreachable Code and Exhaustiveness Checking `__ has more information about exhaustiveness " +"checking with static typing." +msgstr "" +"`Unreachable Code and Exhaustiveness Checking `__ には、静的型付けによる網羅性チェックについての詳しい情報があります。" + +#: ../../library/typing.rst:2972 +msgid "Ask a static type checker to reveal the inferred type of an expression." +msgstr "静的型チェッカーに対し、式の推論された型を明示するよう求めます。" + +#: ../../library/typing.rst:2974 +msgid "" +"When a static type checker encounters a call to this function, it emits a " +"diagnostic with the inferred type of the argument. For example::" +msgstr "" +"静的型チェッカーがこの関数の呼び出しに遭遇すると、引数の推論された型と共に診断メッセージを発行します。例::" + +#: ../../library/typing.rst:2977 +msgid "" +"x: int = 1\n" +"reveal_type(x) # Revealed type is \"builtins.int\"" +msgstr "" + +#: ../../library/typing.rst:2980 +msgid "" +"This can be useful when you want to debug how your type checker handles a " +"particular piece of code." +msgstr "" +"これは、型チェッカーが特定のコードをどのように扱うかをデバッグしたい場合に有用です。" + +#: ../../library/typing.rst:2983 +msgid "" +"At runtime, this function prints the runtime type of its argument to :data:" +"`sys.stderr` and returns the argument unchanged (allowing the call to be " +"used within an expression)::" +msgstr "" +"実行時に、この関数は引数の実行時型を :data:`sys.stderr` に出力し、引数を変更せずに返します" +"(これにより、呼び出しを式内で使用できます)::" + +#: ../../library/typing.rst:2987 +msgid "" +"x = reveal_type(1) # prints \"Runtime type is int\"\n" +"print(x) # prints \"1\"" +msgstr "" + +#: ../../library/typing.rst:2990 +msgid "" +"Note that the runtime type may be different from (more or less specific " +"than) the type statically inferred by a type checker." +msgstr "" +"実行時型は、型チェッカーにより静的に推論された型と異なる場合があることに注意してください。" +"(より具体的であったり、より抽象的であったりすることがあります。)" + +#: ../../library/typing.rst:2993 +msgid "" +"Most type checkers support ``reveal_type()`` anywhere, even if the name is " +"not imported from ``typing``. Importing the name from ``typing``, however, " +"allows your code to run without runtime errors and communicates intent more " +"clearly." +msgstr "" +"ほとんどの型チェッカーは、名前が ``typing`` からインポートされていなくても、どこででも ``reveal_type()`` をサポートします。" +"しかし、``typing`` から名前をインポートすることで、コードが実行時エラーなしで実行されるようになり、意図もより明確に伝わります。" + +#: ../../library/typing.rst:3004 +msgid "" +"Decorator to mark an object as providing :func:`dataclass `-like behavior." +msgstr "" +"オブジェクトが :func:`dataclass ` のような動作を提供することをマークするデコレーターです。" + +#: ../../library/typing.rst:3007 +msgid "" +"``dataclass_transform`` may be used to decorate a class, metaclass, or a " +"function that is itself a decorator. The presence of " +"``@dataclass_transform()`` tells a static type checker that the decorated " +"object performs runtime \"magic\" that transforms a class in a similar way " +"to :func:`@dataclasses.dataclass `." +msgstr "" +"``dataclass_transform`` は、クラス、メタクラス、またはデコレーターである関数を装飾するために使用できます。" +"``@dataclass_transform()`` の存在は、静的型チェッカーに対して、装飾されたオブジェクトが、" +":func:`@dataclasses.dataclass ` と同様の方法でクラスを変換する実行時の「魔法」を実行することを告げます。" + +#: ../../library/typing.rst:3014 +msgid "Example usage with a decorator function:" +msgstr "デコレーター関数での使用例:" + +#: ../../library/typing.rst:3016 +msgid "" +"@dataclass_transform()\n" +"def create_model[T](cls: type[T]) -> type[T]:\n" +" ...\n" +" return cls\n" +"\n" +"@create_model\n" +"class CustomerModel:\n" +" id: int\n" +" name: str" +msgstr "" + +#: ../../library/typing.rst:3028 +msgid "On a base class::" +msgstr "ベースクラスでの使用::" + +#: ../../library/typing.rst:3030 +msgid "" +"@dataclass_transform()\n" +"class ModelBase: ...\n" +"\n" +"class CustomerModel(ModelBase):\n" +" id: int\n" +" name: str" +msgstr "" + +#: ../../library/typing.rst:3037 +msgid "On a metaclass::" +msgstr "メタクラスでの使用::" + +#: ../../library/typing.rst:3039 +msgid "" +"@dataclass_transform()\n" +"class ModelMeta(type): ...\n" +"\n" +"class ModelBase(metaclass=ModelMeta): ...\n" +"\n" +"class CustomerModel(ModelBase):\n" +" id: int\n" +" name: str" +msgstr "" + +#: ../../library/typing.rst:3048 +msgid "" +"The ``CustomerModel`` classes defined above will be treated by type checkers " +"similarly to classes created with :func:`@dataclasses.dataclass `. For example, type checkers will assume these classes have " +"``__init__`` methods that accept ``id`` and ``name``." +msgstr "" +"上記で定義した ``CustomerModel`` クラスは、型チェッカーにより、" +":func:`@dataclasses.dataclass ` で作成されたクラスと同様に扱われます。" +"例えば、型チェッカーは、これらのクラスは ``id`` と ``name`` を受け取る ``__init__`` メソッドを持っていると仮定します。" + +#: ../../library/typing.rst:3054 +msgid "" +"The decorated class, metaclass, or function may accept the following bool " +"arguments which type checkers will assume have the same effect as they would " +"have on the :func:`@dataclasses.dataclass` decorator: " +"``init``, ``eq``, ``order``, ``unsafe_hash``, ``frozen``, ``match_args``, " +"``kw_only``, and ``slots``. It must be possible for the value of these " +"arguments (``True`` or ``False``) to be statically evaluated." +msgstr "" +"装飾されたクラス、メタクラス、または関数は、以下のbool引数を受け取ることができます。" +"型チェッカーは、これらの引数が :func:`@dataclasses.dataclass` デコレーターでの効果と同じであると仮定します: " +"``init``、``eq``、``order``、``unsafe_hash``、``frozen``、``match_args``、``kw_only``、``slots``。" +"これらの引数の値(``True`` または ``False``)は静的に評価できる必要があります。" + +#: ../../library/typing.rst:3062 +msgid "" +"The arguments to the ``dataclass_transform`` decorator can be used to " +"customize the default behaviors of the decorated class, metaclass, or " +"function:" +msgstr "" +"``dataclass_transform`` デコレーターへの引数を使用して、装飾されたクラス、メタクラス、または関数のデフォルト動作をカスタマイズできます:" + +#: ../../library/typing.rst:0 +msgid "Parameters" +msgstr "パラメーター" + +#: ../../library/typing.rst:3066 +msgid "" +"Indicates whether the ``eq`` parameter is assumed to be ``True`` or " +"``False`` if it is omitted by the caller. Defaults to ``True``." +msgstr "" +"呼び出し元が省略した場合、``eq`` パラメーターが ``True`` と ``False`` のどちらであると仮定されるかを示します。" +"デフォルトは ``True`` です。" + +#: ../../library/typing.rst:3071 +msgid "" +"Indicates whether the ``order`` parameter is assumed to be ``True`` or " +"``False`` if it is omitted by the caller. Defaults to ``False``." +msgstr "" +"呼び出し元が省略した場合、``order`` パラメーターが ``True`` と ``False`` のどちらであると仮定されるかを示します。" +"デフォルトは ``False`` です。" + +#: ../../library/typing.rst:3076 +msgid "" +"Indicates whether the ``kw_only`` parameter is assumed to be ``True`` or " +"``False`` if it is omitted by the caller. Defaults to ``False``." +msgstr "" +"呼び出し元が省略した場合、``kw_only`` パラメーターが ``True`` と ``False`` のどちらであると仮定されるかを示します。" +"デフォルトは ``False`` です。" + +#: ../../library/typing.rst:3081 +msgid "" +"Indicates whether the ``frozen`` parameter is assumed to be ``True`` or " +"``False`` if it is omitted by the caller. Defaults to ``False``. .. " +"versionadded:: 3.12" +msgstr "" +"呼び出し元が省略した場合、``frozen`` パラメーターが ``True`` と ``False`` のどちらであると仮定されるかを示します。" +"デフォルトは ``False`` です。 .. versionadded:: 3.12" + +#: ../../library/typing.rst:3082 +msgid "" +"Indicates whether the ``frozen`` parameter is assumed to be ``True`` or " +"``False`` if it is omitted by the caller. Defaults to ``False``." +msgstr "" +"呼び出し元が省略した場合、``frozen`` パラメーターが ``True`` と ``False`` のどちらであると仮定されるかを示します。" +"デフォルトは ``False`` です。" + +#: ../../library/typing.rst:3088 +msgid "" +"Specifies a static list of supported classes or functions that describe " +"fields, similar to :func:`dataclasses.field`. Defaults to ``()``." +msgstr "" +"フィールドを記述するサポートされたクラスまたは関数の静的リストを指定します。" +":func:`dataclasses.field` と同様です。デフォルトは ``()`` です。" + +#: ../../library/typing.rst:3094 +msgid "" +"Arbitrary other keyword arguments are accepted in order to allow for " +"possible future extensions." +msgstr "" +"将来的な拡張を可能にするために、任意のその他のキーワード引数が受け入れられます。" + +#: ../../library/typing.rst:3098 +msgid "" +"Type checkers recognize the following optional parameters on field " +"specifiers:" +msgstr "" +"型チェッカーは、フィールド指定子の以下のオプションパラメーターを認識します:" + +#: ../../library/typing.rst:3101 +msgid "**Recognised parameters for field specifiers**" +msgstr "**フィールド指定子の認識されるパラメーター**" + +#: ../../library/typing.rst:3105 +msgid "Parameter name" +msgstr "パラメーター名" + +#: ../../library/typing.rst:3106 +msgid "Description" +msgstr "説明" + +#: ../../library/typing.rst:3107 +msgid "``init``" +msgstr "" + +#: ../../library/typing.rst:3108 +msgid "" +"Indicates whether the field should be included in the synthesized " +"``__init__`` method. If unspecified, ``init`` defaults to ``True``." +msgstr "" +"フィールドが合成された ``__init__`` メソッドに含まれるべきかどうかを示します。" +"指定されない場合、``init`` のデフォルトは ``True`` です。" + +#: ../../library/typing.rst:3111 +msgid "``default``" +msgstr "``default``" + +#: ../../library/typing.rst:3112 +msgid "Provides the default value for the field." +msgstr "フィールドのデフォルト値を提供します。" + +#: ../../library/typing.rst:3113 +msgid "``default_factory``" +msgstr "``default_factory``" + +#: ../../library/typing.rst:3114 +msgid "" +"Provides a runtime callback that returns the default value for the field. If " +"neither ``default`` nor ``default_factory`` are specified, the field is " +"assumed to have no default value and must be provided a value when the class " +"is instantiated." +msgstr "" +"フィールドのデフォルト値を返す実行時コールバックを提供します。" +"``default`` と ``default_factory`` のどちらも指定されていない場合、フィールドにデフォルト値はないとみなされ、" +"クラスのインスタンス化時に値を提供しなければなりません。" + +#: ../../library/typing.rst:3119 +msgid "``factory``" +msgstr "``factory``" + +#: ../../library/typing.rst:3120 +msgid "An alias for the ``default_factory`` parameter on field specifiers." +msgstr "フィールド指定子の ``default_factory`` パラメーターのエイリアスです。" + +#: ../../library/typing.rst:3121 +msgid "``kw_only``" +msgstr "``kw_only``" + +#: ../../library/typing.rst:3122 +msgid "" +"Indicates whether the field should be marked as keyword-only. If ``True``, " +"the field will be keyword-only. If ``False``, it will not be keyword-only. " +"If unspecified, the value of the ``kw_only`` parameter on the object " +"decorated with ``dataclass_transform`` will be used, or if that is " +"unspecified, the value of ``kw_only_default`` on ``dataclass_transform`` " +"will be used." +msgstr "" +"フィールドがキーワード専用としてマークされるべきかどうかを示します。" +"``True`` の場合、フィールドはキーワード専用になります。" +"``False`` の場合、キーワード専用にはなりません。" +"指定されない場合、``dataclass_transform`` で装飾されたオブジェクトの ``kw_only`` パラメーターの値が使用されます。" +"それも指定されない場合、``dataclass_transform`` の ``kw_only_default`` の値が使用されます。" + +#: ../../library/typing.rst:3128 +msgid "``alias``" +msgstr "``alias``" + +#: ../../library/typing.rst:3129 +msgid "" +"Provides an alternative name for the field. This alternative name is used in " +"the synthesized ``__init__`` method." +msgstr "" +"フィールドの代替名を提供します。この代替名は合成された ``__init__`` メソッドで使用されます。" + +#: ../../library/typing.rst:3132 +msgid "" +"At runtime, this decorator records its arguments in the " +"``__dataclass_transform__`` attribute on the decorated object. It has no " +"other runtime effect." +msgstr "" +"実行時に、このデコレーターはその引数を装飾されたオブジェクトの ``__dataclass_transform__`` 属性に記録します。" +"それ以外の実行時の効果はありません。" + +#: ../../library/typing.rst:3136 +msgid "See :pep:`681` for more details." +msgstr "より詳しくは :pep:`681` を参照してください。" + +#: ../../library/typing.rst:3144 +msgid "Decorator for creating overloaded functions and methods." +msgstr "オーバーロードされた関数やメソッドを作成するためのデコレーターです。" + +#: ../../library/typing.rst:3146 +msgid "" +"The ``@overload`` decorator allows describing functions and methods that " +"support multiple different combinations of argument types. A series of " +"``@overload``-decorated definitions must be followed by exactly one non-" +"``@overload``-decorated definition (for the same function/method)." +msgstr "" +"``@overload`` デコレーターにより、引数の型の異なる組み合わせを複数サポートする関数やメソッドを記述できます。" +"``@overload`` で装飾された一連の定義の後には、その関数/メソッドに対して正確に一つの非 ``@overload`` 装飾の定義が必須です。" + +#: ../../library/typing.rst:3151 +msgid "" +"``@overload``-decorated definitions are for the benefit of the type checker " +"only, since they will be overwritten by the non-``@overload``-decorated " +"definition. The non-``@overload``-decorated definition, meanwhile, will be " +"used at runtime but should be ignored by a type checker. At runtime, " +"calling an ``@overload``-decorated function directly will raise :exc:" +"`NotImplementedError`." +msgstr "" +"``@overload`` で装飾された定義は型チェッカーのためだけのもので、非 ``@overload`` 装飾の定義で上書きされます。" +"一方、非 ``@overload`` 装飾の定義は実行時に使用されますが、型チェッカーはこれを無視するべきです。" +"実行時に ``@overload`` 装飾の関数を直接呼び出すと :exc:`NotImplementedError` が発生します。" + +#: ../../library/typing.rst:3159 +msgid "" +"An example of overload that gives a more precise type than can be expressed " +"using a union or a type variable:" +msgstr "" +"ユニオンや型変数では表現できない、より精密な型を提供するオーバーロードの例:" + +#: ../../library/typing.rst:3162 +msgid "" +"@overload\n" +"def process(response: None) -> None:\n" +" ...\n" +"@overload\n" +"def process(response: int) -> tuple[int, str]:\n" +" ...\n" +"@overload\n" +"def process(response: bytes) -> str:\n" +" ...\n" +"def process(response):\n" +" ... # actual implementation goes here" +msgstr "" + +#: ../../library/typing.rst:3176 +msgid "" +"See :pep:`484` for more details and comparison with other typing semantics." +msgstr "詳細と他の型付け意味論との比較は :pep:`484` を参照してください。" + +#: ../../library/typing.rst:3178 +msgid "" +"Overloaded functions can now be introspected at runtime using :func:" +"`get_overloads`." +msgstr "" +"オーバーロードされた関数は、今や :func:`get_overloads` を使用して実行時にイントロスペクトできます。" + +#: ../../library/typing.rst:3185 +msgid "" +"Return a sequence of :func:`@overload `-decorated definitions for " +"*func*." +msgstr "" +"*func* の :func:`@overload ` で装飾された定義のシーケンスを返します。" + +#: ../../library/typing.rst:3188 +msgid "" +"*func* is the function object for the implementation of the overloaded " +"function. For example, given the definition of ``process`` in the " +"documentation for :func:`@overload `, ``get_overloads(process)`` " +"will return a sequence of three function objects for the three defined " +"overloads. If called on a function with no overloads, ``get_overloads()`` " +"returns an empty sequence." +msgstr "" +"*func* はオーバーロードされた関数の実装の関数オブジェクトです。" +"例えば、:func:`@overload ` のドキュメントの ``process`` の定義がある場合、" +"``get_overloads(process)`` は定義された3つのオーバーロードに対して、3つの関数オブジェクトのシーケンスを返します。" +"オーバーロードがない関数で呼び出された場合、``get_overloads()`` は空のシーケンスを返します。" + +#: ../../library/typing.rst:3195 +msgid "" +"``get_overloads()`` can be used for introspecting an overloaded function at " +"runtime." +msgstr "" +"``get_overloads()`` は実行時にオーバーロードされた関数をイントロスペクトするために使用できます。" + +#: ../../library/typing.rst:3203 +msgid "Clear all registered overloads in the internal registry." +msgstr "内部レジストリの登録されたすべてのオーバーロードをクリアします。" + +#: ../../library/typing.rst:3205 +msgid "This can be used to reclaim the memory used by the registry." +msgstr "これはレジストリにより使用されたメモリを回収するために使用できます。" + +#: ../../library/typing.rst:3212 +msgid "Decorator to indicate final methods and final classes." +msgstr "ファイナルメソッドとファイナルクラスを示すデコレーターです。" + +#: ../../library/typing.rst:3214 +msgid "" +"Decorating a method with ``@final`` indicates to a type checker that the " +"method cannot be overridden in a subclass. Decorating a class with " +"``@final`` indicates that it cannot be subclassed." +msgstr "" +"メソッドを ``@final`` で装飾することで、型チェッカーに対して、そのメソッドがサブクラスでオーバーライドできないことを示します。" +"クラスを ``@final`` で装飾することで、そのクラスがサブクラス化できないことを示します。" + +#: ../../library/typing.rst:3220 +msgid "" +"class Base:\n" +" @final\n" +" def done(self) -> None:\n" +" ...\n" +"class Sub(Base):\n" +" def done(self) -> None: # Error reported by type checker\n" +" ...\n" +"\n" +"@final\n" +"class Leaf:\n" +" ...\n" +"class Other(Leaf): # Error reported by type checker\n" +" ..." +msgstr "" + +#: ../../library/typing.rst:3239 +msgid "" +"The decorator will now attempt to set a ``__final__`` attribute to ``True`` " +"on the decorated object. Thus, a check like ``if getattr(obj, \"__final__\", " +"False)`` can be used at runtime to determine whether an object ``obj`` has " +"been marked as final. If the decorated object does not support setting " +"attributes, the decorator returns the object unchanged without raising an " +"exception." +msgstr "" +"デコレーターは装飾されたオブジェクトの ``__final__`` 属性を ``True`` に設定しようとします。" +"したがって、``if getattr(obj, \"__final__\", False)`` のようなチェックを実行時に使用して、" +"オブジェクト ``obj`` がファイナルとしてマークされているかどうかを判定できます。" +"装飾されたオブジェクトが属性の設定をサポートしていない場合、" +"デコレーターは例外を発生させることなく、オブジェクトを変更せずに返します。" + +#: ../../library/typing.rst:3250 +msgid "Decorator to indicate that annotations are not type hints." +msgstr "アノテーションが型ヒントでないことを示すデコレータです。" + +#: ../../library/typing.rst:3252 +msgid "" +"This works as a class or function :term:`decorator`. With a class, it " +"applies recursively to all methods and classes defined in that class (but " +"not to methods defined in its superclasses or subclasses). Type checkers " +"will ignore all annotations in a function or class with this decorator." +msgstr "" +"これはクラスまたは関数の :term:`decorator` として機能します。クラスでは、そのクラスで定義されたすべてのメソッドやクラスに再帰的に適用されます。" +"(しかし、そのスーパークラスやサブクラスで定義されたメソッドには適用されません。)" +"型チェッカーは、このデコレーターが付いた関数やクラスのすべてのアノテーションを無視します。" + +#: ../../library/typing.rst:3258 +msgid "``@no_type_check`` mutates the decorated object in place." +msgstr "``@no_type_check`` は装飾されたオブジェクトをインプレースで変更します。" + +#: ../../library/typing.rst:3262 +msgid "Decorator to give another decorator the :func:`no_type_check` effect." +msgstr "別のデコレータに :func:`no_type_check` の効果を与えるデコレータです。" + +#: ../../library/typing.rst:3264 +msgid "" +"This wraps the decorator with something that wraps the decorated function " +"in :func:`no_type_check`." +msgstr "" +"これはデコレーターを、装飾された関数を :func:`no_type_check` でラップするものでラップします。" +"これは何かの関数をラップするデコレータを :func:`no_type_check` でラップしま" +"す。" + +#: ../../library/typing.rst:3267 +msgid "" +"No type checker ever added support for ``@no_type_check_decorator``. It is " +"therefore deprecated, and will be removed in Python 3.15." +msgstr "" +"どの型チェッカーも ``@no_type_check_decorator`` のサポートを追加しませんでした。" +"そのためこれは非推奨となり、Python 3.15 で削除される予定です。" + +#: ../../library/typing.rst:3273 +msgid "" +"Decorator to indicate that a method in a subclass is intended to override a " +"method or attribute in a superclass." +msgstr "" +"サブクラスのメソッドがスーパークラスのメソッドまたは属性をオーバーライドすることを意図していることを示すデコレーターです。" + +#: ../../library/typing.rst:3276 +msgid "" +"Type checkers should emit an error if a method decorated with ``@override`` " +"does not, in fact, override anything. This helps prevent bugs that may occur " +"when a base class is changed without an equivalent change to a child class." +msgstr "" +"型チェッカーは、``@override`` で装飾されたメソッドが実際には何もオーバーライドしていない場合にエラーを発生させるべきです。" +"これは、ベースクラスが変更されたのに子クラスが同等に変更されない場合に発生する可能性のあるバグを防ぐのに役立ちます。" + +#: ../../library/typing.rst:3283 +msgid "" +"class Base:\n" +" def log_status(self) -> None:\n" +" ...\n" +"\n" +"class Sub(Base):\n" +" @override\n" +" def log_status(self) -> None: # Okay: overrides Base.log_status\n" +" ...\n" +"\n" +" @override\n" +" def done(self) -> None: # Error reported by type checker\n" +" ..." +msgstr "" + +#: ../../library/typing.rst:3298 +msgid "There is no runtime checking of this property." +msgstr "このプロパティの実行時チェックはありません。" + +#: ../../library/typing.rst:3300 +msgid "" +"The decorator will attempt to set an ``__override__`` attribute to ``True`` " +"on the decorated object. Thus, a check like ``if getattr(obj, " +"\"__override__\", False)`` can be used at runtime to determine whether an " +"object ``obj`` has been marked as an override. If the decorated object does " +"not support setting attributes, the decorator returns the object unchanged " +"without raising an exception." +msgstr "" +"デコレーターは装飾されたオブジェクトの ``__override__`` 属性を ``True`` に設定しようとします。" +"したがって、``if getattr(obj, \"__override__\", False)`` のようなチェックを実行時に使用して、" +"オブジェクト ``obj`` がオーバーライドとしてマークされているかどうかを判定できます。" +"装飾されたオブジェクトが属性の設定をサポートしていない場合、" +"デコレーターは例外を発生させることなく、オブジェクトを変更せずに返します。" + +#: ../../library/typing.rst:3307 +msgid "See :pep:`698` for more details." +msgstr "詳細は :pep:`698` を参照してください。" + +#: ../../library/typing.rst:3314 +msgid "Decorator to mark a class or function as unavailable at runtime." +msgstr "クラスまたは関数が実行時に利用できないことをマークするデコレーターです。" + +#: ../../library/typing.rst:3316 +msgid "" +"This decorator is itself not available at runtime. It is mainly intended to " +"mark classes that are defined in type stub files if an implementation " +"returns an instance of a private class::" +msgstr "" +"このデコレータ自身は実行時には使えません。\n" +"このデコレータは主に、実装がプライベートクラスのインスタンスを返す場合に、型" +"スタブファイルに定義されているクラスに対して印を付けるためのものです::" + +#: ../../library/typing.rst:3320 +msgid "" +"@type_check_only\n" +"class Response: # private or not available at runtime\n" +" code: int\n" +" def get_header(self, name: str) -> str: ...\n" +"\n" +"def fetch_response() -> Response: ..." +msgstr "" + +#: ../../library/typing.rst:3327 +msgid "" +"Note that returning instances of private classes is not recommended. It is " +"usually preferable to make such classes public." +msgstr "" +"プライベートクラスのインスタンスを返すのは推奨されません。\n" +"そのようなクラスは公開クラスにするのが望ましいです。" + +#: ../../library/typing.rst:3331 +msgid "Introspection helpers" +msgstr "イントロスペクションヘルパー" + +#: ../../library/typing.rst:3335 +msgid "" +"Return a dictionary containing type hints for a function, method, module or " +"class object." +msgstr "" +"関数、メソッド、モジュールまたはクラスのオブジェクトの型ヒントを含む辞書を返" +"します。" + +#: ../../library/typing.rst:3338 +msgid "" +"This is often the same as ``obj.__annotations__``, but this function makes " +"the following changes to the annotations dictionary:" +msgstr "" +"これは通常 ``obj.__annotations__`` と同じですが、この関数はアノテーション辞書に以下の変更を加えます:" + +#: ../../library/typing.rst:3341 +msgid "" +"Forward references encoded as string literals or :class:`ForwardRef` objects " +"are handled by evaluating them in *globalns*, *localns*, and (where " +"applicable) *obj*'s :ref:`type parameter ` namespace. If " +"*globalns* or *localns* is not given, appropriate namespace dictionaries are " +"inferred from *obj*." +msgstr "" +"文字列リテラルや :class:`ForwardRef` オブジェクトとしてエンコードされた前方参照は、" +"*globalns*、*localns*、および(該当する場合)*obj* の :ref:`type parameter ` 名前空間で評価することによって処理されます。" +"*globalns* や *localns* が与えられない場合、適切な名前空間辞書が *obj* から推論されます。" + +#: ../../library/typing.rst:3346 +msgid "``None`` is replaced with :class:`types.NoneType`." +msgstr "``None`` は :class:`types.NoneType` で置き換えられます。" + +#: ../../library/typing.rst:3347 +msgid "" +"If :func:`@no_type_check ` has been applied to *obj*, an " +"empty dictionary is returned." +msgstr "" +"*obj* に :func:`@no_type_check ` が適用されている場合、空の辞書が返されます。" + +#: ../../library/typing.rst:3349 +msgid "" +"If *obj* is a class ``C``, the function returns a dictionary that merges " +"annotations from ``C``'s base classes with those on ``C`` directly. This is " +"done by traversing :attr:`C.__mro__ ` and iteratively " +"combining ``__annotations__`` dictionaries. Annotations on classes appearing " +"earlier in the :term:`method resolution order` always take precedence over " +"annotations on classes appearing later in the method resolution order." +msgstr "" +"*obj* がクラス ``C`` の場合、この関数は ``C`` のベースクラスからのアノテーションと ``C`` 上のアノテーションを直接マージした辞書を返します。" +"これは :attr:`C.__mro__ ` を辺って ``__annotations__`` 辞書を反復的に結合することで行われます。" +":term:`method resolution order` の早い段階で登場するクラスのアノテーションは、" +"後の段階で登場するクラスのアノテーションより常に優先されます。" + +#: ../../library/typing.rst:3356 +msgid "" +"The function recursively replaces all occurrences of ``Annotated[T, ...]`` " +"with ``T``, unless *include_extras* is set to ``True`` (see :class:" +"`Annotated` for more information)." +msgstr "" +"この関数は、*include_extras* が ``True`` に設定されていない限り、" +"すべての ``Annotated[T, ...]`` を ``T`` で再帰的に置き換えます。" +"(詳細は :class:`Annotated` を参照してください。)" + +#: ../../library/typing.rst:3360 +msgid "" +"See also :func:`inspect.get_annotations`, a lower-level function that " +"returns annotations more directly." +msgstr "" +"より直接的にアノテーションを返す低レベル関数である :func:`inspect.get_annotations` も参照してください。" + +#: ../../library/typing.rst:3365 +msgid "" +"If any forward references in the annotations of *obj* are not resolvable or " +"are not valid Python code, this function will raise an exception such as :" +"exc:`NameError`. For example, this can happen with imported :ref:`type " +"aliases ` that include forward references, or with names " +"imported under :data:`if TYPE_CHECKING `." +msgstr "" +"*obj* のアノテーションの前方参照が解決できないか、有効なPythonコードでない場合、" +"この関数は :exc:`NameError` などの例外を発生させます。" +"例えば、前方参照を含むインポートされた :ref:`type aliases ` や、" +":data:`if TYPE_CHECKING ` の下でインポートされた名前でこれが発生する可能性があります。" + +#: ../../library/typing.rst:3371 +msgid "" +"Added ``include_extras`` parameter as part of :pep:`593`. See the " +"documentation on :data:`Annotated` for more information." +msgstr "" +":pep:`593` の一部として ``include_extras`` パラメーターが追加されました。" +"詳細は :data:`Annotated` のドキュメントを参照してください。" + +#: ../../library/typing.rst:3375 +msgid "" +"Previously, ``Optional[t]`` was added for function and method annotations if " +"a default value equal to ``None`` was set. Now the annotation is returned " +"unchanged." +msgstr "" +"以前は、デフォルト値が ``None`` に設定されている場合、関数やメソッドのアノテーションに ``Optional[t]`` が追加されていました。" +"現在はアノテーションは変更されずに返されます。" + +#: ../../library/typing.rst:3382 +msgid "" +"Get the unsubscripted version of a type: for a typing object of the form " +"``X[Y, Z, ...]`` return ``X``." +msgstr "" +"型の非サブスクリプト版を取得します: ``X[Y, Z, ...]`` の形の型付けオブジェクトに対して ``X`` を返します。" + +#: ../../library/typing.rst:3385 +msgid "" +"If ``X`` is a typing-module alias for a builtin or :mod:`collections` class, " +"it will be normalized to the original class. If ``X`` is an instance of :" +"class:`ParamSpecArgs` or :class:`ParamSpecKwargs`, return the underlying :" +"class:`ParamSpec`. Return ``None`` for unsupported objects." +msgstr "" +"``X`` が組み込みクラスや :mod:`collections` クラスのための typing モジュールのエイリアスである場合、" +"元のクラスに正規化されます。" +"``X`` が :class:`ParamSpecArgs` や :class:`ParamSpecKwargs` のインスタンスである場合、" +"基礎となる :class:`ParamSpec` を返します。サポートされていないオブジェクトには ``None`` を返します。" + +#: ../../library/typing.rst:3391 ../../library/typing.rst:3415 +msgid "Examples:" +msgstr "例:" + +#: ../../library/typing.rst:3393 +msgid "" +"assert get_origin(str) is None\n" +"assert get_origin(Dict[str, int]) is dict\n" +"assert get_origin(Union[int, str]) is Union\n" +"assert get_origin(Annotated[str, \"metadata\"]) is Annotated\n" +"P = ParamSpec('P')\n" +"assert get_origin(P.args) is P\n" +"assert get_origin(P.kwargs) is P" +msgstr "" + +#: ../../library/typing.rst:3407 +msgid "" +"Get type arguments with all substitutions performed: for a typing object of " +"the form ``X[Y, Z, ...]`` return ``(Y, Z, ...)``." +msgstr "" +"すべての置換が実行された型引数を取得します: ``X[Y, Z, ...]`` の形の型付けオブジェクトに対して ``(Y, Z, ...)`` を返します。" + +#: ../../library/typing.rst:3410 +msgid "" +"If ``X`` is a union or :class:`Literal` contained in another generic type, " +"the order of ``(Y, Z, ...)`` may be different from the order of the original " +"arguments ``[Y, Z, ...]`` due to type caching. Return ``()`` for unsupported " +"objects." +msgstr "" +"``X`` が、他のジェネリック型に含まれるユニオンや :class:`Literal` である場合、" +"型キャッシュのために ``(Y, Z, ...)`` の順序が元の引数 ``[Y, Z, ...]`` の順序と異なる場合があります。" +"サポートされていないオブジェクトには ``()`` を返します。" + +#: ../../library/typing.rst:3417 +msgid "" +"assert get_args(int) == ()\n" +"assert get_args(Dict[int, str]) == (int, str)\n" +"assert get_args(Union[int, str]) == (int, str)" +msgstr "" + +#: ../../library/typing.rst:3427 +msgid "Return the set of members defined in a :class:`Protocol`." +msgstr ":class:`Protocol` で定義されたメンバーの集合を返します。" + +#: ../../library/typing.rst:3429 +msgid "" +">>> from typing import Protocol, get_protocol_members\n" +">>> class P(Protocol):\n" +"... def a(self) -> str: ...\n" +"... b: int\n" +">>> get_protocol_members(P) == frozenset({'a', 'b'})\n" +"True" +msgstr "" + +#: ../../library/typing.rst:3438 +msgid "Raise :exc:`TypeError` for arguments that are not Protocols." +msgstr "プロトコルでない引数に対して :exc:`TypeError` を発生させます。" + +#: ../../library/typing.rst:3444 +msgid "Determine if a type is a :class:`Protocol`." +msgstr "型が :class:`Protocol` かどうかを判定します。" + +#: ../../library/typing.rst:3448 +msgid "" +"class P(Protocol):\n" +" def a(self) -> str: ...\n" +" b: int\n" +"\n" +"is_protocol(P) # => True\n" +"is_protocol(int) # => False" +msgstr "" + +#: ../../library/typing.rst:3459 +msgid "Check if a type is a :class:`TypedDict`." +msgstr "型が :class:`TypedDict` かどうかをチェックします。" + +#: ../../library/typing.rst:3463 +msgid "" +"class Film(TypedDict):\n" +" title: str\n" +" year: int\n" +"\n" +"assert is_typeddict(Film)\n" +"assert not is_typeddict(list | str)\n" +"\n" +"# TypedDict is a factory for creating typed dicts,\n" +"# not a typed dict itself\n" +"assert not is_typeddict(TypedDict)" +msgstr "" + +#: ../../library/typing.rst:3480 +msgid "" +"Class used for internal typing representation of string forward references." +msgstr "" +"文字列の前方参照の内部型付け表現に使用されるクラスです。" + +#: ../../library/typing.rst:3482 +msgid "" +"For example, ``List[\"SomeClass\"]`` is implicitly transformed into " +"``List[ForwardRef(\"SomeClass\")]``. :class:`!ForwardRef` should not be " +"instantiated by a user, but may be used by introspection tools." +msgstr "" +"例えば、``List[\"SomeClass\"]`` は暗黙的に ``List[ForwardRef(\"SomeClass\")]`` に変換されます。" +":class:`!ForwardRef` はユーザーがインスタンス化すべきではありませんが、イントロスペクションツールで使用される場合があります。" + +#: ../../library/typing.rst:3487 +msgid "" +":pep:`585` generic types such as ``list[\"SomeClass\"]`` will not be " +"implicitly transformed into ``list[ForwardRef(\"SomeClass\")]`` and thus " +"will not automatically resolve to ``list[SomeClass]``." +msgstr "" +":pep:`585` の ``list[\"SomeClass\"]`` のようなジェネリック型は、暗黙的に ``list[ForwardRef(\"SomeClass\")]`` に変換されず、" +"したがって自動的に ``list[SomeClass]`` に解決されません。" + +#: ../../library/typing.rst:3493 +msgid "" +"This is now an alias for :class:`annotationlib.ForwardRef`. Several " +"undocumented behaviors of this class have been changed; for example, after a " +"``ForwardRef`` has been evaluated, the evaluated value is no longer cached." +msgstr "" +"これは現在 :class:`annotationlib.ForwardRef` のエイリアスです。このクラスのいくつかの文書化されていない動作が変更されました。" +"例えば、``ForwardRef`` が評価された後、評価された値はもはやキャッシュされません。" + +#: ../../library/typing.rst:3500 +msgid "Evaluate an :class:`annotationlib.ForwardRef` as a :term:`type hint`." +msgstr ":class:`annotationlib.ForwardRef` を :term:`type hint` として評価します。" + +#: ../../library/typing.rst:3502 +msgid "" +"This is similar to calling :meth:`annotationlib.ForwardRef.evaluate`, but " +"unlike that method, :func:`!evaluate_forward_ref` also recursively evaluates " +"forward references nested within the type hint." +msgstr "" +"これは :meth:`annotationlib.ForwardRef.evaluate` を呼び出すのと似ていますが、" +"そのメソッドとは異なり、:func:`!evaluate_forward_ref` は型ヒント内にネストされた前方参照を再帰的に評価します。" + +#: ../../library/typing.rst:3506 +msgid "" +"See the documentation for :meth:`annotationlib.ForwardRef.evaluate` for the " +"meaning of the *owner*, *globals*, *locals*, *type_params*, and *format* " +"parameters." +msgstr "" +"*owner*、*globals*、*locals*、*type_params*、*format* パラメーターの意味については、" +":meth:`annotationlib.ForwardRef.evaluate` のドキュメントを参照してください。" + +#: ../../library/typing.rst:3513 +msgid "" +"A sentinel object used to indicate that a type parameter has no default " +"value. For example:" +msgstr "" +"型パラメーターにデフォルト値がないことを示すために使用されるセンチネルオブジェクトです。例:" + +#: ../../library/typing.rst:3516 +msgid "" +">>> T = TypeVar(\"T\")\n" +">>> T.__default__ is typing.NoDefault\n" +"True\n" +">>> S = TypeVar(\"S\", default=None)\n" +">>> S.__default__ is None\n" +"True" +msgstr "" + +#: ../../library/typing.rst:3528 +msgid "Constant" +msgstr "定数" + +#: ../../library/typing.rst:3532 +msgid "" +"A special constant that is assumed to be ``True`` by 3rd party static type " +"checkers. It's ``False`` at runtime." +msgstr "" +"サードパーティの静的型チェッカーによって ``True`` であると仮定される特別な定数です。" +"実行時には ``False`` です。" + +#: ../../library/typing.rst:3535 +msgid "" +"A module which is expensive to import, and which only contain types used for " +"typing annotations, can be safely imported inside an ``if TYPE_CHECKING:`` " +"block. This prevents the module from actually being imported at runtime; " +"annotations aren't eagerly evaluated (see :pep:`649`) so using undefined " +"symbols in annotations is harmless--as long as you don't later examine them. " +"Your static type analysis tool will set ``TYPE_CHECKING`` to ``True`` during " +"static type analysis, which means the module will be imported and the types " +"will be checked properly during such analysis." +msgstr "" +"インポートが高コストで、型付けアノテーションに使用される型のみを含むモジュールは、" +"``if TYPE_CHECKING:`` ブロック内で安全にインポートできます。" +"これにより、モジュールが実行時に実際にインポートされることを防げます。" +"アノテーションは積極的に評価されないため (:pep:`649` を参照)、" +"アノテーションで未定義のシンボルを使用することは無害です——後でそれらを検査しない限り。" +"静的型解析ツールは静的型解析中に ``TYPE_CHECKING`` を ``True`` に設定します。" +"これはモジュールがインポートされ、その解析中に型が適切にチェックされることを意味します。" + +#: ../../library/typing.rst:3547 +msgid "" +"if TYPE_CHECKING:\n" +" import expensive_mod\n" +"\n" +"def fun(arg: expensive_mod.SomeType) -> None:\n" +" local_var: expensive_mod.AnotherType = other_fun()" +msgstr "" + +#: ../../library/typing.rst:3553 +msgid "" +"If you occasionally need to examine type annotations at runtime which may " +"contain undefined symbols, use :meth:`annotationlib.get_annotations` with a " +"``format`` parameter of :attr:`annotationlib.Format.STRING` or :attr:" +"`annotationlib.Format.FORWARDREF` to safely retrieve the annotations without " +"raising :exc:`NameError`." +msgstr "" +"実行時に未定義のシンボルを含む可能性のある型アノテーションを検査する必要が時々ある場合は、" +"``format`` パラメーターを :attr:`annotationlib.Format.STRING` または :attr:`annotationlib.Format.FORWARDREF` に設定した" +":meth:`annotationlib.get_annotations` を使用して、:exc:`NameError` を発生させることなく安全にアノテーションを取得してください。" + +#: ../../library/typing.rst:3566 +msgid "Deprecated aliases" +msgstr "非推奨のエイリアス" + +#: ../../library/typing.rst:3568 +msgid "" +"This module defines several deprecated aliases to pre-existing standard " +"library classes. These were originally included in the :mod:`!typing` module " +"in order to support parameterizing these generic classes using ``[]``. " +"However, the aliases became redundant in Python 3.9 when the corresponding " +"pre-existing classes were enhanced to support ``[]`` (see :pep:`585`)." +msgstr "" +"このモジュールは、既存の標準ライブラリクラスへのいくつかの非推奨エイリアスを定義しています。" +"これらは元々、これらのジェネリッククラスを ``[]`` を使用してパラメータ化することをサポートするために :mod:`!typing` モジュールに含まれていました。" +"しかし、Python 3.9 で対応する既存クラスが ``[]`` をサポートするように強化されたとき、これらのエイリアスは冗長になりました (:pep:`585` を参照)。" + +#: ../../library/typing.rst:3575 +msgid "" +"The redundant types are deprecated as of Python 3.9. However, while the " +"aliases may be removed at some point, removal of these aliases is not " +"currently planned. As such, no deprecation warnings are currently issued by " +"the interpreter for these aliases." +msgstr "" +"冗長な型はPython 3.9で非推奨となりました。しかし、これらのエイリアスはいつかの時点で削除される可能性があるものの、" +"これらのエイリアスの削除は現在のところ予定されていません。そのため、現在のところ、" +"これらのエイリアスに対してインタープリターによる非推奨警告は発行されていません。" + +#: ../../library/typing.rst:3580 +msgid "" +"If at some point it is decided to remove these deprecated aliases, a " +"deprecation warning will be issued by the interpreter for at least two " +"releases prior to removal. The aliases are guaranteed to remain in the :mod:" +"`!typing` module without deprecation warnings until at least Python 3.14." +msgstr "" +"いつかの時点でこれらの非推奨エイリアスを削除することが決定された場合、" +"削除の少なくとも2リリース前にインタープリターによる非推奨警告が発行されます。" +"これらのエイリアスは、少なくともPython 3.14までは非推奨警告なしで :mod:`!typing` モジュールに残ることが保証されています。" + +#: ../../library/typing.rst:3585 +msgid "" +"Type checkers are encouraged to flag uses of the deprecated types if the " +"program they are checking targets a minimum Python version of 3.9 or newer." +msgstr "" +"型チェッカーは、チェックしているプログラムが最低Pythonバージョンを3.9以降を対象としている場合、" +"非推奨型の使用にフラグを立てることが推奨されています。" + +#: ../../library/typing.rst:3591 +msgid "Aliases to built-in types" +msgstr "組み込み型のエイリアス" + +#: ../../library/typing.rst:3595 +msgid "Deprecated alias to :class:`dict`." +msgstr ":class:`dict` の非推奨なエイリアス。" + +#: ../../library/typing.rst:3597 +msgid "" +"Note that to annotate arguments, it is preferred to use an abstract " +"collection type such as :class:`~collections.abc.Mapping` rather than to " +"use :class:`dict` or :class:`!typing.Dict`." +msgstr "" +"引数にアノテーションを付ける場合、:class:`dict` や :class:`!typing.Dict` を使用するよりも、" +":class:`~collections.abc.Mapping` などの抽象コレクション型を使用することが好ましいことに注意してください。" + +#: ../../library/typing.rst:3601 +msgid "" +":class:`builtins.dict ` now supports subscripting (``[]``). See :pep:" +"`585` and :ref:`types-genericalias`." +msgstr "" +":class:`builtins.dict ` は添字表記 (``[]``) をサポートするようになりま" +"した。\n" +":pep:`585` と :ref:`types-genericalias` を参照してください。" + +#: ../../library/typing.rst:3607 +msgid "Deprecated alias to :class:`list`." +msgstr ":class:`list` の非推奨なエイリアス。" + +#: ../../library/typing.rst:3609 +msgid "" +"Note that to annotate arguments, it is preferred to use an abstract " +"collection type such as :class:`~collections.abc.Sequence` or :class:" +"`~collections.abc.Iterable` rather than to use :class:`list` or :class:`!" +"typing.List`." +msgstr "" +"引数にアノテーションを付ける場合、:class:`list` や :class:`!typing.List` を使用するよりも、" +":class:`~collections.abc.Sequence` や :class:`~collections.abc.Iterable` などの抽象コレクション型を使用することが好ましいことに注意してください。" + +#: ../../library/typing.rst:3614 +msgid "" +":class:`builtins.list ` now supports subscripting (``[]``). See :pep:" +"`585` and :ref:`types-genericalias`." +msgstr "" +":class:`builtins.list ` は添字表記 (``[]``) をサポートするようになりま" +"した。:pep:`585` と :ref:`types-genericalias` を参照してください。" + +#: ../../library/typing.rst:3620 +msgid "Deprecated alias to :class:`builtins.set `." +msgstr ":class:`builtins.set ` の非推奨なエイリアス。" + +#: ../../library/typing.rst:3622 +msgid "" +"Note that to annotate arguments, it is preferred to use an abstract " +"collection type such as :class:`collections.abc.Set` rather than to use :" +"class:`set` or :class:`typing.Set`." +msgstr "" +"引数にアノテーションを付ける場合、:class:`set` や :class:`typing.Set` を使用するよりも、" +":class:`collections.abc.Set` などの抽象コレクション型を使用することが好ましいことに注意してください。" + +#: ../../library/typing.rst:3626 +msgid "" +":class:`builtins.set ` now supports subscripting (``[]``). See :pep:" +"`585` and :ref:`types-genericalias`." +msgstr "" +":class:`builtins.set ` は添字表記 (``[]``) をサポートするようになりまし" +"た。\n" +":pep:`585` と :ref:`types-genericalias` を参照してください。" + +#: ../../library/typing.rst:3632 +msgid "Deprecated alias to :class:`builtins.frozenset `." +msgstr ":class:`builtins.frozenset ` の非推奨なエイリアス。" + +#: ../../library/typing.rst:3634 +msgid "" +":class:`builtins.frozenset ` now supports subscripting (``[]``). " +"See :pep:`585` and :ref:`types-genericalias`." +msgstr "" +":class:`builtins.frozenset ` は添字表記 (``[]``) をサポートするよ" +"うになりました。\n" +":pep:`585` と :ref:`types-genericalias` を参照してください。" + +#: ../../library/typing.rst:3641 +msgid "Deprecated alias for :class:`tuple`." +msgstr ":class:`tuple` の非推奨なエイリアス。" + +#: ../../library/typing.rst:3643 +msgid "" +":class:`tuple` and ``Tuple`` are special-cased in the type system; see :ref:" +"`annotating-tuples` for more details." +msgstr "" +":class:`tuple` と ``Tuple`` は型システムで特別扱いされます。詳細は :ref:`annotating-tuples` を参照してください。" + +#: ../../library/typing.rst:3646 +msgid "" +":class:`builtins.tuple ` now supports subscripting (``[]``). See :pep:" +"`585` and :ref:`types-genericalias`." +msgstr "" +":class:`builtins.tuple ` は添字表記 (``[]``) をサポートするようになり" +"ました。\n" +":pep:`585` と :ref:`types-genericalias` を参照してください。" + +#: ../../library/typing.rst:3652 +msgid "Deprecated alias to :class:`type`." +msgstr ":class:`type` の非推奨なエイリアス。" + +#: ../../library/typing.rst:3654 +msgid "" +"See :ref:`type-of-class-objects` for details on using :class:`type` or " +"``typing.Type`` in type annotations." +msgstr "" +"型アノテーションで :class:`type` や ``typing.Type`` を使用する詳細は :ref:`type-of-class-objects` を参照してください。" + +#: ../../library/typing.rst:3659 +msgid "" +":class:`builtins.type ` now supports subscripting (``[]``). See :pep:" +"`585` and :ref:`types-genericalias`." +msgstr "" +":class:`builtins.type ` は添字表記 (``[]``) をサポートするようになりま" +"した。\n" +":pep:`585` と :ref:`types-genericalias` を参照してください。" + +#: ../../library/typing.rst:3666 +msgid "Aliases to types in :mod:`collections`" +msgstr ":mod:`collections` の型のエイリアス" + +#: ../../library/typing.rst:3670 +msgid "Deprecated alias to :class:`collections.defaultdict`." +msgstr ":class:`collections.defaultdict` の非推奨なエイリアス。" + +#: ../../library/typing.rst:3674 +msgid "" +":class:`collections.defaultdict` now supports subscripting (``[]``). See :" +"pep:`585` and :ref:`types-genericalias`." +msgstr "" +":class:`collections.defaultdict` は添字表記 (``[]``) をサポートするようになり" +"ました。\n" +":pep:`585` と :ref:`types-genericalias` を参照してください。" + +#: ../../library/typing.rst:3680 +msgid "Deprecated alias to :class:`collections.OrderedDict`." +msgstr ":class:`collections.OrderedDict` の非推奨なエイリアス。" + +#: ../../library/typing.rst:3684 +msgid "" +":class:`collections.OrderedDict` now supports subscripting (``[]``). See :" +"pep:`585` and :ref:`types-genericalias`." +msgstr "" +":class:`collections.OrderedDict` は添字表記 (``[]``) をサポートするようになり" +"ました。\n" +":pep:`585` と :ref:`types-genericalias` を参照してください。" + +#: ../../library/typing.rst:3690 +msgid "Deprecated alias to :class:`collections.ChainMap`." +msgstr ":class:`collections.ChainMap` の非推奨なエイリアス。" + +#: ../../library/typing.rst:3694 +msgid "" +":class:`collections.ChainMap` now supports subscripting (``[]``). See :pep:" +"`585` and :ref:`types-genericalias`." +msgstr "" +":class:`collections.ChainMap` は添字表記 (``[]``) をサポートするようになりま" +"した。\n" +":pep:`585` と :ref:`types-genericalias` を参照してください。" + +#: ../../library/typing.rst:3700 +msgid "Deprecated alias to :class:`collections.Counter`." +msgstr ":class:`collections.Counter` の非推奨なエイリアス。" + +#: ../../library/typing.rst:3704 +msgid "" +":class:`collections.Counter` now supports subscripting (``[]``). See :pep:" +"`585` and :ref:`types-genericalias`." +msgstr "" +":class:`collections.Counter` は添字表記 (``[]``) をサポートするようになりまし" +"た。\n" +":pep:`585` と :ref:`types-genericalias` を参照してください。" + +#: ../../library/typing.rst:3710 +msgid "Deprecated alias to :class:`collections.deque`." +msgstr ":class:`collections.deque` の非推奨なエイリアス。" + +#: ../../library/typing.rst:3714 +msgid "" +":class:`collections.deque` now supports subscripting (``[]``). See :pep:" +"`585` and :ref:`types-genericalias`." +msgstr "" +":class:`collections.deque` は添字表記 (``[]``) をサポートするようになりまし" +"た。\n" +":pep:`585` と :ref:`types-genericalias` を参照してください。" + +#: ../../library/typing.rst:3721 +msgid "Aliases to other concrete types" +msgstr "その他の具体型のエイリアス" + +#: ../../library/typing.rst:3726 +msgid "" +"Deprecated aliases corresponding to the return types from :func:`re.compile` " +"and :func:`re.match`." +msgstr "" +":func:`re.compile` と :func:`re.match` の返り値の型に対応する非推奨エイリアスです。" + +#: ../../library/typing.rst:3729 +msgid "" +"These types (and the corresponding functions) are generic over :data:" +"`AnyStr`. ``Pattern`` can be specialised as ``Pattern[str]`` or " +"``Pattern[bytes]``; ``Match`` can be specialised as ``Match[str]`` or " +"``Match[bytes]``." +msgstr "" +"これらの型(および対応する関数)は :data:`AnyStr` のジェネリックです。" +"``Pattern`` は ``Pattern[str]`` や ``Pattern[bytes]`` として特化でき、" +"``Match`` は ``Match[str]`` や ``Match[bytes]`` として特化できます。" + +#: ../../library/typing.rst:3734 +msgid "" +"Classes ``Pattern`` and ``Match`` from :mod:`re` now support ``[]``. See :" +"pep:`585` and :ref:`types-genericalias`." +msgstr "" +":mod:`re` の ``Pattern`` と ``Match`` クラスは ``[]`` をサポートするようになりました。" +":pep:`585` と :ref:`types-genericalias` を参照してください。" + +#: ../../library/typing.rst:3740 +msgid "Deprecated alias for :class:`str`." +msgstr ":class:`str` の非推奨なエイリアス。" + +#: ../../library/typing.rst:3742 +msgid "" +"``Text`` is provided to supply a forward compatible path for Python 2 code: " +"in Python 2, ``Text`` is an alias for ``unicode``." +msgstr "" +"``Text`` はPython 2コードのために前方互換パスを提供するために提供されています:" +"Python 2では、``Text`` は ``unicode`` のエイリアスです。" + +#: ../../library/typing.rst:3746 +msgid "" +"Use ``Text`` to indicate that a value must contain a unicode string in a " +"manner that is compatible with both Python 2 and Python 3::" +msgstr "" +"``Text`` は Python 2 と Python 3 の両方と互換性のある方法で値が unicode 文字" +"列を含んでいなければならない場合に使用してください。" + +#: ../../library/typing.rst:3749 +msgid "" +"def add_unicode_checkmark(text: Text) -> Text:\n" +" return text + u' \\u2713'" +msgstr "" + +#: ../../library/typing.rst:3754 +msgid "" +"Python 2 is no longer supported, and most type checkers also no longer " +"support type checking Python 2 code. Removal of the alias is not currently " +"planned, but users are encouraged to use :class:`str` instead of ``Text``." +msgstr "" +"Python 2はもはやサポートされておらず、ほとんどの型チェッカーもPython 2コードの型チェックをサポートしなくなりました。" +"エイリアスの削除は現在のところ予定されていませんが、ユーザーは ``Text`` の代わりに :class:`str` を使用することが推奨されています。" + +#: ../../library/typing.rst:3764 +msgid "Aliases to container ABCs in :mod:`collections.abc`" +msgstr ":mod:`collections.abc` のコンテナ ABC のエイリアス" + +#: ../../library/typing.rst:3768 +msgid "Deprecated alias to :class:`collections.abc.Set`." +msgstr ":class:`collections.abc.Set` の非推奨なエイリアス。" + +#: ../../library/typing.rst:3770 +msgid "" +":class:`collections.abc.Set` now supports subscripting (``[]``). See :pep:" +"`585` and :ref:`types-genericalias`." +msgstr "" +":class:`collections.abc.Set` は添字表記 (``[]``) をサポートするようになりまし" +"た。\n" +":pep:`585` と :ref:`types-genericalias` を参照してください。" + +#: ../../library/typing.rst:3776 +msgid "Deprecated alias to :class:`collections.abc.Collection`." +msgstr ":class:`collections.abc.Collection` の非推奨なエイリアス。" + +#: ../../library/typing.rst:3780 +msgid "" +":class:`collections.abc.Collection` now supports subscripting (``[]``). See :" +"pep:`585` and :ref:`types-genericalias`." +msgstr "" +":class:`collections.abc.Collection` は添字表記 (``[]``) をサポートするように" +"なりました。\n" +":pep:`585` と :ref:`types-genericalias` を参照してください。" + +#: ../../library/typing.rst:3786 +msgid "Deprecated alias to :class:`collections.abc.Container`." +msgstr ":class:`collections.abc.Container` の非推奨なエイリアス。" + +#: ../../library/typing.rst:3788 +msgid "" +":class:`collections.abc.Container` now supports subscripting (``[]``). See :" +"pep:`585` and :ref:`types-genericalias`." +msgstr "" +":class:`collections.abc.Container` は添字表記 (``[]``) をサポートするようにな" +"りました。\n" +":pep:`585` と :ref:`types-genericalias` を参照してください。" + +#: ../../library/typing.rst:3794 +msgid "Deprecated alias to :class:`collections.abc.ItemsView`." +msgstr ":class:`collections.abc.ItemsView` の非推奨なエイリアス。" + +#: ../../library/typing.rst:3796 +msgid "" +":class:`collections.abc.ItemsView` now supports subscripting (``[]``). See :" +"pep:`585` and :ref:`types-genericalias`." +msgstr "" +":class:`collections.abc.ItemsView` は添字表記 (``[]``) をサポートするようにな" +"りました。\n" +":pep:`585` と :ref:`types-genericalias` を参照してください。" + +#: ../../library/typing.rst:3802 +msgid "Deprecated alias to :class:`collections.abc.KeysView`." +msgstr ":class:`collections.abc.KeysView` の非推奨なエイリアス。" + +#: ../../library/typing.rst:3804 +msgid "" +":class:`collections.abc.KeysView` now supports subscripting (``[]``). See :" +"pep:`585` and :ref:`types-genericalias`." +msgstr "" +":class:`collections.abc.KeysView` は添字表記 (``[]``) をサポートするようにな" +"りました。\n" +":pep:`585` と :ref:`types-genericalias` を参照してください。" + +#: ../../library/typing.rst:3810 +msgid "Deprecated alias to :class:`collections.abc.Mapping`." +msgstr ":class:`collections.abc.Mapping` の非推奨なエイリアス。" + +#: ../../library/typing.rst:3812 +msgid "" +":class:`collections.abc.Mapping` now supports subscripting (``[]``). See :" +"pep:`585` and :ref:`types-genericalias`." +msgstr "" +":class:`collections.abc.Mapping` は添字表記 (``[]``) をサポートするようになり" +"ました。\n" +":pep:`585` と :ref:`types-genericalias` を参照してください。" + +#: ../../library/typing.rst:3818 +msgid "Deprecated alias to :class:`collections.abc.MappingView`." +msgstr ":class:`collections.abc.MappingView` の非推奨なエイリアス。" + +#: ../../library/typing.rst:3820 +msgid "" +":class:`collections.abc.MappingView` now supports subscripting (``[]``). " +"See :pep:`585` and :ref:`types-genericalias`." +msgstr "" +":class:`collections.abc.MappingView` は添字表記 (``[]``) をサポートするように" +"なりました。\n" +":pep:`585` と :ref:`types-genericalias` を参照してください。" + +#: ../../library/typing.rst:3826 +msgid "Deprecated alias to :class:`collections.abc.MutableMapping`." +msgstr ":class:`collections.abc.MutableMapping` の非推奨なエイリアス。" + +#: ../../library/typing.rst:3828 +msgid "" +":class:`collections.abc.MutableMapping` now supports subscripting (``[]``). " +"See :pep:`585` and :ref:`types-genericalias`." +msgstr "" +":class:`collections.abc.MutableMapping` は添字表記 (``[]``) をサポートするよ" +"うになりました。\n" +":pep:`585` と :ref:`types-genericalias` を参照してください。" + +#: ../../library/typing.rst:3835 +msgid "Deprecated alias to :class:`collections.abc.MutableSequence`." +msgstr ":class:`collections.abc.MutableSequence` の非推奨なエイリアス。" + +#: ../../library/typing.rst:3837 +msgid "" +":class:`collections.abc.MutableSequence` now supports subscripting (``[]``). " +"See :pep:`585` and :ref:`types-genericalias`." +msgstr "" +":class:`collections.abc.MutableSequence` は添字表記 (``[]``) をサポートするよ" +"うになりました。\n" +":pep:`585` と :ref:`types-genericalias` を参照してください。" + +#: ../../library/typing.rst:3844 +msgid "Deprecated alias to :class:`collections.abc.MutableSet`." +msgstr ":class:`collections.abc.MutableSet` の非推奨なエイリアス。" + +#: ../../library/typing.rst:3846 +msgid "" +":class:`collections.abc.MutableSet` now supports subscripting (``[]``). See :" +"pep:`585` and :ref:`types-genericalias`." +msgstr "" +":class:`collections.abc.MutableSet` は添字表記 (``[]``) をサポートするように" +"なりました。\n" +":pep:`585` と :ref:`types-genericalias` を参照してください。" + +#: ../../library/typing.rst:3852 +msgid "Deprecated alias to :class:`collections.abc.Sequence`." +msgstr ":class:`collections.abc.Sequence` の非推奨なエイリアス。" + +#: ../../library/typing.rst:3854 +msgid "" +":class:`collections.abc.Sequence` now supports subscripting (``[]``). See :" +"pep:`585` and :ref:`types-genericalias`." +msgstr "" +":class:`collections.abc.Sequence` は添字表記 (``[]``) をサポートするようにな" +"りました。\n" +":pep:`585` と :ref:`types-genericalias` を参照してください。" + +#: ../../library/typing.rst:3860 +msgid "Deprecated alias to :class:`collections.abc.ValuesView`." +msgstr ":class:`collections.abc.ValuesView` の非推奨なエイリアス。" + +#: ../../library/typing.rst:3862 +msgid "" +":class:`collections.abc.ValuesView` now supports subscripting (``[]``). See :" +"pep:`585` and :ref:`types-genericalias`." +msgstr "" +":class:`collections.abc.ValuesView` は添字表記 (``[]``) をサポートするように" +"なりました。\n" +":pep:`585` と :ref:`types-genericalias` を参照してください。" + +#: ../../library/typing.rst:3869 +msgid "Aliases to asynchronous ABCs in :mod:`collections.abc`" +msgstr ":mod:`collections.abc` の非同期 ABC のエイリアス" + +#: ../../library/typing.rst:3873 +msgid "Deprecated alias to :class:`collections.abc.Coroutine`." +msgstr ":class:`collections.abc.Coroutine` の非推奨なエイリアス。" + +#: ../../library/typing.rst:3875 +msgid "" +"See :ref:`annotating-generators-and-coroutines` for details on using :class:" +"`collections.abc.Coroutine` and ``typing.Coroutine`` in type annotations." +msgstr "" +"型アノテーションで :class:`collections.abc.Coroutine` と ``typing.Coroutine`` を使用する詳細は :ref:`annotating-generators-and-coroutines` を参照してください。" + +#: ../../library/typing.rst:3881 +msgid "" +":class:`collections.abc.Coroutine` now supports subscripting (``[]``). See :" +"pep:`585` and :ref:`types-genericalias`." +msgstr "" +":class:`collections.abc.Coroutine` は添字表記 (``[]``) をサポートするようにな" +"りました。\n" +":pep:`585` と :ref:`types-genericalias` を参照してください。" + +#: ../../library/typing.rst:3887 +msgid "Deprecated alias to :class:`collections.abc.AsyncGenerator`." +msgstr ":class:`collections.abc.AsyncGenerator` の非推奨なエイリアス。" + +#: ../../library/typing.rst:3889 +msgid "" +"See :ref:`annotating-generators-and-coroutines` for details on using :class:" +"`collections.abc.AsyncGenerator` and ``typing.AsyncGenerator`` in type " +"annotations." +msgstr "" +"型アノテーションで :class:`collections.abc.AsyncGenerator` と ``typing.AsyncGenerator`` を使用する詳細は :ref:`annotating-generators-and-coroutines` を参照してください。" + +#: ../../library/typing.rst:3895 +msgid "" +":class:`collections.abc.AsyncGenerator` now supports subscripting (``[]``). " +"See :pep:`585` and :ref:`types-genericalias`." +msgstr "" +":class:`collections.abc.AsyncGenerator` は添字表記 (``[]``) をサポートするよ" +"うになりました。\n" +":pep:`585` と :ref:`types-genericalias` を参照してください。" + +#: ../../library/typing.rst:3900 +msgid "The ``SendType`` parameter now has a default." +msgstr "``SendType`` パラメーターにデフォルト値が設定されました。" + +#: ../../library/typing.rst:3905 +msgid "Deprecated alias to :class:`collections.abc.AsyncIterable`." +msgstr ":class:`collections.abc.AsyncIterable` の非推奨なエイリアス。" + +#: ../../library/typing.rst:3909 +msgid "" +":class:`collections.abc.AsyncIterable` now supports subscripting (``[]``). " +"See :pep:`585` and :ref:`types-genericalias`." +msgstr "" +":class:`collections.abc.AsyncIterable` は添字表記 (``[]``) をサポートするよう" +"になりました。\n" +":pep:`585` と :ref:`types-genericalias` を参照してください。" + +#: ../../library/typing.rst:3915 +msgid "Deprecated alias to :class:`collections.abc.AsyncIterator`." +msgstr ":class:`collections.abc.AsyncIterator` の非推奨なエイリアス。" + +#: ../../library/typing.rst:3919 +msgid "" +":class:`collections.abc.AsyncIterator` now supports subscripting (``[]``). " +"See :pep:`585` and :ref:`types-genericalias`." +msgstr "" +":class:`collections.abc.AsyncIterator` は添字表記 (``[]``) をサポートするよう" +"になりました。\n" +":pep:`585` と :ref:`types-genericalias` を参照してください。" + +#: ../../library/typing.rst:3925 +msgid "Deprecated alias to :class:`collections.abc.Awaitable`." +msgstr ":class:`collections.abc.Awaitable` の非推奨なエイリアス。" + +#: ../../library/typing.rst:3929 +msgid "" +":class:`collections.abc.Awaitable` now supports subscripting (``[]``). See :" +"pep:`585` and :ref:`types-genericalias`." +msgstr "" +":class:`collections.abc.Awaitable` は添字表記 (``[]``) をサポートするようにな" +"りました。\n" +":pep:`585` と :ref:`types-genericalias` を参照してください。" + +#: ../../library/typing.rst:3936 +msgid "Aliases to other ABCs in :mod:`collections.abc`" +msgstr ":mod:`collections.abc` のその他の ABC のエイリアス" + +#: ../../library/typing.rst:3940 +msgid "Deprecated alias to :class:`collections.abc.Iterable`." +msgstr ":class:`collections.abc.Iterable` の非推奨なエイリアス。" + +#: ../../library/typing.rst:3942 +msgid "" +":class:`collections.abc.Iterable` now supports subscripting (``[]``). See :" +"pep:`585` and :ref:`types-genericalias`." +msgstr "" +":class:`collections.abc.Iterable` は添字表記 (``[]``) をサポートするようにな" +"りました。\n" +":pep:`585` と :ref:`types-genericalias` を参照してください。" + +#: ../../library/typing.rst:3948 +msgid "Deprecated alias to :class:`collections.abc.Iterator`." +msgstr ":class:`collections.abc.Iterator` の非推奨なエイリアス。" + +#: ../../library/typing.rst:3950 +msgid "" +":class:`collections.abc.Iterator` now supports subscripting (``[]``). See :" +"pep:`585` and :ref:`types-genericalias`." +msgstr "" +":class:`collections.abc.Iterator` は添字表記 (``[]``) をサポートするようにな" +"りました。\n" +":pep:`585` と :ref:`types-genericalias` を参照してください。" + +#: ../../library/typing.rst:3956 +msgid "Deprecated alias to :class:`collections.abc.Callable`." +msgstr ":class:`collections.abc.Callable` の非推奨なエイリアス。" + +#: ../../library/typing.rst:3958 +msgid "" +"See :ref:`annotating-callables` for details on how to use :class:" +"`collections.abc.Callable` and ``typing.Callable`` in type annotations." +msgstr "" +"型アノテーションで :class:`collections.abc.Callable` と ``typing.Callable`` を使用する方法の詳細は :ref:`annotating-callables` を参照してください。" + +#: ../../library/typing.rst:3961 +msgid "" +":class:`collections.abc.Callable` now supports subscripting (``[]``). See :" +"pep:`585` and :ref:`types-genericalias`." +msgstr "" +":class:`collections.abc.Callable` は添字表記 (``[]``) をサポートするようにな" +"りました。\n" +":pep:`585` と :ref:`types-genericalias` を参照してください。" + +#: ../../library/typing.rst:3971 +msgid "Deprecated alias to :class:`collections.abc.Generator`." +msgstr ":class:`collections.abc.Generator` の非推奨なエイリアス。" + +#: ../../library/typing.rst:3973 +msgid "" +"See :ref:`annotating-generators-and-coroutines` for details on using :class:" +"`collections.abc.Generator` and ``typing.Generator`` in type annotations." +msgstr "" +"型アノテーションで :class:`collections.abc.Generator` と ``typing.Generator`` を使用する詳細は :ref:`annotating-generators-and-coroutines` を参照してください。" + +#: ../../library/typing.rst:3977 +msgid "" +":class:`collections.abc.Generator` now supports subscripting (``[]``). See :" +"pep:`585` and :ref:`types-genericalias`." +msgstr "" +":class:`collections.abc.Generator` は添字表記 (``[]``) をサポートするようにな" +"りました。\n" +":pep:`585` と :ref:`types-genericalias` を参照してください。" + +#: ../../library/typing.rst:3981 +msgid "Default values for the send and return types were added." +msgstr "send と return の型にデフォルト値が追加されました。" + +#: ../../library/typing.rst:3986 +msgid "Deprecated alias to :class:`collections.abc.Hashable`." +msgstr ":class:`collections.abc.Hashable` の非推奨なエイリアス。" + +#: ../../library/typing.rst:3988 +msgid "Use :class:`collections.abc.Hashable` directly instead." +msgstr "代わりに :class:`collections.abc.Hashable` を直接使用してください。" + +#: ../../library/typing.rst:3993 +msgid "Deprecated alias to :class:`collections.abc.Reversible`." +msgstr ":class:`collections.abc.Reversible` の非推奨なエイリアス。" + +#: ../../library/typing.rst:3995 +msgid "" +":class:`collections.abc.Reversible` now supports subscripting (``[]``). See :" +"pep:`585` and :ref:`types-genericalias`." +msgstr "" +":class:`collections.abc.Reversible` は添字表記 (``[]``) をサポートするように" +"なりました。\n" +":pep:`585` と :ref:`types-genericalias` を参照してください。" + +#: ../../library/typing.rst:4001 +msgid "Deprecated alias to :class:`collections.abc.Sized`." +msgstr ":class:`collections.abc.Sized` の非推奨なエイリアス。" + +#: ../../library/typing.rst:4003 +msgid "Use :class:`collections.abc.Sized` directly instead." +msgstr "代わりに :class:`collections.abc.Sized` を直接使用してください。" + +#: ../../library/typing.rst:4009 +msgid "Aliases to :mod:`contextlib` ABCs" +msgstr ":mod:`contextlib` ABC のエイリアス" + +#: ../../library/typing.rst:4013 +msgid "Deprecated alias to :class:`contextlib.AbstractContextManager`." +msgstr ":class:`contextlib.AbstractContextManager` の非推奨なエイリアス。" + +#: ../../library/typing.rst:4015 +msgid "" +"The first type parameter, ``T_co``, represents the type returned by the :" +"meth:`~object.__enter__` method. The optional second type parameter, " +"``ExitT_co``, which defaults to ``bool | None``, represents the type " +"returned by the :meth:`~object.__exit__` method." +msgstr "" +"最初の型パラメーター ``T_co`` は :meth:`~object.__enter__` メソッドによって返される型を表します。" +"オプションの2番目の型パラメーター ``ExitT_co`` はデフォルトで ``bool | None`` で、" +":meth:`~object.__exit__` メソッドによって返される型を表します。" + +#: ../../library/typing.rst:4022 +msgid "" +":class:`contextlib.AbstractContextManager` now supports subscripting " +"(``[]``). See :pep:`585` and :ref:`types-genericalias`." +msgstr "" +":class:`contextlib.AbstractContextManager` は添字表記 (``[]``) をサポートする" +"ようになりました。\n" +":pep:`585` と :ref:`types-genericalias` を参照してください。" + +#: ../../library/typing.rst:4027 +msgid "Added the optional second type parameter, ``ExitT_co``." +msgstr "オプションの2番目の型パラメーター ``ExitT_co`` が追加されました。" + +#: ../../library/typing.rst:4032 +msgid "Deprecated alias to :class:`contextlib.AbstractAsyncContextManager`." +msgstr ":class:`contextlib.AbstractAsyncContextManager` の非推奨なエイリアス。" + +#: ../../library/typing.rst:4034 +msgid "" +"The first type parameter, ``T_co``, represents the type returned by the :" +"meth:`~object.__aenter__` method. The optional second type parameter, " +"``AExitT_co``, which defaults to ``bool | None``, represents the type " +"returned by the :meth:`~object.__aexit__` method." +msgstr "" +"最初の型パラメーター ``T_co`` は :meth:`~object.__aenter__` メソッドによって返される型を表します。" +"オプションの2番目の型パラメーター ``AExitT_co`` はデフォルトで ``bool | None`` で、" +":meth:`~object.__aexit__` メソッドによって返される型を表します。" + +#: ../../library/typing.rst:4041 +msgid "" +":class:`contextlib.AbstractAsyncContextManager` now supports subscripting " +"(``[]``). See :pep:`585` and :ref:`types-genericalias`." +msgstr "" +":class:`contextlib.AbstractAsyncContextManager` は添字表記 (``[]``) をサポー" +"トするようになりました。\n" +":pep:`585` と :ref:`types-genericalias` を参照してください。" + +#: ../../library/typing.rst:4046 +msgid "Added the optional second type parameter, ``AExitT_co``." +msgstr "オプションの2番目の型パラメーター ``AExitT_co`` が追加されました。" + +#: ../../library/typing.rst:4050 +msgid "Deprecation Timeline of Major Features" +msgstr "メジャーな機能の非推奨時系列" + +#: ../../library/typing.rst:4052 +msgid "" +"Certain features in ``typing`` are deprecated and may be removed in a future " +"version of Python. The following table summarizes major deprecations for " +"your convenience. This is subject to change, and not all deprecations are " +"listed." +msgstr "" +"``typing`` の機能の中には非推奨のものがあり、Python の将来のバージョンで削除" +"される可能性があります。以下の表は主な非推奨機能をまとめたものです。これは変" +"更される可能性があり、すべての非推奨機能がリストされているわけではありませ" +"ん。" + +#: ../../library/typing.rst:4059 +msgid "Feature" +msgstr "機能" + +#: ../../library/typing.rst:4060 +msgid "Deprecated in" +msgstr "非推奨となるバージョン" + +#: ../../library/typing.rst:4061 +msgid "Projected removal" +msgstr "削除予定のバージョン" + +#: ../../library/typing.rst:4062 +msgid "PEP/issue" +msgstr "PEP/issue" + +#: ../../library/typing.rst:4063 +msgid "``typing`` versions of standard collections" +msgstr "標準コレクションのエイリアス" + +#: ../../library/typing.rst:4064 +msgid "3.9" +msgstr "3.9" + +#: ../../library/typing.rst:4065 +msgid "Undecided (see :ref:`deprecated-aliases` for more information)" +msgstr "未定(:ref:`deprecated-aliases` を参照)" + +#: ../../library/typing.rst:4066 +msgid ":pep:`585`" +msgstr ":pep:`585`" + +#: ../../library/typing.rst:4067 +msgid ":data:`typing.Text`" +msgstr ":data:`typing.Text`" + +#: ../../library/typing.rst:4068 +msgid "3.11" +msgstr "3.11" + +#: ../../library/typing.rst:4069 ../../library/typing.rst:4073 +#: ../../library/typing.rst:4077 +msgid "Undecided" +msgstr "未定" + +#: ../../library/typing.rst:4070 +msgid ":gh:`92332`" +msgstr ":gh:`92332`" + +#: ../../library/typing.rst:4071 +msgid ":class:`typing.Hashable` and :class:`typing.Sized`" +msgstr ":class:`typing.Hashable`、:class:`typing.Sized`" + +#: ../../library/typing.rst:4072 ../../library/typing.rst:4076 +msgid "3.12" +msgstr "3.12" + +#: ../../library/typing.rst:4074 +msgid ":gh:`94309`" +msgstr ":gh:`94309`" + +#: ../../library/typing.rst:4075 +msgid ":data:`typing.TypeAlias`" +msgstr ":data:`typing.TypeAlias`" + +#: ../../library/typing.rst:4078 +msgid ":pep:`695`" +msgstr ":pep:`695`" + +#: ../../library/typing.rst:4079 +msgid ":func:`@typing.no_type_check_decorator `" +msgstr ":func:`@typing.no_type_check_decorator `" + +#: ../../library/typing.rst:4080 ../../library/typing.rst:4084 +msgid "3.13" +msgstr "3.13" + +#: ../../library/typing.rst:4081 +msgid "3.15" +msgstr "3.15" + +#: ../../library/typing.rst:4082 +msgid ":gh:`106309`" +msgstr ":gh:`106309`" + +#: ../../library/typing.rst:4083 +msgid ":data:`typing.AnyStr`" +msgstr ":data:`typing.AnyStr`" + +#: ../../library/typing.rst:4085 +msgid "3.18" +msgstr "3.18" + +#: ../../library/typing.rst:4086 +msgid ":gh:`105578`" +msgstr ":gh:`105578`" diff --git a/translation_quality_check.py b/translation_quality_check.py new file mode 100644 index 000000000..9cf3be2ce --- /dev/null +++ b/translation_quality_check.py @@ -0,0 +1,166 @@ +#!/usr/bin/env python3 +""" +翻訳品質統合チェックスクリプト +複数のチェックを組み合わせて翻訳品質を総合的に評価 +""" +import re +import sys +from typing import Dict, List, Tuple +from improved_untranslated_check import improved_untranslated_check + +def check_rst_syntax_preservation(filename: str) -> Tuple[bool, List[str]]: + """ + reStructuredText構文が保持されているかチェック + """ + issues = [] + + try: + with open(filename, 'r', encoding='utf-8') as f: + content = f.read() + except FileNotFoundError: + return False, [f'ファイル {filename} が見つかりません'] + + # msgstrの中でRST構文が壊れていないかチェック + msgstr_pattern = r'msgstr\s+"([^"]*(?:\n"[^"]*)*)"' + msgstrs = re.findall(msgstr_pattern, content, re.MULTILINE) + + for i, msgstr in enumerate(msgstrs): + if not msgstr.strip(): + continue + + # 一般的なRST構文チェック + if ':' in msgstr and '`' in msgstr: + # ロール構文のチェック (:func:`name` など) + role_pattern = r':[a-zA-Z]+:`[^`]+`' + if re.search(r':[a-zA-Z]+:`[^`]*[^\w\s\.~\-_][^`]*`', msgstr): + issues.append(f'msgstr {i+1}: 不正なロール構文の可能性') + + # リンク構文のチェック + if '_` <' in msgstr and '>`_' not in msgstr: + issues.append(f'msgstr {i+1}: 不完全なリンク構文') + + return len(issues) == 0, issues + +def check_terminology_consistency(filename: str) -> Tuple[bool, List[str]]: + """ + 専門用語の統一性をチェック + """ + issues = [] + + try: + with open(filename, 'r', encoding='utf-8') as f: + content = f.read() + except FileNotFoundError: + return False, [f'ファイル {filename} が見つかりません'] + + # 翻訳された部分のみを抽出 + msgstr_pattern = r'msgstr\s+"([^"]*(?:\n"[^"]*)*)"' + msgstrs = re.findall(msgstr_pattern, content, re.MULTILINE) + translated_text = ' '.join([m for m in msgstrs if m.strip()]) + + # 用語の統一をチェック + terminology_checks = [ + (r'(?:関数|function)', r'ファンクション', '「関数」と「ファンクション」の混在'), + (r'(?:メソッド|method)', r'メソード', '「メソッド」と「メソード」の混在'), + (r'(?:パラメーター|パラメータ)', None, '「パラメーター」と「パラメータ」の混在'), + (r'(?:引数|argument)', r'アーギュメント', '「引数」と「アーギュメント」の混在'), + (r'(?:戻り値|返り値|return value)', None, '戻り値表現の不統一'), + ] + + for pattern, avoid_pattern, message in terminology_checks: + matches = re.findall(pattern, translated_text, re.IGNORECASE) + if len(set(matches)) > 1: # 複数の表現が混在 + issues.append(message + f': {set(matches)}') + + if avoid_pattern and re.search(avoid_pattern, translated_text, re.IGNORECASE): + issues.append(f'非推奨用語の使用: {avoid_pattern}') + + return len(issues) == 0, issues + +def comprehensive_quality_check(filename: str) -> Dict: + """ + 包括的な翻訳品質チェック + """ + results = { + 'filename': filename, + 'overall_pass': True, + 'checks': {} + } + + print(f'🔍 翻訳品質統合チェック: {filename}') + print('=' * 80) + + # 1. 未翻訳エントリチェック + print('1. 未翻訳エントリチェック...') + untranslated_count, untranslated_entries = improved_untranslated_check(filename) + untranslated_pass = untranslated_count == 0 + results['checks']['untranslated'] = { + 'pass': untranslated_pass, + 'count': untranslated_count, + 'entries': untranslated_entries[:5] # 最初の5個のみ + } + + if untranslated_pass: + print(' ✅ 未翻訳エントリなし') + else: + print(f' ❌ 未翻訳エントリ: {untranslated_count}個') + results['overall_pass'] = False + + # 2. RST構文保持チェック + print('2. reStructuredText構文チェック...') + rst_pass, rst_issues = check_rst_syntax_preservation(filename) + results['checks']['rst_syntax'] = { + 'pass': rst_pass, + 'issues': rst_issues + } + + if rst_pass: + print(' ✅ RST構文は適切に保持されています') + else: + print(f' ⚠️ RST構文の問題: {len(rst_issues)}個') + for issue in rst_issues[:3]: # 最初の3個のみ表示 + print(f' - {issue}') + + # 3. 用語統一チェック + print('3. 専門用語統一性チェック...') + term_pass, term_issues = check_terminology_consistency(filename) + results['checks']['terminology'] = { + 'pass': term_pass, + 'issues': term_issues + } + + if term_pass: + print(' ✅ 用語の統一性は良好です') + else: + print(f' ⚠️ 用語統一の改善余地: {len(term_issues)}個') + for issue in term_issues: + print(f' - {issue}') + + # 総合判定 + print('\n' + '=' * 80) + if results['overall_pass']: + print('🎉 翻訳品質チェック: 合格') + print(' すべての翻訳対象エントリが完了しています。') + else: + print('⚠️ 翻訳品質チェック: 要改善') + print(' 未翻訳エントリの解決が必要です。') + + print('=' * 80) + + return results + +def main(): + if len(sys.argv) < 2: + print('使用方法: python3 translation_quality_check.py ') + sys.exit(1) + + filename = sys.argv[1] + results = comprehensive_quality_check(filename) + + # 結果をJSON形式で保存することも可能 + # import json + # with open(f'{filename}_quality_report.json', 'w', encoding='utf-8') as f: + # json.dump(results, f, ensure_ascii=False, indent=2) + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/validate_translation.py b/validate_translation.py new file mode 100644 index 000000000..985178785 --- /dev/null +++ b/validate_translation.py @@ -0,0 +1,61 @@ +#!/usr/bin/env python3 +import re +import sys + +def validate_po_file(filename): + """ + Validate .po file for untranslated entries without syntax errors + """ + try: + with open(filename, 'r', encoding='utf-8') as f: + content = f.read() + except FileNotFoundError: + print(f'❌ ファイル {filename} が見つかりません') + return False + + # Simple regex pattern to find untranslated entries + # Look for msgstr "" with no content between quotes + pattern = r'msgstr\s*""\s*\n' + untranslated_simple = re.findall(pattern, content) + + # More comprehensive check for truly empty msgstr + entries = content.split('\n\n') + empty_msgstr_count = 0 + translatable_empty = 0 + + for entry in entries: + if 'msgid' in entry and 'msgstr' in entry: + # Check if msgstr is empty + msgstr_match = re.search(r'msgstr\s*"([^"]*)"', entry) + if msgstr_match and msgstr_match.group(1).strip() == '': + empty_msgstr_count += 1 + + # Check if it's translatable content + msgid_match = re.search(r'msgid\s*"([^"]*)"', entry) + if msgid_match: + msgid_content = msgid_match.group(1) + # Simple heuristic: if it contains common code patterns, skip + if not any(pattern in msgid_content for pattern in [ + 'def ', 'class ', 'import ', '>>>', 'print(', 'assert ', + 'return ', 'if __name__', 'try:', 'except:', '.py', + 'http://', 'https://' + ]): + # This might be translatable + if len(msgid_content.strip()) > 0: + translatable_empty += 1 + + print(f'📊 翻訳検証結果: {filename}') + print(f'=' * 60) + print(f'空のmsgstr総数: {empty_msgstr_count}') + print(f'翻訳が必要と思われる空のmsgstr: {translatable_empty}') + + if translatable_empty == 0: + print('✅ 翻訳対象エントリはすべて翻訳済みと思われます') + return True + else: + print(f'⚠️ {translatable_empty}個のエントリが未翻訳の可能性があります') + return False + +if __name__ == "__main__": + filename = sys.argv[1] if len(sys.argv) > 1 else 'library/typing.po' + validate_po_file(filename) \ No newline at end of file