Skip to content

Commit

Permalink
revert default and use 'None' instead
Browse files Browse the repository at this point in the history
  • Loading branch information
BurnzZ committed Oct 18, 2022
1 parent 5fdf4a1 commit e38bd52
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 10 deletions.
4 changes: 2 additions & 2 deletions tests/po_lib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ 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


@handle_urls("example.com", instead_of=POTopLevelOverriden2)
class POTopLevel2(POBase):
expected_instead_of = POTopLevelOverriden2
expected_patterns = Patterns(["example.com"])
expected_to_return = dict
expected_to_return = None
expected_meta = {} # type: ignore
2 changes: 1 addition & 1 deletion tests/po_lib/a_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion tests/po_lib/nested_package/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion tests/po_lib/nested_package/a_nested_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion tests/po_lib_sub/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion tests/po_lib_to_return/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion web_poet/_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion web_poet/pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]):
Expand Down
9 changes: 8 additions & 1 deletion web_poet/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -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::
Expand Down

0 comments on commit e38bd52

Please sign in to comment.