2929from .csstranslator import GenericTranslator , HTMLTranslator
3030from .utils import extract_regex , flatten , iflatten , shorten
3131
32-
3332_SelectorType = TypeVar ("_SelectorType" , bound = "Selector" )
3433_ParserType = Union [etree .XMLParser , etree .HTMLParser ]
3534# simplified _OutputMethodArg from types-lxml
@@ -135,18 +134,14 @@ def __getitem__(
135134 ) -> Union [_SelectorType , "SelectorList[_SelectorType]" ]:
136135 o = super ().__getitem__ (pos )
137136 if isinstance (pos , slice ):
138- return self .__class__ (
139- typing .cast ("SelectorList[_SelectorType]" , o )
140- )
137+ return self .__class__ (typing .cast ("SelectorList[_SelectorType]" , o ))
141138 else :
142139 return typing .cast (_SelectorType , o )
143140
144141 def __getstate__ (self ) -> None :
145142 raise TypeError ("can't pickle SelectorList objects" )
146143
147- def jmespath (
148- self , query : str , ** kwargs : Any
149- ) -> "SelectorList[_SelectorType]" :
144+ def jmespath (self , query : str , ** kwargs : Any ) -> "SelectorList[_SelectorType]" :
150145 """
151146 Call the ``.jmespath()`` method for each element in this list and return
152147 their results flattened as another :class:`SelectorList`.
@@ -158,9 +153,7 @@ def jmespath(
158153
159154 selector.jmespath('author.name', options=jmespath.Options(dict_cls=collections.OrderedDict))
160155 """
161- return self .__class__ (
162- flatten ([x .jmespath (query , ** kwargs ) for x in self ])
163- )
156+ return self .__class__ (flatten ([x .jmespath (query , ** kwargs ) for x in self ]))
164157
165158 def xpath (
166159 self ,
@@ -185,9 +178,7 @@ def xpath(
185178 selector.xpath('//a[href=$url]', url="http://www.example.com")
186179 """
187180 return self .__class__ (
188- flatten (
189- [x .xpath (xpath , namespaces = namespaces , ** kwargs ) for x in self ]
190- )
181+ flatten ([x .xpath (xpath , namespaces = namespaces , ** kwargs ) for x in self ])
191182 )
192183
193184 def css (self , query : str ) -> "SelectorList[_SelectorType]" :
@@ -211,9 +202,7 @@ def re(
211202 Passing ``replace_entities`` as ``False`` switches off these
212203 replacements.
213204 """
214- return flatten (
215- [x .re (regex , replace_entities = replace_entities ) for x in self ]
216- )
205+ return flatten ([x .re (regex , replace_entities = replace_entities ) for x in self ])
217206
218207 @typing .overload
219208 def re_first (
@@ -316,9 +305,7 @@ def drop(self) -> None:
316305_NOT_SET = object ()
317306
318307
319- def _get_root_from_text (
320- text : str , * , type : str , ** lxml_kwargs : Any
321- ) -> etree ._Element :
308+ def _get_root_from_text (text : str , * , type : str , ** lxml_kwargs : Any ) -> etree ._Element :
322309 return create_root_node (text , _ctgroup [type ]["_parser" ], ** lxml_kwargs )
323310
324311
@@ -583,9 +570,7 @@ def make_selector(x: Any) -> _SelectorType: # closure function
583570 return self .__class__ (root = x , _expr = query )
584571
585572 result = [make_selector (x ) for x in result ]
586- return typing .cast (
587- SelectorList [_SelectorType ], self .selectorlist_cls (result )
588- )
573+ return typing .cast (SelectorList [_SelectorType ], self .selectorlist_cls (result ))
589574
590575 def xpath (
591576 self : _SelectorType ,
@@ -611,9 +596,7 @@ def xpath(
611596 selector.xpath('//a[href=$url]', url="http://www.example.com")
612597 """
613598 if self .type not in ("html" , "xml" , "text" ):
614- raise ValueError (
615- f"Cannot use xpath on a Selector of type { self .type !r} "
616- )
599+ raise ValueError (f"Cannot use xpath on a Selector of type { self .type !r} " )
617600 if self .type in ("html" , "xml" ):
618601 try :
619602 xpathev = self .root .xpath
@@ -654,9 +637,7 @@ def xpath(
654637 )
655638 for x in result
656639 ]
657- return typing .cast (
658- SelectorList [_SelectorType ], self .selectorlist_cls (result )
659- )
640+ return typing .cast (SelectorList [_SelectorType ], self .selectorlist_cls (result ))
660641
661642 def css (self : _SelectorType , query : str ) -> SelectorList [_SelectorType ]:
662643 """
@@ -670,9 +651,7 @@ def css(self: _SelectorType, query: str) -> SelectorList[_SelectorType]:
670651 .. _cssselect: https://pypi.python.org/pypi/cssselect/
671652 """
672653 if self .type not in ("html" , "xml" , "text" ):
673- raise ValueError (
674- f"Cannot use css on a Selector of type { self .type !r} "
675- )
654+ raise ValueError (f"Cannot use css on a Selector of type { self .type !r} " )
676655 return self .xpath (self ._css2xpath (query ))
677656
678657 def _css2xpath (self , query : str ) -> str :
0 commit comments