Skip to content

bpo-29620: iterate over a copy of sys.modules#4800

Merged
akuchling merged 2 commits into
python:masterfrom
kernc:patch-1
Jun 11, 2020
Merged

bpo-29620: iterate over a copy of sys.modules#4800
akuchling merged 2 commits into
python:masterfrom
kernc:patch-1

Conversation

@kernc

@kernc kernc commented Dec 11, 2017

Copy link
Copy Markdown
Contributor

Fixes https://bugs.python.org/issue29620 by wrapping sys.modules.values() into a tuple before iteration.

https://bugs.python.org/issue29620

@serhiy-storchaka serhiy-storchaka left a comment

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.

Could you please add a test? It is enough to create a types.ModuleType subclass with the __warningregistry__ property (or the __getattr__() method) which mutates sys.modules and add its instance to sys.modules.

Add also a news entry (see https://devguide.python.org/committing/#what-s-new-and-news-entries).

Comment thread Lib/unittest/case.py Outdated
@kernc

kernc commented Aug 21, 2018

Copy link
Copy Markdown
Contributor Author

Done. Hope it's ok.

Comment thread Lib/unittest/test/test_case.py Outdated
Comment thread Lib/unittest/test/test_case.py Outdated
Comment thread Misc/NEWS.d/next/Library/2018-08-21-16-20-33.bpo-29620.xxx666.rst Outdated
Comment thread Misc/NEWS.d/next/Library/2018-08-21-16-20-33.bpo-29620.xxx666.rst Outdated
@kernc

kernc commented Aug 22, 2018

Copy link
Copy Markdown
Contributor Author

Updated. Thanks.

@kernc

kernc commented Sep 17, 2018

Copy link
Copy Markdown
Contributor Author

@serhiy-storchaka Do you find any other issues?

@lettergram

Copy link
Copy Markdown

@kernc I'm running into this issue - is it at all possible to prioritize this issue?

@lettergram

Copy link
Copy Markdown

@serhiy-storchaka Would it be possible to review this PR or is there something I can do?

@kernc kernc changed the title bpo-29620: iterate over a tuple of sys.modules bpo-29620: iterate over a list of sys.modules Oct 29, 2019
@kernc kernc changed the title bpo-29620: iterate over a list of sys.modules bpo-29620: iterate over a copy of sys.modules Oct 29, 2019
@lettergram

Copy link
Copy Markdown

@serhiy-storchaka If there's any way either myself or @kernc could help, please let me know!

If there's someone else / something else we need to do please let us know.

@pelillian

Copy link
Copy Markdown

@serhiy-storchaka Any chance you could take a look at this?

@lettergram

Copy link
Copy Markdown

@serhiy-storchaka is there anything else required for review?

@csabella
csabella requested review from serhiy-storchaka and removed request for serhiy-storchaka January 17, 2020 12:15
Comment thread Lib/unittest/test/test_case.py Outdated
@lettergram

Copy link
Copy Markdown

@akuchling Looks like this is good?

@csabella

Copy link
Copy Markdown
Contributor

@akuchling, should this be merged? Thanks!

@akuchling
akuchling merged commit 46398fb into python:master Jun 11, 2020
@miss-islington

Copy link
Copy Markdown
Contributor

Thanks @kernc for the PR, and @akuchling for merging it 🌮🎉.. I'm working now to backport this PR to: 3.7, 3.8.
🐍🍒⛏🤖 I'm not a witch! I'm not a witch!

@bedevere-bot

Copy link
Copy Markdown

GH-20816 is a backport of this pull request to the 3.8 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jun 11, 2020
unittest.TestCase.assertWarns no longer raises a RuntimeException
when accessing a module's ``__warningregistry__`` causes importation of a new
module, or when a new module is imported in another thread.

Patch by Kernc.
(cherry picked from commit 46398fb)

Co-authored-by: kernc <kerncece@gmail.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jun 11, 2020
unittest.TestCase.assertWarns no longer raises a RuntimeException
when accessing a module's ``__warningregistry__`` causes importation of a new
module, or when a new module is imported in another thread.

Patch by Kernc.
(cherry picked from commit 46398fb)

Co-authored-by: kernc <kerncece@gmail.com>
@bedevere-bot

Copy link
Copy Markdown

GH-20817 is a backport of this pull request to the 3.7 branch.

akuchling pushed a commit that referenced this pull request Jun 11, 2020
unittest.TestCase.assertWarns no longer raises a RuntimeException
when accessing a module's ``__warningregistry__`` causes importation of a new
module, or when a new module is imported in another thread.
(cherry picked from commit 46398fb)

Co-authored-by: kernc <kerncece@gmail.com>
akuchling pushed a commit that referenced this pull request Jun 11, 2020
unittest.TestCase.assertWarns no longer raises a RuntimeException
when accessing a module's ``__warningregistry__`` causes importation of a new
module, or when a new module is imported in another thread.
(cherry picked from commit 46398fb)

Co-authored-by: kernc <kerncece@gmail.com>
@miss-islington

Copy link
Copy Markdown
Contributor

Thanks @kernc for the PR, and @akuchling for merging it 🌮🎉.. I'm working now to backport this PR to: 3.9.
🐍🍒⛏🤖

@bedevere-bot

Copy link
Copy Markdown

GH-29605 is a backport of this pull request to the 3.9 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Nov 18, 2021
unittest.TestCase.assertWarns no longer raises a RuntimeException
when accessing a module's ``__warningregistry__`` causes importation of a new
module, or when a new module is imported in another thread.

Patch by Kernc.
(cherry picked from commit 46398fb)

Co-authored-by: kernc <kerncece@gmail.com>
ambv pushed a commit that referenced this pull request Nov 18, 2021
unittest.TestCase.assertWarns no longer raises a RuntimeException
when accessing a module's ``__warningregistry__`` causes importation of a new
module, or when a new module is imported in another thread.

Patch by Kernc.
(cherry picked from commit 46398fb)

Co-authored-by: kernc <kerncece@gmail.com>
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.

10 participants