@@ -1084,31 +1084,40 @@ static PyObject *
1084
1084
RectExport_scalebyIp (RectObject * self , PyObject * args , PyObject * kwargs )
1085
1085
{
1086
1086
float factor_x , factor_y = 0 ;
1087
-
1088
- static char * keywords [] = {"x" , "y" , NULL };
1089
-
1090
- if (kwargs ) {
1091
- PyObject * scale_by = PyDict_GetItemString (kwargs , "scale_by" );
1092
- float temp_x , temp_y = 0 ;
1093
-
1094
- if (scale_by ) {
1095
- if (PyDict_Size (kwargs ) > 1 ) {
1096
- return RAISE (PyExc_TypeError ,
1097
- "The 'scale_by' keyword cannot be combined with "
1098
- "other arguments." );
1087
+ PyObject * scale_by =
1088
+ kwargs ? PyDict_GetItemString (kwargs , "scale_by" ) : NULL ;
1089
+ if (scale_by ) {
1090
+ if (PyDict_Size (kwargs ) > 1 ) {
1091
+ return RAISE (PyExc_TypeError ,
1092
+ "The 'scale_by' keyword cannot be combined with "
1093
+ "other arguments." );
1094
+ }
1095
+ if (!pg_TwoFloatsFromObj (scale_by , & factor_x , & factor_y )) {
1096
+ return RAISE (PyExc_TypeError ,
1097
+ "The 'scale_by' argument must be a number pair" );
1098
+ }
1099
+ }
1100
+ else {
1101
+ static char * keywords [] = {"x" , "y" , NULL };
1102
+ PyObject * arg_x , * arg_y = NULL ;
1103
+ if (!PyArg_ParseTupleAndKeywords (args , kwargs , "O|O" , keywords , & arg_x ,
1104
+ & arg_y )) {
1105
+ return NULL ;
1106
+ }
1107
+ if (!pg_TwoFloatsFromObj (arg_x , & factor_x , & factor_y )) {
1108
+ /* Not a sequence, so try handling int separately */
1109
+ if (!pg_FloatFromObj (arg_x , & factor_x )) {
1110
+ return RAISE (PyExc_TypeError , "Argument 'x' must be a number" );
1099
1111
}
1100
- if (! pg_TwoFloatsFromObj ( scale_by , & temp_x , & temp_y )) {
1101
- return RAISE (PyExc_TypeError , "number pair expected " );
1112
+ if (arg_y && ! pg_FloatFromObj ( arg_y , & factor_y )) {
1113
+ return RAISE (PyExc_TypeError , "Argument 'y' must be a number " );
1102
1114
}
1103
- PyDict_SetItemString (kwargs , "x" , PyFloat_FromDouble (temp_x ));
1104
- PyDict_SetItemString (kwargs , "y" , PyFloat_FromDouble (temp_y ));
1105
- PyDict_DelItemString (kwargs , "scale_by" );
1106
1115
}
1107
- }
1108
-
1109
- if (! PyArg_ParseTupleAndKeywords ( args , kwargs , "f|f" , keywords , & factor_x ,
1110
- & factor_y )) {
1111
- return RAISE ( PyExc_TypeError , "Float values expected." );
1116
+ else if ( arg_y ) {
1117
+ return RAISE (
1118
+ PyExc_TypeError ,
1119
+ "Cannot pass argument 'y' after passing a sequence scale" );
1120
+ }
1112
1121
}
1113
1122
1114
1123
factor_x = factor_x < 0 ? - factor_x : factor_x ;
@@ -1130,7 +1139,11 @@ RectExport_scaleby(RectObject *self, PyObject *args, PyObject *kwargs)
1130
1139
{
1131
1140
RectObject * returnRect = (RectObject * )RectExport_subtypeNew4 (
1132
1141
Py_TYPE (self ), self -> r .x , self -> r .y , self -> r .w , self -> r .h );
1133
- RectExport_scalebyIp (returnRect , args , kwargs );
1142
+ PyObject * tmp = RectExport_scalebyIp (returnRect , args , kwargs );
1143
+ if (!tmp ) {
1144
+ return NULL ;
1145
+ }
1146
+ Py_DECREF (tmp );
1134
1147
return (PyObject * )returnRect ;
1135
1148
}
1136
1149
0 commit comments