Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-44136: remove pathlib._Flavour #26141

Closed
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove flavour.is_supported
barneygale committed May 15, 2021
commit 3d277071ec5ecf19e2b12fe9d521cf01c4f0abfc
11 changes: 4 additions & 7 deletions Lib/pathlib.py
Original file line number Diff line number Diff line change
@@ -57,8 +57,6 @@ class _WindowsFlavour(_Flavour):

has_drv = True

is_supported = (os.name == 'nt')

def casefold(self, s):
return s.lower()

@@ -69,8 +67,6 @@ def casefold_parts(self, parts):
class _PosixFlavour(_Flavour):
has_drv = False

is_supported = (os.name != 'nt')

def casefold(self, s):
return s

@@ -788,6 +784,7 @@ class PurePosixPath(PurePath):
"""
_flavour = _posix_flavour
_pathmod = posixpath
_supported = (os.name != 'nt')
_case_insensitive = False
__slots__ = ()

@@ -828,6 +825,7 @@ class PureWindowsPath(PurePath):
"""
_flavour = _windows_flavour
_pathmod = ntpath
_supported = (os.name == 'nt')
_case_insensitive = True
_drive_letters = set('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')
_ext_namespace_prefix = '\\\\?\\'
@@ -940,11 +938,10 @@ class Path(PurePath):
def __new__(cls, *args, **kwargs):
if cls is Path:
cls = WindowsPath if os.name == 'nt' else PosixPath
self = cls._from_parts(args)
if not self._flavour.is_supported:
elif not cls._supported:
raise NotImplementedError("cannot instantiate %r on your system"
% (cls.__name__,))
return self
return cls._from_parts(args)

def _make_child_relpath(self, part):
# This is an optimization used for dir walking. `part` must be
2 changes: 1 addition & 1 deletion Lib/test/test_pathlib.py
Original file line number Diff line number Diff line change
@@ -2400,7 +2400,7 @@ def test_concrete_class(self):
self.assertIs(type(p),
pathlib.WindowsPath if os.name == 'nt' else pathlib.PosixPath)

def test_unsupported_flavour(self):
def test_unsupported_type(self):
if os.name == 'nt':
self.assertRaises(NotImplementedError, pathlib.PosixPath)
else: