PyCall.jl icon indicating copy to clipboard operation
PyCall.jl copied to clipboard

fix getproperty exceptions

Open aplavin opened this issue 3 years ago • 1 comments

this throws KeyError as before when the attribute isn't there (AttributeError in python) when the attribute is present, but its computation throws a python exception, this PR rethrows it in julia

see https://github.com/JuliaPy/PyCall.jl/issues/696

aplavin avatar Jul 30 '22 08:07 aplavin

Codecov Report

Merging #997 (d2b9cd0) into master (b27bd5a) will decrease coverage by 0.01%. The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #997      +/-   ##
==========================================
- Coverage   68.36%   68.35%   -0.02%     
==========================================
  Files          20       20              
  Lines        2023     2038      +15     
==========================================
+ Hits         1383     1393      +10     
- Misses        640      645       +5     
Flag Coverage Δ
unittests 68.35% <100.00%> (-0.02%) :arrow_down:

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/PyCall.jl 72.18% <100.00%> (+1.49%) :arrow_up:
src/gui.jl 0.00% <0.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

codecov-commenter avatar Jul 30 '22 08:07 codecov-commenter

bump

aplavin avatar Aug 19 '22 13:08 aplavin

Looks good, modulo a couple of minor tweaks noted above.

stevengj avatar Aug 19 '22 17:08 stevengj

I also pushed the corresponding setproperty fix, if you know the proper way to check the exception please update it as well! For now, getproperty tests fail with your changes.

aplavin avatar Aug 20 '22 14:08 aplavin

What is e.T that pyisinstance(e.T, @pyglobalobjptr(:PyExc_AttributeError)) fails to give the expected result?

stevengj avatar Aug 20 '22 14:08 stevengj

In the two corresponding cases, it's:

e.T = PyObject <class 'ValueError'>
# and
e.T = PyObject <class 'AttributeError'>

aplavin avatar Aug 20 '22 14:08 aplavin

What does pyisinstance(e.T, @pyglobalobjptr(:PyExc_AttributeError)) return in those cases?

stevengj avatar Aug 20 '22 19:08 stevengj

Oh, I see the problem. e.T is not an instance of AttributeError, it is the type itself. So the correct check is

if PyPtr(e.T) != @pyglobalobjptr(:PyExc_AttributeError)

(The goal here is to avoid the string conversion. Also, checking whether it is actually PyExc_AttributeError, not just named "AttributeError", is in principle more robust.)

stevengj avatar Aug 20 '22 20:08 stevengj