Unify more format strings
This commit is contained in:
parent
9a0b940302
commit
7a81724595
@ -226,7 +226,7 @@ KRK_METHOD(map,__init__,{
|
|||||||
for (int i = 2; i < argc; ++i) {
|
for (int i = 2; i < argc; ++i) {
|
||||||
KrkClass * type = krk_getType(argv[i]);
|
KrkClass * type = krk_getType(argv[i]);
|
||||||
if (!type->_iter) {
|
if (!type->_iter) {
|
||||||
return krk_runtimeError(vm.exceptions->typeError, "'%s' is not iterable", krk_typeName(argv[i]));
|
return krk_runtimeError(vm.exceptions->typeError, "'%s' object is not iterable", krk_typeName(argv[i]));
|
||||||
}
|
}
|
||||||
krk_push(argv[i]);
|
krk_push(argv[i]);
|
||||||
KrkValue asIter = krk_callSimple(OBJECT_VAL(type->_iter), 1, 0);
|
KrkValue asIter = krk_callSimple(OBJECT_VAL(type->_iter), 1, 0);
|
||||||
@ -301,7 +301,7 @@ KRK_METHOD(filter,__init__,{
|
|||||||
krk_attachNamedValue(&self->fields, "_function", argv[1]);
|
krk_attachNamedValue(&self->fields, "_function", argv[1]);
|
||||||
KrkClass * type = krk_getType(argv[2]);
|
KrkClass * type = krk_getType(argv[2]);
|
||||||
if (!type->_iter) {
|
if (!type->_iter) {
|
||||||
return krk_runtimeError(vm.exceptions->typeError, "'%s' is not iterable", krk_typeName(argv[2]));
|
return krk_runtimeError(vm.exceptions->typeError, "'%s' object is not iterable", krk_typeName(argv[2]));
|
||||||
}
|
}
|
||||||
krk_push(argv[2]);
|
krk_push(argv[2]);
|
||||||
KrkValue asIter = krk_callSimple(OBJECT_VAL(type->_iter), 1, 0);
|
KrkValue asIter = krk_callSimple(OBJECT_VAL(type->_iter), 1, 0);
|
||||||
@ -367,7 +367,7 @@ KRK_METHOD(enumerate,__init__,{
|
|||||||
/* Attach iterator */
|
/* Attach iterator */
|
||||||
KrkClass * type = krk_getType(argv[1]);
|
KrkClass * type = krk_getType(argv[1]);
|
||||||
if (!type->_iter) {
|
if (!type->_iter) {
|
||||||
return krk_runtimeError(vm.exceptions->typeError, "'%s' is not iterable", krk_typeName(argv[1]));
|
return krk_runtimeError(vm.exceptions->typeError, "'%s' object is not iterable", krk_typeName(argv[1]));
|
||||||
}
|
}
|
||||||
krk_push(argv[1]);
|
krk_push(argv[1]);
|
||||||
KrkValue asIter = krk_callSimple(OBJECT_VAL(type->_iter), 1, 0);
|
KrkValue asIter = krk_callSimple(OBJECT_VAL(type->_iter), 1, 0);
|
||||||
|
14
src/vm.c
14
src/vm.c
@ -544,7 +544,7 @@ static void multipleDefs(KrkClosure * closure, int destination) {
|
|||||||
positionals->count++; \
|
positionals->count++; \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
int krk_processComplexArguments(int argCount, KrkValueArray * positionals, KrkTable * keywords) {
|
int krk_processComplexArguments(int argCount, KrkValueArray * positionals, KrkTable * keywords, const char * name) {
|
||||||
size_t kwargsCount = AS_INTEGER(krk_currentThread.stackTop[-1]);
|
size_t kwargsCount = AS_INTEGER(krk_currentThread.stackTop[-1]);
|
||||||
krk_pop(); /* Pop the arg counter */
|
krk_pop(); /* Pop the arg counter */
|
||||||
argCount--;
|
argCount--;
|
||||||
@ -568,18 +568,18 @@ int krk_processComplexArguments(int argCount, KrkValueArray * positionals, KrkTa
|
|||||||
unpackIterableFast(value);
|
unpackIterableFast(value);
|
||||||
} else if (AS_INTEGER(key) == KWARGS_DICT) { /* unpack dict */
|
} else if (AS_INTEGER(key) == KWARGS_DICT) { /* unpack dict */
|
||||||
if (!IS_INSTANCE(value)) {
|
if (!IS_INSTANCE(value)) {
|
||||||
krk_runtimeError(vm.exceptions->typeError, "**expression value is not a dict.");
|
krk_runtimeError(vm.exceptions->typeError, "%s(): **expression value is not a dict.", name);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
for (size_t i = 0; i < AS_DICT(value)->capacity; ++i) {
|
for (size_t i = 0; i < AS_DICT(value)->capacity; ++i) {
|
||||||
KrkTableEntry * entry = &AS_DICT(value)->entries[i];
|
KrkTableEntry * entry = &AS_DICT(value)->entries[i];
|
||||||
if (!IS_KWARGS(entry->key)) {
|
if (!IS_KWARGS(entry->key)) {
|
||||||
if (!IS_STRING(entry->key)) {
|
if (!IS_STRING(entry->key)) {
|
||||||
krk_runtimeError(vm.exceptions->typeError, "**expression contains non-string key");
|
krk_runtimeError(vm.exceptions->typeError, "%s(): **expression contains non-string key", name);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (!krk_tableSet(keywords, entry->key, entry->value)) {
|
if (!krk_tableSet(keywords, entry->key, entry->value)) {
|
||||||
krk_runtimeError(vm.exceptions->typeError, "got multiple values for argument '%s'", AS_CSTRING(entry->key));
|
krk_runtimeError(vm.exceptions->typeError, "%s() got multiple values for argument '%s'", name, AS_CSTRING(entry->key));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -589,7 +589,7 @@ int krk_processComplexArguments(int argCount, KrkValueArray * positionals, KrkTa
|
|||||||
}
|
}
|
||||||
} else if (IS_STRING(key)) {
|
} else if (IS_STRING(key)) {
|
||||||
if (!krk_tableSet(keywords, key, value)) {
|
if (!krk_tableSet(keywords, key, value)) {
|
||||||
krk_runtimeError(vm.exceptions->typeError, "got multiple values for argument '%s'", AS_CSTRING(key));
|
krk_runtimeError(vm.exceptions->typeError, "%s() got multiple values for argument '%s'", name, AS_CSTRING(key));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -627,7 +627,7 @@ static int call(KrkClosure * closure, int argCount, int extra) {
|
|||||||
keywords = AS_DICT(myDict);
|
keywords = AS_DICT(myDict);
|
||||||
|
|
||||||
/* This processes the existing argument list into a ValueArray and a Table with the args and keywords */
|
/* This processes the existing argument list into a ValueArray and a Table with the args and keywords */
|
||||||
if (!krk_processComplexArguments(argCount, positionals, keywords)) goto _errorDuringPositionals;
|
if (!krk_processComplexArguments(argCount, positionals, keywords, closure->function->name ? closure->function->name->chars : "<unnamed>")) goto _errorDuringPositionals;
|
||||||
argCount--; /* It popped the KWARGS value from the top, so we have one less argument */
|
argCount--; /* It popped the KWARGS value from the top, so we have one less argument */
|
||||||
|
|
||||||
/* Do we already know we have too many arguments? Let's bail before doing a bunch of work. */
|
/* Do we already know we have too many arguments? Let's bail before doing a bunch of work. */
|
||||||
@ -811,7 +811,7 @@ int krk_callValue(KrkValue callee, int argCount, int extra) {
|
|||||||
krk_currentThread.scratchSpace[0] = myList;
|
krk_currentThread.scratchSpace[0] = myList;
|
||||||
KrkValue myDict = krk_dict_of(0,NULL,0);
|
KrkValue myDict = krk_dict_of(0,NULL,0);
|
||||||
krk_currentThread.scratchSpace[1] = myDict;
|
krk_currentThread.scratchSpace[1] = myDict;
|
||||||
if (!krk_processComplexArguments(argCount, AS_LIST(myList), AS_DICT(myDict))) {
|
if (!krk_processComplexArguments(argCount, AS_LIST(myList), AS_DICT(myDict), AS_NATIVE(callee)->name)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
argCount--; /* Because that popped the kwargs value */
|
argCount--; /* Because that popped the kwargs value */
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
1, 2, 3, test, <class 'object'>, 7, 9, 10;
|
1, 2, 3, test, <class 'object'>, 7, 9, 10;
|
||||||
a, b, 1, 2, 3, 7, 1, 2, 3test
|
a, b, 1, 2, 3, 7, 1, 2, 3test
|
||||||
1 apples <class 'object'>
|
1 apples <class 'object'>
|
||||||
got multiple values for argument 'a'
|
format() got multiple values for argument 'a'
|
||||||
|
@ -6,7 +6,7 @@ None None
|
|||||||
None 5
|
None 5
|
||||||
function() missing required positional argument: 'positional2'
|
function() missing required positional argument: 'positional2'
|
||||||
function() got multiple values for argument 'positional1'
|
function() got multiple values for argument 'positional1'
|
||||||
got multiple values for argument 'keyword2'
|
function() got multiple values for argument 'keyword2'
|
||||||
1 abc
|
1 abc
|
||||||
None 4
|
None 4
|
||||||
function() got multiple values for argument 'positional1'
|
function() got multiple values for argument 'positional1'
|
||||||
|
Loading…
Reference in New Issue
Block a user