FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python-docs-de/howto/annotations.po at sync-upstream-3.15 · python/python-docs-de · GitHub
python
python-docs-de
Repository navigation
Code
Issues
Pull requests
2
(2)
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
python-docs-de
/
howto
/
annotations.po
Copy path
More file actions
More file actions
Latest commit
History
History
History
563 lines (513 loc) · 25.2 KB
Breadcrumbs
python-docs-de
/
howto
/
annotations.po
Copy path
File metadata and controls
563 lines (513 loc) · 25.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
#
German translation of the Python documentation.
#
Copyright (C) 2001 Python Software Foundation
#
This file is distributed under the same license as the Python package.
#
#
Translators:
#
Swen Bachmann, 2026
#
msgid ""
msgstr ""
"
Project-Id-Version
:
Python 3.15\n
"
"
Report-Msgid-Bugs-To
:
\n
"
"
POT-Creation-Date
:
2026-09-14 20:17+0000\n
"
"
PO-Revision-Date
:
2026-10-15 06:00+0200\n
"
"
Last-Translator
:
python-doc bot, 2025\n
"
"
Language-Team
:
German (https://github.com/python/python-docs-de)\n
"
"
Language
:
de\n
"
"
MIME-Version
:
1.0\n
"
"
Content-Type
:
text/plain; charset=UTF-8\n
"
"
Content-Transfer-Encoding
:
8bit\n
"
"
Plural-Forms
:
nplurals=2; plural=(n != 1);\n
"
#:
../../howto/annotations.rst:5
msgid
"Annotations Best Practices"
msgstr
"Best Practices für Annotationen"
#:
../../howto/annotations.rst:7
msgid
"Abstract"
msgstr
"Zusammenfassung"
#:
../../howto/annotations.rst:9
msgid
""
"This document is designed to encapsulate the best practices for working with "
"annotations dicts. If you write Python code that examines "
"``__annotations__`` on Python objects, we encourage you to follow the "
"guidelines described below."
msgstr
""
"Dieses Dokument soll die Best Practices für die Arbeit mit Annotations-"
"Dictionarys bündeln. Wenn du Python-Code schreibst, der ``__annotations__`` "
"an Python-Objekten untersucht, empfehlen wir dir, den unten beschriebenen "
"Richtlinien zu folgen."
#:
../../howto/annotations.rst:14
msgid
""
"The document is organized into four sections: best practices for accessing "
"the annotations of an object in Python versions 3.10 and newer, best "
"practices for accessing the annotations of an object in Python versions 3.9 "
"and older, other best practices for ``__annotations__`` that apply to any "
"Python version, and quirks of ``__annotations__``."
msgstr
""
"Das Dokument ist in vier Abschnitte gegliedert: Best Practices für den "
"Zugriff auf die Annotationen eines Objekts in Python 3.10 und neuer, Best "
"Practices für den Zugriff auf die Annotationen eines Objekts in Python 3.9 "
"und älter, weitere Best Practices zu ``__annotations__``, die für jede "
"Python-Version gelten, und Eigenheiten von ``__annotations__``."
#:
../../howto/annotations.rst:24
msgid
""
"Note that this document is specifically about working with "
"``__annotations__``, not uses *for* annotations. If you're looking for "
"information on how to use
\"
type hints
\"
in your code, please see the :mod:"
"`typing` module."
msgstr
""
"Beachte, dass es in diesem Dokument ausdrücklich um die Arbeit *mit* "
"``__annotations__`` geht, nicht um Verwendungszwecke *für* Annotationen. "
"Wenn du Informationen dazu suchst, wie du „Type Hints“ in deinem Code "
"verwendest, lies bitte beim Modul :mod:`typing` nach."
#:
../../howto/annotations.rst:31
msgid
"Accessing The Annotations Dict Of An Object In Python 3.10 And Newer"
msgstr
""
"Zugriff auf das Annotations-Dictionary eines Objekts in Python 3.10 und neuer"
#:
../../howto/annotations.rst:33
msgid
""
"Python 3.10 adds a new function to the standard library: :func:`inspect."
"get_annotations`. In Python versions 3.10 through 3.13, calling this "
"function is the best practice for accessing the annotations dict of any "
"object that supports annotations. This function can also
\"
un-stringize
\"
"
"stringized annotations for you."
msgstr
""
"Python 3.10 ergänzt die Standardbibliothek um eine neue Funktion: :func:"
"`inspect.get_annotations`. In den Python-Versionen 3.10 bis 3.13 ist der "
"Aufruf dieser Funktion die beste Vorgehensweise, um auf das Annotations-"
"Dictionary eines beliebigen Objekts zuzugreifen, das Annotationen "
"unterstützt. Diese Funktion kann Annotationen, die als Zeichenketten "
"vorliegen, für dich auch wieder zurückwandeln."
#:
../../howto/annotations.rst:40
msgid
""
"In Python 3.14, there is a new :mod:`annotationlib` module with "
"functionality for working with annotations. This includes a :func:"
"`annotationlib.get_annotations` function, which supersedes :func:`inspect."
"get_annotations`."
msgstr
""
"In Python 3.14 gibt es ein neues Modul :mod:`annotationlib` mit "
"Funktionalität für die Arbeit mit Annotationen. Dazu gehört eine Funktion :"
"func:`annotationlib.get_annotations`, die :func:`inspect.get_annotations` "
"ersetzt."
#:
../../howto/annotations.rst:45
msgid
""
"If for some reason :func:`inspect.get_annotations` isn't viable for your use "
"case, you may access the ``__annotations__`` data member manually. Best "
"practice for this changed in Python 3.10 as well: as of Python 3.10, ``o."
"__annotations__`` is guaranteed to *always* work on Python functions, "
"classes, and modules. If you're certain the object you're examining is one "
"of these three *specific* objects, you may simply use ``o.__annotations__`` "
"to get at the object's annotations dict."
msgstr
""
"Wenn :func:`inspect.get_annotations` für deinen Anwendungsfall aus "
"irgendeinem Grund nicht in Frage kommt, kannst du auf das Datenelement "
"``__annotations__`` auch von Hand zugreifen. Die beste Vorgehensweise dafür "
"hat sich mit Python 3.10 ebenfalls geändert: Seit Python 3.10 ist "
"garantiert, dass ``o.__annotations__`` bei Python-Funktionen, -Klassen und -"
"Modulen *immer* funktioniert. Wenn du sicher bist, dass das untersuchte "
"Objekt eines dieser drei *bestimmten* Objekte ist, kannst du einfach ``o."
"__annotations__`` verwenden, um an das Annotations-Dictionary des Objekts zu "
"kommen."
#:
../../howto/annotations.rst:55
msgid
""
"However, other types of callables--for example, callables created by :func:"
"`functools.partial`--may not have an ``__annotations__`` attribute defined. "
"When accessing the ``__annotations__`` of a possibly unknown object, best "
"practice in Python versions 3.10 and newer is to call :func:`getattr` with "
"three arguments, for example ``getattr(o, '__annotations__', None)``."
msgstr
""
"Andere Arten von aufrufbaren Objekten – zum Beispiel solche, die von :func:"
"`functools.partial` erzeugt werden – haben möglicherweise kein Attribut "
"``__annotations__`` definiert. Beim Zugriff auf ``__annotations__`` eines "
"möglicherweise unbekannten Objekts ist es in Python 3.10 und neuer die beste "
"Vorgehensweise, :func:`getattr` mit drei Argumenten aufzurufen, zum Beispiel "
"``getattr(o, '__annotations__', None)``."
#:
../../howto/annotations.rst:63
msgid
""
"Before Python 3.10, accessing ``__annotations__`` on a class that defines no "
"annotations but that has a parent class with annotations would return the "
"parent's ``__annotations__``. In Python 3.10 and newer, the child class's "
"annotations will be an empty dict instead."
msgstr
""
"Vor Python 3.10 gab der Zugriff auf ``__annotations__`` bei einer Klasse, "
"die selbst keine Annotationen definiert, aber eine Elternklasse mit "
"Annotationen hat, die ``__annotations__`` der Elternklasse zurück. In Python "
"3.10 und neuer sind die Annotationen der Kindklasse stattdessen ein leeres "
"Dictionary."
#:
../../howto/annotations.rst:71
msgid
"Accessing The Annotations Dict Of An Object In Python 3.9 And Older"
msgstr
""
"Zugriff auf das Annotations-Dictionary eines Objekts in Python 3.9 und älter"
#:
../../howto/annotations.rst:73
msgid
""
"In Python 3.9 and older, accessing the annotations dict of an object is much "
"more complicated than in newer versions. The problem is a design flaw in "
"these older versions of Python, specifically to do with class annotations."
msgstr
""
"In Python 3.9 und älter ist der Zugriff auf das Annotations-Dictionary eines "
"Objekts deutlich umständlicher als in neueren Versionen. Die Ursache ist ein "
"Entwurfsfehler in diesen älteren Python-Versionen, der speziell die "
"Klassenannotationen betrifft."
#:
../../howto/annotations.rst:78
msgid
""
"Best practice for accessing the annotations dict of other objects--"
"functions, other callables, and modules--is the same as best practice for "
"3.10, assuming you aren't calling :func:`inspect.get_annotations`: you "
"should use three-argument :func:`getattr` to access the object's "
"``__annotations__`` attribute."
msgstr
""
"Die beste Vorgehensweise für den Zugriff auf das Annotations-Dictionary "
"anderer Objekte – Funktionen, andere aufrufbare Objekte und Module – ist "
"dieselbe wie bei 3.10, sofern du :func:`inspect.get_annotations` nicht "
"aufrufst: Du solltest :func:`getattr` mit drei Argumenten verwenden, um auf "
"das Attribut ``__annotations__`` des Objekts zuzugreifen."
#:
../../howto/annotations.rst:85
msgid
""
"Unfortunately, this isn't best practice for classes. The problem is that, "
"since ``__annotations__`` is optional on classes, and because classes can "
"inherit attributes from their base classes, accessing the "
"``__annotations__`` attribute of a class may inadvertently return the "
"annotations dict of a *base class.* As an example::"
msgstr
""
"Für Klassen ist das leider nicht die beste Vorgehensweise. Das Problem ist: "
"Da ``__annotations__`` bei Klassen optional ist und Klassen Attribute von "
"ihren Basisklassen erben können, kann der Zugriff auf das Attribut "
"``__annotations__`` einer Klasse unbeabsichtigt das Annotations-Dictionary "
"einer *Basisklasse* zurückgeben. Ein Beispiel::"
#:
../../howto/annotations.rst:92
msgid
""
"class Base:\n"
" a: int = 3\n"
" b: str = 'abc'\n"
"\n"
"class Derived(Base):\n"
" pass\n"
"\n"
"print(Derived.__annotations__)"
msgstr
""
"class Base:\n"
" a: int = 3\n"
" b: str = 'abc'\n"
"\n"
"class Derived(Base):\n"
" pass\n"
"\n"
"print(Derived.__annotations__)"
#:
../../howto/annotations.rst:101
msgid
"This will print the annotations dict from ``Base``, not ``Derived``."
msgstr
""
"Das gibt das Annotations-Dictionary von ``Base`` aus, nicht von ``Derived``."
#:
../../howto/annotations.rst:104
msgid
""
"Your code will have to have a separate code path if the object you're "
"examining is a class (``isinstance(o, type)``). In that case, best practice "
"relies on an implementation detail of Python 3.9 and before: if a class has "
"annotations defined, they are stored in the class's :attr:`~type.__dict__` "
"dictionary. Since the class may or may not have annotations defined, best "
"practice is to call the :meth:`~dict.get` method on the class dict."
msgstr
""
"Dein Code braucht einen eigenen Zweig für den Fall, dass das untersuchte "
"Objekt eine Klasse ist (``isinstance(o, type)``). In diesem Fall stützt sich "
"die beste Vorgehensweise auf ein Implementierungsdetail von Python 3.9 und "
"davor: Wenn eine Klasse Annotationen definiert hat, sind sie im Dictionary :"
"attr:`~type.__dict__` der Klasse gespeichert. Da die Klasse Annotationen "
"definiert haben kann oder nicht, ist es die beste Vorgehensweise, die "
"Methode :meth:`~dict.get` auf dem Klassen-Dictionary aufzurufen."
#:
../../howto/annotations.rst:112
msgid
""
"To put it all together, here is some sample code that safely accesses the "
"``__annotations__`` attribute on an arbitrary object in Python 3.9 and "
"before::"
msgstr
""
"Alles zusammengenommen folgt hier Beispielcode, der in Python 3.9 und davor "
"sicher auf das Attribut ``__annotations__`` eines beliebigen Objekts "
"zugreift::"
#:
../../howto/annotations.rst:116
msgid
""
"if isinstance(o, type):\n"
" ann = o.__dict__.get('__annotations__', None)\n"
"else:\n"
" ann = getattr(o, '__annotations__', None)"
msgstr
""
"if isinstance(o, type):\n"
" ann = o.__dict__.get('__annotations__', None)\n"
"else:\n"
" ann = getattr(o, '__annotations__', None)"
#:
../../howto/annotations.rst:121
msgid
""
"After running this code, ``ann`` should be either a dictionary or ``None``. "
"You're encouraged to double-check the type of ``ann`` using :func:"
"`isinstance` before further examination."
msgstr
""
"Nach dem Ausführen dieses Codes sollte ``ann`` entweder ein Dictionary oder "
"``None`` sein. Es ist ratsam, den Typ von ``ann`` mit :func:`isinstance` zu "
"prüfen, bevor du weiter damit arbeitest."
#:
../../howto/annotations.rst:126
msgid
""
"Note that some exotic or malformed type objects may not have a :attr:`~type."
"__dict__` attribute, so for extra safety you may also wish to use :func:"
"`getattr` to access :attr:`!__dict__`."
msgstr
""
"Beachte, dass manche exotischen oder fehlerhaften Typobjekte kein Attribut :"
"attr:`~type.__dict__` haben. Zur zusätzlichen Sicherheit kannst du also auch "
"für den Zugriff auf :attr:`!__dict__` :func:`getattr` verwenden."
#:
../../howto/annotations.rst:132
msgid
"Manually Un-Stringizing Stringized Annotations"
msgstr
"Annotationen von Hand aus Zeichenketten zurückwandeln"
#:
../../howto/annotations.rst:134
msgid
""
"In situations where some annotations may be
\"
stringized
\"
, and you wish to "
"evaluate those strings to produce the Python values they represent, it "
"really is best to call :func:`inspect.get_annotations` to do this work for "
"you."
msgstr
""
"In Situationen, in denen manche Annotationen als Zeichenketten vorliegen und "
"du diese Zeichenketten auswerten möchtest, um die Python-Werte zu erhalten, "
"die sie darstellen, ist es wirklich am besten, :func:`inspect."
"get_annotations` aufzurufen und diese Arbeit dort machen zu lassen."
#:
../../howto/annotations.rst:140
msgid
""
"If you're using Python 3.9 or older, or if for some reason you can't use :"
"func:`inspect.get_annotations`, you'll need to duplicate its logic. You're "
"encouraged to examine the implementation of :func:`inspect.get_annotations` "
"in the current Python version and follow a similar approach."
msgstr
""
"Wenn du Python 3.9 oder älter verwendest oder :func:`inspect."
"get_annotations` aus irgendeinem Grund nicht nutzen kannst, musst du dessen "
"Logik nachbauen. Es ist ratsam, sich die Implementierung von :func:`inspect."
"get_annotations` in der aktuellen Python-Version anzuschauen und ähnlich "
"vorzugehen."
#:
../../howto/annotations.rst:146
msgid
""
"In a nutshell, if you wish to evaluate a stringized annotation on an "
"arbitrary object ``o``:"
msgstr
""
"Kurz gefasst: Wenn du eine als Zeichenkette vorliegende Annotation an einem "
"beliebigen Objekt ``o`` auswerten möchtest:"
#:
../../howto/annotations.rst:149
msgid
""
"If ``o`` is a module, use ``o.__dict__`` as the ``globals`` when calling :"
"func:`eval`."
msgstr
""
"Ist ``o`` ein Modul, verwende beim Aufruf von :func:`eval` ``o.__dict__`` "
"als ``globals``."
#:
../../howto/annotations.rst:151
msgid
""
"If ``o`` is a class, use ``sys.modules[o.__module__].__dict__`` as the "
"``globals``, and ``dict(vars(o))`` as the ``locals``, when calling :func:"
"`eval`."
msgstr
""
"Ist ``o`` eine Klasse, verwende beim Aufruf von :func:`eval` ``sys.modules[o."
"__module__].__dict__`` als ``globals`` und ``dict(vars(o))`` als ``locals``."
#:
../../howto/annotations.rst:154
msgid
""
"If ``o`` is a wrapped callable using :func:`functools.update_wrapper`, :deco:"
"`functools.wraps`, or :func:`functools.partial`, iteratively unwrap it by "
"accessing either ``o.__wrapped__`` or ``o.func`` as appropriate, until you "
"have found the root unwrapped function."
msgstr
""
"Ist ``o`` ein aufrufbares Objekt, das mit :func:`functools.update_wrapper`, :"
"deco:`functools.wraps` oder :func:`functools.partial` umhüllt wurde, wickle "
"es Schritt für Schritt aus, indem du je nach Fall auf ``o.__wrapped__`` oder "
"``o.func`` zugreifst, bis du die zugrunde liegende, nicht umhüllte Funktion "
"gefunden hast."
#:
../../howto/annotations.rst:158
msgid
""
"If ``o`` is a callable (but not a class), use :attr:`o.__globals__ <function."
"__globals__>` as the globals when calling :func:`eval`."
msgstr
""
"Ist ``o`` ein aufrufbares Objekt (aber keine Klasse), verwende beim Aufruf "
"von :func:`eval` :attr:`o.__globals__ <function.__globals__>` als globals."
#:
../../howto/annotations.rst:162
msgid
""
"However, not all string values used as annotations can be successfully "
"turned into Python values by :func:`eval`. String values could theoretically "
"contain any valid string, and in practice there are valid use cases for type "
"hints that require annotating with string values that specifically *can't* "
"be evaluated. For example:"
msgstr
""
"Allerdings lassen sich nicht alle Zeichenkettenwerte, die als Annotationen "
"verwendet werden, von :func:`eval` erfolgreich in Python-Werte überführen. "
"Zeichenkettenwerte könnten theoretisch jede gültige Zeichenkette enthalten, "
"und in der Praxis gibt es gültige Anwendungsfälle für Type Hints, die "
"Annotationen mit Zeichenkettenwerten erfordern, die ausdrücklich *nicht* "
"auswertbar sind. Zum Beispiel:"
#:
../../howto/annotations.rst:169
msgid
""
":pep:`604` union types using ``|``, before support for this was added to "
"Python 3.10."
msgstr
""
"Union-Typen nach :pep:`604` mit ``|``, bevor die Unterstützung dafür in "
"Python 3.10 ergänzt wurde."
#:
../../howto/annotations.rst:171
msgid
""
"Definitions that aren't needed at runtime, only imported when :const:`typing."
"TYPE_CHECKING` is true."
msgstr
""
"Definitionen, die zur Laufzeit nicht gebraucht werden und nur importiert "
"werden, wenn :const:`typing.TYPE_CHECKING` wahr ist."
#:
../../howto/annotations.rst:174
msgid
""
"If :func:`eval` attempts to evaluate such values, it will fail and raise an "
"exception. So, when designing a library API that works with annotations, "
"it's recommended to only attempt to evaluate string values when explicitly "
"requested to by the caller."
msgstr
""
"Versucht :func:`eval`, solche Werte auszuwerten, scheitert es und löst eine "
"Ausnahme aus. Wenn du also eine Bibliotheks-API entwirfst, die mit "
"Annotationen arbeitet, ist es empfehlenswert, Zeichenkettenwerte nur dann "
"auszuwerten, wenn der Aufrufer das ausdrücklich verlangt."
#:
../../howto/annotations.rst:182
msgid
"Best Practices For ``__annotations__`` In Any Python Version"
msgstr
"Best Practices für ``__annotations__`` in jeder Python-Version"
#:
../../howto/annotations.rst:184
msgid
""
"You should avoid assigning to the ``__annotations__`` member of objects "
"directly. Let Python manage setting ``__annotations__``."
msgstr
""
"Du solltest es vermeiden, dem Element ``__annotations__`` von Objekten "
"direkt etwas zuzuweisen. Lass Python das Setzen von ``__annotations__`` "
"verwalten."
#:
../../howto/annotations.rst:187
msgid
""
"If you do assign directly to the ``__annotations__`` member of an object, "
"you should always set it to a ``dict`` object."
msgstr
""
"Wenn du dem Element ``__annotations__`` eines Objekts doch direkt etwas "
"zuweist, solltest du immer ein ``dict``-Objekt setzen."
#:
../../howto/annotations.rst:190
msgid
""
"You should avoid accessing ``__annotations__`` directly on any object. "
"Instead, use :func:`annotationlib.get_annotations` (Python 3.14+) or :func:"
"`inspect.get_annotations` (Python 3.10+)."
msgstr
""
"Du solltest es vermeiden, bei einem Objekt direkt auf ``__annotations__`` "
"zuzugreifen. Verwende stattdessen :func:`annotationlib.get_annotations` "
"(Python 3.14+) oder :func:`inspect.get_annotations` (Python 3.10+)."
#:
../../howto/annotations.rst:194
msgid
""
"If you do directly access the ``__annotations__`` member of an object, you "
"should ensure that it's a dictionary before attempting to examine its "
"contents."
msgstr
""
"Wenn du doch direkt auf das Element ``__annotations__`` eines Objekts "
"zugreifst, solltest du sicherstellen, dass es ein Dictionary ist, bevor du "
"dessen Inhalt untersuchst."
#:
../../howto/annotations.rst:198
msgid
"You should avoid modifying ``__annotations__`` dicts."
msgstr
""
"Du solltest es vermeiden, ``__annotations__``-Dictionarys zu verändern."
#:
../../howto/annotations.rst:200
msgid
""
"You should avoid deleting the ``__annotations__`` attribute of an object."
msgstr
""
"Du solltest es vermeiden, das Attribut ``__annotations__`` eines Objekts zu "
"löschen."
#:
../../howto/annotations.rst:205
msgid
"``__annotations__`` Quirks"
msgstr
"Eigenheiten von ``__annotations__``"
#:
../../howto/annotations.rst:207
msgid
""
"In all versions of Python 3, function objects lazy-create an annotations "
"dict if no annotations are defined on that object. You can delete the "
"``__annotations__`` attribute using ``del fn.__annotations__``, but if you "
"then access ``fn.__annotations__`` the object will create a new empty dict "
"that it will store and return as its annotations. Deleting the annotations "
"on a function before it has lazily created its annotations dict will throw "
"an ``AttributeError``; using ``del fn.__annotations__`` twice in a row is "
"guaranteed to always throw an ``AttributeError``."
msgstr
""
"In allen Versionen von Python 3 erzeugen Funktionsobjekte bei Bedarf ein "
"Annotations-Dictionary, wenn an diesem Objekt keine Annotationen definiert "
"sind. Du kannst das Attribut ``__annotations__`` mit ``del fn."
"__annotations__`` löschen. Greifst du danach aber auf ``fn.__annotations__`` "
"zu, erzeugt das Objekt ein neues leeres Dictionary, das es speichert und als "
"seine Annotationen zurückgibt. Löschst du die Annotationen einer Funktion, "
"bevor sie ihr Annotations-Dictionary bei Bedarf erzeugt hat, wird ein "
"``AttributeError`` ausgelöst; ``del fn.__annotations__`` zweimal "
"hintereinander löst garantiert immer einen ``AttributeError`` aus."
#:
../../howto/annotations.rst:217
msgid
""
"Everything in the above paragraph also applies to class and module objects "
"in Python 3.10 and newer."
msgstr
""
"Alles im obigen Absatz gilt in Python 3.10 und neuer auch für Klassen- und "
"Modulobjekte."
#:
../../howto/annotations.rst:220
msgid
""
"In all versions of Python 3, you can set ``__annotations__`` on a function "
"object to ``None``. However, subsequently accessing the annotations on that "
"object using ``fn.__annotations__`` will lazy-create an empty dictionary as "
"per the first paragraph of this section. This is *not* true of modules and "
"classes, in any Python version; those objects permit setting "
"``__annotations__`` to any Python value, and will retain whatever value is "
"set."
msgstr
""
"In allen Versionen von Python 3 kannst du ``__annotations__`` an einem "
"Funktionsobjekt auf ``None`` setzen. Greifst du anschließend über ``fn."
"__annotations__`` auf die Annotationen dieses Objekts zu, wird gemäß dem "
"ersten Absatz dieses Abschnitts allerdings bei Bedarf ein leeres Dictionary "
"erzeugt. Für Module und Klassen gilt das in *keiner* Python-Version. Diese "
"Objekte erlauben es, ``__annotations__`` auf einen beliebigen Python-Wert zu "
"setzen, und behalten den gesetzten Wert."
#:
../../howto/annotations.rst:228
msgid
""
"If Python stringizes your annotations for you (using ``from __future__ "
"import annotations``), and you specify a string as an annotation, the string "
"will itself be quoted. In effect the annotation is quoted *twice.* For "
"example::"
msgstr
""
"Wenn Python deine Annotationen für dich in Zeichenketten umwandelt (über "
"``from __future__ import annotations``) und du eine Zeichenkette als "
"Annotation angibst, wird die Zeichenkette selbst in Anführungszeichen "
"gesetzt. Die Annotation wird damit *zweifach* in Anführungszeichen gesetzt. "
"Zum Beispiel::"
#:
../../howto/annotations.rst:234
msgid
""
"from __future__ import annotations\n"
"def foo(a:
\"
str
\"
): pass\n"
"\n"
"print(foo.__annotations__)"
msgstr
""
"from __future__ import annotations\n"
"def foo(a:
\"
str
\"
): pass\n"
"\n"
"print(foo.__annotations__)"
#:
../../howto/annotations.rst:239
msgid
""
"This prints ``{'a':
\"
'str'
\"
}``. This shouldn't really be considered a "
"
\"
quirk
\"
; it's mentioned here simply because it might be surprising."
msgstr
""
"Das gibt ``{'a':
\"
'str'
\"
}`` aus. Das sollte man nicht wirklich als "
"„Eigenheit“ betrachten. Es wird hier nur erwähnt, weil es überraschen kann."
#:
../../howto/annotations.rst:242
msgid
""
"If you use a class with a custom metaclass and access ``__annotations__`` on "
"the class, you may observe unexpected behavior; see :pep:`749 <749#pep749-"
"metaclasses>` for some examples. You can avoid these quirks by using :func:"
"`annotationlib.get_annotations` on Python 3.14+ or :func:`inspect."
"get_annotations` on Python 3.10+. On earlier versions of Python, you can "
"avoid these bugs by accessing the annotations from the class's :attr:`~type."
"__dict__` (for example, ``cls.__dict__.get('__annotations__', None)``)."
msgstr
""
"Wenn du eine Klasse mit einer eigenen Metaklasse verwendest und bei der "
"Klasse auf ``__annotations__`` zugreifst, kann unerwartetes Verhalten "
"auftreten. Einige Beispiele dazu findest du in :pep:`749 <749#pep749-"
"metaclasses>`. Du kannst diese Eigenheiten vermeiden, indem du unter Python "
"3.14+ :func:`annotationlib.get_annotations` oder unter Python 3.10+ :func:"
"`inspect.get_annotations` verwendest. In früheren Python-Versionen kannst du "
"diese Fehler vermeiden, indem du die Annotationen über :attr:`~type."
"__dict__` der Klasse ausliest (zum Beispiel ``cls.__dict__."
"get('__annotations__', None)``)."
#:
../../howto/annotations.rst:251
msgid
""
"In some versions of Python, instances of classes may have an "
"``__annotations__`` attribute. However, this is not supported functionality. "
"If you need the annotations of an instance, you can use :func:`type` to "
"access its class (for example, ``annotationlib."
"get_annotations(type(myinstance))`` on Python 3.14+)."
msgstr
""
"In manchen Python-Versionen können Instanzen von Klassen ein Attribut "
"``__annotations__`` haben. Das ist allerdings keine unterstützte "
"Funktionalität. Wenn du die Annotationen einer Instanz brauchst, kannst du "
"mit :func:`type` auf deren Klasse zugreifen (zum Beispiel ``annotationlib."
"get_annotations(type(myinstance))`` unter Python 3.14+)."
Back
|
FazBrowse Home
|
New Git URL