◐ Shell
clean mode source ↗

bpo-24132: Add direct subclassing of PurePath/Path in pathlib by kfollstad · Pull Request #26906 · python/cpython

added 7 commits

June 24, 2021 13:54
Add tests to verify previously untested black-box class properties of
PurePath and Path in pathlib. Collectively, these tests verify all the
ways the classes represent themselves via isinstance, issubclass,
__repr__(), etc. Moreover all class instances spawned by PurePath or
Path are also similarly tested.
Add expected failing tests to pathlib that will verify the ability
of PurePath and Path to be subclassed by users. As part of this,
test all of the black-box class properties of the newly subclassed
Path-like class instances, and the instances generated by their methods.
Existing is_mount method in Path was Posix only and not cross-
platform even though it was in a cross-platform base class. The existing
design relied upon being overriden later in WindowsPath. Consolidated
code from both into new Path.is_mount() which is now cross-plaform
similiar to all of the other Path methods.
Replace hardcorded references to pathlib.Path to facilitate making
Path extensible.
Replace factory functionality of PurePath and Path with a psuedo-factory
which appears to generate it's derived subclasses, but instead just
masquerades the new instance as one of the subclasses. Doing so makes
the resultant versions of PurePath and Path directly subclassable and as
such allows them to pass all of the previously failing subclass tests.
Add tests mirroring existing comparison tests for PurePosixPath
and PureWindowsPath but extending them to direct subclasses of PurePath.
Add documentation highlighting the new direct subclass functionality of
PurePath and Path. Also add new is_posix & is_windows doctest conditions
so that system specific doctest code can still be tested instead of just
being taken as a literal block and always skipped.

kfollstad

merwok

merwok