[IronPython] Compiler error for invalid field access
fuzzyman at voidspace.org.uk
Sun Aug 5 12:56:04 PDT 2007
> I'm using the following code to compile python code:
> SystemState state = new SystemState();
> MyCompilerSink sink = new MyCompilerSink();
> CompilerContext context = new CompilerContext(string.Empty, sink);
> Parser parser = Parser.FromString(state, context, "my code");
> it works find for finding syntax mistakes - but I also wan to know about
> invalid property names / method names. If for example the code uses the
> expression 'self.Name' I would like to see a compilation error if the object
> does not have a 'Name' property.
> Is there a way to do it?
Python does not generate 'compile' errors for these sorts of problems.
Python is dynamically typed, so it doesn't know about the type of
objects at compile time - instead errors will be generated at runtime.
As well as catching errors at compilation (syntax errors) you will also
need to catch potential errors where these objects are used. This is the
joy and the pain of using a dynamically typed language.
All the best,
More information about the Users