Cannot prettify soup with copied elements
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Beautiful Soup |
Fix Released
|
Undecided
|
Unassigned |
Bug Description
I have a project that uses `copy.copy()` extensively to make copies of elements in a soup (it diffs HTML documents). After updating to Beautiful Soup v4.8.0, I can no longer call `prettify()` on the soup instances with copied elements in them:
```py
from bs4 import BeautifulSoup
import copy
html = '''<!doctype html>
<html>
<head>
<body>
<p>Here is some text.</p>
</body>
</html>
'''
# Make a soup
soup = BeautifulSoup(html, 'lxml')
# Add a copied element
paragraph2 = copy.copy(soup.p)
paragraph2.
soup.body.
# Prettifying now raises an error in:
# bs4/element.py in _should_
soup.prettify()
```
`_should_
Later on in `_should_
It looks like this changed in rev 506: https:/
I use element copying extensively in an HTML diffing tool I work on in order to wrap changed parts of the document in tags indicating whether they were inserted or deleted, and in wrapping some `<style>` and `<script>` tags in `<template>` tags in order to delete them.
description: | updated |
Changed in beautifulsoup: | |
status: | Fix Committed → Fix Released |
Hi, any updates on this? Is there a good workaround for the regression?