On Tue, Sep 7, 2010 at 08:12, Nick Coghlan <ncogh...@gmail.com> wrote:
> On Tue, Sep 7, 2010 at 5:46 AM, brian.curtin <python-check...@python.org> > wrote: > > Modified: python/branches/py3k/Lib/ntpath.py > > > ============================================================================== > > --- python/branches/py3k/Lib/ntpath.py (original) > > +++ python/branches/py3k/Lib/ntpath.py Mon Sep 6 21:46:17 2010 > > @@ -10,7 +10,6 @@ > > import stat > > import genericpath > > from genericpath import * > > -from nt import _getfileinformation > > > > __all__ = ["normcase","isabs","join","splitdrive","split","splitext", > > "basename","dirname","commonprefix","getsize","getmtime", > > @@ -656,4 +655,10 @@ > > > > def sameopenfile(f1, f2): > > """Test whether two file objects reference the same file""" > > - return _getfileinformation(f1) == _getfileinformation(f2) > > + try: > > + from nt import _getfileinformation > > + return _getfileinformation(f1) == _getfileinformation(f2) > > + except ImportError: > > + # On other operating systems, return True if the file > descriptors > > + # are the same. > > + return f1 == f2 > > Given the potential deadlock problems with imports inside functions, > I'd prefer to see this written as either: > > try: > from nt import _getfileinformation > def sameopenfile(f1, f2): > return _getfileinformation(f1) == _getfileinformation(f2) > except ImportError: > # On other operating systems, return True if the file descriptors > # are the same. > def sameopenfile(f1, f2): > return f1 == f2 > sameopenfile.__doc__ = "Test whether two file objects reference the same > file" > > or as: > > try: > from nt import _getfileinformation > except ImportError: > # On other operating systems, file comparison is by file descriptor anyway > # so a separate file information object is unnecessary > def _getfileinformation(f): return f > > def sameopenfile(f1, f2): > """Test whether two file objects reference the same file""" > return _getfileinformation(f1) == _getfileinformation(f2) > > The latter is cleaner code, while the former is likely an unnecessary > micro-optimisation. > > Cheers, > Nick. Similar idea(s) would also apply to the function right above that, samefile. I'll create a new issue for cleaning this up.
_______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com