diff --git a/parsel/selector.py b/parsel/selector.py index d734f56..e39a55a 100644 --- a/parsel/selector.py +++ b/parsel/selector.py @@ -22,7 +22,7 @@ ) from warnings import warn -import html_text # type: ignore[import] +import html_text # type: ignore[import-untyped] import jmespath from lxml import etree, html from lxml.html.clean import Cleaner # pylint: disable=no-name-in-module @@ -275,14 +275,6 @@ def getall( extract = getall - # TODO: bring types back - # @typing.overload - # def get(self, default: None = None) -> Optional[str]: - # pass - # - # @typing.overload - # def get(self, default: str) -> str: - # pass def get( self, default: Optional[str] = None, @@ -291,7 +283,7 @@ def get( cleaner: Union[str, None, Cleaner] = "auto", guess_punct_space: bool = True, guess_layout: bool = True, - ) -> Optional[str]: + ) -> Any: """ Return the result of ``.get()`` for the first element in this list. If the list is empty, return the ``default`` value. @@ -822,14 +814,11 @@ def get( ) try: - return typing.cast( - str, - etree.tostring( - tree, - method=_ctgroup[self.type]["_tostring_method"], - encoding="unicode", - with_tail=False, - ), + etree.tostring( + tree, + method=_ctgroup[self.type]["_tostring_method"], + encoding="unicode", + with_tail=False, ) except (AttributeError, TypeError): if tree is True: @@ -975,7 +964,7 @@ def cleaned( else: cleaner_obj = cleaner - root = cleaner_obj.clean_html(self.root) # type: ignore[type-var] + root = cleaner_obj.clean_html(self.root) return self.__class__( root=root, _expr=self._expr, diff --git a/tests/test_selector.py b/tests/test_selector.py index 8b5e554..ae34e9c 100644 --- a/tests/test_selector.py +++ b/tests/test_selector.py @@ -1356,19 +1356,19 @@ class SelectorTextTestCase(unittest.TestCase): """ - def test_text_get(self): + def test_text_get(self) -> None: sel = self.sscls(text="

title:

some text

") txt = sel.get(text=True) self.assertEqual(txt, "title:\n\nsome text") - def test_text_getall(self): + def test_text_getall(self) -> None: sel = self.sscls(text="").getall( text=True ) self.assertEqual(1, len(sel)) self.assertEqual("option1\noption2", sel[0]) - def test_text_cleaned_get(self): + def test_text_cleaned_get(self) -> None: sel = ( self.sscls(text="

paragraph

") .cleaned("html") @@ -1376,27 +1376,27 @@ def test_text_cleaned_get(self): ) self.assertEqual("paragraph", sel) - def test_text_get_guess_punct_space_false(self): + def test_text_get_guess_punct_space_false(self) -> None: sel = self.sscls(text='

hello"Folks"

') txt = sel.get(text=True, guess_punct_space=False) self.assertEqual(txt, 'hello "Folks"') - def test_text_get_guess_layout_false(self): + def test_text_get_guess_layout_false(self) -> None: sel = self.sscls(text="") txt = sel.get(text=True, guess_layout=False) self.assertEqual(txt, "option1 option2") - def test_text_get_guess_layout_true(self): + def test_text_get_guess_layout_true(self) -> None: sel = self.sscls(text="") txt = sel.get(text=True, guess_layout=True) self.assertEqual(txt, "option1\noption2") - def test_text_css_multiple(self): + def test_text_css_multiple(self) -> None: html = self.sscls(text=self.html_body) items = html.css(".product .price").getall(text=True) self.assertEqual(items, ["Price: 100", "Price: 200"]) - def test_text_xpath_get(self): + def test_text_xpath_get(self) -> None: html = self.sscls(text=self.html_body) self.assertEqual( html.xpath('//div[@class="product"]/span').getall(text=True),