Try and fake pathlib2 before pathlib
See original GitHub issueIs your feature request related to a problem? Please describe.
pathlib2 is only used if pathlib is not found. As pathlib is now included for python>=3.4 pathlib2 will not be faked for these newer versions of python even if it is present in a project. As I understand it the ‘correct’ usage of pathlib2 is not to use conditional imports such as in the extra_packages.py as highlighted in this issue on the pathlib2 repo, but rather to use pathlib2 directly in place of pathlib where compatibility between different python versions is required.
This means (AFAIK) that if I want to use pathlib2 in my project and have it faked I have to use the Patcher and modules_to_patch option - and then have to reload certain modules as a result.
Describe the solution you’d like
I think it would be better to flip the logic in extra_packages.py to first try and load pathlib2 and then only if this is not present to load pathlib. pathlib2 has to be explicitly downloaded whereas pathlib is included in the standard library so there should be fewer instances where the wrong module is patched. Alternatively I don’t know if it would be possible/advisable to patch both modules with the faked module?
Issue Analytics
- State:
- Created 5 years ago
- Comments:11 (8 by maintainers)

Top Related StackOverflow Question
Ok, nothing came up, so I made a new PyPi release (something will come up tomorrow for sure…) Closing.
@peteboothroyd - I made some changes to the
pathlibhandling in master due to a regression I introduced with the changes for this issue. It would be nice if you could check if the current master still works for you (regarding pathlib/pathlib3), before I make another release with the change.