Skip to content

Commit

Permalink
Round #3 of removing string_types
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric-Arellano committed Jun 29, 2019
1 parent 717b593 commit 6f1b9d9
Show file tree
Hide file tree
Showing 8 changed files with 7 additions and 19 deletions.
1 change: 0 additions & 1 deletion src/python/pants/base/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ python_library(
dependencies=[
'3rdparty/python/twitter/commons:twitter.common.collections',
'3rdparty/python/twitter/commons:twitter.common.dirutil',
'3rdparty/python:six',
],
)

Expand Down
3 changes: 1 addition & 2 deletions src/python/pants/base/validation.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# Copyright 2014 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).

from six import string_types
from twitter.common.collections import OrderedSet
from twitter.common.dirutil.fileset import Fileset


def assert_list(obj, expected_type=string_types, can_be_none=True, default=(), key_arg=None,
def assert_list(obj, expected_type=str, can_be_none=True, default=(), key_arg=None,
allowable=(list, Fileset, OrderedSet, set, tuple), raise_type=ValueError):
"""
This function is used to ensure that parameters set by users in BUILD files are of acceptable types.
Expand Down
1 change: 0 additions & 1 deletion src/python/pants/ivy/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
python_library(
dependencies = [
'3rdparty/python/twitter/commons:twitter.common.collections',
'3rdparty/python:six',
'src/python/pants/base:build_environment',
'src/python/pants/java/distribution',
'src/python/pants/java:executor',
Expand Down
5 changes: 2 additions & 3 deletions src/python/pants/ivy/ivy.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import os.path
from contextlib import contextmanager

from six import string_types
from twitter.common.collections import maybe_list

from pants.java import util
Expand Down Expand Up @@ -33,12 +32,12 @@ def __init__(self, classpath, ivy_settings=None, ivy_resolution_cache_dir=None,
"""
self._classpath = maybe_list(classpath)
self._ivy_settings = ivy_settings
if self._ivy_settings and not isinstance(self._ivy_settings, string_types):
if self._ivy_settings and not isinstance(self._ivy_settings, str):
raise ValueError('ivy_settings must be a string, given {} of type {}'.format(
self._ivy_settings, type(self._ivy_settings)))

self._ivy_resolution_cache_dir = ivy_resolution_cache_dir
if not isinstance(self._ivy_resolution_cache_dir, string_types):
if not isinstance(self._ivy_resolution_cache_dir, str):
raise ValueError('ivy_resolution_cache_dir must be a string, given {} of type {}'.format(
self._ivy_resolution_cache_dir, type(self._ivy_resolution_cache_dir)))

Expand Down
2 changes: 1 addition & 1 deletion src/python/pants/net/http/fetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ def download(self, url, listener=None, path_or_fd=None, chunk_size_bytes=None, t
"""
@contextmanager
def download_fp(_path_or_fd):
if _path_or_fd and not isinstance(_path_or_fd, six.string_types):
if _path_or_fd and not isinstance(_path_or_fd, str):
yield _path_or_fd, _path_or_fd.name
else:
if not _path_or_fd:
Expand Down
8 changes: 2 additions & 6 deletions src/python/pants/option/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from contextlib import contextmanager
from hashlib import sha1

import six
from twitter.common.collections import OrderedSet

from pants.base.build_environment import get_buildroot, get_pants_cachedir, get_pants_configdir
Expand Down Expand Up @@ -123,7 +122,7 @@ def update_dir_from_seed_values(key, default):

return configparser.ConfigParser(all_seed_values)

def get(self, section, option, type_=six.string_types, default=None):
def get(self, section, option, type_=str, default=None):
"""Retrieves option from the specified section (or 'DEFAULT') and attempts to parse it as type.
If the specified section does not exist or is missing a definition for the option, the value is
Expand All @@ -137,10 +136,7 @@ def _getinstance(self, section, option, type_, default=None):
return default

raw_value = self.get_value(section, option)
# We jump through some hoops here to deal with the fact that `six.string_types` is a tuple of
# types.
if (type_ == six.string_types or
(isinstance(type_, type) and issubclass(type_, six.string_types))):
if type_ == str:
return raw_value

key = '{}.{}'.format(section, option)
Expand Down
1 change: 0 additions & 1 deletion src/python/pants/util/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ python_library(
sources = ['contextutil.py'],
dependencies = [
'3rdparty/python:ansicolors',
'3rdparty/python:future',
':dirutil',
':tarutil',
],
Expand Down
5 changes: 1 addition & 4 deletions src/python/pants/util/contextutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from socketserver import TCPServer

from colors import green
from future.utils import string_types

from pants.util.dirutil import safe_delete
from pants.util.tarutil import TarFile
Expand Down Expand Up @@ -291,9 +290,7 @@ def open_tar(path_or_file, *args, **kwargs):
If path_or_file is a file, caller must close it separately.
"""
(path, fileobj) = ((path_or_file, None) if isinstance(path_or_file, string_types)
else (None, path_or_file)) # TODO(#6071): stop using six.string_types
# This should only accept python3 `str`, not byte strings.
(path, fileobj) = (path_or_file, None) if isinstance(path_or_file, str) else (None, path_or_file)
with closing(TarFile.open(path, *args, fileobj=fileobj, **kwargs)) as tar:
yield tar

Expand Down

0 comments on commit 6f1b9d9

Please sign in to comment.