Commit 376658fa authored by Victor Stinner's avatar Victor Stinner

Issue #11726: Fix linecache example in the doc

Use a Python source file (linecache.__file__) instead of /etc/passwd.

Modify also linecache docstrings to clarify the linecache is written to cache
Python source files, not any text files.
parent 93f0665f
...@@ -51,5 +51,5 @@ The :mod:`linecache` module defines the following functions: ...@@ -51,5 +51,5 @@ The :mod:`linecache` module defines the following functions:
Example:: Example::
>>> import linecache >>> import linecache
>>> linecache.getline('/etc/passwd', 4) >>> linecache.getline(linecache.__file__, 8)
'sys:x:3:3:sys:/dev:/bin/sh\n' 'import sys\n'
"""Cache lines from files. """Cache lines from Python source files.
This is intended to read lines from modules imported -- hence if a filename This is intended to read lines from modules imported -- hence if a filename
is not found, it will look down the module search path for a file by is not found, it will look down the module search path for a file by
...@@ -32,7 +32,7 @@ def clearcache(): ...@@ -32,7 +32,7 @@ def clearcache():
def getlines(filename, module_globals=None): def getlines(filename, module_globals=None):
"""Get the lines for a file from the cache. """Get the lines for a Python source file from the cache.
Update the cache if it doesn't contain an entry for this file already.""" Update the cache if it doesn't contain an entry for this file already."""
if filename in cache: if filename in cache:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment