Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove deprecated code #2130

Merged
merged 4 commits into from
Nov 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ Version 8.1.0
Unreleased

- Drop support for Python 3.6. :pr:`2129`
- Remove previously deprecated code. :pr:`2130`

- ``Group.resultcallback`` is renamed to ``result_callback``.
- ``autocompletion`` parameter to ``Command`` is renamed to
``shell_complete``.
- ``get_terminal_size`` is removed, use
``shutil.get_terminal_size`` instead.
- ``get_os_args`` is removed, use ``sys.argv[1:]`` instead.

- Single options boolean flags with ``show_default=True`` only show
the default if it is ``True``. :issue:`1971`

Expand Down
2 changes: 0 additions & 2 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ Utilities

.. autofunction:: pause

.. autofunction:: get_terminal_size

.. autofunction:: get_binary_stream

.. autofunction:: get_text_stream
Expand Down
2 changes: 0 additions & 2 deletions src/click/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
from .termui import confirm as confirm
from .termui import echo_via_pager as echo_via_pager
from .termui import edit as edit
from .termui import get_terminal_size as get_terminal_size
from .termui import getchar as getchar
from .termui import launch as launch
from .termui import pause as pause
Expand All @@ -68,7 +67,6 @@
from .utils import format_filename as format_filename
from .utils import get_app_dir as get_app_dir
from .utils import get_binary_stream as get_binary_stream
from .utils import get_os_args as get_os_args
from .utils import get_text_stream as get_text_stream
from .utils import open_file as open_file

Expand Down
46 changes: 0 additions & 46 deletions src/click/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1568,17 +1568,6 @@ def function(__value, *args, **kwargs): # type: ignore

return decorator

def resultcallback(self, replace: bool = False) -> t.Callable[[F], F]:
import warnings

warnings.warn(
"'resultcallback' has been renamed to 'result_callback'."
" The old name will be removed in Click 8.1.",
DeprecationWarning,
stacklevel=2,
)
return self.result_callback(replace=replace)

def format_commands(self, ctx: Context, formatter: HelpFormatter) -> None:
"""Extra format methods for multi methods that adds all the commands
after the options.
Expand Down Expand Up @@ -2020,11 +2009,6 @@ def __init__(
t.Union[t.List["CompletionItem"], t.List[str]],
]
] = None,
autocompletion: t.Optional[
t.Callable[
[Context, t.List[str], str], t.List[t.Union[t.Tuple[str, str], str]]
]
] = None,
) -> None:
self.name, self.opts, self.secondary_opts = self._parse_decls(
param_decls or (), expose_value
Expand All @@ -2048,36 +2032,6 @@ def __init__(
self.is_eager = is_eager
self.metavar = metavar
self.envvar = envvar

if autocompletion is not None:
import warnings

warnings.warn(
"'autocompletion' is renamed to 'shell_complete'. The old name is"
" deprecated and will be removed in Click 8.1. See the docs about"
" 'Parameter' for information about new behavior.",
DeprecationWarning,
stacklevel=2,
)

def shell_complete(
ctx: Context, param: "Parameter", incomplete: str
) -> t.List["CompletionItem"]:
from click.shell_completion import CompletionItem

out = []

for c in autocompletion(ctx, [], incomplete): # type: ignore
if isinstance(c, tuple):
c = CompletionItem(c[0], help=c[1])
elif isinstance(c, str):
c = CompletionItem(c)

if c.value.startswith(incomplete):
out.append(c)

return out

self._custom_shell_complete = shell_complete

if __debug__:
Expand Down
20 changes: 0 additions & 20 deletions src/click/termui.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,26 +252,6 @@ def confirm(
return rv


def get_terminal_size() -> os.terminal_size:
"""Returns the current size of the terminal as tuple in the form
``(width, height)`` in columns and rows.

.. deprecated:: 8.0
Will be removed in Click 8.1. Use
:func:`shutil.get_terminal_size` instead.
"""
import shutil
import warnings

warnings.warn(
"'click.get_terminal_size()' is deprecated and will be removed"
" in Click 8.1. Use 'shutil.get_terminal_size()' instead.",
DeprecationWarning,
stacklevel=2,
)
return shutil.get_terminal_size()


def echo_via_pager(
text_or_generator: t.Union[t.Iterable[str], t.Callable[[], t.Iterable[str]], str],
color: t.Optional[bool] = None,
Expand Down
19 changes: 0 additions & 19 deletions src/click/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,25 +379,6 @@ def open_file(
return f


def get_os_args() -> t.Sequence[str]:
"""Returns the argument part of ``sys.argv``, removing the first
value which is the name of the script.

.. deprecated:: 8.0
Will be removed in Click 8.1. Access ``sys.argv[1:]`` directly
instead.
"""
import warnings

warnings.warn(
"'get_os_args' is deprecated and will be removed in Click 8.1."
" Access 'sys.argv[1:]' directly instead.",
DeprecationWarning,
stacklevel=2,
)
return sys.argv[1:]


def format_filename(
filename: t.Union[str, bytes, os.PathLike], shorten: bool = False
) -> str:
Expand Down
14 changes: 0 additions & 14 deletions tests/test_shell_completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,20 +161,6 @@ def custom(ctx, param, incomplete):
assert _get_words(cli, ["a", "b"], "c") == ["C"]


def test_autocompletion_deprecated():
# old function takes args and not param, returns all values, can mix
# strings and tuples
def custom(ctx, args, incomplete):
assert isinstance(args, list)
return [("art", "x"), "bat", "cat"]

with pytest.deprecated_call():
cli = Command("cli", params=[Argument(["x"], autocompletion=custom)])

assert _get_words(cli, [], "") == ["art", "bat", "cat"]
assert _get_words(cli, [], "c") == ["cat"]


def test_option_multiple():
cli = Command(
"type",
Expand Down