Skip to content

Commit b92fa54

Browse files
committed
Grab and ClassIsAndAttribute use match-case and are sorted a little better.
1 parent d7bfa6f commit b92fa54

2 files changed

Lines changed: 14 additions & 12 deletions

File tree

astToolkit/_toolClassIsAndAttribute.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -635,17 +635,17 @@ def workhorse(node: ast.AST) -> TypeGuard[hasDOTtag] | bool:
635635

636636
@staticmethod
637637
@overload
638-
def targetIs(astClass: type[hasDOTtarget_Name], attributeCondition: Callable[[ast.Name], bool]) -> Callable[[ast.AST], TypeGuard[hasDOTtarget_Name] | bool]:
638+
def targetIs(astClass: type[hasDOTtarget_expr], attributeCondition: Callable[[ast.expr], bool]) -> Callable[[ast.AST], TypeGuard[hasDOTtarget_expr] | bool]:
639639
...
640640

641641
@staticmethod
642642
@overload
643-
def targetIs(astClass: type[hasDOTtarget_NameOrAttributeOrSubscript], attributeCondition: Callable[[ast.Name | ast.Attribute | ast.Subscript], bool]) -> Callable[[ast.AST], TypeGuard[hasDOTtarget_NameOrAttributeOrSubscript] | bool]:
643+
def targetIs(astClass: type[hasDOTtarget_Name], attributeCondition: Callable[[ast.Name], bool]) -> Callable[[ast.AST], TypeGuard[hasDOTtarget_Name] | bool]:
644644
...
645645

646646
@staticmethod
647647
@overload
648-
def targetIs(astClass: type[hasDOTtarget_expr], attributeCondition: Callable[[ast.expr], bool]) -> Callable[[ast.AST], TypeGuard[hasDOTtarget_expr] | bool]:
648+
def targetIs(astClass: type[hasDOTtarget_NameOrAttributeOrSubscript], attributeCondition: Callable[[ast.Name | ast.Attribute | ast.Subscript], bool]) -> Callable[[ast.AST], TypeGuard[hasDOTtarget_NameOrAttributeOrSubscript] | bool]:
649649
...
650650

651651
@staticmethod
@@ -706,12 +706,12 @@ def workhorse(node: ast.AST) -> TypeGuard[hasDOTupper] | bool:
706706

707707
@staticmethod
708708
@overload
709-
def valueIs(astClass: type[hasDOTvalue_ConstantValueType], attributeCondition: Callable[[ConstantValueType], bool]) -> Callable[[ast.AST], TypeGuard[hasDOTvalue_ConstantValueType] | bool]:
709+
def valueIs(astClass: type[hasDOTvalue_boolOrNone], attributeCondition: Callable[[bool], bool]) -> Callable[[ast.AST], TypeGuard[hasDOTvalue_boolOrNone] | bool]:
710710
...
711711

712712
@staticmethod
713713
@overload
714-
def valueIs(astClass: type[hasDOTvalue_boolOrNone], attributeCondition: Callable[[bool], bool]) -> Callable[[ast.AST], TypeGuard[hasDOTvalue_boolOrNone] | bool]:
714+
def valueIs(astClass: type[hasDOTvalue_ConstantValueType], attributeCondition: Callable[[ConstantValueType], bool]) -> Callable[[ast.AST], TypeGuard[hasDOTvalue_ConstantValueType] | bool]:
715715
...
716716

717717
@staticmethod

astToolkit/_toolGrab.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# pyright: reportMatchNotExhaustive=false
12
"""This file is generated automatically, so changes to this file will be lost."""
23
from astToolkit import (
34
ConstantValueType, hasDOTannotation, hasDOTarg, hasDOTargs, hasDOTargtypes, hasDOTasname,
@@ -173,15 +174,16 @@ def workhorse(node: hasDOTdecorator_list) -> hasDOTdecorator_list:
173174
node.decorator_list = action(node.decorator_list) # pyright: ignore[reportArgumentType, reportAttributeAccessIssue]
174175
return node
175176
return workhorse
176-
if sys.version_info >= (3, 13):
177+
match sys.version_info:
178+
case version if version >= (3, 13):
177179

178-
@staticmethod
179-
def default_valueAttribute(action: Callable[[ast.expr], ast.expr]) -> Callable[[hasDOTdefault_value], hasDOTdefault_value]:
180+
@staticmethod
181+
def default_valueAttribute(action: Callable[[ast.expr], ast.expr]) -> Callable[[hasDOTdefault_value], hasDOTdefault_value]:
180182

181-
def workhorse(node: hasDOTdefault_value) -> hasDOTdefault_value:
182-
node.default_value = action(node.default_value) # pyright: ignore[reportArgumentType, reportAttributeAccessIssue]
183-
return node
184-
return workhorse
183+
def workhorse(node: hasDOTdefault_value) -> hasDOTdefault_value:
184+
node.default_value = action(node.default_value) # pyright: ignore[reportArgumentType, reportAttributeAccessIssue]
185+
return node
186+
return workhorse
185187

186188
@staticmethod
187189
def defaultsAttribute(action: Callable[[Sequence[ast.expr]], Sequence[ast.expr]]) -> Callable[[hasDOTdefaults], hasDOTdefaults]:

0 commit comments

Comments
 (0)