Commit fe565665 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Merge pull request #130 from tjhance/fix_error_msg

fixed object.__new__ error message for >=2.7.4
parents fe1ee643 a5cb0a5b
......@@ -22,6 +22,8 @@ int PYTHON_VERSION_MAJOR = DEFAULT_PYTHON_MAJOR_VERSION;
int PYTHON_VERSION_MINOR = DEFAULT_PYTHON_MINOR_VERSION;
int PYTHON_VERSION_MICRO = DEFAULT_PYTHON_MICRO_VERSION;
int PYTHON_VERSION_HEX = version_hex(PYTHON_VERSION_MAJOR, PYTHON_VERSION_MINOR, PYTHON_VERSION_MICRO);
int MAX_OPT_ITERATIONS = 1;
bool FORCE_OPTIMIZE = false;
......
......@@ -22,7 +22,11 @@ extern "C" {
extern int GLOBAL_VERBOSITY;
#define VERBOSITY(x) GLOBAL_VERBOSITY
// Version number we're targeting:
extern int PYTHON_VERSION_MAJOR, PYTHON_VERSION_MINOR, PYTHON_VERSION_MICRO;
extern int PYTHON_VERSION_MAJOR, PYTHON_VERSION_MINOR, PYTHON_VERSION_MICRO, PYTHON_VERSION_HEX;
inline int version_hex(int major, int minor, int micro, int level = 0, int serial = 0) {
return (major << 24) | (minor << 16) | (micro << 8) | (level << 4) | (serial << 0);
}
extern int MAX_OPT_ITERATIONS;
......
......@@ -3241,7 +3241,7 @@ Box* typeCallInternal(BoxedFunction* f, CallRewriteArgs* rewrite_args, ArgPassSp
ArgPassSpec new_argspec = argspec;
if (npassed_args > 1 && new_attr == typeLookup(object_cls, _new_str, NULL)) {
if (init_attr == typeLookup(object_cls, _init_str, NULL)) {
raiseExcHelper(TypeError, "object.__new__() takes no parameters");
raiseExcHelper(TypeError, objectNewParameterTypeErrorMsg());
} else {
new_argspec = ArgPassSpec(1);
}
......@@ -3315,7 +3315,7 @@ Box* typeCallInternal(BoxedFunction* f, CallRewriteArgs* rewrite_args, ArgPassSp
// assert(0 && "I don't think this should be reached");
if (new_attr == NULL && npassed_args != 1) {
// TODO not npassed args, since the starargs or kwargs could be null
raiseExcHelper(TypeError, "object.__new__() takes no parameters");
raiseExcHelper(TypeError, objectNewParameterTypeErrorMsg());
}
}
......
......@@ -18,6 +18,7 @@
#include <stdint.h>
#include <string>
#include "core/options.h"
#include "core/types.h"
namespace pyston {
......@@ -118,5 +119,13 @@ bool isUserDefined(BoxedClass* cls);
Box* callCLFunc(CLFunction* f, CallRewriteArgs* rewrite_args, int num_output_args, BoxedClosure* closure,
BoxedGenerator* generator, Box* oarg1, Box* oarg2, Box* oarg3, Box** oargs);
static const char* objectNewParameterTypeErrorMsg() {
if (PYTHON_VERSION_HEX >= version_hex(2, 7, 4)) {
return "object() takes no parameters";
} else {
return "object.__new__() takes no parameters";
}
}
}
#endif
......@@ -579,7 +579,7 @@ Box* objectNew(BoxedClass* cls, BoxedTuple* args) {
if (args->elts.size() != 0) {
// TODO slow
if (typeLookup(cls, "__init__", NULL) == typeLookup(object_cls, "__init__", NULL))
raiseExcHelper(TypeError, "object.__new__() takes no parameters");
raiseExcHelper(TypeError, objectNewParameterTypeErrorMsg());
}
assert(cls->tp_basicsize >= sizeof(Box));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment