@@ -554,36 +554,48 @@ def normpath(path):
554554 return prefix + sep .join (comps )
555555
556556
557- def _abspath_fallback (path ):
558- """Return the absolute version of a path as a fallback function in case
559- `nt._getfullpathname` is not available or raises OSError. See bpo-31047 for
560- more.
561-
562- """
563-
564- path = os .fspath (path )
565- if not isabs (path ):
566- if isinstance (path , bytes ):
567- cwd = os .getcwdb ()
568- else :
569- cwd = os .getcwd ()
570- path = join (cwd , path )
571- return normpath (path )
572-
573557# Return an absolute path.
574558try :
575559 from nt import _getfullpathname
576560
577561except ImportError : # not running on Windows - mock up something sensible
578- abspath = _abspath_fallback
562+ def abspath (path ):
563+ """Return the absolute version of a path."""
564+ path = os .fspath (path )
565+ if not isabs (path ):
566+ if isinstance (path , bytes ):
567+ cwd = os .getcwdb ()
568+ else :
569+ cwd = os .getcwd ()
570+ path = join (cwd , path )
571+ return normpath (path )
579572
580573else : # use native Windows method on Windows
581574 def abspath (path ):
582575 """Return the absolute version of a path."""
583576 try :
584577 return _getfullpathname (normpath (path ))
585578 except (OSError , ValueError ):
586- return _abspath_fallback (path )
579+ # See gh-75230, handle outside for cleaner traceback
580+ pass
581+ path = os .fspath (path )
582+ if not isabs (path ):
583+ if isinstance (path , bytes ):
584+ sep = b'/'
585+ cwd = os .getcwdb ()
586+ else :
587+ sep = '/'
588+ cwd = os .getcwd ()
589+ drive , root , path = splitroot (path )
590+ if drive and drive != splitroot (cwd )[0 ]:
591+ try :
592+ path = join (_getfullpathname (drive ), path )
593+ except (OSError , ValueError ):
594+ # Invalid drive \x00: on Windows; assume root directory
595+ path = drive + sep + path
596+ else :
597+ path = join (cwd , root + path )
598+ return normpath (path )
587599
588600try :
589601 from nt import _findfirstfile , _getfinalpathname , readlink as _nt_readlink
0 commit comments