[IronPython] Compiler error for invalid field access
fuzzyman at voidspace.org.uk
Sun Aug 5 13:11:14 PDT 2007
> Executing the code to know if there is a problem or not is not what I wish
> for. I really can't do it because in my case the context does not exist.
> I will try to create a 'fake' context in order to run the code, but I'm not
> sure it is a good idea..
I presume you are executing the code *somewhere*. What about catching
the error there? (Or creating a 'safe execution' method that does the
error trapping and routing all calls through that?)
> Chip Norkus wrote:
>> On Sun Aug 05, 2007; 12:51PM -0700, Ori wrote:
>>> 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
>>> does not have a 'Name' property.
>> Because objects are mutable Python by its nature does not resolve
>> member/property references until they occur within the code. Consider
>> the following example (which is valid functional Python):
>> class foo(object):
>> setup = False
>> f = foo()
>> def bar(f):
>> if f.setup:
>> f.baz = "hi"
>> print f.baz
>> f.setup = True
>> print "setup"
>>> Is there a way to do it?
>>> View this message in context:
>>> Sent from the IronPython mailing list archive at Nabble.com.
>>> Users mailing list
>>> Users at lists.ironpython.com
>> personal: chip norkus; irc: wd; wd at teleri.net
>> info: finger wd at teleri.net for plan or keys; http://telekinesis.org
>> Users mailing list
>> Users at lists.ironpython.com
More information about the Users