From b8b816de1fabaeb1ca9c30013b0d8fcbdf200af3 Mon Sep 17 00:00:00 2001 From: Atsuo Ishimoto Date: Sun, 6 Jul 2025 10:22:37 +0900 Subject: [PATCH 1/5] 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 2/5] 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 3/5] 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 4/5] 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 5/5] 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 ""