Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork48
Description
In GitLab by @mignon.cicchetti on Jun 13, 2020, 03:25
Hi,
I stumbled upon another issue similar tohttps://gitlab.com/python-devs/importlib_metadata/-/issues/116. If bothpathlib andpathlib2 are installed on python <3.5, thenpathlib is used. (cf). However, that pathlib (in contrast to pathlib of python3.5) does not support read_bytes(), read_text() and maybe others. For example the test suite fails with errors like:
======================================================================ERROR: test_read_bytes (importlib_resources.tests.test_files.OpenDiskTests)----------------------------------------------------------------------Traceback (most recent call last): File ".../importlib_resources/tests/test_files.py", line 13, in test_read_bytes actual = files.joinpath('utf-8.file').read_bytes()AttributeError: 'PosixPath' object has no attribute 'read_bytes'I suggest instead of choosing the library to import based on ImportError, to chose it based on the python version:
if sys.version_info > (3,5): from pathlib import Path, PurePathelse: from pathlib2 import Path, PurePath # type: ignoreif sys.version_info > (3,): from contextlib import suppresselse: from contextlib2 import suppress # type: ignore(I took the version numbers to check against from importlib_metadata.)
Remark: I have no clue on what versions the other import stuff was introduced (singledispatch, abc, zipfile, ...). So maybe they should also be guarded by version number instead of by ImportError.