Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c043384

Browse files
authored
Merge pull request #11060 from ciupicri/bugfix-11059
FileLink: accept path-like objects (#11059)
2 parents 631f5fe + 164e1b2 commit c043384

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

IPython/lib/display.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Authors : MinRK, gregcaporaso, dannystaple
44
"""
55
from os.path import exists, isfile, splitext, abspath, join, isdir
6-
from os import walk, sep
6+
from os import walk, sep, fsdecode
77

88
from IPython.core.display import DisplayObject
99

@@ -334,7 +334,7 @@ def __init__(self,
334334
if isdir(path):
335335
raise ValueError("Cannot display a directory using FileLink. "
336336
"Use FileLinks to display '%s'." % path)
337-
self.path = path
337+
self.path = fsdecode(path)
338338
self.url_prefix = url_prefix
339339
self.result_html_prefix = result_html_prefix
340340
self.result_html_suffix = result_html_suffix

IPython/lib/tests/test_display.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
#-----------------------------------------------------------------------------
1515
from tempfile import NamedTemporaryFile, mkdtemp
1616
from os.path import split, join as pjoin, dirname
17+
import sys
18+
try:
19+
import pathlib
20+
except ImportError:
21+
pass
1722

1823
# Third-party imports
1924
import nose.tools as nt
@@ -33,6 +38,9 @@
3338
def test_instantiation_FileLink():
3439
"""FileLink: Test class can be instantiated"""
3540
fl = display.FileLink('example.txt')
41+
# TODO: remove if when only Python >= 3.6 is supported
42+
if sys.version_info >= (3, 6):
43+
fl = display.FileLink(pathlib.PurePath('example.txt'))
3644

3745
def test_warning_on_non_existant_path_FileLink():
3846
"""FileLink: Calling _repr_html_ on non-existant files returns a warning

0 commit comments

Comments
 (0)