-
Notifications
You must be signed in to change notification settings - Fork 503
Improve robustness of Python completion model #1229
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
Conversation
Remove the `dict` variable from `ctkAbstractPythonManager::pythonAttributes` as it was redundant. All relevant operations now directly use object.
7bc9d81
to
c741fd9
Compare
It all looks good except hiding |
else | ||
{ | ||
// failed to invoke callable, no completions are available | ||
PyErr_Clear(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PyErr_Clear(); | |
this->handleErrorAsWarning(); |
Instead of blindly discarding error ... we could introduce a new function handleErrorAsWarning
allowing those to be logged while avoiding them to be reported in the Python console.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using the updated VTK version in Slicer/Slicer#8238, I can confirm that SetInterpolate
is showing again:
I'm not sure what excludeGetSet
is really doing here as I see both the property and Getter related to getting the Slicer node ID. Unless this is an artifact of doing an incremental build rather than a fresh clean build.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After adding dn = n.GetDisplayNode()
appendParenthesis = False
excludeGetSet = False
withGetSets = set(slicer.app.pythonManager().pythonAttributes("dn", "__main__", appendParenthesis, excludeGetSet))
excludeGetSet = True
withoutGetSets = set(slicer.app.pythonManager().pythonAttributes("dn", "__main__", appendParenthesis, excludeGetSet))
print(withGetSets - withoutGetSets)
There are few issues:
As pointed out by @lassoan excluding the property from completion will be confusing, instead we want them to be listed by with a lower priority (e.g at the end) |
Yeah putting the older Get/Set methods at the end could be a good way to discourage that auto-complete in favor of the more python property ones as part of a transition period starting now. Then ultimately the Get/Set autocompletion could be removed in the future. ITK had already switched to the more python interface as part of ITK 5 (https://discourse.itk.org/t/itk-5-0-beta-1-pythonic-interface/1271). |
…ython This may be useful to inspect the input provided to the Python completion model.
…_object` Clear error if attempt to get an object or dictionary attribute failed while iterating over items.
Ensure `classToInstantiate` is properly managed by incrementing its reference count when retrieved via `PyDict_GetItemString`, which returns a borrowed reference. This allows safely calling `Py_DECREF` afterward, regardless of whether the object came from a dictionary or via `PyObject_GetAttrString`, whic 8000 h returns a new reference.
c741fd9
to
c1ed918
Compare
Frmo @lassoan
From @jamesobutler
It turns out that those methods are already added last. I just removed the attempt to remove the This topic is now ready for integration 🚀 |
@lassoan @jamesobutler Once this is approved & integrated, I will then:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've done an incremental build locally to try out the SetInterpolate/interpolate options and used them successfully with autocomplete.
This pull request includes a series of improvements and bug fixes to the
ctkAbstractPythonManager::pythonAttributes
and related methods improving the autocompletion model. The changes focus on simplifying the code, improving memory management, and ensuring more accurate and error-resilient behavior when inspecting Python objects.Exclude property-like accessors from autocompletionclassToInstantiate
dict
variableRelated pull request: