Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Returns doesn't work in some subclasses #182

Closed
wRAR opened this issue Jul 21, 2023 · 2 comments · Fixed by #184
Closed

Returns doesn't work in some subclasses #182

wRAR opened this issue Jul 21, 2023 · 2 comments · Fixed by #184
Labels
bug Something isn't working

Comments

@wRAR
Copy link
Member

wRAR commented Jul 21, 2023

Similar to zytedata/zyte-common-items#49, even though the code is different, it's also not recursive and fails on e.g. this:

def test_returns_inheritance() -> None:
    @attrs.define
    class MyItem:
        name: str

    class BasePage(ItemPage[MyItem]):
        @field
        def name(self):
            return "hello"

    MetadataT = TypeVar("MetadataT")

    class HasMetadata(Generic[MetadataT]):
        pass

    class DummyMetadata:
        pass

    class Page(BasePage, HasMetadata[DummyMetadata]):
        pass

    page = Page()
    assert page.item_cls is MyItem
@wRAR wRAR added the bug Something isn't working label Jul 21, 2023
@wRAR
Copy link
Member Author

wRAR commented Jul 21, 2023

The issues are different though: the zyte-common-items code looks for HasMetadata and doesn't find it while the web-poet code looks just for some GenericAlias and in this testcase finds the wrong one.

@wRAR
Copy link
Member Author

wRAR commented Jul 27, 2023

Not sure what is the correct implementation here as the current code handles all kinds of generic base classes, including ItemPage, WebPage, Returns, Extractor etc. All of them descend from Returns though, so maybe we should check the class with isinstance, not for equality.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant