openzim / python-scraperlib

Collection of Python code to re-use across Python-based scrapers
GNU General Public License v3.0
20 stars 18 forks source link

`Archive.get_item` type hint is wrong #196

Closed benoit74 closed 1 month ago

benoit74 commented 1 month ago

Archive.get_item type hint suggest that it returns a zimscraperlib.zim.items.Item while in fact it return a libzim.writer.Item.

We should either fix the code (preferably) or the type hint (would be sad)

rgaudin commented 1 month ago

Why would it be sad to fix the signature? Is this type useless? If so the issue should be about deleting it rather than this collateral

benoit74 commented 1 month ago

The zimscraperlib.zim.items.Item type is useful, so this is why I do not want to fix the signature which is correct. But then the code should really return such an object, and not a libzim.writer.Item.

benoit74 commented 1 month ago

The problem is that today I can't use item.mimetype because the type checker complains, and I can't use item.get_mimetype() because it fails at runtime.

rgaudin commented 1 month ago

Ah I thought it was the other way around. Indeed we should return it.

benoit74 commented 1 month ago

In fact type hint is wrong, it is a writing item. We should fix type hint with libzim reading item which is sufficient.

benoit74 commented 1 month ago

Fixed by https://github.com/openzim/python-scraperlib/pull/202