Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ def test_absolute_outside(self, tmp_cwd):
assert formatted == filepath
assert formatted.is_absolute()

def test_path_is_cwd(self, tmp_cwd):
filepath = pathlib.Path.cwd()
formatted = utils.format_path(filepath)
assert formatted == pathlib.Path(".")
assert not formatted.is_absolute()


def check_decorator_names(code, expected_names):
decorator_names = []
Expand Down
10 changes: 5 additions & 5 deletions vulture/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,27 +45,27 @@ def _safe_eval(node, default):
return default


def condition_is_always_false(condition):
def condition_is_always_false(condition: ast.AST) -> bool:
return not _safe_eval(condition, True)


def condition_is_always_true(condition):
def condition_is_always_true(condition: ast.AST) -> bool:
return _safe_eval(condition, False)


def is_ast_string(node):
def is_ast_string(node: ast.AST) -> bool:
return isinstance(node, ast.Constant) and isinstance(node.value, str)


def format_path(path):
def format_path(path: pathlib.Path) -> pathlib.Path:
try:
return path.relative_to(pathlib.Path.cwd())
except ValueError:
# Path is not below the current directory.
return path


def get_decorator_name(decorator):
def get_decorator_name(decorator: ast.expr) -> str:
if isinstance(decorator, ast.Call):
decorator = decorator.func
try:
Expand Down
Loading