1414from __future__ import annotations
1515
1616import re
17- from typing import TYPE_CHECKING , Optional , cast
17+ from typing import TYPE_CHECKING , cast
1818
1919from cssselect .parser import (
2020 Attrib ,
@@ -290,7 +290,7 @@ def xpath(self, parsed_selector: Tree) -> XPathExpr:
290290 """Translate any parsed selector object."""
291291 type_name = type (parsed_selector ).__name__
292292 method = cast (
293- "Optional[ Callable[[Tree], XPathExpr]] " ,
293+ "Callable[[Tree], XPathExpr] | None " ,
294294 getattr (self , f"xpath_{ type_name .lower ()} " , None ),
295295 )
296296 if method is None :
@@ -352,7 +352,7 @@ def xpath_function(self, function: Function) -> XPathExpr:
352352 """Translate a functional pseudo-class."""
353353 method_name = "xpath_{}_function" .format (function .name .replace ("-" , "_" ))
354354 method = cast (
355- "Optional[ Callable[[XPathExpr, Function], XPathExpr]] " ,
355+ "Callable[[XPathExpr, Function], XPathExpr] | None " ,
356356 getattr (self , method_name , None ),
357357 )
358358 if not method :
@@ -363,7 +363,7 @@ def xpath_pseudo(self, pseudo: Pseudo) -> XPathExpr:
363363 """Translate a pseudo-class."""
364364 method_name = "xpath_{}_pseudo" .format (pseudo .ident .replace ("-" , "_" ))
365365 method = cast (
366- "Optional[ Callable[[XPathExpr], XPathExpr]] " ,
366+ "Callable[[XPathExpr], XPathExpr] | None " ,
367367 getattr (self , method_name , None ),
368368 )
369369 if not method :
@@ -375,7 +375,7 @@ def xpath_attrib(self, selector: Attrib) -> XPathExpr:
375375 """Translate an attribute selector."""
376376 operator = self .attribute_operator_mapping [selector .operator ]
377377 method = cast (
378- "Callable[[XPathExpr, str, Optional[ str] ], XPathExpr]" ,
378+ "Callable[[XPathExpr, str, str | None ], XPathExpr]" ,
379379 getattr (self , f"xpath_attrib_{ operator } " ),
380380 )
381381 if self .lower_case_attribute_names :
0 commit comments