Terry J. Reedy email@example.com added the comment:
The help(linecache) Description is more specific as to the intention (based on traceback usage):
"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 that name."
My experiments show that this is too specific. It *can* read any file that it can find and decode as utf-8 (default, or you say, locale encoding or coding in cookie line).
Find = absolute path
'A. HISTORY OF THE SOFTWARE\n'
or relative path on sys.path
'Please refer to the IDLEfork and IDLE CVS repositories for\n'
'Writing an IDLE extension\n'
Decode fails on byte illegal for utf-8:
UnicodeDecodeError: 'utf8' codec can't decode byte 0xf6 in position 1566: invalid start byte
(It reads and decodes entire file even though only line 1 was requested. It choked on Löwis. I believe Py3 distributed text files should be utf-8 instead of latin-1.)
If I got rules right, doc should say "Filename must be an absolute path or relative path that can be found on sys.path." and "File must be utf-8 encoded or locale encoded or a Python file with a coding cookie."
(If you tried /etc/passwd, how did it fail?)
---------- nosy: +terry.reedy