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

gh-79951: IDLE - Convert menudefs to dictionary #11615

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

csabella
Copy link
Contributor

@csabella csabella commented Jan 18, 2019

PoC to convert menudefs to a dictionary to make indexing the correct menu easier.

Copy link
Member

@terryjreedy terryjreedy left a comment

Choose a reason for hiding this comment

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

My previous comment, based on insufficient information, assumed that you were doing a total conversion to a dict of dicts. Only converting the top level list of tuples of key and sublists makes this much more feasible, and it should make testing a bit easier and mistakes less likely. Passing on Appveyer is very encouraging.

I believe the trailing whitespace in zzdummy is before the deleted ')'. Will fix. Wait to fit the conflict until I fix the fix (after I submit this).

After opening a new issue, change the bpo number in the initial comment (3 places) as well as the title.

I am pretty sure the extension menu processing code can be adjusted to handle both old and new formats. A test_zzdummy should try both. This is needed first, perhaps as a separate issue.

A possible solution to the 'application' issue is to add 'application':None as the first dict item and then ignore or delete it if not Carbon Aqua. Tal's solution is not bad since it only copies references to the value lists.

@python python deleted a comment from bedevere-bot Jan 18, 2019
@csabella
Copy link
Contributor Author

I think there's an easy solution for extensions. In fill_menus, add after the check for None:

if isinstance(menudefs, list):
    menudefs = dict(menudefs)

Should I modify the PR? I didn't want to change it if you were in the middle of pushing a change.

@terryjreedy
Copy link
Member

That looks plausible, and I am done. Go ahead with revisions.

* 3rd party extensions may define menudefs using the old list format,
  so, if it's a list, convert it to a dictionary.
* Add tests for fill_menus.
@csabella
Copy link
Contributor Author

csabella commented Jan 20, 2019

I've added the change for menudefs and I also added the fill_menus test from #3669, with some changes for the new menudefs type.

@taleinat
Copy link
Contributor

Have you tested this with existing extensions? IIRC they usually modify the menudefs rather than override them. If so, the backwards compatibility approach used here won't work. Rather, we'll need to still expose menudefs as a list of tuples, but perhaps have an alternate internal representation as a dict.

Alternatively, and more simply, drop backwards compatibility, and just have this be a dict from now on. Extensions can add a version check and appropriate code for versions where this has been introduced. This is simple enough that any IDLE extensions actually in use that would be used with such new versions of IDLE would be easily upgraded. This is what I'm leaning towards.

@taleinat
Copy link
Contributor

taleinat commented Jun 11, 2019

Another option: We could also keep the existing "list of tuples" representation, and just add a few helper functions for access by name rather than by index. This would be 100% backwards compatible, make IDLE's code more readable, and reduce the likelihood of indexing bugs like #79951. So perhaps the best of both worlds.

@taleinat
Copy link
Contributor

taleinat commented Jun 11, 2019

To summarize, the 3 options I've lined out are:

  1. Convert to dicts, keeping external "list of tuples"-like interface.
  2. Break backwards compatibility and just use a dict.
  3. Stay with the current "list of tuples" representation; add a few helper functions for by-name access.

@terryjreedy
Copy link
Member

The intent of the issue is a) to make idlelib code a little clearer and robust and b) to facilitate translations. I will comment more on the latter elsewhere another time. I do not intend to abandon past extensions, at least not with this change. So I expect to revise the code that merges extension menu defs after I otherwise like the patch.

The dummy extension, zzdummy, exists to test things like this. There is no automated test (yet). To use it, the menudefs have to be uncommented. I think I commented them out to avoid having inactive menu entries or something. Then, does IDLE start, is the menu altered, and does it work.

@terryjreedy terryjreedy self-assigned this Nov 2, 2022
@terryjreedy terryjreedy changed the title bpo-35770: Convert menudefs to dictionary gh-79951: IDLE - Convert menudefs to dictionary Nov 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants