tk0miya / docutils-stubs

The Unlicense
9 stars 5 forks source link

List[subclass] is incompatible with List[superclass] #38

Closed danieleades closed 3 years ago

danieleades commented 3 years ago

https://github.com/tk0miya/docutils-stubs/blob/24b92fe1e4732e5e29567a11b7aa402ac25a4bba/docutils-stubs/parsers/rst/__init__.pyi#L50

subclasses of Directive will return, i believe, lists of subclasses of Node, rather than lists of Node.

List[Derived] is not compatible with List[Base] (see http://mypy.readthedocs.io/en/latest/generics.html#variance-of-generic-types)

this throws an error with the sphinx extension 'todo' example

is it possible to use Sequence here instead of List?

danieleades commented 3 years ago

another option might be to use a Generic parameter? i'm really not sure of the best solution here

tk0miya commented 3 years ago

Indeed. But I don't know a better way to describe its type.

+1 for using Sequence instead.