XMLParsedAsHTMLWarning does not include stacklevel
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Beautiful Soup |
Fix Committed
|
Undecided
|
Unassigned |
Bug Description
Original report from Marc Müller:
I’ve been noticing a warning in one of my test suites recently. The warning itself is probably fine, however it’s emitted on bs4 itself and not at the right stacklevel which made it quite difficult to debug and actually find the culprit.
```
venv/lib/
/.../
It looks like you're parsing an XML document using an HTML parser. If this really is an HTML document (maybe it's XHTML?), […].
warnings.warn(
```
Setting a stacklevel of 10 in `builder/
```
diff --git a/bs4/builder/
index 2e39745..76c16ad 100644
--- a/bs4/builder/
+++ b/bs4/builder/
@@ -543,7 +543,8 @@ class DetectsXMLParse
def _warn(cls):
"""Issue a warning about XML being parsed as HTML."""
- XMLParsedAsHTML
+ XMLParsedAsHTML
+ stacklevel=10
)
def _initialize_
```
Changed in beautifulsoup: | |
status: | New → Triaged |
Changed in beautifulsoup: | |
status: | In Progress → Fix Committed |
Since _warn() is called from two different places (warn_if_ markup_ looks_like_ xml and _root_tag_ encountered) it probably needs a different stacklevel at each place. And warn_if_ markup_ looks_like_ xml is potentially called at a different place by each TreeBuilder.