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

Rewrite OrderedDict as dict() #1563

Closed
jacobtylerwalls opened this issue May 10, 2023 · 4 comments · Fixed by #1625
Closed

Rewrite OrderedDict as dict() #1563

jacobtylerwalls opened this issue May 10, 2023 · 4 comments · Fixed by #1625

Comments

@jacobtylerwalls
Copy link
Member

music21 version
dev

Problem summary
music21's test suite doesn't pass against the Python 3.12 alphas due to python/cpython#101661.

Example failing test

Expected:
    OrderedDict([(Terminus.LOW, <music21.scale.intervalNetwork.Node id=Terminus.LOW>),
                 (0, <music21.scale.intervalNetwork.Node id=0>),
                 (1, <music21.scale.intervalNetwork.Node id=1>),
                 ...
                 (5, <music21.scale.intervalNetwork.Node id=5>),
                 (Terminus.HIGH, <music21.scale.intervalNetwork.Node id=Terminus.HIGH>)])
Got:
    OrderedDict({Terminus.LOW: <music21.scale.intervalNetwork.Node id=Terminus.LOW>, 0: <music21.scale.intervalNetwork.Node id=0>, 1: <music21.scale.intervalNetwork.Node id=1>, 2: <music21.scale.intervalNetwork.Node id=2>, 3: <music21.scale.intervalNetwork.Node id=3>, 4: <music21.scale.intervalNetwork.Node id=4>, 5: <music21.scale.intervalNetwork.Node id=5>, Terminus.HIGH: <music21.scale.intervalNetwork.Node id=Terminus.HIGH>})

Expected vs. actual behavior
My first instinct was to suggest:

  • updating the expected results to show 3.12 output going forward
  • add a doctest-rewriting shim for earlier versions

But then... I realized that the effort could be better spent just rewriting the features to use dict().

We don't seem to be using the features that still make OrderedDict non-obsolete (like move_to_end()), but this would have to be checked as part of the work.


@mscuthbert what do you think is a better use of maintenance effort? (I'm volunteering to do it...)

@mscuthbert
Copy link
Member

I think that it'd be good to rewrite most of our OrderedDict usage with dict() since order has been guaranteed since 3.7 (has been on my mental agenda for a while).

This one though I'm a bit scared about -- need to look at it more depth after Friday (end of term) -- since it is designed to be manipulated and the order is extremely important.

I generally don't put much effort into making doctests etc. work until a python version reaches Beta. (At alpha, I only am concerned about "from music21 import *" works) Since patches and removal have happened in the past.

I wish the python team thought more about multi-version doctest maintenance when making changes.

@jacobtylerwalls
Copy link
Member Author

I generally don't put much effort into making doctests etc. work until a python version reaches Beta. (At alpha, I only am concerned about "from music21 import *" works) Since patches and removal have happened in the past.

👍
Last summer I found some more exciting things than doctests, so I just wanted to see what was coming down the pike. I think the beta will be out before end of May.

@jacobtylerwalls
Copy link
Member Author

Another potential reason to keep OrderedDict would be in case the dicts ever need to compare unequal if the order differs. So I'll keep an eye out for that as I go.

@mscuthbert
Copy link
Member

I think that we should split this into two issues:

  1. Find places where OrderedDicts are being used that are now irrelevant after 3.7 became the minimum version
  2. Future-proof doc testing against 3.12 by exempting OrderedDict from doctests.

I'll work on the second right now. I'll do what I did on previous cases where the doc test format changed too much (I had a lot of experience with this when we were supporting Python 2 and Python 3 simultaneously). In the initial version, Python 3.12 will ignore the content of OrderedDict doctests; it'll assume that they always work and we'll check the code on Py3.10 and 3.11 runs. Later when Python 3.12 is fully supported and works on all dependencies and has a substantial user base (probably a year from now), I'll swap the logic so that Python 3.11 (and Py3.10 if still music21 supported) assumes that doctests are working and we'll change all the tests to resemble Python 3.12 output.

It's a good chance to test that I can still implement a parentheses matching stack taking into account nested and backslashed parentheses. I haven't done that for a bit and code that once did it inside music21 is gone.

mscuthbert added a commit that referenced this issue Jun 27, 2023
Does enough for this to be Fixes #1563 -- we can change other places as other PRs.

@jacobtylerwalls -- can you eyeball this or test it on 3.12?  I don't have my test computer where I install Python betas anymore.
jacobtylerwalls pushed a commit that referenced this issue Jun 27, 2023
…1625)

Does enough for this to be Fixes #1563 -- we can change other places as other PRs.
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 a pull request may close this issue.

2 participants