aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/tools/python3/Objects
diff options
context:
space:
mode:
authorAlexander Smirnov <alex@ydb.tech>2024-07-08 15:54:05 +0000
committerAlexander Smirnov <alex@ydb.tech>2024-07-08 15:54:05 +0000
commitfc7be18c76af2e700641f3598c4856baeef1428e (patch)
tree11dbca45eb321c3a4dd08b12152acc6ef5dd3fa9 /contrib/tools/python3/Objects
parentec0e7ed6da6fb317741fd8468602949a1362eca5 (diff)
parentc92cb9d3a19331916f0c274d80e67f02a62caa9b (diff)
downloadydb-fc7be18c76af2e700641f3598c4856baeef1428e.tar.gz
Merge branch 'rightlib' into mergelibs-240708-1553
Diffstat (limited to 'contrib/tools/python3/Objects')
-rw-r--r--contrib/tools/python3/Objects/clinic/complexobject.c.h9
-rw-r--r--contrib/tools/python3/Objects/complexobject.c9
-rw-r--r--contrib/tools/python3/Objects/genobject.c47
-rw-r--r--contrib/tools/python3/Objects/typeobject.c18
4 files changed, 70 insertions, 13 deletions
diff --git a/contrib/tools/python3/Objects/clinic/complexobject.c.h b/contrib/tools/python3/Objects/clinic/complexobject.c.h
index e92c6e9858..f0c841c12a 100644
--- a/contrib/tools/python3/Objects/clinic/complexobject.c.h
+++ b/contrib/tools/python3/Objects/clinic/complexobject.c.h
@@ -97,9 +97,12 @@ PyDoc_STRVAR(complex_new__doc__,
"complex(real=0, imag=0)\n"
"--\n"
"\n"
-"Create a complex number from a real part and an optional imaginary part.\n"
+"Create a complex number from a string or numbers.\n"
"\n"
-"This is equivalent to (real + imag*1j) where imag defaults to 0.");
+"If a string is given, parse it as a complex number.\n"
+"If a single number is given, convert it to a complex number.\n"
+"If the \'real\' or \'imag\' arguments are given, create a complex number\n"
+"with the specified real and imaginary components.");
static PyObject *
complex_new_impl(PyTypeObject *type, PyObject *r, PyObject *i);
@@ -160,4 +163,4 @@ skip_optional_pos:
exit:
return return_value;
}
-/*[clinic end generated code: output=52e85a1e258425d6 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=9558b8449db17dc1 input=a9049054013a1b77]*/
diff --git a/contrib/tools/python3/Objects/complexobject.c b/contrib/tools/python3/Objects/complexobject.c
index aee03ddfb0..7f7e7e6b08 100644
--- a/contrib/tools/python3/Objects/complexobject.c
+++ b/contrib/tools/python3/Objects/complexobject.c
@@ -885,14 +885,17 @@ complex.__new__ as complex_new
real as r: object(c_default="NULL") = 0
imag as i: object(c_default="NULL") = 0
-Create a complex number from a real part and an optional imaginary part.
+Create a complex number from a string or numbers.
-This is equivalent to (real + imag*1j) where imag defaults to 0.
+If a string is given, parse it as a complex number.
+If a single number is given, convert it to a complex number.
+If the 'real' or 'imag' arguments are given, create a complex number
+with the specified real and imaginary components.
[clinic start generated code]*/
static PyObject *
complex_new_impl(PyTypeObject *type, PyObject *r, PyObject *i)
-/*[clinic end generated code: output=b6c7dd577b537dc1 input=f4c667f2596d4fd1]*/
+/*[clinic end generated code: output=b6c7dd577b537dc1 input=ff4268dc540958a4]*/
{
PyObject *tmp;
PyNumberMethods *nbr, *nbi = NULL;
diff --git a/contrib/tools/python3/Objects/genobject.c b/contrib/tools/python3/Objects/genobject.c
index bc58409c18..dc034a4b72 100644
--- a/contrib/tools/python3/Objects/genobject.c
+++ b/contrib/tools/python3/Objects/genobject.c
@@ -403,6 +403,7 @@ gen_close(PyGenObject *gen, PyObject *args)
* StopIteration. */
if (exception_handler_depth == 1) {
gen->gi_frame_state = FRAME_COMPLETED;
+ _PyFrame_ClearLocals((_PyInterpreterFrame *)gen->gi_iframe);
Py_RETURN_NONE;
}
}
@@ -1786,6 +1787,7 @@ async_gen_asend_send(PyAsyncGenASend *o, PyObject *arg)
if (o->ags_state == AWAITABLE_STATE_INIT) {
if (o->ags_gen->ag_running_async) {
+ o->ags_state = AWAITABLE_STATE_CLOSED;
PyErr_SetString(
PyExc_RuntimeError,
"anext(): asynchronous generator is already running");
@@ -1829,10 +1831,24 @@ async_gen_asend_throw(PyAsyncGenASend *o, PyObject *const *args, Py_ssize_t narg
return NULL;
}
+ if (o->ags_state == AWAITABLE_STATE_INIT) {
+ if (o->ags_gen->ag_running_async) {
+ o->ags_state = AWAITABLE_STATE_CLOSED;
+ PyErr_SetString(
+ PyExc_RuntimeError,
+ "anext(): asynchronous generator is already running");
+ return NULL;
+ }
+
+ o->ags_state = AWAITABLE_STATE_ITER;
+ o->ags_gen->ag_running_async = 1;
+ }
+
result = gen_throw((PyGenObject*)o->ags_gen, args, nargs);
result = async_gen_unwrap_value(o->ags_gen, result);
if (result == NULL) {
+ o->ags_gen->ag_running_async = 0;
o->ags_state = AWAITABLE_STATE_CLOSED;
}
@@ -2221,9 +2237,34 @@ async_gen_athrow_throw(PyAsyncGenAThrow *o, PyObject *const *args, Py_ssize_t na
return NULL;
}
+ if (o->agt_state == AWAITABLE_STATE_INIT) {
+ if (o->agt_gen->ag_running_async) {
+ o->agt_state = AWAITABLE_STATE_CLOSED;
+ if (o->agt_args == NULL) {
+ PyErr_SetString(
+ PyExc_RuntimeError,
+ "aclose(): asynchronous generator is already running");
+ }
+ else {
+ PyErr_SetString(
+ PyExc_RuntimeError,
+ "athrow(): asynchronous generator is already running");
+ }
+ return NULL;
+ }
+
+ o->agt_state = AWAITABLE_STATE_ITER;
+ o->agt_gen->ag_running_async = 1;
+ }
+
retval = gen_throw((PyGenObject*)o->agt_gen, args, nargs);
if (o->agt_args) {
- return async_gen_unwrap_value(o->agt_gen, retval);
+ retval = async_gen_unwrap_value(o->agt_gen, retval);
+ if (retval == NULL) {
+ o->agt_gen->ag_running_async = 0;
+ o->agt_state = AWAITABLE_STATE_CLOSED;
+ }
+ return retval;
} else {
/* aclose() mode */
if (retval && _PyAsyncGenWrappedValue_CheckExact(retval)) {
@@ -2233,6 +2274,10 @@ async_gen_athrow_throw(PyAsyncGenAThrow *o, PyObject *const *args, Py_ssize_t na
PyErr_SetString(PyExc_RuntimeError, ASYNC_GEN_IGNORED_EXIT_MSG);
return NULL;
}
+ if (retval == NULL) {
+ o->agt_gen->ag_running_async = 0;
+ o->agt_state = AWAITABLE_STATE_CLOSED;
+ }
if (PyErr_ExceptionMatches(PyExc_StopAsyncIteration) ||
PyErr_ExceptionMatches(PyExc_GeneratorExit))
{
diff --git a/contrib/tools/python3/Objects/typeobject.c b/contrib/tools/python3/Objects/typeobject.c
index 0c9a876f70..7ebc7a9804 100644
--- a/contrib/tools/python3/Objects/typeobject.c
+++ b/contrib/tools/python3/Objects/typeobject.c
@@ -1506,8 +1506,11 @@ type_set_annotations(PyTypeObject *type, PyObject *value, void *context)
static PyObject *
type_get_type_params(PyTypeObject *type, void *context)
{
- PyObject *params = PyDict_GetItemWithError(lookup_tp_dict(type), &_Py_ID(__type_params__));
+ if (type == &PyType_Type) {
+ return PyTuple_New(0);
+ }
+ PyObject *params = PyDict_GetItemWithError(lookup_tp_dict(type), &_Py_ID(__type_params__));
if (params) {
return Py_NewRef(params);
}
@@ -5481,15 +5484,19 @@ object_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
return NULL;
}
comma_w_quotes_sep = PyUnicode_FromString("', '");
+ if (!comma_w_quotes_sep) {
+ Py_DECREF(sorted_methods);
+ return NULL;
+ }
joined = PyUnicode_Join(comma_w_quotes_sep, sorted_methods);
- method_count = PyObject_Length(sorted_methods);
- Py_DECREF(sorted_methods);
+ Py_DECREF(comma_w_quotes_sep);
if (joined == NULL) {
- Py_DECREF(comma_w_quotes_sep);
+ Py_DECREF(sorted_methods);
return NULL;
}
+ method_count = PyObject_Length(sorted_methods);
+ Py_DECREF(sorted_methods);
if (method_count == -1) {
- Py_DECREF(comma_w_quotes_sep);
Py_DECREF(joined);
return NULL;
}
@@ -5501,7 +5508,6 @@ object_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
method_count > 1 ? "s" : "",
joined);
Py_DECREF(joined);
- Py_DECREF(comma_w_quotes_sep);
return NULL;
}
PyObject *obj = type->tp_alloc(type, 0);