Skip to content

Commit a4862f9

Browse files
committed
XXX get/setters
1 parent d19fefb commit a4862f9

File tree

2 files changed

+172
-16
lines changed

2 files changed

+172
-16
lines changed

Modules/_decimal/_decimal.c

Lines changed: 49 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -898,17 +898,29 @@ Dec_CONTEXT_GET_ULONG(traps)
898898
Dec_CONTEXT_GET_ULONG(status)
899899
#endif
900900

901+
/*[clinic input]
902+
@getter
903+
_decimal.Context.rounding
904+
[clinic start generated code]*/
905+
901906
static PyObject *
902-
context_getround(PyObject *self, void *Py_UNUSED(closure))
907+
_decimal_Context_rounding_get_impl(PyObject *self)
908+
/*[clinic end generated code: output=d51ea72c02519e0e input=b2e141a5321a8ca5]*/
903909
{
904910
int i = mpd_getround(CTX(self));
905911
decimal_state *state = get_module_state_from_ctx(self);
906912

907913
return Py_NewRef(state->round_map[i]);
908914
}
909915

916+
/*[clinic input]
917+
@getter
918+
_decimal.Context.capitals
919+
[clinic start generated code]*/
920+
910921
static PyObject *
911-
context_getcapitals(PyObject *self, void *Py_UNUSED(closure))
922+
_decimal_Context_capitals_get_impl(PyObject *self)
923+
/*[clinic end generated code: output=1fad922d399d298d input=1a3170642a406774]*/
912924
{
913925
return PyLong_FromLong(CtxCaps(self));
914926
}
@@ -1084,8 +1096,14 @@ _decimal_Context__unsafe_setemax_impl(PyObject *self, Py_ssize_t x)
10841096
}
10851097
#endif
10861098

1099+
/*[clinic input]
1100+
@setter
1101+
_decimal.Context.rounding
1102+
[clinic start generated code]*/
1103+
10871104
static int
1088-
context_setround(PyObject *self, PyObject *value, void *Py_UNUSED(closure))
1105+
_decimal_Context_rounding_set_impl(PyObject *self, PyObject *value)
1106+
/*[clinic end generated code: output=f090920a8cb03d2d input=beb560982050fb94]*/
10891107
{
10901108
mpd_context_t *ctx;
10911109
int x;
@@ -1104,8 +1122,14 @@ context_setround(PyObject *self, PyObject *value, void *Py_UNUSED(closure))
11041122
return 0;
11051123
}
11061124

1125+
/*[clinic input]
1126+
@setter
1127+
_decimal.Context.capitals
1128+
[clinic start generated code]*/
1129+
11071130
static int
1108-
context_setcapitals(PyObject *self, PyObject *value, void *Py_UNUSED(closure))
1131+
_decimal_Context_capitals_set_impl(PyObject *self, PyObject *value)
1132+
/*[clinic end generated code: output=3320d89e359b51d5 input=5a9ffb955d18f727]*/
11091133
{
11101134
mpd_ssize_t x;
11111135

@@ -1345,7 +1369,7 @@ context_setattrs(PyObject *self, PyObject *prec, PyObject *rounding,
13451369
if (prec != Py_None && context_setprec(self, prec, NULL) < 0) {
13461370
return -1;
13471371
}
1348-
if (rounding != Py_None && context_setround(self, rounding, NULL) < 0) {
1372+
if (rounding != Py_None && _decimal_Context_rounding_set(self, rounding, NULL) < 0) {
13491373
return -1;
13501374
}
13511375
if (emin != Py_None && context_setemin(self, emin, NULL) < 0) {
@@ -1354,7 +1378,7 @@ context_setattrs(PyObject *self, PyObject *prec, PyObject *rounding,
13541378
if (emax != Py_None && context_setemax(self, emax, NULL) < 0) {
13551379
return -1;
13561380
}
1357-
if (capitals != Py_None && context_setcapitals(self, capitals, NULL) < 0) {
1381+
if (capitals != Py_None && _decimal_Context_capitals_set(self, capitals, NULL) < 0) {
13581382
return -1;
13591383
}
13601384
if (clamp != Py_None && context_setclamp(self, clamp, NULL) < 0) {
@@ -1759,8 +1783,8 @@ static PyGetSetDef context_getsets [] =
17591783
{ "prec", context_getprec, context_setprec, NULL, NULL},
17601784
{ "Emax", context_getemax, context_setemax, NULL, NULL},
17611785
{ "Emin", context_getemin, context_setemin, NULL, NULL},
1762-
{ "rounding", context_getround, context_setround, NULL, NULL},
1763-
{ "capitals", context_getcapitals, context_setcapitals, NULL, NULL},
1786+
_DECIMAL_CONTEXT_ROUNDING_GETSETDEF
1787+
_DECIMAL_CONTEXT_CAPITALS_GETSETDEF
17641788
{ "clamp", context_getclamp, context_setclamp, NULL, NULL},
17651789
#ifdef EXTRA_FUNCTIONALITY
17661790
{ "_allcr", context_getallcr, context_setallcr, NULL, NULL},
@@ -6163,19 +6187,30 @@ _decimal_Decimal___trunc___impl(PyObject *self, PyTypeObject *cls)
61636187
return dec_as_long(self, context, MPD_ROUND_DOWN);
61646188
}
61656189

6166-
/* real and imag */
6190+
/*[clinic input]
6191+
@getter
6192+
_decimal.Decimal.real
6193+
[clinic start generated code]*/
6194+
61676195
static PyObject *
6168-
dec_real(PyObject *self, void *Py_UNUSED(closure))
6196+
_decimal_Decimal_real_get_impl(PyObject *self)
6197+
/*[clinic end generated code: output=a21e0af6b45ef7cb input=79fe3da48f0903a2]*/
61696198
{
61706199
return Py_NewRef(self);
61716200
}
61726201

6202+
/*[clinic input]
6203+
@getter
6204+
_decimal.Decimal.imag
6205+
[clinic start generated code]*/
6206+
61736207
static PyObject *
6174-
dec_imag(PyObject *self, void *Py_UNUSED(closure))
6208+
_decimal_Decimal_imag_get_impl(PyObject *self)
6209+
/*[clinic end generated code: output=74a3c50f9e0099f9 input=f0e73326a2ef2706]*/
61756210
{
61766211
PyObject *result;
61776212

6178-
decimal_state *state = get_module_state_by_def(Py_TYPE(self));
6213+
decimal_state *state = get_module_state_by_def(Py_TYPE(self));
61796214
result = dec_alloc(state);
61806215
if (result == NULL) {
61816216
return NULL;
@@ -6185,11 +6220,10 @@ dec_imag(PyObject *self, void *Py_UNUSED(closure))
61856220
return result;
61866221
}
61876222

6188-
61896223
static PyGetSetDef dec_getsets [] =
61906224
{
6191-
{ "real", dec_real, NULL, NULL, NULL},
6192-
{ "imag", dec_imag, NULL, NULL, NULL},
6225+
_DECIMAL_DECIMAL_REAL_GETSETDEF
6226+
_DECIMAL_DECIMAL_IMAG_GETSETDEF
61936227
{NULL}
61946228
};
61956229

Modules/_decimal/clinic/_decimal.c.h

Lines changed: 123 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)