This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: os.path.sameopenfile documentation wrong.
Type: Stage:
Components: Documentation Versions: Python 2.3
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: georg.brandl, georg.brandl, jemfinch
Priority: normal Keywords:

Created on 2004-08-03 03:35 by jemfinch, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (3)
msg21910 - (view) Author: Jeremy Fincher (jemfinch) Date: 2004-08-03 03:35
At http://docs.python.org/lib/module-os.path.html it very clearly 
states this:

sameopenfile(fp1, fp2)

Return True if the file objects fp1 and fp2 refer to the same file. 
The two file objects may represent different file descriptors. 
Availability: Macintosh, Unix.

However, on my OSX box, the source to posixpath.py clearly says 
otherwise:

def sameopenfile(fp1, fp2):
    """Test whether two open file objects reference the same file"""
    s1 = os.fstat(fp1)
    s2 = os.fstat(fp2)
    return samestat(s1, s2)

I.e., sameopenfile accepts two integer filenos, not two file objects.  
Running it gives this exception:

  File "/System/Library/Frameworks/Python.framework/Versions/
2.3/lib/python2.3/site-packages/supybot/plugins/Tail.py", line 77, 
in samefile
    return os.path.sameopenfile(fd1, fd2)
  File "/System/Library/Frameworks/Python.framework/Versions/
2.3/lib/python2.3/posixpath.py", line 220, in sameopenfile
    s1 = os.fstat(fp1)
TypeError: an integer is required

Perhaps the (much more useful) documented behavior can be 
retained, and two if statements added to the definition of 
sameopenfile:

if not isinstance(fp1, int): fp1 = fp1.fileno()
if not isinstance(fp2, int): fp2 = fp2.fileno()
msg21911 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2005-07-08 21:48
Logged In: YES 
user_id=1188172

The question is, should we fix the docs or the
implementation? Or add the suggested hybrid-solution
(drawback: no other function that deals with files currently
allows file objects and descriptors).
msg21912 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2006-07-30 11:08
Logged In: YES 
user_id=849994

The function is not needed so often to warrant a
implementation change.

Fixed the docs in rev. 50974, 50975 (2.4).
History
Date User Action Args
2022-04-11 14:56:06adminsetgithub: 40676
2004-08-03 03:35:35jemfinchcreate