Mixing of pathlib and pathlib2
*importlib_metadata* mixes *pathlib* and *pathlib2* on python <=3.5 if both are installed.
If both *pathlib* and *pathlib2* are installed on a python distribution <= 3.5, then the test suite passes Path objects of *pathlib* to functions of *pathlib2*.
The issue manifests itself when running the test suite in the form of the following error
```
======================================================================
ERROR: test_distribution_at_pathlib (importlib_metadata.tests.test_api.OffSysPathTests)
Demonstrate how to load metadata direct from a directory.
----------------------------------------------------------------------
Traceback (most recent call last):
File ".../importlib_metadata/tests/test_api.py", line 170, in test_distribution_at_pathlib
dist = Distribution.at(dist_info_path)
File ".../importlib_metadata/__init__.py", line 222, in at
return PathDistribution(pathlib.Path(path))
File "/usr/lib64/python2.7/site-packages/pathlib2/__init__.py", line 1192, in new
self = cls._from_parts(args, init=False)
File "/usr/lib64/python2.7/site-packages/pathlib2/__init__.py", line 848, in from_parts
drv, root, parts = self._parse_args(args)
File "/usr/lib64/python2.7/site-packages/pathlib2/_init__.py", line 840, in _parse_args
% type(a))
TypeError: argument should be a str object or an os.PathLike object returning str, not <class 'pathlib.PosixPath'>
----------------------------------------------------------------------
```
I spare you the code analysis and just point out the imports:
`importlib_metadata/tests/fixtures.py`:
```
try:
import pathlib
except ImportError:
import pathlib2 as pathlib
```
`importlib_metadata/_compat.py`:
```
if sys.version_info > (3, 5): # pragma: nocover
import pathlib
else: # pragma: nocover
import pathlib2 as pathlib
```
Making these imports consistent (preferably using the version of `_compat.py`) solves the issue.
And while we are at it: These imports (*pathlib* on python >3.5, *pathlib2* on python<=3.5) do not coincide with the advertised dependencies in setup.cfg:
```
python_requires = >=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*
install_requires =
zipp>=0.5
pathlib2; python_version < '3'
contextlib2; python_version < '3'
```
Note: I haven't done any analysis with respect to *contextlib* and *contextlib2*. So maybe there is another mixup hiding.
issue