@@ -136,8 +136,7 @@ def parse_simple_selector(tokens, namespaces):
136136 if next == ':' :
137137 next = tokens .next ()
138138 if next is None or next .type != 'ident' :
139- raise SelectorError (
140- next , f'Expected a pseudo-element name, got { next } ' )
139+ raise SelectorError (next , f'Expected a pseudo-element name, got { next } ' )
141140 value = next .lower_value
142141 if value not in SUPPORTED_PSEUDO_ELEMENTS :
143142 raise SelectorError (
@@ -154,8 +153,7 @@ def parse_simple_selector(tokens, namespaces):
154153 if name in ('is' , 'where' , 'not' , 'has' ):
155154 return parse_logical_combination (next , namespaces , name ), None
156155 else :
157- return (
158- FunctionalPseudoClassSelector (name , next .arguments ), None )
156+ return (FunctionalPseudoClassSelector (name , next .arguments ), None )
159157 else :
160158 raise SelectorError (next , f'unexpected { next } token.' )
161159 else :
@@ -185,8 +183,7 @@ def parse_logical_combination(matches_any_token, namespaces, name):
185183
186184def parse_attribute_selector (tokens , namespaces ):
187185 tokens .skip_whitespace ()
188- qualified_name = parse_qualified_name (
189- tokens , namespaces , is_attribute = True )
186+ qualified_name = parse_qualified_name (tokens , namespaces , is_attribute = True )
190187 if qualified_name is None :
191188 next = tokens .next ()
192189 raise SelectorError (next , f'expected attribute name, got { next } ' )
@@ -204,12 +201,10 @@ def parse_attribute_selector(tokens, namespaces):
204201 next = tokens .next ()
205202 if next is None or next .type not in ('ident' , 'string' ):
206203 next_type = 'None' if next is None else next .type
207- raise SelectorError (
208- next , f'expected attribute value, got { next_type } ' )
204+ raise SelectorError (next , f'expected attribute value, got { next_type } ' )
209205 value = next .value
210206 else :
211- raise SelectorError (
212- peek , f'expected attribute selector operator, got { peek } ' )
207+ raise SelectorError (peek , f'expected attribute selector operator, got { peek } ' )
213208
214209 tokens .skip_whitespace ()
215210 next = tokens .next ()
@@ -221,8 +216,7 @@ def parse_attribute_selector(tokens, namespaces):
221216 case_sensitive = True
222217 else :
223218 raise SelectorError (next , f'expected ], got { next .type } ' )
224- return AttributeSelector (
225- namespace , local_name , operator , value , case_sensitive )
219+ return AttributeSelector (namespace , local_name , operator , value , case_sensitive )
226220
227221
228222def parse_qualified_name (tokens , namespaces , is_attribute = False ):
@@ -246,15 +240,13 @@ def parse_qualified_name(tokens, namespaces, is_attribute=False):
246240 namespace = namespaces .get (first_ident .value )
247241 if namespace is None :
248242 raise SelectorError (
249- first_ident ,
250- f'undefined namespace prefix: { first_ident .value } ' )
243+ first_ident , f'undefined namespace prefix: { first_ident .value } ' )
251244 elif peek == '*' :
252245 next = tokens .next ()
253246 peek = tokens .peek ()
254247 if peek != '|' :
255248 if is_attribute :
256- raise SelectorError (
257- next , f'expected local name, got { next .type } ' )
249+ raise SelectorError (next , f'expected local name, got { next .type } ' )
258250 return namespaces .get (None , None ), None
259251 tokens .next ()
260252 namespace = None
@@ -405,10 +397,7 @@ def __init__(self, namespace):
405397 self .namespace = namespace
406398
407399 def __repr__ (self ):
408- if self .namespace == '' :
409- return '|'
410- else :
411- return f'{{{ self .namespace } }}|'
400+ return '|' if self .namespace == '' else f'{{{ self .namespace } }}|'
412401
413402
414403class IDSelector :
0 commit comments