bpo-24132: Add direct subclassing of PurePath/Path in pathlib by kfollstad · Pull Request #26906 · python/cpython
added 7 commits
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 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters