Fix Python default args when using kwargs

Recent default arg handling fixes didn't fix the case when kwargs is turned on
This commit is contained in:
William S Fulton 2015-01-15 07:54:36 +00:00
commit afba5b755a
3 changed files with 37 additions and 24 deletions

View file

@ -79,9 +79,9 @@
static const size_type hello = 3; static const size_type hello = 3;
}; };
int rfoo( const size_type& x = Hello::hello, const Hello& y = Hello() ) int rfoo( int n = 0, const size_type& x = Hello::hello, const Hello& y = Hello() )
{ {
return x; return n - x;
} }
%} %}
%{ %{

View file

@ -51,7 +51,7 @@ if foo_fn(b=2) != 3:
raise RuntimeError raise RuntimeError
#Funtions with keywords #Functions with keywords
if foo_kw(_from=2) != 4: if foo_kw(_from=2) != 4:
raise RuntimeError raise RuntimeError
@ -65,3 +65,17 @@ if foo_mm(min=2) != 4:
if foo_mm(max=3) != 4: if foo_mm(max=3) != 4:
raise RuntimeError raise RuntimeError
#Default args with references
if rfoo(n=123) != 120:
raise RuntimeError
if rfoo(x=10) != -10:
raise RuntimeError
if rfoo(n=11, x=22) != -11:
raise RuntimeError
if rfoo(x=11, n=22) != 11:
raise RuntimeError

View file

@ -1976,32 +1976,31 @@ public:
bool is_representable_as_pyargs(Node *n) { bool is_representable_as_pyargs(Node *n) {
bool is_representable = true; bool is_representable = true;
if (Getattr(n, "sym:overloaded")) { ParmList *plist = CopyParmList(Getattr(n, "parms"));
ParmList *plist = CopyParmList(Getattr(n, "parms")); Parm *p;
Parm *p; Parm *pnext;
Parm *pnext;
for (p = plist; p; p = pnext) { for (p = plist; p; p = pnext) {
pnext = NIL; pnext = NIL;
String *tm = Getattr(p, "tmap:in"); String *tm = Getattr(p, "tmap:in");
if (tm) { if (tm) {
pnext = Getattr(p, "tmap:in:next"); pnext = Getattr(p, "tmap:in:next");
if (checkAttribute(p, "tmap:in:numinputs", "0")) { if (checkAttribute(p, "tmap:in:numinputs", "0")) {
continue; continue;
}
} }
if (!pnext) { }
pnext = nextSibling(p); if (!pnext) {
} pnext = nextSibling(p);
if (String *value = Getattr(p, "value")) { }
String *type = Getattr(p, "type"); if (String *value = Getattr(p, "value")) {
if (!convertValue(value, type)) { String *type = Getattr(p, "type");
is_representable = false; if (!convertValue(value, type)) {
break; is_representable = false;
} break;
} }
} }
} }
return is_representable; return is_representable;
} }