From ff47fb64569ddbd65ef34c33e7cafc030c69a34e Mon Sep 17 00:00:00 2001 From: Paul Vinciguerra Date: Tue, 6 Aug 2019 19:58:24 -0400 Subject: vppapigen map: raise ValueError when fieldname is python keyword When working on the lb api, one of the field names was chosen as 'as' (application server). Since 'as' is a python keyword, the field was renamed to _1 in vpp_papi. This changeset instead fails early with a descriptive message, hopefully saving others time troubleshooting the issue. ValueError: Fieldname 'as' is a python keyword and is not accessible via the python API. Type: feature Change-Id: Ib048d97de0e392645540092e356cf8989848c947 Signed-off-by: Paul Vinciguerra --- src/tools/vppapigen/vppapigen.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/tools/vppapigen/vppapigen.py') diff --git a/src/tools/vppapigen/vppapigen.py b/src/tools/vppapigen/vppapigen.py index 8ae991c9c95..52ffb6a18f1 100755 --- a/src/tools/vppapigen/vppapigen.py +++ b/src/tools/vppapigen/vppapigen.py @@ -5,6 +5,7 @@ import ply.lex as lex import ply.yacc as yacc import sys import argparse +import keyword import logging import binascii import os @@ -293,6 +294,9 @@ class Field(): def __init__(self, fieldtype, name, limit=None): self.type = 'Field' self.fieldtype = fieldtype + if name in keyword.kwlist: + raise ValueError("Fieldname {!r} is a python keyword and is not " + "accessible via the python API. ".format(name)) self.fieldname = name self.limit = limit -- cgit 1.2.3-korg