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.text_type
  • Loading branch information
Harmon758 committed Feb 7, 2020
commit 2f312616d212cbcea57db34290b141497926b853
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 (
text_type, # @UnusedImport
force_bytes, # @UnusedImport
force_text # @UnusedImport
)
Expand Down
3 changes: 1 addition & 2 deletions git/objects/commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
parse_actor_and_date,
from_timestamp,
)
from git.compat import text_type

from time import (
time,
Expand Down Expand Up @@ -436,7 +435,7 @@ def _serialize(self, stream):
write(b"\n")

# write plain bytes, be sure its encoded according to our encoding
if isinstance(self.message, text_type):
if isinstance(self.message, str):
write(self.message.encode(self.encoding))
else:
write(self.message)
Expand Down
5 changes: 2 additions & 3 deletions git/objects/fun.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
from stat import S_ISDIR
from git.compat import (
safe_decode,
defenc,
text_type
defenc
)

__all__ = ('tree_to_stream', 'tree_entries_from_data', 'traverse_trees_recursive',
Expand Down Expand Up @@ -33,7 +32,7 @@ def tree_to_stream(entries, write):
# hence we must convert to an utf8 string for it to work properly.
# According to my tests, this is exactly what git does, that is it just
# takes the input literally, which appears to be utf8 on linux.
if isinstance(name, text_type):
if isinstance(name, str):
name = name.encode(defenc)
write(b''.join((mode_str, b' ', name, b'\0', binsha)))
# END for each item
Expand Down
5 changes: 2 additions & 3 deletions git/repo/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
handle_process_output
)
from git.compat import (
text_type,
defenc,
safe_decode,
is_win,
Expand Down Expand Up @@ -476,7 +475,7 @@ def commit(self, rev=None):
:return: ``git.Commit``"""
if rev is None:
return self.head.commit
return self.rev_parse(text_type(rev) + "^0")
return self.rev_parse(str(rev) + "^0")

def iter_trees(self, *args, **kwargs):
""":return: Iterator yielding Tree objects
Expand All @@ -498,7 +497,7 @@ def tree(self, rev=None):
operations might have unexpected results."""
if rev is None:
return self.head.commit.tree
return self.rev_parse(text_type(rev) + "^{tree}")
return self.rev_parse(str(rev) + "^{tree}")

def iter_commits(self, rev=None, paths='', **kwargs):
"""A list of Commit objects representing the history of a given ref/commit
Expand Down
7 changes: 3 additions & 4 deletions git/test/test_commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
Actor,
)
from git import Repo
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 @@ -142,7 +141,7 @@ def test_unicode_actor(self):
self.assertEqual(len(name), 9)
special = Actor._from_string(u"%s <[email protected]>" % name)
self.assertEqual(special.name, name)
assert isinstance(special.name, text_type)
assert isinstance(special.name, str)

def test_traversal(self):
start = self.rorepo.commit("a4d06724202afccd2b5c54f81bcf2bf26dea7fff")
Expand Down Expand Up @@ -286,8 +285,8 @@ def test_serialization_unicode_support(self):
# create a commit with unicode in the message, and the author's name
# Verify its serialization and deserialization
cmt = self.rorepo.commit('0.1.6')
assert isinstance(cmt.message, text_type) # it automatically decodes it as such
assert isinstance(cmt.author.name, text_type) # same here
assert isinstance(cmt.message, str) # it automatically decodes it as such
assert isinstance(cmt.author.name, str) # same here

cmt.message = u"üäêèß"
self.assertEqual(len(cmt.message), 5)
Expand Down