Skip to content

Commit fe3a652

Browse files
committed
gh-103624: Ignore DeprecationWarning when getting package metadata in pydoc
1 parent da2273f commit fe3a652

File tree

2 files changed

+32
-24
lines changed

2 files changed

+32
-24
lines changed

Lib/pydoc.py

+30-24
Original file line numberDiff line numberDiff line change
@@ -766,13 +766,15 @@ def docmodule(self, object, name=None, mod=None, *ignored):
766766
except TypeError:
767767
filelink = '(built-in)'
768768
info = []
769-
if hasattr(object, '__version__'):
770-
version = str(object.__version__)
771-
if version[:11] == '$' + 'Revision: ' and version[-1:] == '$':
772-
version = version[11:-1].strip()
773-
info.append('version %s' % self.escape(version))
774-
if hasattr(object, '__date__'):
775-
info.append(self.escape(str(object.__date__)))
769+
with warnings.catch_warnings():
770+
warnings.simplefilter("ignore", DeprecationWarning)
771+
if hasattr(object, '__version__'):
772+
version = str(object.__version__)
773+
if version[:11] == '$' + 'Revision: ' and version[-1:] == '$':
774+
version = version[11:-1].strip()
775+
info.append('version %s' % self.escape(version))
776+
if hasattr(object, '__date__'):
777+
info.append(self.escape(str(object.__date__)))
776778
if info:
777779
head = head + ' (%s)' % ', '.join(info)
778780
docloc = self.getdocloc(object)
@@ -852,12 +854,14 @@ def docmodule(self, object, name=None, mod=None, *ignored):
852854
contents.append(self.document(value, key))
853855
result = result + self.bigsection(
854856
'Data', 'data', '<br>\n'.join(contents))
855-
if hasattr(object, '__author__'):
856-
contents = self.markup(str(object.__author__), self.preformat)
857-
result = result + self.bigsection('Author', 'author', contents)
858-
if hasattr(object, '__credits__'):
859-
contents = self.markup(str(object.__credits__), self.preformat)
860-
result = result + self.bigsection('Credits', 'credits', contents)
857+
with warnings.catch_warnings():
858+
warnings.simplefilter("ignore", DeprecationWarning)
859+
if hasattr(object, '__author__'):
860+
contents = self.markup(str(object.__author__), self.preformat)
861+
result = result + self.bigsection('Author', 'author', contents)
862+
if hasattr(object, '__credits__'):
863+
contents = self.markup(str(object.__credits__), self.preformat)
864+
result = result + self.bigsection('Credits', 'credits', contents)
861865

862866
return result
863867

@@ -1286,17 +1290,19 @@ def docmodule(self, object, name=None, mod=None):
12861290
contents.append(self.docother(value, key, name, maxlen=70))
12871291
result = result + self.section('DATA', '\n'.join(contents))
12881292

1289-
if hasattr(object, '__version__'):
1290-
version = str(object.__version__)
1291-
if version[:11] == '$' + 'Revision: ' and version[-1:] == '$':
1292-
version = version[11:-1].strip()
1293-
result = result + self.section('VERSION', version)
1294-
if hasattr(object, '__date__'):
1295-
result = result + self.section('DATE', str(object.__date__))
1296-
if hasattr(object, '__author__'):
1297-
result = result + self.section('AUTHOR', str(object.__author__))
1298-
if hasattr(object, '__credits__'):
1299-
result = result + self.section('CREDITS', str(object.__credits__))
1293+
with warnings.catch_warnings():
1294+
warnings.simplefilter("ignore", DeprecationWarning)
1295+
if hasattr(object, '__version__'):
1296+
version = str(object.__version__)
1297+
if version[:11] == '$' + 'Revision: ' and version[-1:] == '$':
1298+
version = version[11:-1].strip()
1299+
result = result + self.section('VERSION', version)
1300+
if hasattr(object, '__date__'):
1301+
result = result + self.section('DATE', str(object.__date__))
1302+
if hasattr(object, '__author__'):
1303+
result = result + self.section('AUTHOR', str(object.__author__))
1304+
if hasattr(object, '__credits__'):
1305+
result = result + self.section('CREDITS', str(object.__credits__))
13001306
try:
13011307
file = inspect.getabsfile(object)
13021308
except TypeError:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Ignore :exc:`DeprecationWarning` when getting package metadata in
2+
:mod:`pydoc`.

0 commit comments

Comments
 (0)