From e86bf379f8ca1ddd9c6479499a1988e1b47b794a Mon Sep 17 00:00:00 2001 From: Kevin Lloyd Bernal Date: Mon, 16 Jan 2023 20:50:42 +0800 Subject: [PATCH] =?UTF-8?q?rename=20page=5Fobject=5Ffor=5Fitem()=20?= =?UTF-8?q?=E2=86=92=20page=5Fcls=5Ffor=5Fitem()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.rst | 2 +- docs/page-objects/rules.rst | 6 +++--- tests/test_rules.py | 4 ++-- web_poet/rules.py | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index b343f8ae..e4a134e7 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -9,7 +9,7 @@ TBR * :meth:`web_poet.rules.RulesRegistry.add_rule` * :meth:`web_poet.rules.RulesRegistry.overrides_for` - * :meth:`web_poet.rules.RulesRegistry.page_object_for_item` + * :meth:`web_poet.rules.RulesRegistry.page_cls_for_item` * Improved the performance of :meth:`web_poet.rules.RulesRegistry.search` where passing a single parameter of either ``instead_of`` or ``to_return`` results diff --git a/docs/page-objects/rules.rst b/docs/page-objects/rules.rst index d521717d..c5597675 100644 --- a/docs/page-objects/rules.rst +++ b/docs/page-objects/rules.rst @@ -423,20 +423,20 @@ by passing the webpage URL. For example: It returns a :class:`Mapping` where the *key* represents the page object class that is overridden or replaced by the page object class in the *value*. -.. _rules-page_object_for_item-example: +.. _rules-page_cls_for_item-example: Identify the page object that could create the item """"""""""""""""""""""""""""""""""""""""""""""""""" Suppose you want to retrieve the page object class that is able to create the item class that you want from a given webpage, you can use -:meth:`~.RulesRegistry.page_object_for_item`. For example: +:meth:`~.RulesRegistry.page_cls_for_item`. For example: .. code-block:: python from web_poet import default_registry - page_cls = default_registry.page_object_for_item( + page_cls = default_registry.page_cls_for_item( "http://books.toscrape.com/catalogue/sapiens-a-brief-history-of-humankind_996/index.html", Book ) diff --git a/tests/test_rules.py b/tests/test_rules.py index 0e6ca96f..88faa457 100644 --- a/tests/test_rules.py +++ b/tests/test_rules.py @@ -401,12 +401,12 @@ def test_overrides_for() -> None: } -def test_page_object_for_item() -> None: +def test_page_cls_for_item() -> None: # This is not associated with any rule. class FakeItem: pass - method = default_registry.page_object_for_item + method = default_registry.page_cls_for_item for cls in [str, RequestUrl, ResponseUrl]: url = cls("https://example.com") diff --git a/web_poet/rules.py b/web_poet/rules.py index c368eb13..232f537c 100644 --- a/web_poet/rules.py +++ b/web_poet/rules.py @@ -380,13 +380,13 @@ def overrides_for( result[replaced_page] = page return result - def page_object_for_item( + def page_cls_for_item( self, url: Union[_Url, str], item_cls: Type ) -> Optional[Type]: """Return the page object class associated with the given URL that's able to produce the given ``item_cls``. - See example: :ref:`rules-page_object_for_item-example`. + See example: :ref:`rules-page_cls_for_item-example`. """ if item_cls is None: return None