Skip to content

Commit

Permalink
Add in backport of astunparse where needed in static checks (#42503)
Browse files Browse the repository at this point in the history
  • Loading branch information
ashb authored Sep 26, 2024
1 parent 9d01d03 commit 3de9e14
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions hatch_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@
"blinker>=1.7.0",
],
"devel-static-checks": [
"astunparse>=1.6.3; python_version < '3.9'",
"black>=23.12.0",
"pre-commit>=3.5.0",
"ruff==0.5.5",
Expand Down
8 changes: 7 additions & 1 deletion scripts/ci/pre_commit/check_deferrable_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@
import sys
from typing import Iterator

if hasattr(ast, "unparse"):
# Py 3.9+
unparse = ast.unparse
else:
from astunparse import unparse # type: ignore[no-redef]

import libcst as cst
from libcst.codemod import CodemodContext
from libcst.codemod.visitors import AddImportsVisitor
Expand Down Expand Up @@ -78,7 +84,7 @@ def leave_Param(self, original_node: cst.Param, updated_node: cst.Param) -> cst.

def _is_valid_deferrable_default(default: ast.AST) -> bool:
"""Check whether default is 'conf.getboolean("operators", "default_deferrable", fallback=False)'"""
return ast.unparse(default) == "conf.getboolean('operators', 'default_deferrable', fallback=False)"
return unparse(default) == "conf.getboolean('operators', 'default_deferrable', fallback=False)"


def iter_check_deferrable_default_errors(module_filename: str) -> Iterator[str]:
Expand Down

0 comments on commit 3de9e14

Please sign in to comment.