gh-76007: `pydoc`: Catch `DeprecationWarning` for stdlib module `__version__` attributes by StanFromIreland · Pull Request #139997 · python/cpython · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
55 changes: 37 additions & 18 deletions Lib/pydoc.py
26 changes: 26 additions & 0 deletions Lib/test/test_pydoc/test_pydoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2305,6 +2305,32 @@ def test_sys_path_adjustment_when_curdir_already_included(self):
trailing_argv0dir = trailing_curdir + [self.argv0dir]
self.assertIsNone(self._get_revised_path(trailing_argv0dir))

def test__get_version(self):
import json
import warnings

class MyModule:
__name__ = 'my_module'

@property
def __version__(self):
warnings._deprecated("__version__", remove=(3, 20))
return "1.2.3"

module = MyModule()
doc = pydoc.Doc()
with warnings.catch_warnings(record=True) as w: # TODO: remove in 3.20
warnings.simplefilter("always")
version = doc._get_version(json)
self.assertEqual(version, "2.0.9")
Comment thread
StanFromIreland marked this conversation as resolved.
self.assertEqual(len(w), 0)

with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
version = doc._get_version(module)
self.assertEqual(version, "1.2.3")
self.assertEqual(len(w), 1)


def setUpModule():
thread_info = threading_helper.threading_setup()
Expand Down
Loading