Skip to content

Commit 3f0a00a

Browse files
make mypy happy
1 parent 36d80e2 commit 3f0a00a

File tree

3 files changed

+27
-11
lines changed

3 files changed

+27
-11
lines changed

src/borg/fuse.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,17 @@
99
import time
1010
from collections import defaultdict, Counter
1111
from signal import SIGINT
12+
from typing import TYPE_CHECKING
1213

1314
from .constants import ROBJ_FILE_STREAM, zeros
14-
from .fuse_impl import llfuse, has_pyfuse3, ENOATTR
15+
16+
if TYPE_CHECKING:
17+
# For type checking, assume llfuse is available
18+
# This allows mypy to understand llfuse.Operations
19+
import llfuse
20+
from .fuse_impl import has_pyfuse3, ENOATTR
21+
else:
22+
from .fuse_impl import llfuse, has_pyfuse3, ENOATTR
1523

1624

1725
if has_pyfuse3:

src/borg/fuse_impl.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,46 +4,50 @@
44

55
import errno
66
import os
7+
import types
78

89
ENOATTR = getattr(errno, "ENOATTR", getattr(errno, "ENODATA", None))
910

1011
BORG_FUSE_IMPL = os.environ.get("BORG_FUSE_IMPL", "mfusepy,pyfuse3,llfuse")
1112

13+
hlfuse: types.ModuleType | None = None
14+
llfuse: types.ModuleType | None = None
15+
1216
for FUSE_IMPL in BORG_FUSE_IMPL.split(","):
1317
FUSE_IMPL = FUSE_IMPL.strip()
1418
if FUSE_IMPL == "pyfuse3":
1519
try:
16-
import pyfuse3 as llfuse
20+
import pyfuse3
1721
except ImportError:
1822
pass
1923
else:
24+
llfuse = pyfuse3
2025
has_llfuse = False
2126
has_pyfuse3 = True
2227
has_mfusepy = False
2328
has_any_fuse = True
2429
ENOATTR = llfuse.ENOATTR
25-
hlfuse = None # noqa
2630
break
2731
elif FUSE_IMPL == "llfuse":
2832
try:
29-
import llfuse
33+
import llfuse as llfuse_module
3034
except ImportError:
3135
pass
3236
else:
37+
llfuse = llfuse_module
3338
has_llfuse = True
3439
has_pyfuse3 = False
3540
has_mfusepy = False
3641
has_any_fuse = True
3742
ENOATTR = llfuse.ENOATTR
38-
hlfuse = None # noqa
3943
break
4044
elif FUSE_IMPL == "mfusepy":
4145
try:
42-
import mfusepy as hlfuse
46+
import mfusepy
4347
except ImportError:
4448
pass
4549
else:
46-
llfuse = None # noqa
50+
hlfuse = mfusepy
4751
has_llfuse = False
4852
has_pyfuse3 = False
4953
has_mfusepy = True
@@ -55,8 +59,6 @@
5559
else:
5660
raise RuntimeError("Unknown FUSE implementation in BORG_FUSE_IMPL: '%s'." % BORG_FUSE_IMPL)
5761
else:
58-
llfuse = None # noqa
59-
hlfuse = None # noqa
6062
has_llfuse = False
6163
has_pyfuse3 = False
6264
has_mfusepy = False

src/borg/hlfuse.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,16 @@
55
import stat
66
import time
77
from collections import Counter
8+
from typing import TYPE_CHECKING
89

910
from .constants import ROBJ_FILE_STREAM, zeros, ROBJ_DONTCARE
1011

11-
from .fuse_impl import hlfuse
12+
if TYPE_CHECKING:
13+
# For type checking, assume mfusepy is available
14+
# This allows mypy to understand hlfuse.Operations
15+
import mfusepy as hlfuse
16+
else:
17+
from .fuse_impl import hlfuse
1218

1319
from .logger import create_logger
1420

@@ -28,7 +34,7 @@
2834
from .remote import RemoteRepository
2935

3036
BLOCK_SIZE = 512 # Standard filesystem block size for st_blocks and statfs
31-
DEBUG_LOG = None # os.path.join(os.getcwd(), "fuse_debug.log")
37+
DEBUG_LOG: str | None = None # os.path.join(os.getcwd(), "fuse_debug.log")
3238

3339

3440
def debug_log(msg):

0 commit comments

Comments
 (0)