summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--examples/aliases/aliases.py6
-rw-r--r--examples/complex/complex/cli.py2
-rw-r--r--examples/validation/validation.py7
-rw-r--r--src/click/_bashcomplete.py6
-rw-r--r--src/click/_termui_impl.py3
-rw-r--r--src/click/_winconsole.py6
-rw-r--r--src/click/termui.py12
-rw-r--r--src/click/testing.py8
-rw-r--r--src/click/types.py9
-rw-r--r--src/click/utils.py9
-rw-r--r--tests/test_imports.py9
-rw-r--r--tests/test_utils.py19
12 files changed, 25 insertions, 71 deletions
diff --git a/examples/aliases/aliases.py b/examples/aliases/aliases.py
index e7f850d..bf09500 100644
--- a/examples/aliases/aliases.py
+++ b/examples/aliases/aliases.py
@@ -1,12 +1,8 @@
+import configparser
import os
import click
-try:
- import configparser
-except ImportError:
- import ConfigParser as configparser
-
class Config(object):
"""The config in this example only holds aliases."""
diff --git a/examples/complex/complex/cli.py b/examples/complex/complex/cli.py
index c539fe8..bb43613 100644
--- a/examples/complex/complex/cli.py
+++ b/examples/complex/complex/cli.py
@@ -39,8 +39,6 @@ class ComplexCLI(click.MultiCommand):
def get_command(self, ctx, name):
try:
- if sys.version_info[0] == 2:
- name = name.encode("ascii", "replace")
mod = __import__(
"complex.commands.cmd_{}".format(name), None, None, ["cli"]
)
diff --git a/examples/validation/validation.py b/examples/validation/validation.py
index c4f7352..3ca5745 100644
--- a/examples/validation/validation.py
+++ b/examples/validation/validation.py
@@ -1,9 +1,6 @@
-import click
+from urllib import parse as urlparse
-try:
- from urllib import parse as urlparse
-except ImportError:
- import urlparse
+import click
def validate_count(ctx, param, value):
diff --git a/src/click/_bashcomplete.py b/src/click/_bashcomplete.py
index cbabd8d..9e963f7 100644
--- a/src/click/_bashcomplete.py
+++ b/src/click/_bashcomplete.py
@@ -1,6 +1,7 @@
import copy
import os
import re
+from collections import abc
from .core import Argument
from .core import MultiCommand
@@ -9,11 +10,6 @@ from .parser import split_arg_string
from .types import Choice
from .utils import echo
-try:
- from collections import abc
-except ImportError:
- import collections as abc
-
WORDBREAK = "="
# Note, only BASH version 4.4 and later have the nosort option.
diff --git a/src/click/_termui_impl.py b/src/click/_termui_impl.py
index 1a6adf1..2ea695e 100644
--- a/src/click/_termui_impl.py
+++ b/src/click/_termui_impl.py
@@ -125,9 +125,6 @@ class ProgressBar(object):
# twice works and does "what you want".
return next(iter(self))
- # Python 2 compat
- next = __next__
-
def is_fast(self):
return time.time() - self.start <= self.short_limit
diff --git a/src/click/_winconsole.py b/src/click/_winconsole.py
index 18310ad..5a3cdaa 100644
--- a/src/click/_winconsole.py
+++ b/src/click/_winconsole.py
@@ -32,11 +32,11 @@ from ._compat import _NonClosingTextIOWrapper
try:
from ctypes import pythonapi
-
- PyObject_GetBuffer = pythonapi.PyObject_GetBuffer
- PyBuffer_Release = pythonapi.PyBuffer_Release
except ImportError:
pythonapi = None
+else:
+ PyObject_GetBuffer = pythonapi.PyObject_GetBuffer
+ PyBuffer_Release = pythonapi.PyBuffer_Release
c_ssize_p = POINTER(c_ssize_t)
diff --git a/src/click/termui.py b/src/click/termui.py
index 73f35f5..dd51cdf 100644
--- a/src/click/termui.py
+++ b/src/click/termui.py
@@ -216,14 +216,10 @@ def get_terminal_size():
"""Returns the current size of the terminal as tuple in the form
``(width, height)`` in columns and rows.
"""
- # If shutil has get_terminal_size() (Python 3.3 and later) use that
- if sys.version_info >= (3, 3):
- import shutil
-
- shutil_get_terminal_size = getattr(shutil, "get_terminal_size", None)
- if shutil_get_terminal_size:
- sz = shutil_get_terminal_size()
- return sz.columns, sz.lines
+ import shutil
+
+ if hasattr(shutil, "get_terminal_size"):
+ return shutil.get_terminal_size()
# We provide a sensible default for get_winterm_size() when being invoked
# inside a subprocess. Without this, it would not provide a useful input.
diff --git a/src/click/testing.py b/src/click/testing.py
index 9c3c012..eef3399 100644
--- a/src/click/testing.py
+++ b/src/click/testing.py
@@ -110,9 +110,7 @@ class CliRunner(object):
works in single-threaded systems without any concurrency as it changes the
global interpreter state.
- :param charset: the character set for the input and output data. This is
- UTF-8 by default and should not be changed currently as
- the reporting to Click only works in Python 2 properly.
+ :param charset: the character set for the input and output data.
:param env: a dictionary with environment variables for overriding.
:param echo_stdin: if this is set to `True`, then reading from stdin writes
to stdout. This is useful for showing examples in
@@ -125,9 +123,7 @@ class CliRunner(object):
independently
"""
- def __init__(self, charset=None, env=None, echo_stdin=False, mix_stderr=True):
- if charset is None:
- charset = "utf-8"
+ def __init__(self, charset="utf-8", env=None, echo_stdin=False, mix_stderr=True):
self.charset = charset
self.env = env or {}
self.echo_stdin = echo_stdin
diff --git a/src/click/types.py b/src/click/types.py
index 5647df5..d794235 100644
--- a/src/click/types.py
+++ b/src/click/types.py
@@ -721,11 +721,10 @@ def convert_type(ty, default=None):
#: A dummy parameter type that just does nothing. From a user's
-#: perspective this appears to just be the same as `STRING` but internally
-#: no string conversion takes place. This is necessary to achieve the
-#: same bytes/unicode behavior on Python 2/3 in situations where you want
-#: to not convert argument types. This is usually useful when working
-#: with file paths as they can appear in bytes and unicode.
+#: perspective this appears to just be the same as `STRING` but
+#: internally no string conversion takes place if the input was bytes.
+#: This is usually useful when working with file paths as they can
+#: appear in bytes and unicode.
#:
#: For path related uses the :class:`Path` type is a better choice but
#: there are situations where an unprocessed type is useful which is why
diff --git a/src/click/utils.py b/src/click/utils.py
index f5aac49..0f634bb 100644
--- a/src/click/utils.py
+++ b/src/click/utils.py
@@ -232,11 +232,10 @@ def echo(message=None, file=None, nl=True, err=False, color=None):
else:
message += b"\n"
- # If there is a message, and we're in Python 3, and the value looks
- # like bytes, we manually need to find the binary stream and write the
- # message in there. This is done separately so that most stream
- # types will work as you would expect. Eg: you can write to StringIO
- # for other cases.
+ # If there is a message and the value looks like bytes, we manually
+ # need to find the binary stream and write the message in there.
+ # This is done separately so that most stream types will work as you
+ # would expect. Eg: you can write to StringIO for other cases.
if message and is_bytes(message):
binary_file = _find_binary_writer(file)
if binary_file is not None:
diff --git a/tests/test_imports.py b/tests/test_imports.py
index b99d453..be8730f 100644
--- a/tests/test_imports.py
+++ b/tests/test_imports.py
@@ -6,10 +6,7 @@ from click._compat import WIN
IMPORT_TEST = b"""\
-try:
- import __builtin__ as builtins
-except ImportError:
- import builtins
+import builtins
found_imports = set()
real_import = builtins.__import__
@@ -61,9 +58,7 @@ def test_light_imports():
[sys.executable, "-"], stdin=subprocess.PIPE, stdout=subprocess.PIPE
)
rv = c.communicate(IMPORT_TEST)[0]
-
- if sys.version_info[0] != 2:
- rv = rv.decode("utf-8")
+ rv = rv.decode("utf-8")
imported = json.loads(rv)
for module in imported:
diff --git a/tests/test_utils.py b/tests/test_utils.py
index d86f59b..2ca1a8a 100644
--- a/tests/test_utils.py
+++ b/tests/test_utils.py
@@ -1,6 +1,7 @@
import os
import stat
import sys
+from io import StringIO
import pytest
@@ -19,19 +20,7 @@ def test_echo(runner):
bytes = outstreams[0].getvalue().replace(b"\r\n", b"\n")
assert bytes == b"\xe2\x98\x83\nDD\n42ax"
- # If we are in Python 2, we expect that writing bytes into a string io
- # does not do anything crazy. In Python 3
- if sys.version_info[0] == 2:
- import StringIO
-
- sys.stdout = x = StringIO.StringIO()
- try:
- click.echo("\xf6")
- finally:
- sys.stdout = sys.__stdout__
- assert x.getvalue() == "\xf6\n"
-
- # And in any case, if wrapped, we expect bytes to survive.
+ # if wrapped, we expect bytes to survive.
@click.command()
def cli():
click.echo(b"\xf6")
@@ -224,10 +213,6 @@ def test_echo_color_flag(monkeypatch, capfd):
def test_echo_writing_to_standard_error(capfd, monkeypatch):
def emulate_input(text):
"""Emulate keyboard input."""
- if sys.version_info[0] == 2:
- from StringIO import StringIO
- else:
- from io import StringIO
monkeypatch.setattr(sys, "stdin", StringIO(text))
click.echo("Echo to standard output")