Skip to content

Commit

Permalink
rename page_object_for_item() → page_cls_for_item()
Browse files Browse the repository at this point in the history
  • Loading branch information
BurnzZ committed Jan 16, 2023
1 parent 1ab1a43 commit e86bf37
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions docs/page-objects/rules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions web_poet/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e86bf37

Please sign in to comment.