From ac495a3a4bb6f5485310e15dfa8e45adc96dc300 Mon Sep 17 00:00:00 2001 From: Kai Chen Date: Wed, 22 Jul 2020 13:35:45 -0700 Subject: [PATCH] Use abstract base class for ShellComplete --- src/click/shell_completion.py | 10 +++++++--- tests/test_imports.py | 1 + 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/click/shell_completion.py b/src/click/shell_completion.py index 098852caf..48347329f 100644 --- a/src/click/shell_completion.py +++ b/src/click/shell_completion.py @@ -1,6 +1,8 @@ import copy import os import re +from abc import ABC +from abc import abstractmethod from collections import abc from subprocess import PIPE from subprocess import run @@ -125,7 +127,7 @@ def start_of_option(param_str): return param_str and param_str[:1] == "-" -class ShellComplete: +class ShellComplete(ABC): """The ShellComplete class acts as the minimal API contract of a completion class. It is not intended to be used directly as :meth:`source` and :meth:`complete` must be overridden. @@ -146,6 +148,7 @@ def __init__(self, prog_name, complete_var, cli): self.complete_var = complete_var self.cli = cli + @abstractmethod def source(self): """Returns the string to be echoed during activation, and is automatically invoked by :func:`shell_complete`. The string @@ -154,8 +157,9 @@ def source(self): The default implementation is raising a not implemented error. """ - raise NotImplementedError("source function needs to be overridden") + pass + @abstractmethod def complete(self): """This function is automatically invoked during completion by :func:`shell_complete`. It can be used to get completion responses @@ -165,7 +169,7 @@ def complete(self): The default implementation is raising a not implemented error. """ - raise NotImplementedError("complete function needs to be overridden") + pass class BashComplete(ShellComplete): diff --git a/tests/test_imports.py b/tests/test_imports.py index b52fc4910..f1d8dd2f6 100644 --- a/tests/test_imports.py +++ b/tests/test_imports.py @@ -48,6 +48,7 @@ def tracking_import(module, locals=None, globals=None, fromlist=None, "pipes", "subprocess", "copy", + "abc", } if WIN: