-
-
Notifications
You must be signed in to change notification settings - Fork 507
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Bug report
What's wrong
I'm having a similar issue to #1000 when type annotating django sitemaps.
The following is not passing:
class OfferSitemap(Sitemap):
priority = 1
changefreq = "always"
def items(self) -> QuerySet[Offer]:
return Offer.objects.all()
def location(self, item: Offer) -> str:
return reverse(
"myapp:detail-offer",
kwargs={
"provider_name": item.provider.url_name,
"offer_name": item.url_name,
},
)
# error: Argument 1 of "location" is incompatible with supertype "Sitemap"; supertype defines the argument type as "Model"
# note: This violates the Liskov substitution principle
How is that should be
From the docs:
items() is a method that returns a sequence or QuerySet of objects. The objects returned will get passed to any callable methods corresponding to a sitemap property (location, lastmod, changefreq, and priority).
I think the type could be more generic because the items
method is the one that determines the type of the item
variable every other methods are using. Maybe taking a similar approach to #800 with an _Item
Typevar ?
Let me know if you think this is a correct approach and I'll be happy to submit a PR to address that.
Cheers
System information
- OS: ubuntu20.04
python
version: 3.8django
version: 3.2.15mypy
version: 0.950django-stubs
version: 1.11.0django-stubs-ext
version: 0.5.0
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working