From 4f72a78684bbfcdc43ceeabb240ceee54706c4b0 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Fri, 27 Oct 2006 23:31:49 +0000 Subject: Jiwon Seo's PEP 3102 implementation. See SF#1549670. The compiler package has not yet been updated. --- Python/symtable.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'Python/symtable.c') diff --git a/Python/symtable.c b/Python/symtable.c index 8f19e0bd00..b0ebed408b 100644 --- a/Python/symtable.c +++ b/Python/symtable.c @@ -893,6 +893,17 @@ error: } \ } +#define VISIT_KWONLYDEFAULTS(ST, KW_DEFAULTS) { \ + int i = 0; \ + asdl_seq *seq = (KW_DEFAULTS); /* avoid variable capture */ \ + for (i = 0; i < asdl_seq_LEN(seq); i++) { \ + expr_ty elt = (expr_ty)asdl_seq_GET(seq, i); \ + if (!elt) continue; /* can be NULL */ \ + if (!symtable_visit_expr((ST), elt)) \ + return 0; \ + } \ +} + static int symtable_new_tmpname(struct symtable *st) { @@ -910,6 +921,8 @@ symtable_new_tmpname(struct symtable *st) return 1; } + + static int symtable_visit_stmt(struct symtable *st, stmt_ty s) { @@ -919,6 +932,9 @@ symtable_visit_stmt(struct symtable *st, stmt_ty s) return 0; if (s->v.FunctionDef.args->defaults) VISIT_SEQ(st, expr, s->v.FunctionDef.args->defaults); + if (s->v.FunctionDef.args->kw_defaults) + VISIT_KWONLYDEFAULTS(st, + s->v.FunctionDef.args->kw_defaults); if (s->v.FunctionDef.decorators) VISIT_SEQ(st, expr, s->v.FunctionDef.decorators); if (!symtable_enter_block(st, s->v.FunctionDef.name, @@ -1262,6 +1278,8 @@ symtable_visit_arguments(struct symtable *st, arguments_ty a) */ if (a->args && !symtable_visit_params(st, a->args, 1)) return 0; + if (a->kwonlyargs && !symtable_visit_params(st, a->kwonlyargs, 1)) + return 0; if (a->vararg) { if (!symtable_add_def(st, a->vararg, DEF_PARAM)) return 0; -- cgit v1.2.1