FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python-docs-ja/library/annotationlib.po at 3.14 · python/python-docs-ja · GitHub
python
python-docs-ja
Repository navigation
Code
Issues
Pull requests
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
python-docs-ja
/
library
/
annotationlib.po
Copy path
More file actions
More file actions
Latest commit
History
History
History
1426 lines (1268 loc) · 67.2 KB
Breadcrumbs
python-docs-ja
/
library
/
annotationlib.po
Copy path
File metadata and controls
1426 lines (1268 loc) · 67.2 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#
SOME DESCRIPTIVE TITLE.
#
Copyright (C) 2001 Python Software Foundation
#
This file is distributed under the same license as the Python package.
#
FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#
Translators:
#
python-doc bot, 2025
#
#,
fuzzy
msgid ""
msgstr ""
"
Project-Id-Version
:
Python 3.15\n
"
"
Report-Msgid-Bugs-To
:
\n
"
"
POT-Creation-Date
:
2026-10-13 19:59+0000\n
"
"
PO-Revision-Date
:
2025-09-16 00:00+0000\n
"
"
Last-Translator
:
python-doc bot, 2025\n
"
"
Language-Team
:
Japanese (https://app.transifex.com/python-doc/teams/5390/
"
"
ja/)\n
"
"
Language
:
ja\n
"
"
MIME-Version
:
1.0\n
"
"
Content-Type
:
text/plain; charset=UTF-8\n
"
"
Content-Transfer-Encoding
:
8bit\n
"
"
Plural-Forms
:
nplurals=1; plural=0;\n
"
msgid
":mod:`!annotationlib` --- Functionality for introspecting annotations"
msgstr
":mod:`!annotationlib` --- アノテーションを調べるための機能"
msgid
"**Source code:** :source:`Lib/annotationlib.py`"
msgstr
"**ソースコード:** :source:`Lib/annotationlib.py`"
msgid
""
"The :mod:`!annotationlib` module provides tools for introspecting :term:"
"`annotations <annotation>` on modules, classes, and functions."
msgstr
""
":mod:`!annotationlib` モジュールは、モジュール、クラス、関数の :term:`アノ"
"テーション <annotation>` を調べるためのツールを提供します。"
msgid
""
"Annotations are :ref:`lazily evaluated <lazy-evaluation>` and often contain "
"forward references to objects that are not yet defined when the annotation "
"is created. This module provides a set of low-level tools that can be used "
"to retrieve annotations in a reliable way, even in the presence of forward "
"references and other edge cases."
msgstr
""
"アノテーションは :ref:`遅延評価 <lazy-evaluation>` され、作成時にはまだ定義さ"
"れていないオブジェクトへの前方参照を含むことがよくあります。\n"
"このモジュールは、前方参照やその他の特殊な場合があっても、アノテーションを確"
"実に取得するための低水準のツール群を提供します。"
msgid
""
"This module supports retrieving annotations in three main formats (see :"
"class:`Format`), each of which works best for different use cases:"
msgstr
""
"このモジュールは、アノテーションを取得するための三つの主要な形式をサポートし"
"ます (:class:`Format` を参照)。\n"
"それぞれ適した用途が異なります。"
msgid
""
":attr:`~Format.VALUE` evaluates the annotations and returns their value. "
"This is most straightforward to work with, but it may raise errors, for "
"example if the annotations contain references to undefined names."
msgstr
""
":attr:`~Format.VALUE` は、アノテーションを評価してその値を返します。\n"
"最も直接的に扱える形式ですが、未定義の名前を参照するアノテーションなどでは、"
"エラーが発生する場合があります。"
msgid
""
":attr:`~Format.FORWARDREF` returns :class:`ForwardRef` objects for "
"annotations that cannot be resolved, allowing you to inspect the annotations "
"without evaluating them. This is useful when you need to work with "
"annotations that may contain unresolved forward references."
msgstr
""
":attr:`~Format.FORWARDREF` は、解決できないアノテーションに対して :class:"
"`ForwardRef` オブジェクトを返すので、それらを評価せずに調べられます。\n"
"未解決の前方参照を含む可能性のあるアノテーションを扱う場合に便利です。"
msgid
""
":attr:`~Format.STRING` returns the annotations as a string, similar to how "
"it would appear in the source file. This is useful for documentation "
"generators that want to display annotations in a readable way."
msgstr
""
":attr:`~Format.STRING` は、ソースファイルでの表記に近い文字列としてアノテー"
"ションを返します。\n"
"アノテーションを読みやすく表示するドキュメント生成ツールなどに便利です。"
msgid
""
"The :func:`get_annotations` function is the main entry point for retrieving "
"annotations. Given a function, class, or module, it returns an annotations "
"dictionary in the requested format. This module also provides functionality "
"for working directly with the :term:`annotate function` that is used to "
"evaluate annotations, such as :func:`get_annotate_from_class_namespace` and :"
"func:`call_annotate_function`, as well as the :func:`call_evaluate_function` "
"function for working with :term:`evaluate functions <evaluate function>`."
msgstr
""
"アノテーションを取得する主な入口は :func:`get_annotations` 関数です。\n"
"関数、クラス、モジュールを渡すと、指定した形式のアノテーション辞書を返しま"
"す。\n"
"このモジュールには、アノテーションの評価に使う :term:`annotate 関数 "
"<annotate function>` を直接扱う :func:`get_annotate_from_class_namespace` "
"や :func:`call_annotate_function`、および :term:`evaluate 関数 <evaluate "
"function>` を扱う :func:`call_evaluate_function` もあります。"
msgid
""
"Most functionality in this module can execute arbitrary code; see :ref:`the "
"security section <annotationlib-security>` for more information."
msgstr
""
"このモジュールの大半の機能では、任意のコードが実行される可能性があります。\n"
"詳しくは :ref:`セキュリティの節 <annotationlib-security>` を参照してくださ"
"い。"
msgid
""
":pep:`649` proposed the current model for how annotations work in Python."
msgstr
""
"現在の Python のアノテーションの動作モデルは :pep:`649` で提案されました。"
msgid
""
":pep:`749` expanded on various aspects of :pep:`649` and introduced the :mod:"
"`!annotationlib` module."
msgstr
""
":pep:`749` は :pep:`649` のさまざまな側面を詳しく規定し、:mod:`!"
"annotationlib` モジュールを導入しました。"
msgid
""
":ref:`annotations-howto` provides best practices for working with "
"annotations."
msgstr
""
"アノテーションを扱う際の推奨方法は :ref:`annotations-howto` を参照してくださ"
"い。"
msgid
""
":pypi:`typing-extensions` provides a backport of :func:`get_annotations` "
"that works on earlier versions of Python."
msgstr
""
":pypi:`typing-extensions` は、以前の Python バージョンでも使える :func:"
"`get_annotations` のバックポートを提供します。"
msgid
"Annotation semantics"
msgstr
"アノテーションの意味論"
msgid
""
"The way annotations are evaluated has changed over the history of Python 3, "
"and currently still depends on a :ref:`future import <future>`. There have "
"been execution models for annotations:"
msgstr
""
"Python 3 の歴史の中で、アノテーションの評価方法は変化してきました。\n"
"現在も :ref:`future インポート <future>` によって動作が変わります。\n"
"これまで、次の実行モデルが使われてきました。"
msgid
""
"*Stock semantics* (default in Python 3.0 through 3.13; see :pep:`3107` and :"
"pep:`526`): Annotations are evaluated eagerly, as they are encountered in "
"the source code."
msgstr
""
"*従来の意味論* (Python 3.0 から 3.13 までのデフォルト。:pep:`3107` と :pep:"
"`526` を参照): ソースコード内でアノテーションに到達した時点で、即座に評価しま"
"す。"
msgid
""
"*Stringified annotations* (used with ``from __future__ import annotations`` "
"in Python 3.7 and newer; see :pep:`563`): Annotations are stored as strings "
"only."
msgstr
""
"*文字列化されたアノテーション* (Python 3.7 以降で ``from __future__ import "
"annotations`` を使った場合。:pep:`563` を参照): アノテーションを文字列として"
"のみ保存します。"
msgid
""
"*Deferred evaluation* (default in Python 3.14 and newer; see :pep:`649` and :"
"pep:`749`): Annotations are evaluated lazily, only when they are accessed."
msgstr
""
"*遅延評価* (Python 3.14 以降のデフォルト。:pep:`649` と :pep:`749` を参照): "
"アノテーションにアクセスしたときに初めて評価します。"
msgid
"As an example, consider the following program::"
msgstr
"例として、次のプログラムを考えます。 ::"
msgid
""
"def func(a: Cls) -> None:\n"
" print(a)\n"
"\n"
"class Cls: pass\n"
"\n"
"print(func.__annotations__)"
msgstr
""
"def func(a: Cls) -> None:\n"
" print(a)\n"
"\n"
"class Cls: pass\n"
"\n"
"print(func.__annotations__)"
msgid
"This will behave as follows:"
msgstr
"動作は次のようになります。"
msgid
""
"Under stock semantics (Python 3.13 and earlier), it will throw a :exc:"
"`NameError` at the line where ``func`` is defined, because ``Cls`` is an "
"undefined name at that point."
msgstr
""
"従来の意味論 (Python 3.13 以前) では、``func`` を定義する行で :exc:"
"`NameError` が送出されます。\n"
"その時点では ``Cls`` が未定義だからです。"
msgid
""
"Under stringified annotations (if ``from __future__ import annotations`` is "
"used), it will print ``{'a': 'Cls', 'return': 'None'}``."
msgstr
""
"文字列化されたアノテーション (``from __future__ import annotations`` を使った"
"場合) では、``{'a': 'Cls', 'return': 'None'}`` が表示されます。"
msgid
""
"Under deferred evaluation (Python 3.14 and later), it will print ``{'a': "
"<class 'Cls'>, 'return': None}``."
msgstr
""
"遅延評価 (Python 3.14 以降) では、``{'a': <class 'Cls'>, 'return': None}`` が"
"表示されます。"
msgid
""
"Stock semantics were used when function annotations were first introduced in "
"Python 3.0 (by :pep:`3107`) because this was the simplest, most obvious way "
"to implement annotations. The same execution model was used when variable "
"annotations were introduced in Python 3.6 (by :pep:`526`). However, stock "
"semantics caused problems when using annotations as type hints, such as a "
"need to refer to names that are not yet defined when the annotation is "
"encountered. In addition, there were performance problems with executing "
"annotations at module import time. Therefore, in Python 3.7, :pep:`563` "
"introduced the ability to store annotations as strings using the ``from "
"__future__ import annotations`` syntax. The plan at the time was to "
"eventually make this behavior the default, but a problem appeared: "
"stringified annotations are more difficult to process for those who "
"introspect annotations at runtime. An alternative proposal, :pep:`649`, "
"introduced the third execution model, deferred evaluation, and was "
"implemented in Python 3.14. Stringified annotations are still used if ``from "
"__future__ import annotations`` is present, but this behavior will "
"eventually be removed."
msgstr
""
"Python 3.0 で関数のアノテーションが初めて導入されたとき (:pep:`3107`)、実装方"
"法として最も単純で分かりやすかったため、従来の意味論が採用されました。\n"
"Python 3.6 で変数のアノテーションが導入されたとき (:pep:`526`) も、同じ実行モ"
"デルが使われました。\n"
"しかし、アノテーションを型ヒントとして使うと、アノテーションに到達した時点で"
"はまだ定義されていない名前を参照したい場合などに、問題が生じました。\n"
"また、モジュールのインポート時にアノテーションを評価することには、性能上の問"
"題もありました。\n"
"そのため、Python 3.7 では :pep:`563` により、``from __future__ import "
"annotations`` という構文でアノテーションを文字列として保存する機能が導入され"
"ました。\n"
"当初は将来この動作をデフォルトにする予定でしたが、実行時にアノテーションを調"
"べる用途では、文字列化されたアノテーションを処理しにくいという問題が現れまし"
"た。\n"
"代案の :pep:`649` は、三つ目の実行モデルである遅延評価を導入し、Python 3.14 "
"に実装されました。\n"
"``from __future__ import annotations`` がある場合は今も文字列化されたアノテー"
"ションが使われますが、この動作はいずれ削除される予定です。"
#:
../../library/annotationlib.rst:121
msgid
"Classes"
msgstr
"クラス"
msgid
""
"An :class:`~enum.IntEnum` describing the formats in which annotations can be "
"returned. Members of the enum, or their equivalent integer values, can be "
"passed to :func:`get_annotations` and other functions in this module, as "
"well as to :attr:`~object.__annotate__` functions."
msgstr
""
"アノテーションを返す形式を表す :class:`~enum.IntEnum` です。\n"
"列挙型のメンバーまたは対応する整数値を、:func:`get_annotations` などのこのモ"
"ジュールの関数や、:attr:`~object.__annotate__` 関数に渡せます。"
msgid
"Values are the result of evaluating the annotation expressions."
msgstr
"値は、アノテーションの式を評価した結果です。"
msgid
""
"Special value used to signal that an annotate function is being evaluated in "
"a special environment with fake globals. When passed this value, annotate "
"functions should either return the same value as for the :attr:`Format."
"VALUE` format, or raise :exc:`NotImplementedError` to signal that they do "
"not support execution in this environment. This format is only used "
"internally and should not be passed to the functions in this module."
msgstr
""
"annotate 関数が、仮のグローバル名前空間を持つ特別な環境で評価されていることを"
"示す特別な値です。\n"
"この値を渡された annotate 関数は、:attr:`Format.VALUE` 形式と同じ値を返すか、"
"この環境での実行をサポートしないことを示す :exc:`NotImplementedError` を送出"
"する必要があります。\n"
"この形式は内部でのみ使われ、このモジュールの関数に渡すべきではありません。"
msgid
""
"Values are real annotation values (as per :attr:`Format.VALUE` format) for "
"defined values, and :class:`ForwardRef` proxies for undefined values. Real "
"objects may contain references to :class:`ForwardRef` proxy objects."
msgstr
""
"定義済みの値には実際のアノテーションの値 (:attr:`Format.VALUE` 形式と同じ)、"
"未定義の値には :class:`ForwardRef` プロキシを使います。\n"
"実際のオブジェクトが :class:`ForwardRef` プロキシオブジェクトへの参照を含むこ"
"ともあります。"
msgid
""
"Values are the text string of the annotation as it appears in the source "
"code, up to modifications including, but not restricted to, whitespace "
"normalizations and constant values optimizations."
msgstr
""
"値は、ソースコード内のアノテーションの表記を文字列にしたものです。\n"
"ただし、空白の正規化や定数値の最適化などの変更が加わる場合があり、変更はこれ"
"らに限りません。"
msgid
""
"The exact values of these strings may change in future versions of Python."
msgstr
""
"これらの文字列の厳密な値は、将来の Python バージョンで変わる可能性がありま"
"す。"
msgid
"A proxy object for forward references in annotations."
msgstr
"アノテーションの前方参照を表すプロキシオブジェクトです。"
msgid
""
"Instances of this class are returned when the :attr:`~Format.FORWARDREF` "
"format is used and annotations contain a name that cannot be resolved. This "
"can happen when a forward reference is used in an annotation, such as when a "
"class is referenced before it is defined."
msgstr
""
":attr:`~Format.FORWARDREF` 形式を使い、アノテーションに解決できない名前が含ま"
"れている場合、このクラスのインスタンスが返されます。\n"
"例えば、定義前のクラスを参照するなど、アノテーションが前方参照を含む場合に起"
"こります。"
msgid
""
"A string containing the code that was evaluated to produce the :class:"
"`~ForwardRef`. The string may not be exactly equivalent to the original "
"source."
msgstr
""
":class:`~ForwardRef` を生成するために評価されたコードを含む文字列です。\n"
"元のソースコードと完全には一致しない場合があります。"
msgid
"Evaluate the forward reference, returning its value."
msgstr
"前方参照を評価し、その値を返します。"
msgid
""
"If the *format* argument is :attr:`~Format.VALUE` (the default), this method "
"may throw an exception, such as :exc:`NameError`, if the forward reference "
"refers to a name that cannot be resolved. The arguments to this method can "
"be used to provide bindings for names that would otherwise be undefined. If "
"the *format* argument is :attr:`~Format.FORWARDREF`, the method will never "
"throw an exception, but may return a :class:`~ForwardRef` instance. For "
"example, if the forward reference object contains the code "
"``list[undefined]``, where ``undefined`` is a name that is not defined, "
"evaluating it with the :attr:`~Format.FORWARDREF` format will return "
"``list[ForwardRef('undefined')]``. If the *format* argument is :attr:"
"`~Format.STRING`, the method will return :attr:`~ForwardRef.__forward_arg__`."
msgstr
""
"``format`` 引数が :attr:`~Format.VALUE` (デフォルト) の場合、前方参照が解決で"
"きない名前を参照していると、:exc:`NameError` などの例外が送出されることがあり"
"ます。\n"
"このメソッドの引数を使うと、そうしなければ未定義となる名前に値を束縛できま"
"す。\n"
"``format`` 引数が :attr:`~Format.FORWARDREF` の場合、メソッドは例外を送出せ"
"ず、:class:`~ForwardRef` インスタンスを返すことがあります。\n"
"例えば、前方参照オブジェクトが ``list[undefined]`` というコードを含み、"
"``undefined`` が未定義の名前である場合、:attr:`~Format.FORWARDREF` 形式で評価"
"すると ``list[ForwardRef('undefined')]`` を返します。\n"
"``format`` 引数が :attr:`~Format.STRING` の場合は、:attr:`~ForwardRef."
"__forward_arg__` を返します。"
msgid
""
"The *owner* parameter provides the preferred mechanism for passing scope "
"information to this method. The owner of a :class:`~ForwardRef` is the "
"object that contains the annotation from which the :class:`~ForwardRef` "
"derives, such as a module object, type object, or function object."
msgstr
""
"このメソッドにスコープの情報を渡すには、``owner`` パラメーターを使う方法を推"
"奨します。\n"
":class:`~ForwardRef` の所有者は、その :class:`~ForwardRef` の元となったアノ"
"テーションを含むオブジェクトです。\n"
"モジュールオブジェクト、型オブジェクト、関数オブジェクトなどが該当します。"
msgid
""
"The *globals*, *locals*, and *type_params* parameters provide a more precise "
"mechanism for influencing the names that are available when the :class:"
"`~ForwardRef` is evaluated. *globals* and *locals* are passed to :func:"
"`eval`, representing the global and local namespaces in which the name is "
"evaluated. The *type_params* parameter is relevant for objects created using "
"the native syntax for :ref:`generic classes <generic-classes>` and :ref:"
"`functions <generic-functions>`. It is a tuple of :ref:`type parameters "
"<type-params>` that are in scope while the forward reference is being "
"evaluated. For example, if evaluating a :class:`~ForwardRef` retrieved from "
"an annotation found in the class namespace of a generic class ``C``, "
"*type_params* should be set to ``C.__type_params__``."
msgstr
""
"``globals``、``locals``、``type_params`` パラメーターを使うと、:class:"
"`~ForwardRef` の評価時に利用できる名前をより細かく制御できます。\n"
"``globals`` と ``locals`` は :func:`eval` に渡され、名前を評価するグローバル"
"名前空間とローカル名前空間を表します。\n"
"``type_params`` は、:ref:`ジェネリッククラス <generic-classes>` や :ref:`ジェ"
"ネリック関数 <generic-functions>` の専用構文で作成されたオブジェクトに関係し"
"ます。\n"
"前方参照の評価時にスコープ内にある :ref:`型パラメーター <type-params>` のタプ"
"ルです。\n"
"例えば、ジェネリッククラス ``C`` のクラス名前空間にあるアノテーションから取得"
"した :class:`~ForwardRef` を評価する場合、``type_params`` に ``C."
"__type_params__`` を指定してください。"
msgid
""
":class:`~ForwardRef` instances returned by :func:`get_annotations` retain "
"references to information about the scope they originated from, so calling "
"this method with no further arguments may be sufficient to evaluate such "
"objects. :class:`~ForwardRef` instances created by other means may not have "
"any information about their scope, so passing arguments to this method may "
"be necessary to evaluate them successfully."
msgstr
""
":func:`get_annotations` が返す :class:`~ForwardRef` インスタンスは、元のス"
"コープの情報への参照を保持します。\n"
"そのため、追加の引数を指定せずにこのメソッドを呼ぶだけで、評価できる場合があ"
"ります。\n"
"他の方法で作った :class:`~ForwardRef` インスタンスにはスコープの情報がない場"
"合があるため、正しく評価するには引数を渡す必要があるかもしれません。"
msgid
""
"If no *owner*, *globals*, *locals*, or *type_params* are provided and the :"
"class:`~ForwardRef` does not contain information about its origin, empty "
"globals and locals dictionaries are used."
msgstr
""
"``owner``、``globals``、``locals``、``type_params`` をどれも指定せず、:class:"
"`~ForwardRef` に元のスコープの情報がない場合、グローバルとローカルの名前空間"
"には空の辞書を使います。"
#:
../../library/annotationlib.rst:227
msgid
"Functions"
msgstr
"関数"
msgid
""
"Convert an annotations dict containing runtime values to a dict containing "
"only strings. If the values are not already strings, they are converted "
"using :func:`type_repr`. This is meant as a helper for user-provided "
"annotate functions that support the :attr:`~Format.STRING` format but do not "
"have access to the code creating the annotations."
msgstr
""
"実行時の値を含むアノテーション辞書を、文字列だけを含む辞書に変換します。\n"
"値がまだ文字列でなければ、:func:`type_repr` で変換します。\n"
"これは、:attr:`~Format.STRING` 形式をサポートするものの、アノテーションを作成"
"したコードにはアクセスできない、ユーザー定義の annotate 関数を補助するための"
"関数です。"
msgid
""
"For example, this is used to implement the :attr:`~Format.STRING` format "
"for :class:`typing.TypedDict` classes created through the functional syntax:"
msgstr
""
"例えば、関数形式の構文で作成した :class:`typing.TypedDict` クラスの :attr:"
"`~Format.STRING` 形式は、この関数で実装されています。"
msgid
""
">>> from typing import TypedDict\n"
">>> Movie = TypedDict(
\"
movie
\"
, {
\"
name
\"
: str,
\"
year
\"
: int})\n"
">>> get_annotations(Movie, format=Format.STRING)\n"
"{'name': 'str', 'year': 'int'}"
msgstr
""
">>> from typing import TypedDict\n"
">>> Movie = TypedDict(
\"
movie
\"
, {
\"
name
\"
: str,
\"
year
\"
: int})\n"
">>> get_annotations(Movie, format=Format.STRING)\n"
"{'name': 'str', 'year': 'int'}"
msgid
""
"Call the :term:`annotate function` *annotate* with the given *format*, a "
"member of the :class:`Format` enum, and return the annotations dictionary "
"produced by the function."
msgstr
""
":term:`annotate 関数 <annotate function>` ``annotate`` を、:class:`Format` 列"
"挙型のメンバーである ``format`` を指定して呼び出し、その関数が生成したアノ"
"テーション辞書を返します。"
msgid
""
"This helper function is required because annotate functions generated by the "
"compiler for functions, classes, and modules only support the :attr:`~Format."
"VALUE` format when called directly. To support other formats, this function "
"calls the annotate function in a special environment that allows it to "
"produce annotations in the other formats. This is a useful building block "
"when implementing functionality that needs to partially evaluate annotations "
"while a class is being constructed."
msgstr
""
"関数、クラス、モジュールのためにコンパイラが生成する annotate 関数は、直接呼"
"び出した場合には :attr:`~Format.VALUE` 形式しかサポートしないため、この補助関"
"数が必要です。\n"
"他の形式をサポートするため、この関数は特別な環境で annotate 関数を呼び出し、"
"それらの形式のアノテーションを生成できるようにします。\n"
"クラスの作成途中でアノテーションを部分的に評価する機能を実装する際に役立ちま"
"す。"
msgid
""
"*owner* is the object that owns the annotation function, usually a function, "
"class, or module. If provided, it is used in the :attr:`~Format.FORWARDREF` "
"format to produce a :class:`ForwardRef` object that carries more information."
msgstr
""
"``owner`` はアノテーション関数を所有するオブジェクトで、通常は関数、クラス、"
"モジュールのいずれかです。\n"
"指定すると、:attr:`~Format.FORWARDREF` 形式で、より多くの情報を持つ :class:"
"`ForwardRef` オブジェクトを生成するために使われます。"
msgid
""
":PEP:`PEP 649 <649#the-stringizer-and-the-fake-globals-environment>` "
"contains an explanation of the implementation technique used by this "
"function."
msgstr
""
"この関数で使われている実装手法は、:PEP:`PEP 649 <649#the-stringizer-and-the-"
"fake-globals-environment>` で説明されています。"
msgid
""
"Call the :term:`evaluate function` *evaluate* with the given *format*, a "
"member of the :class:`Format` enum, and return the value produced by the "
"function. This is similar to :func:`call_annotate_function`, but the latter "
"always returns a dictionary mapping strings to annotations, while this "
"function returns a single value."
msgstr
""
":term:`evaluate 関数 <evaluate function>` ``evaluate`` を、:class:`Format` 列"
"挙型のメンバーである ``format`` を指定して呼び出し、その関数が生成した値を返"
"します。\n"
":func:`call_annotate_function` と似ていますが、そちらは常に文字列をアノテー"
"ションに対応付ける辞書を返すのに対し、この関数は一つの値を返します。"
msgid
""
"This is intended for use with the evaluate functions generated for lazily "
"evaluated elements related to type aliases and type parameters:"
msgstr
""
"この関数は、型エイリアスや型パラメーターに関係する、遅延評価される要素のため"
"に生成された evaluate 関数で使うことを想定しています。"
msgid
":meth:`typing.TypeAliasType.evaluate_value`, the value of type aliases"
msgstr
":meth:`typing.TypeAliasType.evaluate_value`: 型エイリアスの値"
msgid
":meth:`typing.TypeVar.evaluate_bound`, the bound of type variables"
msgstr
":meth:`typing.TypeVar.evaluate_bound`: 型変数の上限"
msgid
""
":meth:`typing.TypeVar.evaluate_constraints`, the constraints of type "
"variables"
msgstr
":meth:`typing.TypeVar.evaluate_constraints`: 型変数の制約"
msgid
""
":meth:`typing.TypeVar.evaluate_default`, the default value of type variables"
msgstr
":meth:`typing.TypeVar.evaluate_default`: 型変数のデフォルト値"
msgid
""
":meth:`typing.ParamSpec.evaluate_default`, the default value of parameter "
"specifications"
msgstr
""
":meth:`typing.ParamSpec.evaluate_default`: パラメーター仕様のデフォルト値"
msgid
""
":meth:`typing.TypeVarTuple.evaluate_default`, the default value of type "
"variable tuples"
msgstr
""
":meth:`typing.TypeVarTuple.evaluate_default`: 型変数タプルのデフォルト値"
msgid
""
"*owner* is the object that owns the evaluate function, such as the type "
"alias or type variable object."
msgstr
""
"``owner`` は evaluate 関数を所有するオブジェクトです。\n"
"型エイリアスや型変数のオブジェクトなどが該当します。"
msgid
""
"*format* can be used to control the format in which the value is returned:"
msgstr
"``format`` で、値を返す形式を制御できます。"
msgid
""
">>> type Alias = undefined\n"
">>> call_evaluate_function(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')\n"
">>> call_evaluate_function(Alias.evaluate_value, Format.STRING)\n"
"'undefined'"
msgstr
""
">>> type Alias = undefined\n"
">>> call_evaluate_function(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')\n"
">>> call_evaluate_function(Alias.evaluate_value, Format.STRING)\n"
"'undefined'"
msgid
""
"Retrieve the :term:`annotate function` from a class namespace dictionary "
"*namespace*. Return :const:`!None` if the namespace does not contain an "
"annotate function. This is primarily useful before the class has been fully "
"created (e.g., in a metaclass); after the class exists, the annotate "
"function can be retrieved with ``cls.__annotate__``. See :ref:`below "
"<annotationlib-metaclass>` for an example using this function in a metaclass."
msgstr
""
"クラスの名前空間辞書 ``namespace`` から :term:`annotate 関数 <annotate "
"function>` を取得します。\n"
"名前空間に annotate 関数がなければ :const:`!None` を返します。\n"
"主に、クラスの作成が完了する前 (メタクラス内など) に役立ちます。\n"
"クラスができた後は、``cls.__annotate__`` で annotate 関数を取得できます。\n"
"メタクラスでこの関数を使う例は :ref:`後述 <annotationlib-metaclass>` します。"
#:
../../library/annotationlib.rst:331
msgid
"Compute the annotations dict for an object."
msgstr
"オブジェクトに対するアノテーション辞書を計算します。"
msgid
""
"*obj* may be a callable, class, module, or other object with :attr:`~object."
"__annotate__` or :attr:`~object.__annotations__` attributes. Passing any "
"other object raises :exc:`TypeError`."
msgstr
""
"``obj`` には、呼び出し可能オブジェクト、クラス、モジュール、または :attr:"
"`~object.__annotate__` 属性か :attr:`~object.__annotations__` 属性を持つ他の"
"オブジェクトを指定できます。\n"
"それ以外のオブジェクトを渡すと :exc:`TypeError` が送出されます。"
msgid
""
"The *format* parameter controls the format in which annotations are "
"returned, and must be a member of the :class:`Format` enum or its integer "
"equivalent. The different formats work as follows:"
msgstr
""
"``format`` パラメーターはアノテーションを返す形式を制御し、:class:`Format` 列"
"挙型のメンバーまたは対応する整数値を指定する必要があります。\n"
"各形式の動作は次のとおりです。"
msgid
""
"VALUE: :attr:`!object.__annotations__` is tried first; if that does not "
"exist, the :attr:`!object.__annotate__` function is called if it exists."
msgstr
""
"VALUE: まず :attr:`!object.__annotations__` を試します。\n"
"それがなければ、:attr:`!object.__annotate__` 関数があれば呼び出します。"
msgid
""
"FORWARDREF: If :attr:`!object.__annotations__` exists and can be evaluated "
"successfully, it is used; otherwise, the :attr:`!object.__annotate__` "
"function is called. If it does not exist either, :attr:`!object."
"__annotations__` is tried again and any error from accessing it is re-raised."
msgstr
""
"FORWARDREF: :attr:`!object.__annotations__` があり、正常に評価できればそれを"
"使います。\n"
"そうでなければ :attr:`!object.__annotate__` 関数を呼び出します。\n"
"その関数もない場合は、再び :attr:`!object.__annotations__` を試し、アクセス時"
"のエラーを再送出します。"
msgid
""
"When calling :attr:`!object.__annotate__` it is first called with :attr:"
"`~Format.FORWARDREF`. If this is not implemented, it will then check if :"
"attr:`~Format.VALUE_WITH_FAKE_GLOBALS` is supported and use that in the fake "
"globals environment. If neither of these formats are supported, it will fall "
"back to using :attr:`~Format.VALUE`. If :attr:`~Format.VALUE` fails, the "
"error from this call will be raised."
msgstr
""
":attr:`!object.__annotate__` は、まず :attr:`~Format.FORWARDREF` を指定して呼"
"び出します。\n"
"その形式が実装されていなければ、:attr:`~Format.VALUE_WITH_FAKE_GLOBALS` のサ"
"ポートを確認し、仮のグローバル名前空間を持つ環境で使います。\n"
"どちらの形式もサポートされていなければ、:attr:`~Format.VALUE` を使います。\n"
":attr:`~Format.VALUE` での呼び出しが失敗した場合は、そのエラーを送出します。"
msgid
""
"STRING: If :attr:`!object.__annotate__` exists, it is called first; "
"otherwise, :attr:`!object.__annotations__` is used and stringified using :"
"func:`annotations_to_string`."
msgstr
""
"STRING: :attr:`!object.__annotate__` があれば、まずそれを呼び出します。\n"
"なければ :attr:`!object.__annotations__` を使い、:func:"
"`annotations_to_string` で文字列化します。"
msgid
""
"When calling :attr:`!object.__annotate__` it is first called with :attr:"
"`~Format.STRING`. If this is not implemented, it will then check if :attr:"
"`~Format.VALUE_WITH_FAKE_GLOBALS` is supported and use that in the fake "
"globals environment. If neither of these formats are supported, it will fall "
"back to using :attr:`~Format.VALUE` with the result converted using :func:"
"`annotations_to_string`. If :attr:`~Format.VALUE` fails, the error from this "
"call will be raised."
msgstr
""
":attr:`!object.__annotate__` は、まず :attr:`~Format.STRING` を指定して呼び出"
"します。\n"
"その形式が実装されていなければ、:attr:`~Format.VALUE_WITH_FAKE_GLOBALS` のサ"
"ポートを確認し、仮のグローバル名前空間を持つ環境で使います。\n"
"どちらの形式もサポートされていなければ、:attr:`~Format.VALUE` を使い、その結"
"果を :func:`annotations_to_string` で変換します。\n"
":attr:`~Format.VALUE` での呼び出しが失敗した場合は、そのエラーを送出します。"
msgid
""
"Returns a dict. :func:`!get_annotations` returns a new dict every time it's "
"called; calling it twice on the same object will return two different but "
"equivalent dicts."
msgstr
""
"辞書を返します。\n"
":func:`!get_annotations` は呼び出すたびに新しい辞書を返します。\n"
"同じオブジェクトに対して 2 回呼び出すと、内容は同じでも別々の辞書が返されま"
"す。"
msgid
"This function handles several details for you:"
msgstr
"この関数は、次の細部も処理します。"
msgid
""
"If *eval_str* is true, values of type :class:`!str` will be un-stringized "
"using :func:`eval`. This is intended for use with stringized annotations "
"(``from __future__ import annotations``). It is an error to set *eval_str* "
"to true with formats other than :attr:`Format.VALUE`."
msgstr
""
"``eval_str`` が真の場合、:class:`!str` 型の値を :func:`eval` で評価し、文字列"
"化される前の値に戻します。\n"
"これは、文字列化されたアノテーション (``from __future__ import "
"annotations``) で使うことを想定しています。\n"
":attr:`Format.VALUE` 以外の形式で ``eval_str`` を真にすると、エラーになりま"
"す。"
msgid
""
"If *obj* doesn't have an annotations dict, returns an empty dict. (Functions "
"and methods always have an annotations dict; classes, modules, and other "
"types of callables may not.)"
msgstr
""
"``obj`` にアノテーション辞書がなければ、空の辞書を返します。\n"
"(関数とメソッドには常にアノテーション辞書がありますが、クラス、モジュール、他"
"の種類の呼び出し可能オブジェクトにはない場合があります。)"
msgid
""
"Ignores inherited annotations on classes, as well as annotations on "
"metaclasses. If a class doesn't have its own annotations dict, returns an "
"empty dict."
msgstr
""
"クラスが継承したアノテーションと、メタクラスのアノテーションは無視します。\n"
"クラス自体にアノテーション辞書がなければ、空の辞書を返します。"
msgid
""
"All accesses to object members and dict values are done using ``getattr()`` "
"and ``dict.get()`` for safety."
msgstr
""
"安全のため、オブジェクトのメンバーと辞書の値へのアクセスには、すべて "
"``getattr()`` と ``dict.get()`` を使います。"
msgid
""
"*eval_str* controls whether or not values of type :class:`!str` are replaced "
"with the result of calling :func:`eval` on those values:"
msgstr
""
"``eval_str`` は、:class:`!str` 型の値を、その値に対して :func:`eval` を呼び出"
"した結果に置き換えるかどうかを制御します。"
msgid
""
"If eval_str is true, :func:`eval` is called on values of type :class:`!str`. "
"(Note that :func:`!get_annotations` doesn't catch exceptions; if :func:"
"`eval` raises an exception, it will unwind the stack past the :func:`!"
"get_annotations` call.)"
msgstr
""
"``eval_str`` が真の場合、:class:`!str` 型の値に対して :func:`eval` を呼び出し"
"ます。\n"
"(:func:`!get_annotations` は例外を捕捉しません。\n"
":func:`eval` が例外を送出すると、:func:`!get_annotations` の呼び出し元まで伝"
"播します。)"
msgid
""
"If *eval_str* is false (the default), values of type :class:`!str` are "
"unchanged."
msgstr
""
"``eval_str`` が偽 (デフォルト) の場合、:class:`!str` 型の値は変更しません。"
msgid
""
"*globals* and *locals* are passed in to :func:`eval`; see the documentation "
"for :func:`eval` for more information. If *globals* or *locals* is :const:`!"
"None`, this function may replace that value with a context-specific default, "
"contingent on ``type(obj)``:"
msgstr
""
"``globals`` と ``locals`` は :func:`eval` に渡されます。\n"
"詳しくは :func:`eval` のドキュメントを参照してください。\n"
"``globals`` または ``locals`` が :const:`!None` の場合、この関数は "
"``type(obj)`` に応じて、その値を文脈に適したデフォルト値に置き換えることがあ"
"ります。"
msgid
"If *obj* is a module, *globals* defaults to ``obj.__dict__``."
msgstr
""
"``obj`` がモジュールの場合、``globals`` のデフォルト値は ``obj.__dict__`` で"
"す。"
msgid
""
"If *obj* is a class, *globals* defaults to ``sys.modules[obj.__module__]."
"__dict__`` and *locals* defaults to the *obj* class namespace."
msgstr
""
"``obj`` がクラスの場合、``globals`` のデフォルト値は ``sys.modules[obj."
"__module__].__dict__``、``locals`` のデフォルト値は ``obj`` のクラス名前空間"
"です。"
msgid
""
"If *obj* is a callable, *globals* defaults to :attr:`obj.__globals__ "
"<function.__globals__>`, although if *obj* is a wrapped function (using :"
"func:`functools.update_wrapper`) or a :class:`functools.partial` object, it "
"is unwrapped until a non-wrapped function is found."
msgstr
""
"``obj`` が呼び出し可能オブジェクトの場合、``globals`` のデフォルト値は :attr:"
"`obj.__globals__ <function.__globals__>` です。\n"
"ただし、``obj`` が (:func:`functools.update_wrapper` を使って) ラップされた関"
"数か :class:`functools.partial` オブジェクトの場合は、ラップされていない関数"
"が見つかるまでラッパーをたどって外します。"
msgid
""
"Calling :func:`!get_annotations` is best practice for accessing the "
"annotations dict of any object. See :ref:`annotations-howto` for more "
"information on annotations best practices."
msgstr
""
"オブジェクトのアノテーション辞書へのアクセスには、:func:`!get_annotations` の"
"呼び出しを推奨します。\n"
"アノテーションの推奨される扱い方については、:ref:`annotations-howto` を参照し"
"てください。"
msgid
""
">>> def f(a: int, b: str) -> float:\n"
"... pass\n"
">>> get_annotations(f)\n"
"{'a': <class 'int'>, 'b': <class 'str'>, 'return': <class 'float'>}"
msgstr
""
">>> def f(a: int, b: str) -> float:\n"
"... pass\n"
">>> get_annotations(f)\n"
"{'a': <class 'int'>, 'b': <class 'str'>, 'return': <class 'float'>}"
msgid
""
"Convert an arbitrary Python value to a format suitable for use by the :attr:"
"`~Format.STRING` format. This calls :func:`repr` for most objects, but has "
"special handling for some objects, such as type objects."
msgstr
""
"任意の Python の値を、:attr:`~Format.STRING` 形式での使用に適した表現に変換し"
"ます。\n"
"大半のオブジェクトには :func:`repr` を呼び出しますが、型オブジェクトなど一部"
"のオブジェクトには特別な処理を行います。"
msgid
""
"This is meant as a helper for user-provided annotate functions that support "
"the :attr:`~Format.STRING` format but do not have access to the code "
"creating the annotations. It can also be used to provide a user-friendly "
"string representation for other objects that contain values that are "
"commonly encountered in annotations."
msgstr
""
"これは、:attr:`~Format.STRING` 形式をサポートするものの、アノテーションを作成"
"したコードにはアクセスできない、ユーザー定義の annotate 関数を補助するための"
"関数です。\n"
"アノテーションでよく使われる値を含む他のオブジェクトについても、読みやすい文"
"字列表現を提供するために使えます。"
#:
../../library/annotationlib.rst:441
msgid
"Recipes"
msgstr
"レシピ"
msgid
"Using annotations in a metaclass"
msgstr
"メタクラスでのアノテーションの利用"
msgid
""
"A :ref:`metaclass <metaclasses>` may want to inspect or even modify the "
"annotations in a class body during class creation. Doing so requires "
"retrieving annotations from the class namespace dictionary. For classes "
"created with ``from __future__ import annotations``, the annotations will be "
"in the ``__annotations__`` key of the dictionary. For other classes with "
"annotations, :func:`get_annotate_from_class_namespace` can be used to get "
"the annotate function, and :func:`call_annotate_function` can be used to "
"call it and retrieve the annotations. Using the :attr:`~Format.FORWARDREF` "
"format will usually be best, because this allows the annotations to refer to "
"names that cannot yet be resolved when the class is created."
msgstr
""
":ref:`メタクラス <metaclasses>` では、クラスの作成中にクラス本体のアノテー"
"ションを調べたり変更したりしたい場合があります。\n"
"そのためには、クラスの名前空間辞書からアノテーションを取得する必要がありま"
"す。\n"
"``from __future__ import annotations`` を使って作成されたクラスでは、アノテー"
"ションは辞書の ``__annotations__`` キーにあります。\n"
"それ以外のアノテーションを持つクラスでは、:func:"
"`get_annotate_from_class_namespace` で annotate 関数を取得し、:func:"
"`call_annotate_function` で呼び出してアノテーションを取得できます。\n"
"クラスの作成時にはまだ解決できない名前をアノテーションで参照できるよう、通常"
"は :attr:`~Format.FORWARDREF` 形式を使うのが最適です。"
msgid
""
"To modify the annotations, it is best to create a wrapper annotate function "
"that calls the original annotate function, makes any necessary adjustments, "
"and returns the result."
msgstr
""
"アノテーションを変更するには、元の annotate 関数を呼び出して必要な調整を加"
"え、結果を返すラッパーの annotate 関数を作るのがよい方法です。"
msgid
""
"Below is an example of a metaclass that filters out all :class:`typing."
"ClassVar` annotations from the class and puts them in a separate attribute:"
msgstr
""
"次の例は、クラスからすべての :class:`typing.ClassVar` アノテーションを取り出"
"し、別の属性に格納するメタクラスです。"
msgid
""
"import annotationlib\n"
"import typing\n"
"\n"
"class ClassVarSeparator(type):\n"
" def __new__(mcls, name, bases, ns):\n"
" if
\"
__annotations__
\"
in ns: # from __future__ import annotations\n"
" annotations = ns[
\"
__annotations__
\"
]\n"
" classvar_keys = {\n"
" key for key, value in annotations.items()\n"
" # Use string comparison for simplicity; a more robust solution\n"
" # could use annotationlib.ForwardRef.evaluate\n"
" if value.startswith(
\"
ClassVar
\"
)\n"
" }\n"
" classvars = {key: annotations[key] for key in classvar_keys}\n"
" ns[
\"
__annotations__
\"
] = {\n"
" key: value for key, value in annotations.items()\n"
" if key not in classvar_keys\n"
" }\n"
" wrapped_annotate = None\n"
" elif annotate := annotationlib.get_annotate_from_class_namespace(ns):\n"
" annotations = annotationlib.call_annotate_function(\n"
" annotate, format=annotationlib.Format.FORWARDREF\n"
" )\n"
" classvar_keys = {\n"
" key for key, value in annotations.items()\n"
" if typing.get_origin(value) is typing.ClassVar\n"
" }\n"
" classvars = {key: annotations[key] for key in classvar_keys}\n"
"\n"
" def wrapped_annotate(format):\n"
" annos = annotationlib.call_annotate_function(annotate, format, "
"owner=typ)\n"
" return {key: value for key, value in annos.items() if key not in "
"classvar_keys}\n"
"\n"
" else: # no annotations\n"
" classvars = {}\n"
" wrapped_annotate = None\n"
" typ = super().__new__(mcls, name, bases, ns)\n"
"\n"
" if wrapped_annotate is not None:\n"
" # Wrap the original __annotate__ with a wrapper that removes "
"ClassVars\n"
" typ.__annotate__ = wrapped_annotate\n"
" typ.classvars = classvars # Store the ClassVars in a separate "
"attribute\n"
" return typ"
msgstr
""
"import annotationlib\n"
"import typing\n"
"\n"
"class ClassVarSeparator(type):\n"
" def __new__(mcls, name, bases, ns):\n"
" if
\"
__annotations__
\"
in ns: # from __future__ import annotations\n"
" annotations = ns[
\"
__annotations__
\"
]\n"
" classvar_keys = {\n"
" key for key, value in annotations.items()\n"
" # 簡単にするため文字列を比較する。より堅牢な方法には\n"
" # annotationlib.ForwardRef.evaluate を使える\n"
" if value.startswith(
\"
ClassVar
\"
)\n"
" }\n"
" classvars = {key: annotations[key] for key in classvar_keys}\n"
" ns[
\"
__annotations__
\"
] = {\n"
" key: value for key, value in annotations.items()\n"
" if key not in classvar_keys\n"
" }\n"
" wrapped_annotate = None\n"
" elif annotate := annotationlib.get_annotate_from_class_namespace(ns):\n"
" annotations = annotationlib.call_annotate_function(\n"
" annotate, format=annotationlib.Format.FORWARDREF\n"
" )\n"
" classvar_keys = {\n"
" key for key, value in annotations.items()\n"
" if typing.get_origin(value) is typing.ClassVar\n"
" }\n"
" classvars = {key: annotations[key] for key in classvar_keys}\n"
"\n"
" def wrapped_annotate(format):\n"
" annos = annotationlib.call_annotate_function(annotate, format, "
"owner=typ)\n"
" return {key: value for key, value in annos.items() if key not in "
"classvar_keys}\n"
"\n"
" else: # アノテーションなし\n"
" classvars = {}\n"
" wrapped_annotate = None\n"
" typ = super().__new__(mcls, name, bases, ns)\n"
"\n"
" if wrapped_annotate is not None:\n"
" # 元の __annotate__ を、ClassVar を取り除くラッパーで包む\n"
" typ.__annotate__ = wrapped_annotate\n"
" typ.classvars = classvars # ClassVar を別の属性に格納する\n"
" return typ"
msgid
"Creating a custom callable annotate function"
msgstr
"独自の呼び出し可能オブジェクトによる annotate 関数の作成"
msgid
""
"Custom :term:`annotate functions <annotate function>` may be literal "
"functions like those automatically generated for functions, classes, and "
"modules. Or, they may wish to utilise the encapsulation provided by classes, "
"in which case any :term:`callable` can be used as an :term:`annotate "
"function`."
msgstr
""
"独自の :term:`annotate 関数 <annotate function>` は、関数、クラス、モジュール"
"用に自動生成されるものと同じように、通常の関数で実装できます。\n"
"クラスによるカプセル化を使いたい場合には、任意の :term:`呼び出し可能オブジェ"
"クト <callable>` を :term:`annotate 関数 <annotate function>` として使えま"
"す。"
msgid
""
"To provide the :attr:`~Format.VALUE`, :attr:`~Format.STRING`, or :attr:"
"`~Format.FORWARDREF` formats directly, an :term:`annotate function` must "
"provide the following attribute:"
msgstr
""
":attr:`~Format.VALUE`、:attr:`~Format.STRING`、:attr:`~Format.FORWARDREF` 形"
View remainder of file in raw view
Back
|
FazBrowse Home
|
New Git URL