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

Fix test with Python 3.13.1 #2678

Closed
wants to merge 1 commit into from
Closed

Conversation

MeggyCal
Copy link

Tests stopped working with recent Python 3.13, see python/cpython#125846. This change fixes them.

@swt2c
Copy link
Collaborator

swt2c commented Jan 21, 2025

Can you explain a little more how you found this and how this cpython change breaks this test? Just making sure this isn't actually hiding some problem in wxPython.

Is this the error you're trying to fix?

FAILED unittests/test_cmdproc.py::cmdproc_Tests::test_cmdproc3 - TypeError: 'CommandList_iterator' object is not iterable

@MeggyCal
Copy link
Author

Can you explain a little more how you found this and how this cpython change breaks this test? Just making sure this isn't actually hiding some problem in wxPython.

Sure :) I am a packager in (open)SUSE, my colleague updated Python 3.13 from 3.13.0 to 3.13.1 and wxPython tests started to fail. When we reverted back to Python 3.13.0, the tests were OK again.

Is this the error you're trying to fix?

FAILED unittests/test_cmdproc.py::cmdproc_Tests::test_cmdproc3 - TypeError: 'CommandList_iterator' object is not iterable

Yes, this is the one. it is similar to the issue they had in neuronsimulator/nrn@9821eaf, so I also fixed it in the same way.

@swt2c
Copy link
Collaborator

swt2c commented Jan 23, 2025

So, I think this is actually a bug in wxPython that was exposed by this CPython change. Working on figuring out how to fix it.

@DietmarSchwertberger
Copy link
Contributor

DietmarSchwertberger commented Jan 23, 2025

This does not only affect tests, but also application software.
In wxGlade I also had one position where I had to add a list(...):

panel = [w for w in list(scrolled.GetChildren()) if isinstance(w, wx.Panel)][0]

Without the modification:


    panel = [w for w in scrolled.GetChildren() if isinstance(w, wx.Panel)][0]
                        ~~~~~~~~~~~~~~~~~~~~^^

Exception type:      <class 'TypeError'>
Exception details:   'WindowList_iterator' object is not iterable

Unfortunately I was not able to produce a minimal code sample that would show the same behaviour.

References:
wxGlade/wxGlade#565 wxGlade/wxGlade#564 wxGlade/wxGlade#570

@echoix
Copy link
Contributor

echoix commented Jan 23, 2025

Is it only happening when GetChildren is involved?

@DietmarSchwertberger
Copy link
Contributor

Well, for several kinds of iterators:

CommandList_iterator
WindowList_iterator

With a small code sample, I could not provoke the fail with WindowList_iterator / GetChildren, though.

@DietmarSchwertberger
Copy link
Contributor

DietmarSchwertberger commented Jan 23, 2025

@swt2c : could it be related? python/cpython#128161

There is a code example which can also be contained by placing a list(...) around:
failing: [print(i) for i in target]
fixed: [print(i) for i in list(target)]

It can be fixed by adding an __iter__ method to the iterator:

class list2iterator:
    ...
    def __iter__(self):
        return self

So, probably etg_tools/tweaker_tools.py wxListWrapperTemplate needs to be modified.

@swt2c
Copy link
Collaborator

swt2c commented Jan 23, 2025

Yes, the issue is that the iterator objects (e.g., CommandList_iterator) don't implement __iter__. They really just need to be PyObject_SelfIter, but I'm trying to figure out how to tell that to sip.

@swt2c
Copy link
Collaborator

swt2c commented Jan 24, 2025

This should resolve the issue: #2680

@MeggyCal
Copy link
Author

This should resolve the issue: #2680

Hi, thanks for being active on this! The new PR also works for me, so I guess this PR should be closed?

@swt2c
Copy link
Collaborator

swt2c commented Jan 24, 2025

Closed in favor of #2680. Thanks @MeggyCal for reporting the issue.

@swt2c swt2c closed this Jan 24, 2025
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