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

Remove deprecation warning that may create errors #117

Closed
wants to merge 1 commit into from
Closed

Conversation

pchaillo
Copy link
Contributor

On my computer, these 3 lines create an error after my python update (I don't know why).

To be sure to avoid them for users, I just remove it.

What do you think ?

@EulalieCoevoet
Copy link
Member

I would remove the lines instead of commenting them.

@damienmarchal
Copy link
Member

Well, thank @pchaillo for the PR.

In the past the function was probably supposed to be used that way:
index_from_axis(points=[something], axis=[anotherthing], old_indices = 'null')

Using a 'null' string instead of None to pass a None parameter was a bad idea it was probably fixed to replace it with None.
To warn user of the API change, an extra steps was thus added to emit an exception so that calling points can update their code.

As the error message says it (badly):

DeprecationWarning("Attention, old_indices est à 'null', the new norm is old_indices = None")

To fix the error you need to stop pass 'null' in the old_indices parameters and use None.

If you want to make a PR:

  • keep the lines that emit an errror, the fact it trigger in your code shows how usefull it is ;)
  • propose an improved error message to help readers to understand better they have to fix the calling point

@damienmarchal
Copy link
Member

I would remove the lines instead of commenting them.
Eulalie is right, commenting code is a bad practice, always remove.
But... on that specific problem neither commenting or removing is the proper fix :)

@EulalieCoevoet
Copy link
Member

I still vote for a removal : it's been a year, plus the code has been added to the library with the deprecation warning. So I think it's safe to remove it.

But it would be interesting to understand why it triggers an error (and not just a warning as it's supposed to).

@damienmarchal
Copy link
Member

@EulalieCoevoet

The observed behavior is what is expected to be.

The calling point is probably using the old convention passing "null" as parameter. This rise a DeprecationWarning. The exception, if not try-excepted, propagates through the call stack up to the top-level which is actually the SofaPython3 binding. At the place, an exception handler convert it into a Sofa.msg_error... which print an "error".
This could be improved by replacing the use of msg_error for msg_deprecated when catching a child class of DeprecationWarning. We should make a PR to SofaPython3 to implement that.

And thus, depsite Sofa shows it as an Error instead of the Deprecation, the behavior is the one expected... reporting to users they are using the old API.

Small test...

import Sofa

def test(root=None):
    if root == "null":
        raise DeprecationWarning("Yo lo")
    root.addChild("This should work")
    
def createScene(root):
    root.addChild("First")
    test("null")
    root.addChild("Second")

Results in:

[ERROR]   [SofaPython3::SceneLoader] Unable to completely load the scene from file '/home/dmarchal/projects/dev/sofa1/build-clang/bin/test.py'.  
Python exception:   
  DeprecationWarning: Yo lo

At:
  /home/dmarchal/projects/dev/sofa1/build-clang/bin/test.py(5): test
  /home/dmarchal/projects/dev/sofa1/build-clang/bin/test.py(10): createScene

@EulalieCoevoet
Copy link
Member

Okay I see.

@damienmarchal
Copy link
Member

Okay I see.

Here is the improvement for Sofa... but it should probably be generalized to few others points and not only in the SceneLoader. sofa-framework/SofaPython3#384

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.

4 participants