Skip to content

Commit b41d9c7

Browse files
committed
use _HAVE_ARGCOMPLETE flag for import argcomplete
Setting autocomplete to None if it can not be imported from argcomplete now causes mypy to fail with > src/packagename/cli.py:17: error: Incompatible types in assignment (expression has type "None", variable has type "CompletionFinder") [assignment] I'm not aware of a way to add an Optional type hint to autocomplete, so instead of assigning None to it, add a flag named _HAVE_AUTOCOMPLETE to track whether it has been imported. Signed-off-by: Kevin Locke <[email protected]>
1 parent 2468b69 commit b41d9c7

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/packagename/cli.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@
1212
from typing import Any, Sequence
1313

1414
try:
15-
from argcomplete import autocomplete # type: ignore
15+
from argcomplete import autocomplete
16+
17+
_HAVE_AUTOCOMPLETE = True
1618
except ImportError:
17-
autocomplete = None
19+
_HAVE_AUTOCOMPLETE = False
1820

1921
from . import __version__
2022

@@ -105,7 +107,7 @@ def main(argv: Sequence[str] = sys.argv) -> int:
105107
prog=os.path.basename(argv[0]),
106108
)
107109

108-
if autocomplete:
110+
if _HAVE_AUTOCOMPLETE:
109111
exit_code = None
110112

111113
def exit_method(code: int = 0) -> None:

0 commit comments

Comments
 (0)