Skip to content

Commit 768b9ff

Browse files
Harmon758Byron
authored andcommitted
Remove and replace compat.string_types
1 parent 5d22d57 commit 768b9ff

File tree

17 files changed

+31
-49
lines changed

17 files changed

+31
-49
lines changed

git/cmd.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
from textwrap import dedent
2222

2323
from git.compat import (
24-
string_types,
2524
defenc,
2625
force_bytes,
2726
safe_decode,
@@ -1038,7 +1037,7 @@ def _prepare_ref(self, ref):
10381037
if isinstance(ref, bytes):
10391038
# Assume 40 bytes hexsha - bin-to-ascii for some reason returns bytes, not text
10401039
refstr = ref.decode('ascii')
1041-
elif not isinstance(ref, string_types):
1040+
elif not isinstance(ref, str):
10421041
refstr = str(ref) # could be ref-object
10431042

10441043
if not refstr.endswith("\n"):

git/compat.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414

1515
from gitdb.utils.encoding import (
16-
string_types, # @UnusedImport
1716
text_type, # @UnusedImport
1817
force_bytes, # @UnusedImport
1918
force_text # @UnusedImport

git/config.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
from collections import OrderedDict
1717

1818
from git.compat import (
19-
string_types,
2019
defenc,
2120
force_text,
2221
with_metaclass,
@@ -302,7 +301,7 @@ def _acquire_lock(self):
302301
# END single file check
303302

304303
file_or_files = self._file_or_files
305-
if not isinstance(self._file_or_files, string_types):
304+
if not isinstance(self._file_or_files, str):
306305
file_or_files = self._file_or_files.name
307306
# END get filename from handle/stream
308307
# initialize lock base - we want to write
@@ -578,7 +577,7 @@ def write(self):
578577
fp = self._file_or_files
579578

580579
# we have a physical file on disk, so get a lock
581-
is_file_lock = isinstance(fp, string_types + (IOBase, ))
580+
is_file_lock = isinstance(fp, (str, IOBase))
582581
if is_file_lock:
583582
self._lock._obtain_lock()
584583
if not hasattr(fp, "seek"):
@@ -670,7 +669,7 @@ def _string_to_value(self, valuestr):
670669
if vl == 'true':
671670
return True
672671

673-
if not isinstance(valuestr, string_types):
672+
if not isinstance(valuestr, str):
674673
raise TypeError(
675674
"Invalid value type: only int, long, float and str are allowed",
676675
valuestr)

git/exc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
""" Module containing all exceptions thrown throughout the git package, """
77

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

1111

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

5555
self._cmd = safe_decode(command[0])
5656
self._cmdline = u' '.join(safe_decode(i) for i in command)

git/index/base.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import tempfile
1212

1313
from git.compat import (
14-
string_types,
1514
force_bytes,
1615
defenc,
1716
)
@@ -571,7 +570,7 @@ def _preprocess_add_items(self, items):
571570
items = [items]
572571

573572
for item in items:
574-
if isinstance(item, string_types):
573+
if isinstance(item, str):
575574
paths.append(self._to_relative_path(item))
576575
elif isinstance(item, (Blob, Submodule)):
577576
entries.append(BaseIndexEntry.from_blob(item))
@@ -808,7 +807,7 @@ def _items_to_rela_paths(self, items):
808807
for item in items:
809808
if isinstance(item, (BaseIndexEntry, (Blob, Submodule))):
810809
paths.append(self._to_relative_path(item.path))
811-
elif isinstance(item, string_types):
810+
elif isinstance(item, str):
812811
paths.append(self._to_relative_path(item))
813812
else:
814813
raise TypeError("Invalid item type: %r" % item)
@@ -1087,7 +1086,7 @@ def handle_stderr(proc, iter_checked_out_files):
10871086
handle_stderr(proc, rval_iter)
10881087
return rval_iter
10891088
else:
1090-
if isinstance(paths, string_types):
1089+
if isinstance(paths, str):
10911090
paths = [paths]
10921091

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

git/objects/submodule/base.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import git
1010
from git.cmd import Git
1111
from git.compat import (
12-
string_types,
1312
defenc,
1413
is_win,
1514
)
@@ -110,7 +109,7 @@ def __init__(self, repo, binsha, mode=None, path=None, name=None, parent_commit=
110109
if url is not None:
111110
self._url = url
112111
if branch_path is not None:
113-
assert isinstance(branch_path, string_types)
112+
assert isinstance(branch_path, str)
114113
self._branch_path = branch_path
115114
if name is not None:
116115
self._name = name

git/objects/tree.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
from .base import IndexObject
1212
from .blob import Blob
1313
from .submodule.base import Submodule
14-
from git.compat import string_types
1514

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

293-
if isinstance(item, string_types):
292+
if isinstance(item, str):
294293
# compatibility
295294
return self.join(item)
296295
# END index is basestring

git/refs/log.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
import re
22
import time
33

4-
from git.compat import (
5-
string_types,
6-
defenc
7-
)
4+
from git.compat import defenc
85
from git.objects.util import (
96
parse_date,
107
Serializable,
@@ -185,7 +182,7 @@ def iter_entries(cls, stream):
185182
:param stream: file-like object containing the revlog in its native format
186183
or basestring instance pointing to a file to read"""
187184
new_entry = RefLogEntry.from_line
188-
if isinstance(stream, string_types):
185+
if isinstance(stream, str):
189186
stream = file_contents_ro_filepath(stream)
190187
# END handle stream type
191188
while True:

git/refs/symbolic.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import os
22

3-
from git.compat import (
4-
string_types,
5-
defenc
6-
)
3+
from git.compat import defenc
74
from git.objects import Object, Commit
85
from git.util import (
96
join_path,
@@ -300,7 +297,7 @@ def set_reference(self, ref, logmsg=None):
300297
elif isinstance(ref, Object):
301298
obj = ref
302299
write_value = ref.hexsha
303-
elif isinstance(ref, string_types):
300+
elif isinstance(ref, str):
304301
try:
305302
obj = self.repo.rev_parse(ref + "^{}") # optionally deref tags
306303
write_value = obj.hexsha

git/test/lib/helper.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import time
1818
import unittest
1919

20-
from git.compat import string_types, is_win
20+
from git.compat import is_win
2121
from git.util import rmtree, cwd
2222
import gitdb
2323

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

122122
def argument_passer(func):
123123
@wraps(func)
@@ -248,7 +248,7 @@ def case(self, rw_repo, rw_daemon_repo)
248248
"""
249249
from git import Git, Remote # To avoid circular deps.
250250

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

253253
def argument_passer(func):
254254

0 commit comments

Comments
 (0)