Update genericpath from CPython 3.10.6

This commit is contained in:
CPython Developers
2022-08-15 03:57:00 +09:00
committed by Jeong YunWon
parent 10618213d7
commit cc423ba633
2 changed files with 12 additions and 9 deletions

10
Lib/genericpath.py vendored
View File

@@ -95,7 +95,11 @@ def samestat(s1, s2):
# Are two filenames really pointing to the same file?
def samefile(f1, f2):
"""Test whether two pathnames reference the same actual file"""
"""Test whether two pathnames reference the same actual file or directory
This is determined by the device number and i-node number and
raises an exception if an os.stat() call on either pathname fails.
"""
s1 = os.stat(f1)
s2 = os.stat(f2)
return samestat(s1, s2)
@@ -148,7 +152,7 @@ def _check_arg_types(funcname, *args):
elif isinstance(s, bytes):
hasbytes = True
else:
raise TypeError('%s() argument must be str or bytes, not %r' %
(funcname, s.__class__.__name__)) from None
raise TypeError(f'{funcname}() argument must be str, bytes, or '
f'os.PathLike object, not {s.__class__.__name__!r}') from None
if hasstr and hasbytes:
raise TypeError("Can't mix strings and bytes in path components") from None

View File

@@ -8,6 +8,7 @@ import sys
import unittest
import warnings
from test.support import os_helper
from test.support import warnings_helper
from test.support.script_helper import assert_python_ok
from test.support.os_helper import FakePath
@@ -525,8 +526,7 @@ class CommonTest(GenericTest):
def test_join_errors(self):
# Check join() raises friendly TypeErrors.
from .support.warnings_helper import check_warnings
with check_warnings(('', BytesWarning), quiet=True):
with warnings_helper.check_warnings(('', BytesWarning), quiet=True):
errmsg = "Can't mix strings and bytes in path components"
with self.assertRaisesRegex(TypeError, errmsg):
self.pathmodule.join(b'bytes', 'str')
@@ -546,9 +546,8 @@ class CommonTest(GenericTest):
def test_relpath_errors(self):
# Check relpath() raises friendly TypeErrors.
from .support.warnings_helper import check_warnings
with check_warnings(('', (BytesWarning, DeprecationWarning)),
quiet=True):
with warnings_helper.check_warnings(
('', (BytesWarning, DeprecationWarning)), quiet=True):
errmsg = "Can't mix strings and bytes in path components"
with self.assertRaisesRegex(TypeError, errmsg):
self.pathmodule.relpath(b'bytes', 'str')
@@ -568,7 +567,7 @@ class CommonTest(GenericTest):
class PathLikeTests(unittest.TestCase):
def setUp(self):
self.file_name = os_helper.TESTFN.lower()
self.file_name = os_helper.TESTFN
self.file_path = FakePath(os_helper.TESTFN)
self.addCleanup(os_helper.unlink, self.file_name)
create_file(self.file_name, b"test_genericpath.PathLikeTests")