Should not generate error if attribute not found on python object#58
Should not generate error if attribute not found on python object#58greatwolf merged 2 commits intobastibe:masterfrom
Conversation
|
I'm unsure about this. In python, if you access a non-existing attribute eg. If @bastibe @chrisju @sapir, what do you guys think of this PR's design change? |
|
What is lua's default if you access a non-existant key on a table? If the answer is |
|
A non-existing key is synonymous with a |
|
Access a non-existant key in a table in lua will return a nil value. No exceptions, no errors. |
|
@Jayatubi what do you mean by
|
|
@bastibe The error would case the lua enter a error state and force quit if there is no error handling. Just like you get exception in python or C. But normally a nil value is expected instead of a breakage. Expect: But get: |
|
I haven't done Lua in a long time. Lua does not support exceptions, right? |
|
It does sort of by using Admittedly, that's more code to handle the case. I guess the question boils down to how this should be handled, stay with python's way of handling errors by throwing or with lua by returning |
|
This raises an interesting design question. As I understand, and as you mentioned, python treats non-existing and |
|
In my experience when coding in lua it usually expects the non-existing to nil as default behavior. It's seldom to handle exception unless someone or some documentations explicitly mentions, such as invoke external APIs. |
|
It is then a question whether lunatic-python should represent Python objects as table-like or try to be as faithful to Python as possible. Personally, I prefer purity over convenience. After all, it would be relatively easy to prevent that error from Lua by calling Opinions? |
|
Generally lua doesn't have such If the target object is a lua table there could be a wrapper such as: But this could only be used with native lua table, in other words support |
|
I suppose we could take the spirit of "when in Rome" approach. IOW, do what the host language would expect. If using python in lua, lua code typically expects For cases where the user actually wants to distinguish between We can also pose this question on say /r/python and /r/lua to get some feedback; incase there are other important considerations we're overlooking. |
Actually push and return `nil`.
|
Slightly off-topic but @bastibe can you enable travis CI for lunatic under your account? This way, new PR merges can be executed automatically. |
|
@greatwolf Travis CI should be enabled now. |
IMHO, if the attribute is not found on python object it should just return nil otherwise it would break the entire lua state machine.