question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Try and fake pathlib2 before pathlib

See original GitHub issue

Is 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:closed
  • Created 5 years ago
  • Comments:11 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
mrbean-bremencommented, Jan 13, 2019

Ok, nothing came up, so I made a new PyPi release (something will come up tomorrow for sure…) Closing.

0reactions
mrbean-bremencommented, Feb 5, 2019

@peteboothroyd - I made some changes to the pathlib handling 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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

use “pathlib” as module name · Issue #8 · jazzband/pathlib2
i want to use from pathlib import Path Path('foo').mkdir(exist_ok=True) ... Try and fake pathlib2 before pathlib pytest-dev/pyfakefs#462.
Read more >
No module named pathlib2 - python
Trying to run the python script without first loading the source command was the problem. I still haven't wrapped my head around how...
Read more >
Python 3's pathlib Module: Taming the File System
In this tutorial, you will see how to work with file paths—names of directories and files—in Python. You will learn new ways to...
Read more >
pathlib
pathlib offers a set of classes to handle filesystem paths. It offers the following advantages ... q.exists() True >>> q.is_dir() False. Opening a...
Read more >
pathlib — Object-oriented filesystem paths
Source code: Lib/pathlib.py This module offers classes representing filesystem paths with semantics appropriate for different operating systems.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found