Skip to content

Commit ab19b94

Browse files
committed
some manual py2 cleanups
1 parent 30c1e82 commit ab19b94

23 files changed

+31
-59
lines changed

pre_commit/five.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
import six
2-
3-
41
def to_text(s):
52
return s if isinstance(s, str) else s.decode('UTF-8')
63

@@ -9,4 +6,4 @@ def to_bytes(s):
96
return s if isinstance(s, bytes) else s.encode('UTF-8')
107

118

12-
n = to_bytes if six.PY2 else to_text
9+
n = to_text

pre_commit/util.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def __init__(self, returncode, cmd, expected_returncode, stdout, stderr):
8080
self.stdout = stdout
8181
self.stderr = stderr
8282

83-
def to_bytes(self):
83+
def __bytes__(self):
8484
def _indent_or_none(part):
8585
if part:
8686
return b'\n ' + part.replace(b'\n', b'\n ')
@@ -97,11 +97,8 @@ def _indent_or_none(part):
9797
b'stderr:', _indent_or_none(self.stderr),
9898
))
9999

100-
def to_text(self):
101-
return self.to_bytes().decode('UTF-8')
102-
103-
__bytes__ = to_bytes
104-
__str__ = to_text
100+
def __str__(self):
101+
return self.__bytes__().decode('UTF-8')
105102

106103

107104
def _cmd_kwargs(*cmd, **kwargs):

requirements-dev.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
-e .
22

33
coverage
4-
mock
54
pytest
65
pytest-env

setup.cfg

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ install_requires =
2727
identify>=1.0.0
2828
nodeenv>=0.11.1
2929
pyyaml
30-
six
3130
toml
3231
virtualenv>=15.2
3332
importlib-metadata;python_version<"3.8"

testing/resources/python_venv_hooks_repo/foo/__init__.py

Whitespace-only changes.

tests/color_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import sys
2+
from unittest import mock
23

3-
import mock
44
import pytest
55

66
from pre_commit import envcontext

tests/commands/clean_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import os.path
2+
from unittest import mock
23

3-
import mock
44
import pytest
55

66
from pre_commit.commands.clean import clean

tests/commands/init_templatedir_test.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import os.path
2-
3-
import mock
2+
from unittest import mock
43

54
import pre_commit.constants as C
65
from pre_commit.commands.init_templatedir import init_templatedir

tests/commands/install_uninstall_test.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import os.path
22
import re
33
import sys
4-
5-
import mock
4+
from unittest import mock
65

76
import pre_commit.constants as C
87
from pre_commit.commands.install_uninstall import CURRENT_HASH

tests/commands/run_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
import pipes
33
import sys
44
import time
5+
from unittest import mock
56

6-
import mock
77
import pytest
88

99
import pre_commit.constants as C

0 commit comments

Comments
 (0)