rushter / selectolax

Python binding to Modest and Lexbor engines (fast HTML5 parser with CSS selectors).
MIT License
1.16k stars 70 forks source link

[Typing] `_Attributes` in .pyi stub file is missing dictionary methods like `__getitem__` #108

Closed ThirVondukr closed 1 week ago

ThirVondukr commented 9 months ago

Seems like _Attributes is missing methods from dict class, even though documentation states otherwise:

Examples
--------
>>> tree = HTMLParser("<div id='a'></div>")
>>> node = tree.css_first('div')
>>> node.attrs
<div attributes, 1 items>
>>> node.attrs['id']
'a'

Reproduction:

from selectolax.parser import HTMLParser

parser = HTMLParser("")
element = parser.css_first(".class")
print(element.attrs["some-attr"])
main.py:5:7: error: Value of type "_Attributes" is not indexable  [index]
    print(element.attrs["some-attr"])

Python version: 3.11.7 Selectolax version: 0.3.18 Mypy: 1.8.0

ilotoki0804 commented 3 weeks ago

142 will fix this issue.

ilotoki0804 commented 1 week ago

@rushter Can you close this issue as completed? #142 solved this.

ThirVondukr commented 1 week ago

@ilotoki0804 Probably should be closed after the next release, wasn't able to install selectolax from git though to confirm if the issue is solved, but I think it should be fine.

rushter commented 1 week ago

I've deployed a new release.

rushter commented 1 week ago

@ilotoki0804 Thanks for taking care of this.

ThirVondukr commented 1 week ago

Thanks a lot, can confirm that everything works now, I have 150 mypy errors to fix 😭