Skip to content
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

fix getproperty exceptions #997

Merged
merged 9 commits into from
Aug 22, 2022
Merged

fix getproperty exceptions #997

merged 9 commits into from
Aug 22, 2022

Conversation

aplavin
Copy link
Contributor

@aplavin aplavin commented Jul 30, 2022

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

fixes #696

@codecov-commenter
Copy link

codecov-commenter commented Jul 30, 2022

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%) ⬇️

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%) ⬆️
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.

@aplavin aplavin changed the title raise proper exception in getproperty fix getproperty exceptions Aug 4, 2022
@aplavin
Copy link
Contributor Author

aplavin commented Aug 19, 2022

bump

src/PyCall.jl Outdated Show resolved Hide resolved
src/PyCall.jl Outdated Show resolved Hide resolved
@stevengj
Copy link
Member

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

@aplavin
Copy link
Contributor Author

aplavin commented Aug 20, 2022

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.

@stevengj
Copy link
Member

stevengj commented Aug 20, 2022

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

@aplavin
Copy link
Contributor Author

aplavin commented Aug 20, 2022

In the two corresponding cases, it's:

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

@stevengj
Copy link
Member

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

@stevengj
Copy link
Member

stevengj commented Aug 20, 2022

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.)

src/PyCall.jl Outdated Show resolved Hide resolved
src/PyCall.jl Outdated Show resolved Hide resolved
src/PyCall.jl Outdated Show resolved Hide resolved
src/PyCall.jl Outdated Show resolved Hide resolved
@stevengj stevengj merged commit ddb54a8 into JuliaPy:master Aug 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wrong error reported when accessing an attribute
3 participants