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

Drop Python 2 compatible code #233

Merged
merged 1 commit into from
Feb 2, 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
1 change: 0 additions & 1 deletion knack/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from __future__ import print_function
import os
import sys
from collections import defaultdict
Expand Down
9 changes: 4 additions & 5 deletions knack/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
from collections import OrderedDict, defaultdict
from importlib import import_module

import six

from .deprecation import Deprecated
from .preview import PreviewItem
from .experimental import ExperimentalItem
Expand Down Expand Up @@ -152,7 +150,7 @@ def _user_confirmed(confirmation, command_args):
if callable(confirmation):
return confirmation(command_args)
try:
if isinstance(confirmation, six.string_types):
if isinstance(confirmation, str):
return prompt_y_n(confirmation)
return prompt_y_n('Are you sure you want to perform this operation?')
except NoTTYException:
Expand Down Expand Up @@ -242,7 +240,7 @@ def _apply_parameter_info(self, command_name, command):

def create_command(self, name, operation, **kwargs):
""" Constructs the command object that can then be added to the command table """
if not isinstance(operation, six.string_types):
if not isinstance(operation, str):
raise ValueError("Operation must be a string. Got '{}'".format(operation))

name = ' '.join(name.split())
Expand Down Expand Up @@ -278,7 +276,8 @@ def _get_op_handler(operation):
op = getattr(op, part)
if isinstance(op, types.FunctionType):
return op
return six.get_method_function(op)
# MethodType
return op.__func__
except (ValueError, AttributeError):
raise ValueError("The operation '{}' is invalid.".format(operation))

Expand Down
6 changes: 2 additions & 4 deletions knack/deprecation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from six import string_types as STRING_TYPES

from .util import StatusTag

DEFAULT_DEPRECATED_TAG = '[Deprecated]'
Expand Down Expand Up @@ -40,7 +38,7 @@ def ensure_new_style_deprecation(cli_ctx, kwargs, object_type):
deprecate_info = kwargs.get('deprecate_info', None)
if isinstance(deprecate_info, Deprecated):
deprecate_info.object_type = object_type
elif isinstance(deprecate_info, STRING_TYPES):
elif isinstance(deprecate_info, str):
deprecate_info = Deprecated(cli_ctx, redirect=deprecate_info, object_type=object_type)
kwargs['deprecate_info'] = deprecate_info
return deprecate_info
Expand Down Expand Up @@ -111,7 +109,7 @@ def hidden(self):
hidden = False
if isinstance(self.hide, bool):
hidden = self.hide
elif isinstance(self.hide, STRING_TYPES):
elif isinstance(self.hide, str):
hidden = self._version_less_than_or_equal_to(self.hide, self._cli_version)
return hidden

Expand Down
1 change: 0 additions & 1 deletion knack/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from __future__ import print_function, unicode_literals
import argparse
import sys
import textwrap
Expand Down
2 changes: 0 additions & 2 deletions knack/invocation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from __future__ import print_function

import sys

from collections import defaultdict
Expand Down
12 changes: 5 additions & 7 deletions knack/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,22 @@
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from __future__ import print_function

import errno
import json
import traceback
from collections import OrderedDict
from six import StringIO, text_type, u, string_types
from io import StringIO

from .util import CLIError, CommandResultItem, CtxTypeError
from .events import EVENT_INVOKER_POST_PARSE_ARGS, EVENT_PARSER_GLOBAL_CREATE
from .log import get_logger
from .util import CLIError, CommandResultItem, CtxTypeError

logger = get_logger(__name__)


def _decode_str(output):
if not isinstance(output, text_type):
output = u(str(output))
if not isinstance(output, str):
output = str(output)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unicode is already the default in Python 3.

return output


Expand Down Expand Up @@ -227,7 +225,7 @@ def _dump_obj(data, stream):
# and a dictionary value in other...
stream.write('')
else:
to_write = data if isinstance(data, string_types) else str(data)
to_write = data if isinstance(data, str) else str(data)
stream.write(to_write)

@staticmethod
Expand Down
2 changes: 0 additions & 2 deletions knack/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from __future__ import print_function

import argparse

from .deprecation import Deprecated
Expand Down
2 changes: 0 additions & 2 deletions knack/prompting.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from __future__ import print_function
import sys
import getpass
from six.moves import input

from .log import get_logger

Expand Down
8 changes: 4 additions & 4 deletions knack/testsdk/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import tempfile
import shutil
import logging
import six
import io
import vcr

from .patches import patch_time_sleep_api
Expand Down Expand Up @@ -161,7 +161,7 @@ def _process_response_recording(self, response):
response['headers'] = headers

body = response['body']['string']
if body and not isinstance(body, six.string_types):
if body and not isinstance(body, str):
response['body']['string'] = body.decode('utf-8')

for processor in self.recording_processors:
Expand All @@ -179,7 +179,7 @@ def _process_response_recording(self, response):
@classmethod
def _custom_request_query_matcher(cls, r1, r2):
""" Ensure method, path, and query parameters match. """
from six.moves.urllib_parse import urlparse, parse_qs # pylint: disable=useless-suppression
from urllib.parse import urlparse, parse_qs # pylint: disable=useless-suppression

url1 = urlparse(r1.uri)
url2 = urlparse(r2.uri)
Expand Down Expand Up @@ -244,7 +244,7 @@ def _in_process_execute(self, command):
if command.startswith(cli_name_prefixed):
command = command[len(cli_name_prefixed):]

out_buffer = six.StringIO()
out_buffer = io.StringIO()
try:
# issue: stderr cannot be redirect in this form, as a result some failure information
# is lost when command fails.
Expand Down
3 changes: 1 addition & 2 deletions knack/testsdk/recording_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,11 @@ def process_response(self, response):

class LargeResponseBodyReplacer(RecordingProcessor):
def process_response(self, response):
import six
body = response['body']['string']

# backward compatibility. under 2.7 response body is unicode, under 3.5 response body is
# bytes. when set the value back, the same type must be used.
body_is_string = isinstance(body, six.string_types)
body_is_string = isinstance(body, str)

content_in_string = (response['body']['string'] or b'').decode('utf-8')
index = content_in_string.find(LargeResponseBodyProcessor.control_flag)
Expand Down
1 change: 0 additions & 1 deletion scripts/license_verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

# Verify that all *.py files have a license header in the file.

from __future__ import print_function
import os
import sys

Expand Down
2 changes: 0 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from __future__ import print_function
from codecs import open
from setuptools import setup, find_packages

Expand All @@ -17,7 +16,6 @@
'jmespath',
'pygments',
'pyyaml',
'six',
'tabulate'
]

Expand Down
2 changes: 1 addition & 1 deletion tests/test_cli_scenarios.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from unittest import mock
import mock

from six import StringIO
from io import StringIO

from knack import CLI
from knack.commands import CLICommand, CLICommandsLoader
Expand Down
1 change: 0 additions & 1 deletion tests/test_command_with_configured_defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
from __future__ import print_function
import os
import logging
import sys
Expand Down
2 changes: 0 additions & 2 deletions tests/test_deprecation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from __future__ import unicode_literals

import unittest
try:
import mock
Expand Down
2 changes: 0 additions & 2 deletions tests/test_experimental.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from __future__ import unicode_literals, print_function

import unittest
try:
import mock
Expand Down
4 changes: 1 addition & 3 deletions tests/test_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from __future__ import print_function

import unittest
import mock
from collections import OrderedDict
from six import StringIO
from io import StringIO

from knack.output import OutputProducer, format_json, format_json_color, format_yaml, format_yaml_color, \
format_table, format_tsv
Expand Down
2 changes: 1 addition & 1 deletion tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# --------------------------------------------------------------------------------------------

import unittest
from six import StringIO
from io import StringIO

from knack.parser import CLICommandParser
from knack.commands import CLICommand
Expand Down
3 changes: 0 additions & 3 deletions tests/test_preview.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from __future__ import unicode_literals, print_function

import os
import unittest
try:
import mock
Expand Down
2 changes: 1 addition & 1 deletion tests/test_prompting.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import mock
except ImportError:
from unittest import mock
from six import StringIO
from io import StringIO

from knack.prompting import (verify_is_a_tty, NoTTYException, _INVALID_PASSWORD_MSG, prompt,
prompt_int, prompt_pass, prompt_y_n, prompt_t_f, prompt_choice_list)
Expand Down
2 changes: 1 addition & 1 deletion tests/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import tempfile
import shutil
import os
from six import StringIO
from io import StringIO
import logging
from knack.log import CLI_LOGGER_NAME

Expand Down