diff --git a/CHANGELOG b/CHANGELOG index b0e4450..6afa19b 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -5,6 +5,8 @@ [bug=2097262] * Restored the English documentation to the source distribution. [bug=2097237] +* Fixed a regression where HTMLFormatter and XMLFormatter were not + propagating the indent parameter to the superconstructor. [bug=2097272] = 4.13.0 (20250202) diff --git a/bs4/builder/__init__.py b/bs4/builder/__init__.py index 7225f30..5f2b38d 100644 --- a/bs4/builder/__init__.py +++ b/bs4/builder/__init__.py @@ -192,17 +192,11 @@ class TreeBuilder(object): doesn't keep track of this information, then store_line_numbers is irrelevant. - :param attribute_dict_class: A Tag's attribute values (available - as tag.attrs) willl be stored in an instance of this class. - The default is Beautiful Soup's built-in `AttributeDict` class and - you will probably never need to change it. - :param attribute_dict_class: The value of a multi-valued attribute (such as HTML's 'class') willl be stored in an instance of this class. The default is Beautiful Soup's built-in `AttributeValueList`, which is a normal Python list, and you will probably never need to change it. - """ USE_DEFAULT: Any = object() #: :meta private: diff --git a/bs4/formatter.py b/bs4/formatter.py index 34c3351..bfa0876 100644 --- a/bs4/formatter.py +++ b/bs4/formatter.py @@ -83,7 +83,7 @@ class Formatter(EntitySubstitution): void_element_close_prefix: str = "/", cdata_containing_tags: Optional[Set[str]] = None, empty_attributes_are_booleans: bool = False, - indent: int = 1, + indent: Union[int,str] = 1, ): r"""Constructor. @@ -201,7 +201,7 @@ class HTMLFormatter(Formatter): void_element_close_prefix: str = "/", cdata_containing_tags: Optional[Set[str]] = None, empty_attributes_are_booleans: bool = False, - indent: int = 1, + indent: Union[int,str] = 1, ): super(HTMLFormatter, self).__init__( self.HTML, @@ -209,6 +209,7 @@ class HTMLFormatter(Formatter): void_element_close_prefix, cdata_containing_tags, empty_attributes_are_booleans, + indent=indent ) @@ -223,7 +224,7 @@ class XMLFormatter(Formatter): void_element_close_prefix: str = "/", cdata_containing_tags: Optional[Set[str]] = None, empty_attributes_are_booleans: bool = False, - indent: int = 1, + indent: Union[int,str] = 1, ): super(XMLFormatter, self).__init__( self.XML, @@ -231,6 +232,7 @@ class XMLFormatter(Formatter): void_element_close_prefix, cdata_containing_tags, empty_attributes_are_booleans, + indent=indent, ) diff --git a/bs4/tests/test_formatter.py b/bs4/tests/test_formatter.py index a2c64cf..0b840c5 100644 --- a/bs4/tests/test_formatter.py +++ b/bs4/tests/test_formatter.py @@ -109,6 +109,17 @@ class TestFormatter(SoupTest): formatter = Formatter() assert formatter.indent == " " + @pytest.mark.parametrize("formatter,expect", + [ + (HTMLFormatter(indent=1), "

\n a\n

\n"), + (HTMLFormatter(indent=2), "

\n a\n

\n"), + (XMLFormatter(indent=1), "

\n a\n

\n"), + (XMLFormatter(indent="\t"), "

\n\ta\n

\n"), + ] ) + def test_indent_subclasses(self, formatter, expect): + soup = self.soup("

a

") + assert expect == soup.p.prettify(formatter=formatter) + @pytest.mark.parametrize( "s,expect_html,expect_html5", [ diff --git a/tox.ini b/tox.ini index 7b74349..d0ec26d 100644 --- a/tox.ini +++ b/tox.ini @@ -15,7 +15,7 @@ deps = lxml packaging soupsieve>=2.6 pytest>=6 - typing_extensions + typing_extensions>=4.0.0 commands = pytest {tty:--color=yes} {posargs} [testenv:docs]