Skip to content

Commit 95a187b

Browse files
committed
Merge branch 'bugfix/121-unicode-error-on-fastpath' into 'master'
Correct Unicode error on FastPath Closes #121 See merge request python-devs/importlib_metadata!122
2 parents 8d38b1c + 5c37a7e commit 95a187b

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

importlib_metadata/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
email_message_from_string,
3030
PyPy_repr,
3131
unique_ordered,
32+
str,
3233
)
3334
from importlib import import_module
3435
from itertools import starmap
@@ -418,8 +419,8 @@ class FastPath:
418419
"""
419420

420421
def __init__(self, root):
421-
self.root = root
422-
self.base = os.path.basename(root).lower()
422+
self.root = str(root)
423+
self.base = os.path.basename(self.root).lower()
423424

424425
def joinpath(self, child):
425426
return pathlib.Path(self.root, child)

importlib_metadata/_compat.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from __future__ import absolute_import
1+
from __future__ import absolute_import, unicode_literals
22

33
import io
44
import abc
@@ -26,6 +26,8 @@
2626
NotADirectoryError = IOError, OSError
2727
PermissionError = IOError, OSError
2828

29+
str = type('')
30+
2931
suppress = contextlib.suppress
3032

3133
if sys.version_info > (3, 5): # pragma: nocover

importlib_metadata/docs/changelog.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
v1.6.1
66
======
77

8+
* Ensure inputs to FastPath are Unicode. Closes #121.
89
* Tests now rely on ``importlib.resources.files`` (and
910
backport) instead of the older ``path`` function.
1011

importlib_metadata/tests/test_integration.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1+
# coding: utf-8
2+
3+
from __future__ import unicode_literals
4+
15
import unittest
26
import packaging.requirements
37
import packaging.version
48

59
from . import fixtures
610
from .. import (
711
_compat,
12+
distributions,
813
version,
914
)
1015

@@ -40,3 +45,13 @@ def __getattribute__(self, name):
4045
self.fixtures.enter_context(
4146
fixtures.install_finder(ModuleFreeFinder()))
4247
_compat.disable_stdlib_finder()
48+
49+
50+
class FileSystem(fixtures.OnSysPath, fixtures.SiteDir, unittest.TestCase):
51+
def test_unicode_dir_on_sys_path(self):
52+
"""
53+
Ensure a Unicode subdirectory of a directory on sys.path
54+
does not crash.
55+
"""
56+
fixtures.build_files({'☃': {}}, prefix=self.site_dir)
57+
list(distributions())

0 commit comments

Comments
 (0)