New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
wraputils.lua setup_property_access shouldn't override class methods #482
Changes from 1 commit
2d8edb4
5a7c2b5
2e573ff
0df8e2e
0f4a196
f31adf0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -134,32 +134,33 @@ end | |
-- Handle @lua_property decorators. | ||
-- | ||
local function setup_property_access(py_object, self, cls) | ||
local setters = {} | ||
local getters = {} | ||
self.setters = {} | ||
self.getters = {} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suppose that we should somehow hide this objects from |
||
|
||
for name, opts in pairs(py_object.lua_properties) do | ||
getters[name] = unwraps_python_result(drops_self_argument(py_object[opts.getter])) | ||
self.getters[name] = unwraps_python_result(drops_self_argument(py_object[opts.getter])) | ||
if opts.setter ~= nil then | ||
setters[name] = unwraps_python_result(drops_self_argument(py_object[opts.setter])) | ||
self.setters[name] = unwraps_python_result(drops_self_argument(py_object[opts.setter])) | ||
else | ||
setters[name] = function() | ||
self.setters[name] = function() | ||
error("Attribute " .. name .. " is read-only.", 2) | ||
end | ||
end | ||
end | ||
|
||
function cls:__newindex(index, value) | ||
if setters[index] then | ||
return setters[index](self, value) | ||
function cls:__index(index) | ||
if self.getters[index] then | ||
return self.getters[index](self) | ||
else | ||
return rawset(cls, index, value) | ||
return rawget(cls, index) | ||
end | ||
end | ||
|
||
function cls:__index(index) | ||
if getters[index] then | ||
return getters[index](self) | ||
function cls:__newindex(index, value) | ||
if self.setters[index] then | ||
return self.setters[index](self, value) | ||
else | ||
return rawget(cls, index) | ||
return rawset(self, index, value) | ||
end | ||
end | ||
end | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -834,6 +834,35 @@ def test_error_handled_in_callback(self): | |
self.assertStatusCode(resp, 200) | ||
self.assertEqual(resp.text, "error") | ||
|
||
def test_multiple_calls(self): | ||
resp = self.request_lua(""" | ||
local treat = require('treat') | ||
function main(splash) | ||
local o = {false, false, false, false, false, false} | ||
|
||
local timer1 = splash:call_later(function() o[1] = true end, 0.5) | ||
local timer2 = splash:call_later(function() o[2] = true end, 0.5) | ||
local timer3 = splash:call_later(function() o[3] = true end, 0.5) | ||
local timer4 = splash:call_later(function() o[4] = true end, 0.5) | ||
local timer5 = splash:call_later(function() o[5] = true end, 0.5) | ||
local timer6 = splash:call_later(function() o[6] = true end, 0.5) | ||
|
||
timer1:cancel() | ||
timer2:cancel() | ||
timer3:cancel() | ||
timer4:cancel() | ||
timer5:cancel() | ||
timer6:cancel() | ||
|
||
splash:wait(1) | ||
|
||
return treat.as_array(o) | ||
end | ||
""") | ||
|
||
self.assertStatusCode(resp, 200) | ||
self.assertEqual(resp.json(), [False, False, False, False, False, False]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you run this test w/o this fix you will get There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment belongs in the source code, not here. |
||
|
||
|
||
class WithTimeoutTest(BaseLuaRenderTest): | ||
def test_with_timeout(self): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is used to reset the result of the previous
setup_property_access
call.