-
Notifications
You must be signed in to change notification settings - Fork 1
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
PurePathBase
syntax customisation
#7
Comments
I've spent some time playing around with the above implementation sketch (i.e. making On reflection it seems obvious we should favour composition over inheritance; the bit I was missing is that we need to provide an abstract version of class PathModuleBase:
@classmethod
def _unsupported(cls, attr):
raise UnsupportedOperation(f"{cls.__name__}.{attr} is unsupported")
@property
def sep(self):
return self._unsupported('sep')
@property
def altsep(self):
return self._unsupported('altsep')
def normcase(self, path):
return self._unsupported('normcase()')
def isabs(self, path):
return self._unsupported('isabs()')
def join(self, path, *paths):
return self._unsupported('join()')
def split(self, path):
return self._unsupported('split()')
def splitroot(self, path):
return self._unsupported('splitroot()')
def splitdrive(self, path):
drive, root, rel = self.splitroot(path)
return drive, root + rel
def dirname(self, path):
return self.split(path)[0]
def basename(self, path):
return self.split(path)[1] Thus user subclasses of |
It should be possible to make path syntax and normalization more customizable. Very rough plan:
PurePathBase.pathmod
toPurePath.pathmod
drive
androot
?PurePathbase.is_absolute()
andis_reserved()
abstract (or returnFalse
?), move existing implementations toPurePath
is_case_sensitive()
abstract method (or class attribute, likesep
below?)PurePathBase.sep
andaltsep
attributes (defaults"/"
andNone
?)The text was updated successfully, but these errors were encountered: