Skip to content

Fix python 3.11 regression with Python console autocomplete#15885

Merged
seanbudd merged 2 commits into
nvaccess:masterfrom
LeonarddeR:consoleFix
Dec 7, 2023
Merged

Fix python 3.11 regression with Python console autocomplete#15885
seanbudd merged 2 commits into
nvaccess:masterfrom
LeonarddeR:consoleFix

Conversation

@LeonarddeR

Copy link
Copy Markdown
Collaborator

Link to issue number:

Fixes #15872

Summary of the issue:

Since python 3.10, auto completion in the Python Console would fail when trying to complete a string that matches an AutoPropertyObject getter raising NotImplementedError. This is because starting from 3.10, the code responsible for matching no longer catches exceptions for getattr. Instead, it ensures that property descriptors are filtered out. In my opinion, solution from Python is far from ideal, since it doesn't deal with other descriptors, like our baseObject.Getter.

Description of user facing changes

Fixes auto completion

Description of development approach

Copied and adapted code from Python 3.9.

Testing strategy:

Tested str from #15872

Known issues with pull request:

We could also consider keeping the Python 3.11 code, but instead expanding it to baseObject.Getter. This would imply a change in behavior, as properties that raise exceptions would be included in the auto complete list.

Code Review Checklist:

  • Documentation:
    • Change log entry
    • User Documentation
    • Developer / Technical Documentation
    • Context sensitive help for GUI changes
  • Testing:
    • Unit tests
    • System (end to end) tests
    • Manual testing
  • UX of all users considered:
    • Speech
    • Braille
    • Low Vision
    • Different web browsers
    • Localization in other languages / culture than English
  • API is compatible with existing add-ons.
  • Security precautions taken.

@LeonarddeR LeonarddeR requested a review from a team as a code owner December 6, 2023 15:28
@LeonarddeR LeonarddeR requested a review from seanbudd December 6, 2023 15:28
@seanbudd

seanbudd commented Dec 6, 2023

Copy link
Copy Markdown
Member

@LeonarddeR - is it worth raising an issue with python as well?

Comment thread source/pythonConsole.py Outdated

class Completer(rlcompleter.Completer):

def attr_matches(self, text):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add typing annotations

@LeonarddeR

LeonarddeR commented Dec 7, 2023

Copy link
Copy Markdown
Collaborator Author

@LeonarddeR - is it worth raising an issue with python as well?

I'm not sure what the solution should be, adding try/except around getattr again or something else. What I'd propose is creating an abstract class for Non-Data descriptors and check for that instead of for property. Such an abstract base class should also match our baseObject.Getter.
That would however maintain the change in behavior as pointed out in the known issues above.

@LeonarddeR

Copy link
Copy Markdown
Collaborator Author

I filed python/cpython#112821

@seanbudd seanbudd merged commit 97cddb2 into nvaccess:master Dec 7, 2023
@nvaccessAuto nvaccessAuto added this to the 2024.1 milestone Dec 7, 2023
@LeonarddeR LeonarddeR deleted the consoleFix branch August 23, 2025 06:27
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.

Fail to use autocompletion in python console

3 participants