File: util.py

package info (click to toggle)
python-refurb 1.27.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,700 kB
  • sloc: python: 9,468; makefile: 40; sh: 6
file content (17 lines) | stat: -rw-r--r-- 534 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
from mypy.nodes import CallExpr, Expression, NameExpr, OpExpr, RefExpr, Var


def is_pathlike(expr: Expression) -> bool:
    # TODO: just check that the expression is of type `Path` once we actually
    # get proper type checking
    match expr:
        case CallExpr(callee=RefExpr(fullname="pathlib.Path")):
            return True

        case NameExpr(node=Var(type=ty)) if str(ty) == "pathlib.Path":
            return True

        case OpExpr(left=left, op="/") if is_pathlike(left):
            return True

    return False