diff --git a/tests/po_lib/__init__.py b/tests/po_lib/__init__.py index 4a4a7f17..91ae0036 100644 --- a/tests/po_lib/__init__.py +++ b/tests/po_lib/__init__.py @@ -35,7 +35,7 @@ class POTopLevelOverriden2(ItemPage): class POTopLevel1(POBase): expected_instead_of = POTopLevelOverriden1 expected_patterns = Patterns(["example.com"], ["/*.jpg|"], priority=300) - expected_to_return = dict + expected_to_return = None expected_meta = {} # type: ignore @@ -43,5 +43,5 @@ class POTopLevel1(POBase): class POTopLevel2(POBase): expected_instead_of = POTopLevelOverriden2 expected_patterns = Patterns(["example.com"]) - expected_to_return = dict + expected_to_return = None expected_meta = {} # type: ignore diff --git a/tests/po_lib/a_module.py b/tests/po_lib/a_module.py index 474bc3f0..941f48f6 100644 --- a/tests/po_lib/a_module.py +++ b/tests/po_lib/a_module.py @@ -12,5 +12,5 @@ class POModuleOverriden(ItemPage): class POModule(POBase): expected_instead_of = POModuleOverriden expected_patterns = Patterns(["example.com"]) - expected_to_return = dict + expected_to_return = None expected_meta = {"extra_arg": "foo"} # type: ignore diff --git a/tests/po_lib/nested_package/__init__.py b/tests/po_lib/nested_package/__init__.py index 1c722f46..63547ea4 100644 --- a/tests/po_lib/nested_package/__init__.py +++ b/tests/po_lib/nested_package/__init__.py @@ -16,5 +16,5 @@ class PONestedPkgOverriden(ItemPage): class PONestedPkg(POBase): expected_instead_of = PONestedPkgOverriden expected_patterns = Patterns(["example.com", "example.org"], ["/*.jpg|"]) - expected_to_return = dict + expected_to_return = None expected_meta = {} # type: ignore diff --git a/tests/po_lib/nested_package/a_nested_module.py b/tests/po_lib/nested_package/a_nested_module.py index c7473761..5d44b39c 100644 --- a/tests/po_lib/nested_package/a_nested_module.py +++ b/tests/po_lib/nested_package/a_nested_module.py @@ -18,5 +18,5 @@ class PONestedModule(POBase): expected_patterns = Patterns( include=["example.com", "example.org"], exclude=["/*.jpg|"] ) - expected_to_return = dict + expected_to_return = None expected_meta = {} # type: ignore diff --git a/tests/po_lib_sub/__init__.py b/tests/po_lib_sub/__init__.py index 7b367239..50ffd99b 100644 --- a/tests/po_lib_sub/__init__.py +++ b/tests/po_lib_sub/__init__.py @@ -22,5 +22,5 @@ class POLibSubOverriden(ItemPage): class POLibSub(POBase): expected_instead_of = POLibSubOverriden expected_patterns = Patterns(["sub.example"]) - expected_to_return = dict + expected_to_return = None expected_meta = {} # type: ignore diff --git a/tests/po_lib_to_return/__init__.py b/tests/po_lib_to_return/__init__.py index e9457337..eb05241a 100644 --- a/tests/po_lib_to_return/__init__.py +++ b/tests/po_lib_to_return/__init__.py @@ -32,7 +32,7 @@ class SomePage(ItemPage): expected_instead_of = None expected_patterns = Patterns(["example.com"]) - expected_to_return = dict + expected_to_return = None expected_meta = {} @field diff --git a/web_poet/_typing.py b/web_poet/_typing.py index b69e4d8f..9f2578c3 100644 --- a/web_poet/_typing.py +++ b/web_poet/_typing.py @@ -24,7 +24,7 @@ def get_generic_parameter(cls): return args[0] -def get_item_cls(cls, default=dict): +def get_item_cls(cls, default=None): param = get_generic_parameter(cls) if param is None or isinstance(param, typing.TypeVar): # class is not parametrized return default diff --git a/web_poet/pages.py b/web_poet/pages.py index d0944f03..77b39af3 100644 --- a/web_poet/pages.py +++ b/web_poet/pages.py @@ -47,7 +47,7 @@ class Returns(typing.Generic[ItemT]): @property def item_cls(self) -> typing.Type[ItemT]: """Item class""" - return get_item_cls(self.__class__) + return get_item_cls(self.__class__, default=dict) class ItemPage(Injectable, Returns[ItemT]): diff --git a/web_poet/rules.py b/web_poet/rules.py index 24634db6..fdd5dbd0 100644 --- a/web_poet/rules.py +++ b/web_poet/rules.py @@ -46,9 +46,16 @@ class ApplyRule: This doesn't do anything for now but may be useful for future API updates. The main functionality of this class lies in the ``instead_of`` and ``to_return`` - parameter. Should both of these be omitted, then :class:`~.ApplyRule` simply + parameters. Should both of these be omitted, then :class:`~.ApplyRule` simply tags which URL patterns the given Page Object is expected to be used. + As much as possible, the ``to_return`` parameter should capture the Item Class + that the Page Object is capable of returning. Before passing it to :class:`~.ApplyRule`, + the ``to_return`` value is primarily derived from the return class specified + from Page Objects that are subclasses of :class:`~.ItemPage`. However, a + special case exists when a Page Object returns a ``dict`` as an item but then + the rule should have ``to_return=None`` and **NOT** ``to_return=dict``. + More information regarding its usage in :ref:`intro-overrides`. .. tip::