Skip to content

Remove Python 2 compatibility shims #979

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

Merged
merged 32 commits into from
Feb 8, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
ff57c04
Remove str import from builtins
Harmon758 Feb 7, 2020
e0bf255
Remove unnecessary check for sys.getfilesystemencoding
Harmon758 Feb 7, 2020
142c779
Remove and replace compat.FileType
Harmon758 Feb 7, 2020
584ab08
Remove compat.byte_ord
Harmon758 Feb 7, 2020
e564c2f
Remove and replace compat.bchr
Harmon758 Feb 7, 2020
5444787
Remove and replace compat.mviter
Harmon758 Feb 7, 2020
3f21cb1
Remove compat.range
Harmon758 Feb 7, 2020
d0d2a86
Remove and replace compat.xrange
Harmon758 Feb 7, 2020
91e91b2
Remove and replace compat.unicode
Harmon758 Feb 7, 2020
c30880d
Remove Python 2 check for compat.defenc
Harmon758 Feb 7, 2020
2c4d556
Remove and replace compat.binary_type
Harmon758 Feb 7, 2020
8e55323
Remove and replace compat._unichr
Harmon758 Feb 7, 2020
18fc6b2
Remove and replace compat.bytes_chr
Harmon758 Feb 7, 2020
9615ada
Remove surrogateescape error handler for Python 2
Harmon758 Feb 7, 2020
5549ffe
Remove and replace compat.UnicodeMixin
Harmon758 Feb 7, 2020
60c8dc2
Remove checks for Python 2 and/or 3
Harmon758 Feb 7, 2020
6005b89
Remove Python 2 test
Harmon758 Feb 7, 2020
952eaad
Remove compat.PY3
Harmon758 Feb 7, 2020
266187b
Remove and replace compat.MAXSIZE
Harmon758 Feb 7, 2020
8a8b24e
Remove and replace compat.izip
Harmon758 Feb 7, 2020
07df7c9
Remove and replace compat.string_types
Harmon758 Feb 7, 2020
2f31261
Remove and replace compat.text_type
Harmon758 Feb 7, 2020
369de3d
Remove no longer used compat imports
Harmon758 Feb 7, 2020
92348df
Remove no longer used imports in tests
Harmon758 Feb 7, 2020
ebcdb8b
Remove attempt to import ConfigParser for Python 2
Harmon758 Feb 7, 2020
7f250ca
Remove check for Python 2.7
Harmon758 Feb 7, 2020
21d56e2
Remove unnecessary check for logging.NullHandler for Python 2.6
Harmon758 Feb 7, 2020
d96688f
Improve setup.py python_requires
Harmon758 Feb 7, 2020
d0cd5bf
Remove unnecessary check for PermissionError for Python < 3.3
Harmon758 Feb 7, 2020
a611adc
Add to AUTHORS
Harmon758 Feb 7, 2020
d0899a0
Fix requirements.txt formatting
Harmon758 Feb 7, 2020
c5f5911
Remove now unused is_invoking_git variable in test
Harmon758 Feb 7, 2020
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
Prev Previous commit
Next Next commit
Remove and replace compat.string_types
  • Loading branch information
Harmon758 committed Feb 7, 2020
commit 07df7c9ccb8006346873b101c6c0cf79d5244285
3 changes: 1 addition & 2 deletions git/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
from textwrap import dedent

from git.compat import (
string_types,
defenc,
force_bytes,
safe_decode,
Expand Down Expand Up @@ -1038,7 +1037,7 @@ def _prepare_ref(self, ref):
if isinstance(ref, bytes):
# Assume 40 bytes hexsha - bin-to-ascii for some reason returns bytes, not text
refstr = ref.decode('ascii')
elif not isinstance(ref, string_types):
elif not isinstance(ref, str):
refstr = str(ref) # could be ref-object

if not refstr.endswith("\n"):
Expand Down
1 change: 0 additions & 1 deletion git/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@


from gitdb.utils.encoding import (
string_types, # @UnusedImport
text_type, # @UnusedImport
force_bytes, # @UnusedImport
force_text # @UnusedImport
Expand Down
7 changes: 3 additions & 4 deletions git/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from collections import OrderedDict

from git.compat import (
string_types,
defenc,
force_text,
with_metaclass,
Expand Down Expand Up @@ -302,7 +301,7 @@ def _acquire_lock(self):
# END single file check

file_or_files = self._file_or_files
if not isinstance(self._file_or_files, string_types):
if not isinstance(self._file_or_files, str):
file_or_files = self._file_or_files.name
# END get filename from handle/stream
# initialize lock base - we want to write
Expand Down Expand Up @@ -578,7 +577,7 @@ def write(self):
fp = self._file_or_files

# we have a physical file on disk, so get a lock
is_file_lock = isinstance(fp, string_types + (IOBase, ))
is_file_lock = isinstance(fp, (str, IOBase))
if is_file_lock:
self._lock._obtain_lock()
if not hasattr(fp, "seek"):
Expand Down Expand Up @@ -670,7 +669,7 @@ def _string_to_value(self, valuestr):
if vl == 'true':
return True

if not isinstance(valuestr, string_types):
if not isinstance(valuestr, str):
raise TypeError(
"Invalid value type: only int, long, float and str are allowed",
valuestr)
Expand Down
4 changes: 2 additions & 2 deletions git/exc.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
""" Module containing all exceptions thrown throughout the git package, """

from gitdb.exc import * # NOQA @UnusedWildImport skipcq: PYL-W0401, PYL-W0614
from git.compat import safe_decode, string_types
from git.compat import safe_decode


class GitError(Exception):
Expand Down Expand Up @@ -50,7 +50,7 @@ def __init__(self, command, status=None, stderr=None, stdout=None):
status = u'exit code(%s)' % int(status)
except (ValueError, TypeError):
s = safe_decode(str(status))
status = u"'%s'" % s if isinstance(status, string_types) else s
status = u"'%s'" % s if isinstance(status, str) else s

self._cmd = safe_decode(command[0])
self._cmdline = u' '.join(safe_decode(i) for i in command)
Expand Down
9 changes: 4 additions & 5 deletions git/index/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import tempfile

from git.compat import (
string_types,
force_bytes,
defenc,
)
Expand Down Expand Up @@ -571,7 +570,7 @@ def _preprocess_add_items(self, items):
items = [items]

for item in items:
if isinstance(item, string_types):
if isinstance(item, str):
paths.append(self._to_relative_path(item))
elif isinstance(item, (Blob, Submodule)):
entries.append(BaseIndexEntry.from_blob(item))
Expand Down Expand Up @@ -808,7 +807,7 @@ def _items_to_rela_paths(self, items):
for item in items:
if isinstance(item, (BaseIndexEntry, (Blob, Submodule))):
paths.append(self._to_relative_path(item.path))
elif isinstance(item, string_types):
elif isinstance(item, str):
paths.append(self._to_relative_path(item))
else:
raise TypeError("Invalid item type: %r" % item)
Expand Down Expand Up @@ -1087,7 +1086,7 @@ def handle_stderr(proc, iter_checked_out_files):
handle_stderr(proc, rval_iter)
return rval_iter
else:
if isinstance(paths, string_types):
if isinstance(paths, str):
paths = [paths]

# make sure we have our entries loaded before we start checkout_index
Expand Down Expand Up @@ -1224,7 +1223,7 @@ def diff(self, other=diff.Diffable.Index, paths=None, create_patch=False, **kwar
# index against anything but None is a reverse diff with the respective
# item. Handle existing -R flags properly. Transform strings to the object
# so that we can call diff on it
if isinstance(other, string_types):
if isinstance(other, str):
other = self.repo.rev_parse(other)
# END object conversion

Expand Down
3 changes: 1 addition & 2 deletions git/objects/submodule/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import git
from git.cmd import Git
from git.compat import (
string_types,
defenc,
is_win,
)
Expand Down Expand Up @@ -110,7 +109,7 @@ def __init__(self, repo, binsha, mode=None, path=None, name=None, parent_commit=
if url is not None:
self._url = url
if branch_path is not None:
assert isinstance(branch_path, string_types)
assert isinstance(branch_path, str)
self._branch_path = branch_path
if name is not None:
self._name = name
Expand Down
3 changes: 1 addition & 2 deletions git/objects/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from .base import IndexObject
from .blob import Blob
from .submodule.base import Submodule
from git.compat import string_types

from .fun import (
tree_entries_from_data,
Expand Down Expand Up @@ -290,7 +289,7 @@ def __getitem__(self, item):
info = self._cache[item]
return self._map_id_to_type[info[1] >> 12](self.repo, info[0], info[1], join_path(self.path, info[2]))

if isinstance(item, string_types):
if isinstance(item, str):
# compatibility
return self.join(item)
# END index is basestring
Expand Down
7 changes: 2 additions & 5 deletions git/refs/log.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import re
import time

from git.compat import (
string_types,
defenc
)
from git.compat import defenc
from git.objects.util import (
parse_date,
Serializable,
Expand Down Expand Up @@ -185,7 +182,7 @@ def iter_entries(cls, stream):
:param stream: file-like object containing the revlog in its native format
or basestring instance pointing to a file to read"""
new_entry = RefLogEntry.from_line
if isinstance(stream, string_types):
if isinstance(stream, str):
stream = file_contents_ro_filepath(stream)
# END handle stream type
while True:
Expand Down
7 changes: 2 additions & 5 deletions git/refs/symbolic.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import os

from git.compat import (
string_types,
defenc
)
from git.compat import defenc
from git.objects import Object, Commit
from git.util import (
join_path,
Expand Down Expand Up @@ -300,7 +297,7 @@ def set_reference(self, ref, logmsg=None):
elif isinstance(ref, Object):
obj = ref
write_value = ref.hexsha
elif isinstance(ref, string_types):
elif isinstance(ref, str):
try:
obj = self.repo.rev_parse(ref + "^{}") # optionally deref tags
write_value = obj.hexsha
Expand Down
6 changes: 3 additions & 3 deletions git/test/lib/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import time
import unittest

from git.compat import string_types, is_win
from git.compat import is_win
from git.util import rmtree, cwd
import gitdb

Expand Down Expand Up @@ -117,7 +117,7 @@ def with_rw_repo(working_tree_ref, bare=False):
To make working with relative paths easier, the cwd will be set to the working
dir of the repository.
"""
assert isinstance(working_tree_ref, string_types), "Decorator requires ref name for working tree checkout"
assert isinstance(working_tree_ref, str), "Decorator requires ref name for working tree checkout"

def argument_passer(func):
@wraps(func)
Expand Down Expand Up @@ -248,7 +248,7 @@ def case(self, rw_repo, rw_daemon_repo)
"""
from git import Git, Remote # To avoid circular deps.

assert isinstance(working_tree_ref, string_types), "Decorator requires ref name for working tree checkout"
assert isinstance(working_tree_ref, str), "Decorator requires ref name for working tree checkout"

def argument_passer(func):

Expand Down
7 changes: 2 additions & 5 deletions git/test/test_commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@
Actor,
)
from git import Repo
from git.compat import (
string_types,
text_type
)
from git.compat import text_type
from git.objects.util import tzoffset, utc
from git.repo.fun import touch
from git.test.lib import (
Expand Down Expand Up @@ -276,7 +273,7 @@ def test_iter_parents(self):

def test_name_rev(self):
name_rev = self.rorepo.head.commit.name_rev
assert isinstance(name_rev, string_types)
assert isinstance(name_rev, str)

@with_rw_repo('HEAD', bare=True)
def test_serialization(self, rwrepo):
Expand Down
3 changes: 1 addition & 2 deletions git/test/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from git import (
GitConfigParser
)
from git.compat import string_types
from git.config import _OMD, cp
from git.test.lib import (
TestCase,
Expand Down Expand Up @@ -157,7 +156,7 @@ def test_base(self):
num_options += 1
val = r_config.get(section, option)
val_typed = r_config.get_value(section, option)
assert isinstance(val_typed, (bool, int, float, ) + string_types)
assert isinstance(val_typed, (bool, int, float, str))
assert val
assert "\n" not in option
assert "\n" not in val
Expand Down
4 changes: 2 additions & 2 deletions git/test/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
GitCommandError,
CheckoutError,
)
from git.compat import string_types, is_win
from git.compat import is_win
from git.exc import (
HookExecutionError,
InvalidGitRepositoryError
Expand Down Expand Up @@ -388,7 +388,7 @@ def test_index_file_diffing(self, rw_repo):
self.assertEqual(len(e.failed_files), 1)
self.assertEqual(e.failed_files[0], osp.basename(test_file))
self.assertEqual(len(e.failed_files), len(e.failed_reasons))
self.assertIsInstance(e.failed_reasons[0], string_types)
self.assertIsInstance(e.failed_reasons[0], str)
self.assertEqual(len(e.valid_files), 0)
with open(test_file, 'rb') as fd:
s = fd.read()
Expand Down
5 changes: 2 additions & 3 deletions git/test/test_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
GitCommandError
)
from git.cmd import Git
from git.compat import string_types
from git.test.lib import (
TestBase,
with_rw_repo,
Expand Down Expand Up @@ -116,7 +115,7 @@ def _do_test_fetch_result(self, results, remote):
self.assertGreater(len(results), 0)
self.assertIsInstance(results[0], FetchInfo)
for info in results:
self.assertIsInstance(info.note, string_types)
self.assertIsInstance(info.note, str)
if isinstance(info.ref, Reference):
self.assertTrue(info.flags)
# END reference type flags handling
Expand All @@ -133,7 +132,7 @@ def _do_test_push_result(self, results, remote):
self.assertIsInstance(results[0], PushInfo)
for info in results:
self.assertTrue(info.flags)
self.assertIsInstance(info.summary, string_types)
self.assertIsInstance(info.summary, str)
if info.old_commit is not None:
self.assertIsInstance(info.old_commit, Commit)
if info.flags & info.ERROR:
Expand Down
3 changes: 1 addition & 2 deletions git/test/test_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
)
from git.compat import (
is_win,
string_types,
win_encode,
)
from git.exc import (
Expand Down Expand Up @@ -441,7 +440,7 @@ def test_should_display_blame_information(self, git):
# test the 'lines per commit' entries
tlist = b[0][1]
assert_true(tlist)
assert_true(isinstance(tlist[0], string_types))
assert_true(isinstance(tlist[0], str))
assert_true(len(tlist) < sum(len(t) for t in tlist)) # test for single-char bug

# BINARY BLAME
Expand Down
4 changes: 2 additions & 2 deletions git/test/test_submodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import git
from git.cmd import Git
from git.compat import string_types, is_win
from git.compat import is_win
from git.exc import (
InvalidGitRepositoryError,
RepositoryDirtyError
Expand Down Expand Up @@ -79,7 +79,7 @@ def _do_base_tests(self, rwrepo):
self.failUnlessRaises(InvalidGitRepositoryError, getattr, sm, 'branch')

# branch_path works, as its just a string
assert isinstance(sm.branch_path, string_types)
assert isinstance(sm.branch_path, str)

# some commits earlier we still have a submodule, but its at a different commit
smold = next(Submodule.iter_items(rwrepo, self.k_subm_changed))
Expand Down
4 changes: 2 additions & 2 deletions git/test/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import ddt

from git.cmd import dashify
from git.compat import string_types, is_win
from git.compat import is_win
from git.objects.util import (
altz_to_utctz_str,
utctz_to_altz,
Expand Down Expand Up @@ -187,7 +187,7 @@ def assert_rval(rval, veri_time, offset=0):

# now that we are here, test our conversion functions as well
utctz = altz_to_utctz_str(offset)
self.assertIsInstance(utctz, string_types)
self.assertIsInstance(utctz, str)
self.assertEqual(utctz_to_altz(verify_utctz(utctz)), offset)
# END assert rval utility

Expand Down