Skip to content

Commit

Permalink
Remove use of the deprecated ast.Constant.s attribute (#392)
Browse files Browse the repository at this point in the history
The `.s` attribute on `ast.Constant` nodes is an alias to the `.value` attribute. The `.s` alias has been deprecated since Python 3.8, and causes a DeprecationWarning to be emitted on Python 3.12
  • Loading branch information
AlexWaygood authored Jun 26, 2023
1 parent 1ead17d commit 2763a13
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions bugbear.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def _is_identifier(arg):
if not isinstance(arg, ast.Constant) or not isinstance(arg.value, str):
return False

return re.match(r"^[A-Za-z_][A-Za-z0-9_]*$", arg.s) is not None
return re.match(r"^[A-Za-z_][A-Za-z0-9_]*$", arg.value) is not None


def _flatten_excepthandler(node):
Expand Down Expand Up @@ -401,22 +401,22 @@ def visit_Call(self, node):
with suppress(AttributeError, IndexError):
if (
node.func.id in ("getattr", "hasattr")
and node.args[1].s == "__call__"
and node.args[1].value == "__call__"
):
self.errors.append(B004(node.lineno, node.col_offset))
if (
node.func.id == "getattr"
and len(node.args) == 2
and _is_identifier(node.args[1])
and not iskeyword(node.args[1].s)
and not iskeyword(node.args[1].value)
):
self.errors.append(B009(node.lineno, node.col_offset))
elif (
not any(isinstance(n, ast.Lambda) for n in self.node_stack)
and node.func.id == "setattr"
and len(node.args) == 3
and _is_identifier(node.args[1])
and not iskeyword(node.args[1].s)
and not iskeyword(node.args[1].value)
):
self.errors.append(B010(node.lineno, node.col_offset))

Expand Down Expand Up @@ -556,11 +556,11 @@ def check_for_b005(self, node):
if call_path in B005.valid_paths:
return # path is exempt

s = node.args[0].s
if len(s) == 1:
value = node.args[0].value
if len(value) == 1:
return # stripping just one character

if len(s) == len(set(s)):
if len(value) == len(set(value)):
return # no characters appear more than once

self.errors.append(B005(node.lineno, node.col_offset))
Expand Down

0 comments on commit 2763a13

Please sign in to comment.