Skip to content

Cannot display a single dot character as Markdown #14820

Description

@dniku
from IPython import display
display.display(display.Markdown('.'))
---------------------------------------------------------------------------
IsADirectoryError                         Traceback (most recent call last)
<ipython-input-6-0a1e025990e8> in <cell line: 0>()
      1 from IPython import display
----> 2 display.display(display.Markdown('.'))

/usr/local/lib/python3.11/dist-packages/IPython/core/display.py in __init__(self, data, url, filename, metadata)
    635             self.metadata = {}
    636 
--> 637         self.reload()
    638         self._check_data()
    639 

/usr/local/lib/python3.11/dist-packages/IPython/core/display.py in reload(self)
    660         """Reload the raw data from file or URL."""
    661         if self.filename is not None:
--> 662             with open(self.filename, self._read_flags) as f:
    663                 self.data = f.read()
    664         elif self.url is not None:

IsADirectoryError: [Errno 21] Is a directory: '.'

This is because this code explicitly checks whether the data argument to display.Markdown is an existing path, and if so, reads that path instead of displaying the text itself.

This also leads to a weird side effects, allowing to display the files one may not intend to display:

Image

Is it a good idea to decide whether to read a file or to display the text depending on whether the text resolves to an existing path? Perhaps this should be done with a flag instead, i.e. if the user explicitly passes filename=?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions