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