@@ -20,10 +20,16 @@ pyjlany_getattro(xo::PyPtr, ko::PyPtr) = begin
2020 else
2121 return ro
2222 end
23- # Now try to get the corresponding property
23+ # Convert attribute to a string
2424 x = PyJuliaValue_GetValue (xo)
2525 k = PyUnicode_AsString (ko)
2626 isempty (k) && PyErr_IsSet () && return PyNULL
27+ # If has double leading and trailing underscore, do not allow
28+ if length (k) > 4 && startswith (k, " __" ) && endswith (k, " __" )
29+ PyErr_SetString (PyExc_AttributeError (), " '$(PyType_Name (Py_Type (xo))) ' object has no attribute '$k '" )
30+ return PyNULL
31+ end
32+ # Look up a property on the Julia object
2733 k = pyjl_attr_py2jl (k)
2834 @pyjltry begin
2935 v = getproperty (x, Symbol (k))
@@ -48,10 +54,16 @@ pyjlany_setattro(xo::PyPtr, ko::PyPtr, vo::PyPtr) = begin
4854 PyErr_SetString (PyExc_TypeError (), " attribute deletion not supported" )
4955 return Cint (- 1 )
5056 end
51- # Now try to set the corresponding property
57+ # Convert attribute to a string
5258 x = PyJuliaValue_GetValue (xo)
5359 k = PyUnicode_AsString (ko)
5460 isempty (k) && PyErr_IsSet () && return Cint (- 1 )
61+ # If has double leading and trailing underscore, do not allow
62+ if length (k) > 4 && startswith (k, " __" ) && endswith (k, " __" )
63+ PyErr_SetString (PyExc_AttributeError (), " '$(PyType_Name (Py_Type (xo))) ' object has no attribute '$k '" )
64+ return PyNULL
65+ end
66+ # Look up a property on the Julia object
5567 k = pyjl_attr_py2jl (k)
5668 @pyjltry begin
5769 V = propertytype (x, Symbol (k))
0 commit comments