Skip to content
Closed
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
20f1fb4
store __module__ into a variable and restore after __new__ method cre…
srinivasreddy Jan 13, 2025
75c1663
Merge branch 'main' into gh_128772
srinivasreddy Jan 15, 2025
9d0e70f
Preserve __module__
srinivasreddy Jan 15, 2025
86924f2
Reintroduce space
srinivasreddy Jan 15, 2025
a7b4e83
Merge branch 'main' into gh_128772
srinivasreddy Jan 16, 2025
aab2f5b
Merge branch 'main' into gh_128772
srinivasreddy Jan 16, 2025
382299e
Add test case for help(....) function
srinivasreddy Jan 16, 2025
5b879a3
Fix indentation
srinivasreddy Jan 16, 2025
5595a8e
Fix test failure
srinivasreddy Jan 16, 2025
4b3db9e
Update test cases
srinivasreddy Jan 16, 2025
35731f3
Update tests
srinivasreddy Jan 16, 2025
eb5cb3b
order imports
srinivasreddy Jan 16, 2025
7be5d8a
Improve test cases
srinivasreddy Jan 16, 2025
4752d38
Improve test case
srinivasreddy Jan 16, 2025
8b54982
Revert the code since it is in wrong place
srinivasreddy Jan 17, 2025
3c2c9d3
Move the test case to here from Lib/idlelib/idle_test/test_warning.py
srinivasreddy Jan 17, 2025
d48801e
Add blurb
srinivasreddy Jan 17, 2025
08228dc
Update description
srinivasreddy Jan 17, 2025
09d4fa1
Merge branch 'main' into gh_128772
srinivasreddy Jan 17, 2025
57e01d8
Update Misc/NEWS.d/next/Library/2025-01-17-13-38-12.gh-issue-128772.8…
srinivasreddy Jan 21, 2025
2c0b399
Address review comments
srinivasreddy Jan 21, 2025
0eaefef
Revert the change
srinivasreddy Jan 21, 2025
3edb9b1
Remove creating an instance B()
srinivasreddy Jan 21, 2025
96bab8d
Address review comments. Move the deprecated class to a separate data…
srinivasreddy Jan 21, 2025
84175fc
Fix failure
srinivasreddy Jan 21, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 53 additions & 3 deletions Lib/idlelib/idle_test/test_warning.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,17 @@
Revise if output destination changes (http://bugs.python.org/issue18318).
Make sure warnings module is left unaltered (http://bugs.python.org/issue18081).
'''
from idlelib import run
from idlelib import pyshell as shell
import io
import sys
import unittest
from test.support import captured_stderr
import warnings
from contextlib import redirect_stdout
from test.support import captured_stderr
from types import ModuleType

from idlelib import pyshell as shell
from idlelib import run


# Try to capture default showwarning before Idle modules are imported.
showwarning = warnings.showwarning
Expand Down Expand Up @@ -69,5 +75,49 @@ def test_shell_show(self):
self.assertEqual(shellmsg.splitlines(), f.getvalue().splitlines())


class TestDeprecatedHelp(unittest.TestCase):
CODE_SIMPLE = r"""
from warnings import deprecated
@deprecated("Test")
class A:
pass
a = A()
"""
CODE_SUBCLASS = r"""
from warnings import deprecated
@deprecated("Test")
class A:
def __init_subclass__(self, **kwargs):
pass
class B(A):
pass
b = B()
"""
def setUp(self):
self.module = ModuleType("testmodule")

def tearDown(self):
if "testmodule" in sys.modules:
del sys.modules["testmodule"]

def _get_help_output(self, code):
with self.assertWarns(DeprecationWarning) as cm:
exec(code, self.module.__dict__)
sys.modules["testmodule"] = self.module

f = io.StringIO()
with redirect_stdout(f):
help(self.module)

self.assertEqual(str(cm.warning), "Test")
return f.getvalue()

def test_help_output(self):
for code in (self.CODE_SIMPLE, self.CODE_SUBCLASS):
with self.subTest(code=code):
help_output = self._get_help_output(code)
self.assertIn("Help on module testmodule:", help_output)


if __name__ == '__main__':
unittest.main(verbosity=2)
2 changes: 2 additions & 0 deletions Lib/warnings.py
Copy link
Contributor

Choose a reason for hiding this comment

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

It might be that the existing __module__ is overridden on __new__ and __init_subclass__ here, if it already exists.

Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,7 @@ def __new__(cls, *args, **kwargs):
else:
return original_new(cls)

__new__.__module__ = arg.__module__
arg.__new__ = staticmethod(__new__)

original_init_subclass = arg.__init_subclass__
Expand All @@ -635,6 +636,7 @@ def __init_subclass__(*args, **kwargs):

arg.__init_subclass__ = __init_subclass__

__init_subclass__.__module__ = arg.__module__
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe move this one below, to be next to the other __init_subclass__ change

arg.__deprecated__ = __new__.__deprecated__ = msg
__init_subclass__.__deprecated__ = msg
return arg
Expand Down
Loading