-
Notifications
You must be signed in to change notification settings - Fork 15
Closed
Description
Currently, this works fine:
import attrs
from web_poet import HttpResponse, Returns, ItemPage, field
@attrs.define
class BigItem:
x: int
y: int
class BigPage(ItemPage[BigItem]):
@field
def x(self):
return 1
@field
def y(self):
return 2
@attrs.define
class SmallItem:
x: int
class SmallXPage(BigPage, Returns[SmallItem], skip_nonitem_fields=True):
pass
page = SmallXPage()
item = await page.to_item()
print(page._skip_nonitem_fields) # True
print(item) # SmallItem(x=1)
However, if we define an attrs class to have some page dependencies, it doesn't work:
from web_poet import PageParams
@attrs.define
class SmallPage(BigPage, Returns[SmallItem], skip_nonitem_fields=True):
params: PageParams
page = SmallPage(params=PageParams())
print(page._skip_nonitem_fields) # False
item = await page.to_item() # TypeError: __init__() got an unexpected keyword argument 'y'
From the examples above, this stems from page._skip_nonitem_fields
being set to False
when the page object is defined as an attrs class.
Metadata
Metadata
Assignees
Labels
No labels