@@ -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
494499static 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
521530static 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
533544static 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
545558static 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
557572static 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
877900static 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
906936static 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
919954static 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