Skip to content
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

Fix param name to match the doc in SelectorList.xpath() #220

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1130,7 +1130,7 @@ Converting CSS to XPath

When you're using an API that only accepts XPath expressions, it's sometimes
useful to convert CSS to XPath. This allows you to take advantage of the
conciseness of CSS to query elements by classes and the easeness of
conciseness of CSS to query elements by classes and the easiness of
manipulating XPath expressions at the same time.

On those occasions, use the function :func:`~parsel.css2xpath`:
Expand Down
16 changes: 14 additions & 2 deletions parsel/selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""

import sys
from warnings import warn

import six
from lxml import etree, html
Expand Down Expand Up @@ -73,7 +74,7 @@ def __getitem__(self, pos):
def __getstate__(self):
raise TypeError("can't pickle SelectorList objects")

def xpath(self, xpath, namespaces=None, **kwargs):
def xpath(self, query=None, namespaces=None, **kwargs):
"""
Call the ``.xpath()`` method for each element in this list and return
their results flattened as another :class:`SelectorList`.
Expand All @@ -90,7 +91,18 @@ def xpath(self, xpath, namespaces=None, **kwargs):

selector.xpath('//a[href=$url]', url="http://www.example.com")
"""
return self.__class__(flatten([x.xpath(xpath, namespaces=namespaces, **kwargs) for x in self]))
if query is None:
query = kwargs.pop("xpath", None)
if query is not None:
warn(
"The parameter 'xpath' is deprecated, use 'query' instead.",
DeprecationWarning,
stacklevel=2
)
else:
raise ValueError("The 'query' parameter is missing or None")

return self.__class__(flatten([x.xpath(query, namespaces=namespaces, **kwargs) for x in self]))

def css(self, query):
"""
Expand Down