FileLink should accept PathLike objects
See original GitHub issueStarting with Python 3.6, the os.PathLike
interface was introduced so that functions which operate on paths would accept not only str
or bytes
, but also pathlib.PurePath
for example.
IPython.display.FileLink
does not accept PathLike
objects yet:
[In]: IPython.display.FileLink(pathlib.Path(r'C:\Windows\System32\drivers\etc\hosts'))
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
C:\mnt\Anaconda\5.1.0\lib\site-packages\IPython\core\formatters.py in __call__(self, obj)
343 method = get_real_method(obj, self.print_method)
344 if method is not None:
--> 345 return method()
346 return None
347 else:
C:\mnt\Anaconda\5.1.0\lib\site-packages\IPython\lib\display.py in _repr_html_(self)
355 "incorrect path." % self.path)
356
--> 357 return self._format_path()
358
359 def __repr__(self):
C:\mnt\Anaconda\5.1.0\lib\site-packages\IPython\lib\display.py in _format_path(self)
341
342 def _format_path(self):
--> 343 fp = ''.join([self.url_prefix,self.path])
344 return ''.join([self.result_html_prefix,
345 self.html_link_str % (fp, self.path),
TypeError: sequence item 1: expected str instance, WindowsPath found
This could be implemented by calling os.fspath
on the parameter, but care should be taken because the function did not exist before Python 3.6.
Also for what it’s worth pathlib
objects have a method named as_uri()
.
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
TypeError: expected str, bytes or os.PathLike object, not tuple ...
I'm building an application with Django. Whenever I try using os.path.join() in the 'DIRS' list of the TEMPLATES setting I get TypeError: ...
Read more >Python | os.link() method - GeeksforGeeks
src: A path-like object representing the file system path. This is the source file path for which the hard link will be created...
Read more >11.2. os.path — Common pathname manipulations
All of these functions accept either only bytes or only string objects as their parameters. The result is an object of the same...
Read more >Please read!No, idea how to do this without using any - Chegg
PathLike object, not _io.StringIO) The customers.txt file link is: ... that the function does not use 'for': FAILURE: Function should not use 'for'...
Read more >External CSS Stylesheets – How to Link CSS to HTML and ...
In this case you would need to write a path like "css/styles.css" . The type attribute. <link rel=" ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I was think of something like:
And call
fsencode
where it’s needed. Another possibility would be to makefsencode = str
in the fallback, as you suggest.Closed b y #11060.