improved python syntax safety check