mirror of
https://github.com/python/cpython.git
synced 2025-10-07 23:51:16 +00:00
bpo-31802: Fix importing native path module before importing os. (#4017)
This commit is contained in:
parent
e46a8af450
commit
3460198f6b
5 changed files with 42 additions and 32 deletions
|
@ -1,5 +1,17 @@
|
||||||
"""Pathname and path-related operations for the Macintosh."""
|
"""Pathname and path-related operations for the Macintosh."""
|
||||||
|
|
||||||
|
# strings representing various path-related bits and pieces
|
||||||
|
# These are primarily for export; internally, they are hardcoded.
|
||||||
|
# Should be set before imports for resolving cyclic dependency.
|
||||||
|
curdir = ':'
|
||||||
|
pardir = '::'
|
||||||
|
extsep = '.'
|
||||||
|
sep = ':'
|
||||||
|
pathsep = '\n'
|
||||||
|
defpath = ':'
|
||||||
|
altsep = None
|
||||||
|
devnull = 'Dev:Null'
|
||||||
|
|
||||||
import os
|
import os
|
||||||
from stat import *
|
from stat import *
|
||||||
import genericpath
|
import genericpath
|
||||||
|
@ -16,17 +28,6 @@ __all__ = ["normcase","isabs","join","splitdrive","split","splitext",
|
||||||
"curdir","pardir","sep","pathsep","defpath","altsep","extsep",
|
"curdir","pardir","sep","pathsep","defpath","altsep","extsep",
|
||||||
"devnull","realpath","supports_unicode_filenames"]
|
"devnull","realpath","supports_unicode_filenames"]
|
||||||
|
|
||||||
# strings representing various path-related bits and pieces
|
|
||||||
# These are primarily for export; internally, they are hardcoded.
|
|
||||||
curdir = ':'
|
|
||||||
pardir = '::'
|
|
||||||
extsep = '.'
|
|
||||||
sep = ':'
|
|
||||||
pathsep = '\n'
|
|
||||||
defpath = ':'
|
|
||||||
altsep = None
|
|
||||||
devnull = 'Dev:Null'
|
|
||||||
|
|
||||||
def _get_colon(path):
|
def _get_colon(path):
|
||||||
if isinstance(path, bytes):
|
if isinstance(path, bytes):
|
||||||
return b':'
|
return b':'
|
||||||
|
|
|
@ -5,6 +5,18 @@ Instead of importing this module directly, import os and refer to this
|
||||||
module as os.path.
|
module as os.path.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# strings representing various path-related bits and pieces
|
||||||
|
# These are primarily for export; internally, they are hardcoded.
|
||||||
|
# Should be set before imports for resolving cyclic dependency.
|
||||||
|
curdir = '.'
|
||||||
|
pardir = '..'
|
||||||
|
extsep = '.'
|
||||||
|
sep = '\\'
|
||||||
|
pathsep = ';'
|
||||||
|
altsep = '/'
|
||||||
|
defpath = '.;C:\\bin'
|
||||||
|
devnull = 'nul'
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import stat
|
import stat
|
||||||
|
@ -19,17 +31,6 @@ __all__ = ["normcase","isabs","join","splitdrive","split","splitext",
|
||||||
"extsep","devnull","realpath","supports_unicode_filenames","relpath",
|
"extsep","devnull","realpath","supports_unicode_filenames","relpath",
|
||||||
"samefile", "sameopenfile", "samestat", "commonpath"]
|
"samefile", "sameopenfile", "samestat", "commonpath"]
|
||||||
|
|
||||||
# strings representing various path-related bits and pieces
|
|
||||||
# These are primarily for export; internally, they are hardcoded.
|
|
||||||
curdir = '.'
|
|
||||||
pardir = '..'
|
|
||||||
extsep = '.'
|
|
||||||
sep = '\\'
|
|
||||||
pathsep = ';'
|
|
||||||
altsep = '/'
|
|
||||||
defpath = '.;C:\\bin'
|
|
||||||
devnull = 'nul'
|
|
||||||
|
|
||||||
def _get_bothseps(path):
|
def _get_bothseps(path):
|
||||||
if isinstance(path, bytes):
|
if isinstance(path, bytes):
|
||||||
return b'\\/'
|
return b'\\/'
|
||||||
|
|
|
@ -10,6 +10,18 @@ Some of this can actually be useful on non-Posix systems too, e.g.
|
||||||
for manipulation of the pathname component of URLs.
|
for manipulation of the pathname component of URLs.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# Strings representing various path-related bits and pieces.
|
||||||
|
# These are primarily for export; internally, they are hardcoded.
|
||||||
|
# Should be set before imports for resolving cyclic dependency.
|
||||||
|
curdir = '.'
|
||||||
|
pardir = '..'
|
||||||
|
extsep = '.'
|
||||||
|
sep = '/'
|
||||||
|
pathsep = ':'
|
||||||
|
defpath = ':/bin:/usr/bin'
|
||||||
|
altsep = None
|
||||||
|
devnull = '/dev/null'
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import stat
|
import stat
|
||||||
|
@ -25,16 +37,6 @@ __all__ = ["normcase","isabs","join","splitdrive","split","splitext",
|
||||||
"devnull","realpath","supports_unicode_filenames","relpath",
|
"devnull","realpath","supports_unicode_filenames","relpath",
|
||||||
"commonpath"]
|
"commonpath"]
|
||||||
|
|
||||||
# Strings representing various path-related bits and pieces.
|
|
||||||
# These are primarily for export; internally, they are hardcoded.
|
|
||||||
curdir = '.'
|
|
||||||
pardir = '..'
|
|
||||||
extsep = '.'
|
|
||||||
sep = '/'
|
|
||||||
pathsep = ':'
|
|
||||||
defpath = ':/bin:/usr/bin'
|
|
||||||
altsep = None
|
|
||||||
devnull = '/dev/null'
|
|
||||||
|
|
||||||
def _get_sep(path):
|
def _get_sep(path):
|
||||||
if isinstance(path, bytes):
|
if isinstance(path, bytes):
|
||||||
|
|
|
@ -8,6 +8,7 @@ import sys
|
||||||
import unittest
|
import unittest
|
||||||
import warnings
|
import warnings
|
||||||
from test import support
|
from test import support
|
||||||
|
from test.support.script_helper import assert_python_ok
|
||||||
|
|
||||||
|
|
||||||
def create_file(filename, data=b'foo'):
|
def create_file(filename, data=b'foo'):
|
||||||
|
@ -486,6 +487,9 @@ class CommonTest(GenericTest):
|
||||||
with self.assertRaisesRegex(TypeError, 'bytearray'):
|
with self.assertRaisesRegex(TypeError, 'bytearray'):
|
||||||
self.pathmodule.relpath(bytearray(b'foo'), bytearray(b'bar'))
|
self.pathmodule.relpath(bytearray(b'foo'), bytearray(b'bar'))
|
||||||
|
|
||||||
|
def test_import(self):
|
||||||
|
assert_python_ok('-S', '-c', 'import ' + self.pathmodule.__name__)
|
||||||
|
|
||||||
|
|
||||||
class PathLikeTests(unittest.TestCase):
|
class PathLikeTests(unittest.TestCase):
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
Importing native path module (``posixpath``, ``ntpath``) now works even if
|
||||||
|
the ``os`` module still is not imported.
|
Loading…
Add table
Add a link
Reference in a new issue