From 1ec519b1e2333e8cda41cf618036d49851494130 Mon Sep 17 00:00:00 2001 From: Jannis Kowalick Date: Wed, 16 Feb 2022 21:25:44 +0200 Subject: [PATCH] fix type checking for pyright the variable assignment of pathlib confused pyright. This is some magic to enusre that both mypy and pyright correctly understand the type signatures. --- scp.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/scp.py b/scp.py index 52ef0a1..b058123 100644 --- a/scp.py +++ b/scp.py @@ -36,8 +36,11 @@ if TYPE_CHECKING: import paramiko.transport - # unconditionally adding pathlib here because typing only works in python3 anyways and it's in stdlib - PathTypes = Union[str, bytes, "pathlib.PurePath"] + # this is some magic to make sure pyright doesn't get too confused with pathlib potentially being a nullable variable + import pathlib + PurePath = pathlib.PurePath + + PathTypes = Union[str, bytes, PurePath] except ImportError: pass