[issue12603] pydoc.synopsis breaks if filesystem returns mtime of 0 (common for filesystems without mtime)

Josh Triplett report at bugs.python.org
Thu Jul 21 22:33:11 CEST 2011


New submission from Josh Triplett <josh at joshtriplett.org>:

In Python 2.7.2, pydoc.py's synopsis contains this code implementing a cache:

    mtime = os.stat(filename).st_mtime
    lastupdate, result = cache.get(filename, (0, None))
    if lastupdate < mtime:

Many filesystems don't have any concept of mtime or don't have it available, including many FUSE filesystems, as well as our implementation of stat for GRUB in BITS.  Such systems typically return an mtime of 0.  (In addition, 0 represents a valid mtime.)  Since the cache in pydoc.synopsis initializes lastupdate to 0 for entries not found in the cache, this causes synopsis to always return None.  I'd suggest either extending the conditional to check "lastupdate != 0 and lastupdate < mtime" (which would always treat an mtime of 0 as requiring an update, which would make sense for filesystems without valid mtimes) or changing the .get to return (None, None) and checking "lastupdate is not None and lastupdate < mtime", which would treat an mtime of 0 as valid but still handle the case of not having a cache entry the first time.

----------
components: Library (Lib)
messages: 140826
nosy: joshtriplett
priority: normal
severity: normal
status: open
title: pydoc.synopsis breaks if filesystem returns mtime of 0 (common for filesystems without mtime)
versions: Python 2.7

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue12603>
_______________________________________


More information about the Python-bugs-list mailing list