summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarmon <Harmon758@gmail.com>2020-02-07 06:20:23 -0600
committerSebastian Thiel <sebastian.thiel@icloud.com>2020-02-08 10:55:50 +0800
commit768b9fffa58e82d6aa1f799bd5caebede9c9231b (patch)
tree0f995bb2702601f5edc3db05c85169f12e547ee8
parent5d22d57010e064cfb9e0b6160e7bd3bb31dbfffc (diff)
downloadgitpython-768b9fffa58e82d6aa1f799bd5caebede9c9231b.tar.gz
Remove and replace compat.string_types
-rw-r--r--git/cmd.py3
-rw-r--r--git/compat.py1
-rw-r--r--git/config.py7
-rw-r--r--git/exc.py4
-rw-r--r--git/index/base.py9
-rw-r--r--git/objects/submodule/base.py3
-rw-r--r--git/objects/tree.py3
-rw-r--r--git/refs/log.py7
-rw-r--r--git/refs/symbolic.py7
-rw-r--r--git/test/lib/helper.py6
-rw-r--r--git/test/test_commit.py7
-rw-r--r--git/test/test_config.py3
-rw-r--r--git/test/test_index.py4
-rw-r--r--git/test/test_remote.py5
-rw-r--r--git/test/test_repo.py3
-rw-r--r--git/test/test_submodule.py4
-rw-r--r--git/test/test_util.py4
17 files changed, 31 insertions, 49 deletions
diff --git a/git/cmd.py b/git/cmd.py
index 906ee585..cb226acb 100644
--- a/git/cmd.py
+++ b/git/cmd.py
@@ -21,7 +21,6 @@ from collections import OrderedDict
from textwrap import dedent
from git.compat import (
- string_types,
defenc,
force_bytes,
safe_decode,
@@ -1038,7 +1037,7 @@ class Git(LazyMixin):
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"):
diff --git a/git/compat.py b/git/compat.py
index 91676327..d3240c26 100644
--- a/git/compat.py
+++ b/git/compat.py
@@ -13,7 +13,6 @@ import sys
from gitdb.utils.encoding import (
- string_types, # @UnusedImport
text_type, # @UnusedImport
force_bytes, # @UnusedImport
force_text # @UnusedImport
diff --git a/git/config.py b/git/config.py
index 6b45bc63..75f17368 100644
--- a/git/config.py
+++ b/git/config.py
@@ -16,7 +16,6 @@ import re
from collections import OrderedDict
from git.compat import (
- string_types,
defenc,
force_text,
with_metaclass,
@@ -302,7 +301,7 @@ class GitConfigParser(with_metaclass(MetaParserBuilder, cp.RawConfigParser, obje
# 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
@@ -578,7 +577,7 @@ class GitConfigParser(with_metaclass(MetaParserBuilder, cp.RawConfigParser, obje
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"):
@@ -670,7 +669,7 @@ class GitConfigParser(with_metaclass(MetaParserBuilder, cp.RawConfigParser, obje
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)
diff --git a/git/exc.py b/git/exc.py
index 070bf9b7..f75ec5c9 100644
--- a/git/exc.py
+++ b/git/exc.py
@@ -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):
@@ -50,7 +50,7 @@ class CommandError(GitError):
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)
diff --git a/git/index/base.py b/git/index/base.py
index 98c3b0f1..8ff0f982 100644
--- a/git/index/base.py
+++ b/git/index/base.py
@@ -11,7 +11,6 @@ import subprocess
import tempfile
from git.compat import (
- string_types,
force_bytes,
defenc,
)
@@ -571,7 +570,7 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable):
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))
@@ -808,7 +807,7 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable):
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)
@@ -1087,7 +1086,7 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable):
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
@@ -1224,7 +1223,7 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable):
# 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
diff --git a/git/objects/submodule/base.py b/git/objects/submodule/base.py
index 04ca0221..97973a57 100644
--- a/git/objects/submodule/base.py
+++ b/git/objects/submodule/base.py
@@ -9,7 +9,6 @@ import uuid
import git
from git.cmd import Git
from git.compat import (
- string_types,
defenc,
is_win,
)
@@ -110,7 +109,7 @@ class Submodule(IndexObject, Iterable, Traversable):
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
diff --git a/git/objects/tree.py b/git/objects/tree.py
index 90996bfa..469e5395 100644
--- a/git/objects/tree.py
+++ b/git/objects/tree.py
@@ -11,7 +11,6 @@ from . import util
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,
@@ -290,7 +289,7 @@ class Tree(IndexObject, diff.Diffable, util.Traversable, util.Serializable):
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
diff --git a/git/refs/log.py b/git/refs/log.py
index d51c3458..965b26c7 100644
--- a/git/refs/log.py
+++ b/git/refs/log.py
@@ -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,
@@ -185,7 +182,7 @@ class RefLog(list, Serializable):
: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:
diff --git a/git/refs/symbolic.py b/git/refs/symbolic.py
index 766037c1..4784197c 100644
--- a/git/refs/symbolic.py
+++ b/git/refs/symbolic.py
@@ -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,
@@ -300,7 +297,7 @@ class SymbolicReference(object):
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
diff --git a/git/test/lib/helper.py b/git/test/lib/helper.py
index 1c06010f..d7a4c436 100644
--- a/git/test/lib/helper.py
+++ b/git/test/lib/helper.py
@@ -17,7 +17,7 @@ import textwrap
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
@@ -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)
@@ -248,7 +248,7 @@ def with_rw_and_rw_remote_repo(working_tree_ref):
"""
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):
diff --git a/git/test/test_commit.py b/git/test/test_commit.py
index 96a03b20..ca84f6d7 100644
--- a/git/test/test_commit.py
+++ b/git/test/test_commit.py
@@ -17,10 +17,7 @@ from git import (
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 (
@@ -276,7 +273,7 @@ class TestCommit(TestBase):
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):
diff --git a/git/test/test_config.py b/git/test/test_config.py
index 83e510be..ce7a2cde 100644
--- a/git/test/test_config.py
+++ b/git/test/test_config.py
@@ -10,7 +10,6 @@ import io
from git import (
GitConfigParser
)
-from git.compat import string_types
from git.config import _OMD, cp
from git.test.lib import (
TestCase,
@@ -157,7 +156,7 @@ class TestBase(TestCase):
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
diff --git a/git/test/test_index.py b/git/test/test_index.py
index 4a23ceb1..0a2309f9 100644
--- a/git/test/test_index.py
+++ b/git/test/test_index.py
@@ -25,7 +25,7 @@ from git import (
GitCommandError,
CheckoutError,
)
-from git.compat import string_types, is_win
+from git.compat import is_win
from git.exc import (
HookExecutionError,
InvalidGitRepositoryError
@@ -388,7 +388,7 @@ class TestIndex(TestBase):
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()
diff --git a/git/test/test_remote.py b/git/test/test_remote.py
index 3ef47472..2194daec 100644
--- a/git/test/test_remote.py
+++ b/git/test/test_remote.py
@@ -22,7 +22,6 @@ from git import (
GitCommandError
)
from git.cmd import Git
-from git.compat import string_types
from git.test.lib import (
TestBase,
with_rw_repo,
@@ -116,7 +115,7 @@ class TestRemote(TestBase):
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
@@ -133,7 +132,7 @@ class TestRemote(TestBase):
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:
diff --git a/git/test/test_repo.py b/git/test/test_repo.py
index 2d38f150..8ea18aa4 100644
--- a/git/test/test_repo.py
+++ b/git/test/test_repo.py
@@ -38,7 +38,6 @@ from git import (
)
from git.compat import (
is_win,
- string_types,
win_encode,
)
from git.exc import (
@@ -441,7 +440,7 @@ class TestRepo(TestBase):
# 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
diff --git a/git/test/test_submodule.py b/git/test/test_submodule.py
index 94028d83..0d306edc 100644
--- a/git/test/test_submodule.py
+++ b/git/test/test_submodule.py
@@ -8,7 +8,7 @@ from unittest import skipIf
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
@@ -79,7 +79,7 @@ class TestSubmodule(TestBase):
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))
diff --git a/git/test/test_util.py b/git/test/test_util.py
index a4d9d7ad..5faeeacb 100644
--- a/git/test/test_util.py
+++ b/git/test/test_util.py
@@ -13,7 +13,7 @@ from datetime import datetime
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,
@@ -187,7 +187,7 @@ class TestUtils(TestBase):
# 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