-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added findtext and xpath #47
Conversation
def findall( | ||
self, path: _ElemPathArg, namespaces: _NSMapArg | None = None | ||
) -> list[HtmlElement]: ... | ||
def iterfind( | ||
self, path: _ElemPathArg, namespaces: _NSMapArg | None = None | ||
) -> Iterator[HtmlElement]: ... | ||
def xpath( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [mypy] reported by reviewdog 🐶
Signature of "xpath" incompatible with supertype "_Element" [override]
self, | ||
_path: _AnyStr, | ||
*, | ||
namespaces: _NonDefaultNSMapArg | None = None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [mypy] reported by reviewdog 🐶
Name "_NonDefaultNSMapArg" is not defined [name-defined]
_path: _AnyStr, | ||
*, | ||
namespaces: _NonDefaultNSMapArg | None = None, | ||
extensions: _XPathExtFuncArg | None = None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [mypy] reported by reviewdog 🐶
Name "_XPathExtFuncArg" is not defined [name-defined]
namespaces: _NonDefaultNSMapArg | None = None, | ||
extensions: _XPathExtFuncArg | None = None, | ||
smart_strings: bool = True, | ||
**_variables: _XPathVarArg |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [mypy] reported by reviewdog 🐶
Name "_XPathVarArg" is not defined [name-defined]
lxml-stubs/html/_element.pyi
Outdated
extensions: _XPathExtFuncArg | None = None, | ||
smart_strings: bool = True, | ||
**_variables: _XPathVarArg | ||
) -> list[HTMLElement]: ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [mypy] reported by reviewdog 🐶
Name "HTMLElement" is not defined [name-defined]
@@ -195,12 +195,27 @@ class HtmlElement(etree.ElementBase): | |||
def find( | |||
self, path: _ElemPathArg, namespaces: _NSMapArg | None = None | |||
) -> HtmlElement | None: ... | |||
def findtext( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [pyright] reported by reviewdog 🐶
Method "findtext" overrides class "_Element" in an incompatible manner
Parameter "namespaces" is missing in override
Return type mismatch: base method returns type "str | None", override returns type "str | _T@findtext" (reportIncompatibleMethodOverride)
self, | ||
_path: _AnyStr, | ||
*, | ||
namespaces: _NonDefaultNSMapArg | None = None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [pyright] reported by reviewdog 🐶
Type of parameter "namespaces" is partially unknown
Parameter type is "Unknown | None" (reportUnknownParameterType)
self, | ||
_path: _AnyStr, | ||
*, | ||
namespaces: _NonDefaultNSMapArg | None = None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [pyright] reported by reviewdog 🐶
"_NonDefaultNSMapArg" is not defined (reportUndefinedVariable)
_path: _AnyStr, | ||
*, | ||
namespaces: _NonDefaultNSMapArg | None = None, | ||
extensions: _XPathExtFuncArg | None = None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [pyright] reported by reviewdog 🐶
Type of parameter "extensions" is partially unknown
Parameter type is "Unknown | None" (reportUnknownParameterType)
_path: _AnyStr, | ||
*, | ||
namespaces: _NonDefaultNSMapArg | None = None, | ||
extensions: _XPathExtFuncArg | None = None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [pyright] reported by reviewdog 🐶
"_XPathExtFuncArg" is not defined (reportUndefinedVariable)
namespaces: _NonDefaultNSMapArg | None = None, | ||
extensions: _XPathExtFuncArg | None = None, | ||
smart_strings: bool = True, | ||
**_variables: _XPathVarArg |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [pyright] reported by reviewdog 🐶
Type of parameter "_variables" is unknown (reportUnknownParameterType)
namespaces: _NonDefaultNSMapArg | None = None, | ||
extensions: _XPathExtFuncArg | None = None, | ||
smart_strings: bool = True, | ||
**_variables: _XPathVarArg |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [pyright] reported by reviewdog 🐶
"_XPathVarArg" is not defined (reportUndefinedVariable)
lxml-stubs/html/_element.pyi
Outdated
extensions: _XPathExtFuncArg | None = None, | ||
smart_strings: bool = True, | ||
**_variables: _XPathVarArg | ||
) -> list[HTMLElement]: ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [pyright] reported by reviewdog 🐶
"HTMLElement" is not defined (reportUndefinedVariable)
Guess i found out |
Silly mistakes
lxml-stubs/html/_element.pyi
Outdated
def cssselect( | ||
self, | ||
expr: str, | ||
*, | ||
translator: _CSSTransArg = "xml", | ||
) -> list[HtmlElement]: ... | ||
) -> _XPathObject: ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [mypy] reported by reviewdog 🐶
Name "_XPathObject" is not defined [name-defined]
lxml-stubs/html/_element.pyi
Outdated
def cssselect( | ||
self, | ||
expr: str, | ||
*, | ||
translator: _CSSTransArg = "xml", | ||
) -> list[HtmlElement]: ... | ||
) -> _XPathObject: ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [pyright] reported by reviewdog 🐶
"_XPathObject" is not defined (reportUndefinedVariable)
Hopefully works now
@@ -195,18 +198,33 @@ class HtmlElement(etree.ElementBase): | |||
def find( | |||
self, path: _ElemPathArg, namespaces: _NSMapArg | None = None | |||
) -> HtmlElement | None: ... | |||
def findtext( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [mypy] reported by reviewdog 🐶
Signature of "findtext" incompatible with supertype "_Element" [override]
@@ -195,18 +198,33 @@ class HtmlElement(etree.ElementBase): | |||
def find( | |||
self, path: _ElemPathArg, namespaces: _NSMapArg | None = None | |||
) -> HtmlElement | None: ... | |||
def findtext( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [pyright] reported by reviewdog 🐶
Method "findtext" overrides class "_Element" in an incompatible manner
Positional parameter count mismatch; base method has 3, but override has 4
Parameter "namespaces" is missing in override
Return type mismatch: base method returns type "str | None", override returns type "str | _T@findtext" (reportIncompatibleMethodOverride)
so thats why it didnt work
I swear I'm not retarded, just tired
I swear I'm not retarded, just tired |
@dispread No sweat, please do it at your own pace. I'll check again tomorrow, in case you have additional commits related to this change. BTW I want to caution on something:
When a method is absent in a subclass, this means the corresponding method in superclass would be used ( |
@dispread If these changes are all you intended to submit, then they are not needed. As I said before, if the methods don't exist in Feel free to reopen this PR if you have other changes in mind. |
@abelcheung Thanks in advance 👍 |
I see. I'm using vscode with pylance extension, and everything just works automatically. If pycharm really needs a manual override of methods in order to show up, that could indicate either oversight of setting or a missing feature. Even in terms of pure stub itself (disregarding any IDE support), this manual override shouldn't be needed at all. Guess I need to spend some time to get #8 going then. |
If I'll have some free time tomorrow/wednesday I can look into whether it's just my config or something reproducible. |
I can reproduce the problem you have faced with a default installation of Pycharm 2024.1. The autocompletion popup manages to show I manage to find a temporary hack but it's quite ugly. Using the example below: from lxml import html
elem = html.Element('div')
result = elem. # <- no xpath() in autocomplete At this point, try to enforce the type of from lxml.etree import _Element
elem: _Element = html.Element('div') Then the signature of I Will try to continue investigating later on, for now perhaps you can also try out if vscode works fine for you. |
I dont know why they werent already there so I added them.
Peace out