Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 20678fd

Browse files
plamut1st1
authored andcommitted
Add docstrings to public methods from context.c (GH-8531)
1 parent 22d2508 commit 20678fd

3 files changed

Lines changed: 80 additions & 17 deletions

File tree

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -888,6 +888,7 @@ Loïc Lajeanne
888888
David Lam
889889
Thomas Lamb
890890
Valerie Lambert
891+
Peter Lamut
891892
Jean-Baptiste "Jiba" Lamy
892893
Ronan Lamy
893894
Peter Landry

Python/clinic/context.c.h

Lines changed: 36 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/context.c

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -489,12 +489,17 @@ _contextvars.Context.get
489489
key: object
490490
default: object = None
491491
/
492+
493+
Return the value for `key` if `key` has the value in the context object.
494+
495+
If `key` does not exist, return `default`. If `default` is not given,
496+
return None.
492497
[clinic start generated code]*/
493498

494499
static PyObject *
495500
_contextvars_Context_get_impl(PyContext *self, PyObject *key,
496501
PyObject *default_value)
497-
/*[clinic end generated code: output=0c54aa7664268189 input=8d4c33c8ecd6d769]*/
502+
/*[clinic end generated code: output=0c54aa7664268189 input=c8eeb81505023995]*/
498503
{
499504
if (context_check_key_type(key)) {
500505
return NULL;
@@ -516,47 +521,57 @@ _contextvars_Context_get_impl(PyContext *self, PyObject *key,
516521

517522
/*[clinic input]
518523
_contextvars.Context.items
524+
525+
Return all variables and their values in the context object.
526+
527+
The result is returned as a list of 2-tuples (variable, value).
519528
[clinic start generated code]*/
520529

521530
static PyObject *
522531
_contextvars_Context_items_impl(PyContext *self)
523-
/*[clinic end generated code: output=fa1655c8a08502af input=2d570d1455004979]*/
532+
/*[clinic end generated code: output=fa1655c8a08502af input=00db64ae379f9f42]*/
524533
{
525534
return _PyHamt_NewIterItems(self->ctx_vars);
526535
}
527536

528537

529538
/*[clinic input]
530539
_contextvars.Context.keys
540+
541+
Return a list of all variables in the context object.
531542
[clinic start generated code]*/
532543

533544
static PyObject *
534545
_contextvars_Context_keys_impl(PyContext *self)
535-
/*[clinic end generated code: output=177227c6b63ec0e2 input=13005e142fbbf37d]*/
546+
/*[clinic end generated code: output=177227c6b63ec0e2 input=114b53aebca3449c]*/
536547
{
537548
return _PyHamt_NewIterKeys(self->ctx_vars);
538549
}
539550

540551

541552
/*[clinic input]
542553
_contextvars.Context.values
554+
555+
Return a list of all variables’ values in the context object.
543556
[clinic start generated code]*/
544557

545558
static PyObject *
546559
_contextvars_Context_values_impl(PyContext *self)
547-
/*[clinic end generated code: output=d286dabfc8db6dde input=c2cbc40a4470e905]*/
560+
/*[clinic end generated code: output=d286dabfc8db6dde input=6c3d08639ba3bf67]*/
548561
{
549562
return _PyHamt_NewIterValues(self->ctx_vars);
550563
}
551564

552565

553566
/*[clinic input]
554567
_contextvars.Context.copy
568+
569+
Return a shallow copy of the context object.
555570
[clinic start generated code]*/
556571

557572
static PyObject *
558573
_contextvars_Context_copy_impl(PyContext *self)
559-
/*[clinic end generated code: output=30ba8896c4707a15 input=3e3fd72d598653ab]*/
574+
/*[clinic end generated code: output=30ba8896c4707a15 input=ebafdbdd9c72d592]*/
560575
{
561576
return (PyObject *)context_new_from_vars(self->ctx_vars);
562577
}
@@ -872,11 +887,19 @@ contextvar_tp_repr(PyContextVar *self)
872887
_contextvars.ContextVar.get
873888
default: object = NULL
874889
/
890+
891+
Return a value for the context variable for the current context.
892+
893+
If there is no value for the variable in the current context, the method will:
894+
* return the value of the default argument of the method, if provided; or
895+
* return the default value for the context variable, if it was created
896+
with one; or
897+
* raise a LookupError.
875898
[clinic start generated code]*/
876899

877900
static PyObject *
878901
_contextvars_ContextVar_get_impl(PyContextVar *self, PyObject *default_value)
879-
/*[clinic end generated code: output=0746bd0aa2ced7bf input=8d002b02eebbb247]*/
902+
/*[clinic end generated code: output=0746bd0aa2ced7bf input=30aa2ab9e433e401]*/
880903
{
881904
if (!PyContextVar_CheckExact(self)) {
882905
PyErr_SetString(
@@ -901,11 +924,18 @@ _contextvars_ContextVar_get_impl(PyContextVar *self, PyObject *default_value)
901924
_contextvars.ContextVar.set
902925
value: object
903926
/
927+
928+
Call to set a new value for the context variable in the current context.
929+
930+
The required value argument is the new value for the context variable.
931+
932+
Returns a Token object that can be used to restore the variable to its previous
933+
value via the `ContextVar.reset()` method.
904934
[clinic start generated code]*/
905935

906936
static PyObject *
907937
_contextvars_ContextVar_set(PyContextVar *self, PyObject *value)
908-
/*[clinic end generated code: output=446ed5e820d6d60b input=a2d88f57c6d86f7c]*/
938+
/*[clinic end generated code: output=446ed5e820d6d60b input=c0a6887154227453]*/
909939
{
910940
return (PyObject *)PyContextVar_Set(self, value);
911941
}
@@ -914,11 +944,16 @@ _contextvars_ContextVar_set(PyContextVar *self, PyObject *value)
914944
_contextvars.ContextVar.reset
915945
token: object
916946
/
947+
948+
Reset the context variable.
949+
950+
The variable is reset to the value it had before the `ContextVar.set()` that
951+
created the token was used.
917952
[clinic start generated code]*/
918953

919954
static PyObject *
920955
_contextvars_ContextVar_reset(PyContextVar *self, PyObject *token)
921-
/*[clinic end generated code: output=d4ee34d0742d62ee input=4c871b6f1f31a65f]*/
956+
/*[clinic end generated code: output=d4ee34d0742d62ee input=ebe2881e5af4ffda]*/
922957
{
923958
if (!PyContextToken_CheckExact(token)) {
924959
PyErr_Format(PyExc_TypeError,

0 commit comments

Comments
 (0)