Skip to content

Commit 59e97cb

Browse files
Refactor
1 parent cd59287 commit 59e97cb

File tree

1 file changed

+16
-20
lines changed

1 file changed

+16
-20
lines changed

Lib/pydoc.py

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,20 @@ def getdocloc(self, object, basedir=sysconfig.get_path('stdlib')):
576576
docloc = None
577577
return docloc
578578

579+
def get_version(self, object):
580+
if self._is_stdlib_module(object):
581+
with warnings.catch_warnings():
582+
warnings.simplefilter("ignore", DeprecationWarning)
583+
if hasattr(object, '__version__'):
584+
return str(object.__version__)
585+
else:
586+
return None
587+
else:
588+
if hasattr(object, '__version__'):
589+
return str(object.__version__)
590+
else:
591+
return None
592+
579593
def _is_stdlib_module(self, object, basedir=sysconfig.get_path('stdlib')):
580594
try:
581595
file = inspect.getabsfile(object)
@@ -850,16 +864,7 @@ def docmodule(self, object, name=None, mod=None, *ignored):
850864
filelink = '(built-in)'
851865
info = []
852866

853-
if self._is_stdlib_module(object):
854-
with warnings.catch_warnings():
855-
warnings.simplefilter("ignore", DeprecationWarning)
856-
if has_version := hasattr(object, '__version__'):
857-
version = str(object.__version__)
858-
else:
859-
if has_version := hasattr(object, '__version__'):
860-
version = str(object.__version__)
861-
862-
if has_version:
867+
if (version := self.get_version(object)) is not None:
863868
if version[:11] == '$' + 'Revision: ' and version[-1:] == '$':
864869
version = version[11:-1].strip()
865870
info.append('version %s' % self.escape(version))
@@ -1394,16 +1399,7 @@ def docmodule(self, object, name=None, mod=None, *ignored):
13941399
contents.append(self.docother(value, key, name, maxlen=70))
13951400
result = result + self.section('DATA', '\n'.join(contents))
13961401

1397-
if self._is_stdlib_module(object):
1398-
with warnings.catch_warnings():
1399-
warnings.simplefilter("ignore", DeprecationWarning)
1400-
if has_version := hasattr(object, '__version__'):
1401-
version = str(object.__version__)
1402-
else:
1403-
if has_version := hasattr(object, '__version__'):
1404-
version = str(object.__version__)
1405-
1406-
if has_version:
1402+
if (version := self.get_version(object)) is not None:
14071403
if version[:11] == '$' + 'Revision: ' and version[-1:] == '$':
14081404
version = version[11:-1].strip()
14091405
result = result + self.section('VERSION', version)

0 commit comments

Comments
 (0)