Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Usage of pathlib on python<3.5 instead of pathlib2 #97

Closed
@jaraco

Description

@jaraco

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp