This is an example of what I would call a headache caused by adding type hints to an existing untyped library. 馃槄
It's probably fine to ignore this issue because probably nobody is ever going to try and call the method MutableSequence.index(...) on a panflue.MetaList. That said, it's clearly a bug.
I am working around the issue in panflute-stubs by not adding a type hint at all for index and making a specific exception for index to tell stubtest to ignore the absence of a type hint for this attribute.
In the current codebase the declaration of MetaList is
class MetaList(MetaValue, MutableSequence):
which means in inherits from Element the following index attribute:
class Element(object):
...
def __new__(cls, *args, **kwargs):
...
element.index = None
The documentation says it's a int | None and other code in Element confirms.
On the other hand, collections.abc.Sequence (from which collections.abc.MutableSequence derives) has the method:
index(value[, start[, stop])
which is a standard method of sequences in Python, see https://docs.python.org/3/library/stdtypes.html#sequence.index
Mypy if run on the panflute codebase or any attempt by panflute-stubs to type hint index will report the following error:
error: Definition of "index" in base class "Element" is incompatible with definition in base class "Sequence" [misc]
This is an example of what I would call a headache caused by adding type hints to an existing untyped library. 馃槄
It's probably fine to ignore this issue because probably nobody is ever going to try and call the method MutableSequence.index(...) on a panflue.MetaList. That said, it's clearly a bug.
I am working around the issue in
panflute-stubsby not adding a type hint at all forindexand making a specific exception forindexto tellstubtestto ignore the absence of a type hint for this attribute.In the current codebase the declaration of MetaList is
which means in inherits from
Elementthe followingindexattribute:The documentation says it's a
int | Noneand other code in Element confirms.On the other hand,
collections.abc.Sequence(from whichcollections.abc.MutableSequencederives) has the method:which is a standard method of sequences in Python, see https://docs.python.org/3/library/stdtypes.html#sequence.index
Mypy if run on the panflute codebase or any attempt by panflute-stubs to type hint
indexwill report the following error: