Skip to content

Fix #9343: warn when using HTML instead of IFrame#11350

Merged
Carreau merged 1 commit into
ipython:masterfrom
mpenkov:9343
Oct 3, 2018
Merged

Fix #9343: warn when using HTML instead of IFrame#11350
Carreau merged 1 commit into
ipython:masterfrom
mpenkov:9343

Conversation

@mpenkov
Copy link
Copy Markdown
Contributor

@mpenkov mpenkov commented Oct 1, 2018

No description provided.

Comment thread IPython/core/display.py
def __init__(self, data=None, url=None, filename=None, metadata=None):
if data and "<iframe " in data and "</iframe>" in data:
warnings.warn("Consider using IPython.display.IFrame instead")
super(HTML, self).__init__(data=data, url=url, filename=filename, metadata=metadata)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're py3 only, so now you can just use super()

@mock.patch('warnings.warn')
def test_encourage_iframe_over_html(m_warn):
display.HTML('<br />')
m_warn.assert_not_called()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I would have use assert_warns, but that looks good !

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn’t know about that one, thanks!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a look at the link that you posted, it seems specific to pytest, which IPython doesn't use. Did you mean to send this link? Let me know if I misunderstood something.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yes, sorry, and this I just get confused between test runners.

Comment thread IPython/core/display.py
class HTML(TextDisplayObject):

def __init__(self, data=None, url=None, filename=None, metadata=None):
if data and "<iframe " in data and "</iframe>" in data:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering if we should use startswith and endswith that are more efficient and likely more correct, but that looks good.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I had the same thought. There’s a difference between rendering a single iframe vs rendering HTML with an iframe in it. Startswith would be a better idea. We could also account for case differences because HTML is case insensitive.

Let me know if you’d like those changes, or if things are fine as they are.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Up to you. I'll reopen the linked issue add link to this section for further improvements.

@Carreau
Copy link
Copy Markdown
Member

Carreau commented Oct 3, 2018

Thanks !

@Carreau Carreau merged commit 58bfd4f into ipython:master Oct 3, 2018
@Carreau Carreau added this to the 7.1 milestone Oct 3, 2018
@Carreau Carreau mentioned this pull request Oct 3, 2018
@Carreau Carreau added the Hacktoberfest you want to participate to hacktoberfest ? Here is an easy issue. label Oct 13, 2018
@ssxcho
Copy link
Copy Markdown

ssxcho commented Feb 2, 2022

Hi everyone, I am having trouble on this , I need to use '<iframe srcdoc =' , any suggestions on how to bypass this warning ?

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

Labels

Hacktoberfest you want to participate to hacktoberfest ? Here is an easy issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants