-
Notifications
You must be signed in to change notification settings - Fork 187
Closed
Description
Hi! I have a class that does some checking before setting an attribute value, like this (pure Python):
class A:
def __setattr__(self, name, value):
if value == 0:
raise ValueError(value)
# set value...
a = A()
a.a = 5 # OK
a.a = 0 # correct error message:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-9-7600552ca637> in <module>()
----> 1 a.a = 0
<ipython-input-6-585623315894> in __setattr__(self, name, value)
2 def __setattr__(self, name, value):
3 if value == 0:
----> 4 raise ValueError(value)
5 # set value...
6
ValueError: 0However, running the same code with PyCall.jl gives a very confusing error message:
py"""
class A:
def __setattr__(self, name, value):
if value == 0:
raise ValueError(value)
# set value...
"""
a = py"A"()
a.a = 5 # OK
a.a = 0 # completely wrong exception:
ERROR: KeyError: key :a not found
Stacktrace:
[1] setproperty!(::PyObject, ::Symbol, ::Int64) at /users/aplavin/.julia/packages/PyCall/ttONZ/src/PyCall.jl:329
[2] top-level scope at none:0Metadata
Metadata
Assignees
Labels
No labels