@@ -561,36 +561,49 @@ def normpath(path):
561
561
return prefix + sep .join (comps )
562
562
563
563
564
- def _abspath_fallback (path ):
565
- """Return the absolute version of a path as a fallback function in case
566
- `nt._getfullpathname` is not available or raises OSError. See bpo-31047 for
567
- more.
568
-
569
- """
570
-
571
- path = os .fspath (path )
572
- if not isabs (path ):
573
- if isinstance (path , bytes ):
574
- cwd = os .getcwdb ()
575
- else :
576
- cwd = os .getcwd ()
577
- path = join (cwd , path )
578
- return normpath (path )
579
-
580
564
# Return an absolute path.
581
565
try :
582
566
from nt import _getfullpathname
583
567
584
568
except ImportError : # not running on Windows - mock up something sensible
585
- abspath = _abspath_fallback
569
+ def abspath (path ):
570
+ """Return the absolute version of a path."""
571
+ path = os .fspath (path )
572
+ if not isabs (path ):
573
+ if isinstance (path , bytes ):
574
+ cwd = os .getcwdb ()
575
+ else :
576
+ cwd = os .getcwd ()
577
+ path = join (cwd , path )
578
+ return normpath (path )
586
579
587
580
else : # use native Windows method on Windows
588
581
def abspath (path ):
589
582
"""Return the absolute version of a path."""
590
583
try :
591
584
return _getfullpathname (normpath (path ))
592
585
except (OSError , ValueError ):
593
- return _abspath_fallback (path )
586
+ # See gh-75230, handle outside for cleaner traceback
587
+ pass
588
+ path = os .fspath (path )
589
+ if not isabs (path ):
590
+ if isinstance (path , bytes ):
591
+ sep = b'\\ '
592
+ getcwd = os .getcwdb
593
+ else :
594
+ sep = '\\ '
595
+ getcwd = os .getcwd
596
+ drive , root , path = splitroot (path )
597
+ # Either drive or root can be nonempty, but not both.
598
+ if drive or root :
599
+ try :
600
+ path = join (_getfullpathname (drive + root ), path )
601
+ except (OSError , ValueError ):
602
+ # Drive "\0:" cannot exist; use the root directory.
603
+ path = drive + sep + path
604
+ else :
605
+ path = join (getcwd (), path )
606
+ return normpath (path )
594
607
595
608
try :
596
609
from nt import _getfinalpathname , readlink as _nt_readlink
0 commit comments