Skip to content

Commit

Permalink
Use abstract base class for ShellComplete
Browse files Browse the repository at this point in the history
  • Loading branch information
kx-chen committed Jul 22, 2020
1 parent b6f7f64 commit ac495a3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/click/shell_completion.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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):
Expand Down
1 change: 1 addition & 0 deletions tests/test_imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def tracking_import(module, locals=None, globals=None, fromlist=None,
"pipes",
"subprocess",
"copy",
"abc",
}

if WIN:
Expand Down

0 comments on commit ac495a3

Please sign in to comment.