Skip to content

Commit

Permalink
Remove deprecated Python 3.7 ast types (#2271)
Browse files Browse the repository at this point in the history
  • Loading branch information
jp-dark authored Mar 14, 2024
1 parent 382b77c commit 0fcce69
Showing 1 changed file with 3 additions and 35 deletions.
38 changes: 3 additions & 35 deletions apis/python/src/tiledbsoma/_query_condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@
from ._exception import SOMAError
from ._util import pa_types_is_string_or_bytes

# In Python 3.7, a boolean literal like `True` is of type `ast.NameConstant`.
# Above that, it's of type `ast.Constant`.
QueryConditionNodeElem = Union[
ast.Name, ast.Constant, ast.NameConstant, ast.Call, ast.Num, ast.Str, ast.Bytes
]
QueryConditionNodeElem = Union[ast.Name, ast.Constant, ast.NameConstant, ast.Call]


@attrs.define
Expand Down Expand Up @@ -287,12 +283,7 @@ def is_att_node(self, att: QueryConditionNodeElem) -> bool:
if att.func.id != "attr":
return False

return (
isinstance(att.args[0], ast.Constant)
or isinstance(att.args[0], ast.NameConstant)
or isinstance(att.args[0], ast.Str)
or isinstance(att.args[0], ast.Bytes)
)
return isinstance(att.args[0], (ast.Constant, ast.NameConstant))

return isinstance(att, ast.Name)

Expand Down Expand Up @@ -332,13 +323,8 @@ def get_att_from_node(self, node: QueryConditionNodeElem) -> Any:

if isinstance(att_node, ast.Name):
att = str(att_node.id)
elif isinstance(att_node, ast.Constant) or isinstance(
att_node, ast.NameConstant
):
elif isinstance(att_node, ast.Constant):
att = str(att_node.value)
elif isinstance(att_node, ast.Str) or isinstance(att_node, ast.Bytes):
# deprecated in 3.8
att = str(att_node.s)
else:
raise SOMAError(
f"Incorrect type for attribute name: {ast.dump(att_node)}"
Expand Down Expand Up @@ -371,12 +357,6 @@ def get_val_from_node(self, node: QueryConditionNodeElem) -> Any:

if isinstance(val_node, ast.Constant) or isinstance(val_node, ast.NameConstant):
val = val_node.value
elif isinstance(val_node, ast.Num):
# deprecated in 3.8
val = val_node.n
elif isinstance(val_node, ast.Str) or isinstance(val_node, ast.Bytes):
# deprecated in 3.8
val = val_node.s
else:
raise SOMAError(
f"Incorrect type for comparison value: {ast.dump(val_node)}"
Expand Down Expand Up @@ -504,15 +484,3 @@ def visit_UnaryOp(self, node: ast.UnaryOp, sign: int = 1):
)

return node.operand

def visit_Num(self, node: ast.Num) -> ast.Num:
# deprecated in 3.8
return node

def visit_Str(self, node: ast.Str) -> ast.Str:
# deprecated in 3.8
return node

def visit_Bytes(self, node: ast.Bytes) -> ast.Bytes:
# deprecated in 3.8
return node

0 comments on commit 0fcce69

Please sign in to comment.