scrapy / parsel

Parsel lets you extract data from XML/HTML documents using XPath or CSS selectors
BSD 3-Clause "New" or "Revised" License
1.11k stars 137 forks source link

Fix mypy issues #254

Closed wRAR closed 1 year ago

wRAR commented 1 year ago

We currently only run mypy for tests but not for parsel. There are some errors in parsel:

parsel/utils.py:72: error: Item "None" of "Optional[Match[str]]" has no attribute "group"
parsel/selector.py:69: error: Signature of "__getitem__" incompatible with supertype "list"
parsel/selector.py:69: note:      Superclass:
parsel/selector.py:69: note:          @overload
parsel/selector.py:69: note:          def __getitem__(self, SupportsIndex) -> _SelectorType
parsel/selector.py:69: note:          @overload
parsel/selector.py:69: note:          def __getitem__(self, slice) -> List[_SelectorType]
parsel/selector.py:69: note:      Subclass:
parsel/selector.py:69: note:          @overload
parsel/selector.py:69: note:          def __getitem__(self, int) -> _SelectorType
parsel/selector.py:69: note:          @overload
parsel/selector.py:69: note:          def __getitem__(self, slice) -> SelectorList[_SelectorType]
parsel/selector.py:81: error: Incompatible return value type (got "Union[_SelectorType, List[_SelectorType]]", expected "Union[_SelectorType, SelectorList[_SelectorType]]")
parsel/selector.py:81: error: Argument 1 to "SelectorList" has incompatible type "Union[_SelectorType, List[_SelectorType]]"; expected "Iterable[_SelectorType]"
parsel/selector.py:217: error: Signature of "remove" incompatible with supertype "list"
parsel/selector.py:217: note:      Superclass:
parsel/selector.py:217: note:          def remove(self, _SelectorType) -> None
parsel/selector.py:217: note:      Subclass:
parsel/selector.py:217: note:          def remove(self) -> None
parsel/selector.py:217: error: Signature of "remove" incompatible with supertype "MutableSequence"
parsel/selector.py:217: note:          def remove(self, value: _SelectorType) -> None
parsel/selector.py:217: note:          def remove(self) -> None
parsel/selector.py:325: error: Incompatible return value type (got "SelectorList[Selector]", expected "SelectorList[_SelectorType]")
parsel/selector.py:349: error: Incompatible return value type (got "SelectorList[Selector]", expected "SelectorList[_SelectorType]")
wRAR commented 1 year ago

Also, mypy runs with --ignore-missing-imports, this should ideally be removed and the issues fixed (though it looks like it would need typing cssselect first).

wRAR commented 1 year ago

The remove() issue is interesting because it correctly points out that SelectorList.remove() has a different signature, and usage, than list.remove(element).