From cc423ba6335f64145475f99ea2e06cb93168f759 Mon Sep 17 00:00:00 2001 From: CPython Developers <> Date: Mon, 15 Aug 2022 03:57:00 +0900 Subject: [PATCH] Update genericpath from CPython 3.10.6 --- Lib/genericpath.py | 10 +++++++--- Lib/test/test_genericpath.py | 11 +++++------ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/Lib/genericpath.py b/Lib/genericpath.py index e790d7468..309759af2 100644 --- a/Lib/genericpath.py +++ b/Lib/genericpath.py @@ -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 diff --git a/Lib/test/test_genericpath.py b/Lib/test/test_genericpath.py index c8a282acb..01363c3bb 100644 --- a/Lib/test/test_genericpath.py +++ b/Lib/test/test_genericpath.py @@ -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")