Skip to content

Commit 212a9de

Browse files
sync with cpython 2db2b5ea
1 parent 574f9ea commit 212a9de

10 files changed

+2306
-2135
lines changed

glossary.po

Lines changed: 404 additions & 337 deletions
Large diffs are not rendered by default.

library/argparse.po

Lines changed: 309 additions & 314 deletions
Large diffs are not rendered by default.

library/contextvars.po

Lines changed: 78 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ msgid ""
55
msgstr ""
66
"Project-Id-Version: Python 3.13\n"
77
"Report-Msgid-Bugs-To: \n"
8-
"POT-Creation-Date: 2024-09-24 23:08+0000\n"
8+
"POT-Creation-Date: 2024-10-31 00:13+0000\n"
99
"PO-Revision-Date: 2018-07-15 18:56+0800\n"
1010
"Last-Translator: \n"
1111
"Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-"
@@ -203,121 +203,161 @@ msgstr ""
203203

204204
#: ../../library/contextvars.rst:147
205205
msgid ""
206-
"Every thread will have a different top-level :class:`~contextvars.Context` "
207-
"object. This means that a :class:`ContextVar` object behaves in a similar "
208-
"fashion to :func:`threading.local` when values are assigned in different "
209-
"threads."
206+
"Each thread has its own effective stack of :class:`!Context` objects. The :"
207+
"term:`current context` is the :class:`!Context` object at the top of the "
208+
"current thread's stack. All :class:`!Context` objects in the stacks are "
209+
"considered to be *entered*."
210210
msgstr ""
211211

212212
#: ../../library/contextvars.rst:152
213-
msgid "Context implements the :class:`collections.abc.Mapping` interface."
213+
msgid ""
214+
"*Entering* a context, which can be done by calling its :meth:`~Context.run` "
215+
"method, makes the context the current context by pushing it onto the top of "
216+
"the current thread's context stack."
214217
msgstr ""
215218

216219
#: ../../library/contextvars.rst:156
217220
msgid ""
218-
"Execute ``callable(*args, **kwargs)`` code in the context object the *run* "
219-
"method is called on. Return the result of the execution or propagate an "
220-
"exception if one occurred."
221+
"*Exiting* from the current context, which can be done by returning from the "
222+
"callback passed to the :meth:`~Context.run` method, restores the current "
223+
"context to what it was before the context was entered by popping the context "
224+
"off the top of the context stack."
221225
msgstr ""
222226

223-
#: ../../library/contextvars.rst:160
227+
#: ../../library/contextvars.rst:161
224228
msgid ""
225-
"Any changes to any context variables that *callable* makes will be contained "
226-
"in the context object::"
229+
"Since each thread has its own context stack, :class:`ContextVar` objects "
230+
"behave in a similar fashion to :func:`threading.local` when values are "
231+
"assigned in different threads."
227232
msgstr ""
228233

229-
#: ../../library/contextvars.rst:163
234+
#: ../../library/contextvars.rst:165
230235
msgid ""
231-
"var = ContextVar('var')\n"
236+
"Attempting to enter an already entered context, including contexts entered "
237+
"in other threads, raises a :exc:`RuntimeError`."
238+
msgstr ""
239+
240+
#: ../../library/contextvars.rst:168
241+
msgid "After exiting a context, it can later be re-entered (from any thread)."
242+
msgstr ""
243+
244+
#: ../../library/contextvars.rst:170
245+
msgid ""
246+
"Any changes to :class:`ContextVar` values via the :meth:`ContextVar.set` "
247+
"method are recorded in the current context. The :meth:`ContextVar.get` "
248+
"method returns the value associated with the current context. Exiting a "
249+
"context effectively reverts any changes made to context variables while the "
250+
"context was entered (if needed, the values can be restored by re-entering "
251+
"the context)."
252+
msgstr ""
253+
254+
#: ../../library/contextvars.rst:177
255+
msgid "Context implements the :class:`collections.abc.Mapping` interface."
256+
msgstr ""
257+
258+
#: ../../library/contextvars.rst:181
259+
msgid ""
260+
"Enters the Context, executes ``callable(*args, **kwargs)``, then exits the "
261+
"Context. Returns *callable*'s return value, or propagates an exception if "
262+
"one occurred."
263+
msgstr ""
264+
265+
#: ../../library/contextvars.rst:185
266+
#, fuzzy
267+
msgid "Example:"
268+
msgstr "舉例來說: ::"
269+
270+
#: ../../library/contextvars.rst:187
271+
msgid ""
272+
"import contextvars\n"
273+
"\n"
274+
"var = contextvars.ContextVar('var')\n"
232275
"var.set('spam')\n"
276+
"print(var.get()) # 'spam'\n"
277+
"\n"
278+
"ctx = contextvars.copy_context()\n"
233279
"\n"
234280
"def main():\n"
235281
" # 'var' was set to 'spam' before\n"
236282
" # calling 'copy_context()' and 'ctx.run(main)', so:\n"
237-
" # var.get() == ctx[var] == 'spam'\n"
283+
" print(var.get()) # 'spam'\n"
284+
" print(ctx[var]) # 'spam'\n"
238285
"\n"
239286
" var.set('ham')\n"
240287
"\n"
241288
" # Now, after setting 'var' to 'ham':\n"
242-
" # var.get() == ctx[var] == 'ham'\n"
243-
"\n"
244-
"ctx = copy_context()\n"
289+
" print(var.get()) # 'ham'\n"
290+
" print(ctx[var]) # 'ham'\n"
245291
"\n"
246292
"# Any changes that the 'main' function makes to 'var'\n"
247293
"# will be contained in 'ctx'.\n"
248294
"ctx.run(main)\n"
249295
"\n"
250296
"# The 'main()' function was run in the 'ctx' context,\n"
251297
"# so changes to 'var' are contained in it:\n"
252-
"# ctx[var] == 'ham'\n"
298+
"print(ctx[var]) # 'ham'\n"
253299
"\n"
254300
"# However, outside of 'ctx', 'var' is still set to 'spam':\n"
255-
"# var.get() == 'spam'"
256-
msgstr ""
257-
258-
#: ../../library/contextvars.rst:189
259-
msgid ""
260-
"The method raises a :exc:`RuntimeError` when called on the same context "
261-
"object from more than one OS thread, or when called recursively."
301+
"print(var.get()) # 'spam'"
262302
msgstr ""
263303

264-
#: ../../library/contextvars.rst:195
304+
#: ../../library/contextvars.rst:233
265305
msgid "Return a shallow copy of the context object."
266306
msgstr ""
267307

268-
#: ../../library/contextvars.rst:199
308+
#: ../../library/contextvars.rst:237
269309
msgid ""
270310
"Return ``True`` if the *context* has a value for *var* set; return ``False`` "
271311
"otherwise."
272312
msgstr ""
273313

274-
#: ../../library/contextvars.rst:204
314+
#: ../../library/contextvars.rst:242
275315
msgid ""
276316
"Return the value of the *var* :class:`ContextVar` variable. If the variable "
277317
"is not set in the context object, a :exc:`KeyError` is raised."
278318
msgstr ""
279319

280-
#: ../../library/contextvars.rst:210
320+
#: ../../library/contextvars.rst:248
281321
msgid ""
282322
"Return the value for *var* if *var* has the value in the context object. "
283323
"Return *default* otherwise. If *default* is not given, return ``None``."
284324
msgstr ""
285325

286-
#: ../../library/contextvars.rst:216
326+
#: ../../library/contextvars.rst:254
287327
msgid "Return an iterator over the variables stored in the context object."
288328
msgstr ""
289329

290-
#: ../../library/contextvars.rst:221
330+
#: ../../library/contextvars.rst:259
291331
msgid "Return the number of variables set in the context object."
292332
msgstr ""
293333

294-
#: ../../library/contextvars.rst:225
334+
#: ../../library/contextvars.rst:263
295335
msgid "Return a list of all variables in the context object."
296336
msgstr ""
297337

298-
#: ../../library/contextvars.rst:229
338+
#: ../../library/contextvars.rst:267
299339
msgid "Return a list of all variables' values in the context object."
300340
msgstr ""
301341

302-
#: ../../library/contextvars.rst:234
342+
#: ../../library/contextvars.rst:272
303343
msgid ""
304344
"Return a list of 2-tuples containing all variables and their values in the "
305345
"context object."
306346
msgstr ""
307347

308-
#: ../../library/contextvars.rst:239
348+
#: ../../library/contextvars.rst:277
309349
msgid "asyncio support"
310350
msgstr ""
311351

312-
#: ../../library/contextvars.rst:241
352+
#: ../../library/contextvars.rst:279
313353
msgid ""
314354
"Context variables are natively supported in :mod:`asyncio` and are ready to "
315355
"be used without any extra configuration. For example, here is a simple echo "
316356
"server, that uses a context variable to make the address of a remote client "
317357
"available in the Task that handles that client::"
318358
msgstr ""
319359

320-
#: ../../library/contextvars.rst:247
360+
#: ../../library/contextvars.rst:285
321361
msgid ""
322362
"import asyncio\n"
323363
"import contextvars\n"

0 commit comments

Comments
 (0)