Skip to content

Commit 3480a6e

Browse files
authored
Merge pull request #237 from jelmer/drop-python2
Drop Python 2 support and compatibility code
2 parents 7c618b0 + 008165c commit 3480a6e

File tree

7 files changed

+76
-143
lines changed

7 files changed

+76
-143
lines changed

.github/workflows/python-test.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
- name: Install dependencies
2121
run: |
2222
python -m pip install --upgrade pip
23-
pip install pytest coverage pytest-cov six mock
23+
pip install pytest coverage pytest-cov
2424
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
2525
pip install -e .
2626
- name: Test with pytest
@@ -35,7 +35,7 @@ jobs:
3535
strategy:
3636
fail-fast: false
3737
matrix:
38-
python-version: [ "2.7", "3.5", "3.6" ]
38+
python-version: [ "3.6" ]
3939

4040
steps:
4141
- uses: actions/checkout@v3
@@ -46,7 +46,7 @@ jobs:
4646
- name: Install dependencies
4747
run: |
4848
python -m pip install --upgrade pip
49-
pip install pytest coverage pytest-cov six mock
49+
pip install pytest coverage pytest-cov
5050
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
5151
pip install -e .
5252
- name: Test with pytest

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
Python 3+ compatible port of the [configobj](https://pypi.python.org/pypi/configobj/) library.
88

99
The Github CI/CD Pipeline runs tests on python versions:
10-
- 2.7
1110
- 3.5
1211
- 3.6
1312
- 3.7

setup.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,6 @@
4040
DESCRIPTION = 'Config file reading, writing and validation.'
4141
URL = 'https://github.com/DiffSK/configobj'
4242

43-
REQUIRES = """
44-
six
45-
"""
46-
4743
VERSION = ''
4844
with closing(open(os.path.join(__here__, 'src', PACKAGES[0], '_version.py'), 'r')) as handle:
4945
for line in handle.readlines():
@@ -88,8 +84,6 @@
8884
'Intended Audience :: Developers',
8985
'License :: OSI Approved :: BSD License',
9086
'Programming Language :: Python',
91-
'Programming Language :: Python :: 2',
92-
'Programming Language :: Python :: 2.7',
9387
'Programming Language :: Python :: 3',
9488
'Programming Language :: Python :: 3.5',
9589
'Programming Language :: Python :: 3.6',
@@ -120,12 +114,11 @@
120114
py_modules=MODULES,
121115
package_dir={'': 'src'},
122116
packages=PACKAGES,
123-
install_requires=[i.strip() for i in REQUIRES.splitlines() if i.strip()],
124-
python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*',
117+
python_requires='>=3.5',
125118
classifiers=CLASSIFIERS,
126119
keywords=KEYWORDS,
127120
license='BSD (2 clause)',
128121
)
129122

130123
if __name__ == '__main__':
131-
setup(**project)
124+
setup(**project)

src/configobj/__init__.py

Lines changed: 22 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
from codecs import BOM_UTF8, BOM_UTF16, BOM_UTF16_BE, BOM_UTF16_LE
2121

22-
import six
2322
from ._version import __version__
2423

2524
# imported lazily to avoid startup performance hit if it isn't used
@@ -121,10 +120,6 @@ def match_utf8(encoding):
121120
'write_empty_values': False,
122121
}
123122

124-
# this could be replaced if six is used for compatibility, or there are no
125-
# more assertions about items being a string
126-
127-
128123
def getObj(s):
129124
global compiler
130125
if compiler is None:
@@ -553,11 +548,11 @@ def __getitem__(self, key):
553548
"""Fetch the item and do string interpolation."""
554549
val = dict.__getitem__(self, key)
555550
if self.main.interpolation:
556-
if isinstance(val, six.string_types):
551+
if isinstance(val, str):
557552
return self._interpolate(key, val)
558553
if isinstance(val, list):
559554
def _check(entry):
560-
if isinstance(entry, six.string_types):
555+
if isinstance(entry, str):
561556
return self._interpolate(key, entry)
562557
return entry
563558
new = [_check(entry) for entry in val]
@@ -580,7 +575,7 @@ def __setitem__(self, key, value, unrepr=False):
580575
``unrepr`` must be set when setting a value to a dictionary, without
581576
creating a new sub-section.
582577
"""
583-
if not isinstance(key, six.string_types):
578+
if not isinstance(key, str):
584579
raise ValueError('The key "%s" is not a string.' % key)
585580

586581
# add the comment
@@ -614,11 +609,11 @@ def __setitem__(self, key, value, unrepr=False):
614609
if key not in self:
615610
self.scalars.append(key)
616611
if not self.main.stringify:
617-
if isinstance(value, six.string_types):
612+
if isinstance(value, str):
618613
pass
619614
elif isinstance(value, (list, tuple)):
620615
for entry in value:
621-
if not isinstance(entry, six.string_types):
616+
if not isinstance(entry, str):
622617
raise TypeError('Value is not a string "%s".' % entry)
623618
else:
624619
raise TypeError('Value is not a string "%s".' % value)
@@ -959,7 +954,7 @@ def as_bool(self, key):
959954
return False
960955
else:
961956
try:
962-
if not isinstance(val, six.string_types):
957+
if not isinstance(val, str):
963958
# TODO: Why do we raise a KeyError here?
964959
raise KeyError()
965960
else:
@@ -1230,7 +1225,7 @@ def __init__(self, infile=None, options=None, configspec=None, encoding=None,
12301225

12311226

12321227
def _load(self, infile, configspec):
1233-
if isinstance(infile, six.string_types):
1228+
if isinstance(infile, str):
12341229
self.filename = infile
12351230
if os.path.isfile(infile):
12361231
with open(infile, 'rb') as h:
@@ -1298,7 +1293,7 @@ def set_section(in_section, this_section):
12981293
break
12991294
break
13001295

1301-
assert all(isinstance(line, six.string_types) for line in content), repr(content)
1296+
assert all(isinstance(line, str) for line in content), repr(content)
13021297
content = [line.rstrip('\r\n') for line in content]
13031298

13041299
self._parse(content)
@@ -1403,7 +1398,7 @@ def _handle_bom(self, infile):
14031398
else:
14041399
line = infile
14051400

1406-
if isinstance(line, six.text_type):
1401+
if isinstance(line, str):
14071402
# it's already decoded and there's no need to do anything
14081403
# else, just use the _decode utility method to handle
14091404
# listifying appropriately
@@ -1448,7 +1443,7 @@ def _handle_bom(self, infile):
14481443

14491444
# No encoding specified - so we need to check for UTF8/UTF16
14501445
for BOM, (encoding, final_encoding) in list(BOMS.items()):
1451-
if not isinstance(line, six.binary_type) or not line.startswith(BOM):
1446+
if not isinstance(line, bytes) or not line.startswith(BOM):
14521447
# didn't specify a BOM, or it's not a bytestring
14531448
continue
14541449
else:
@@ -1464,30 +1459,26 @@ def _handle_bom(self, infile):
14641459
else:
14651460
infile = newline
14661461
# UTF-8
1467-
if isinstance(infile, six.text_type):
1462+
if isinstance(infile, str):
14681463
return infile.splitlines(True)
1469-
elif isinstance(infile, six.binary_type):
1464+
elif isinstance(infile, bytes):
14701465
return infile.decode('utf-8').splitlines(True)
14711466
else:
14721467
return self._decode(infile, 'utf-8')
14731468
# UTF16 - have to decode
14741469
return self._decode(infile, encoding)
14751470

14761471

1477-
if six.PY2 and isinstance(line, str):
1478-
# don't actually do any decoding, since we're on python 2 and
1479-
# returning a bytestring is fine
1480-
return self._decode(infile, None)
14811472
# No BOM discovered and no encoding specified, default to UTF-8
1482-
if isinstance(infile, six.binary_type):
1473+
if isinstance(infile, bytes):
14831474
return infile.decode('utf-8').splitlines(True)
14841475
else:
14851476
return self._decode(infile, 'utf-8')
14861477

14871478

14881479
def _a_to_u(self, aString):
14891480
"""Decode ASCII strings to unicode if a self.encoding is specified."""
1490-
if isinstance(aString, six.binary_type) and self.encoding:
1481+
if isinstance(aString, bytes) and self.encoding:
14911482
return aString.decode(self.encoding)
14921483
else:
14931484
return aString
@@ -1499,9 +1490,9 @@ def _decode(self, infile, encoding):
14991490
15001491
if is a string, it also needs converting to a list.
15011492
"""
1502-
if isinstance(infile, six.string_types):
1493+
if isinstance(infile, str):
15031494
return infile.splitlines(True)
1504-
if isinstance(infile, six.binary_type):
1495+
if isinstance(infile, bytes):
15051496
# NOTE: Could raise a ``UnicodeDecodeError``
15061497
if encoding:
15071498
return infile.decode(encoding).splitlines(True)
@@ -1510,7 +1501,7 @@ def _decode(self, infile, encoding):
15101501

15111502
if encoding:
15121503
for i, line in enumerate(infile):
1513-
if isinstance(line, six.binary_type):
1504+
if isinstance(line, bytes):
15141505
# NOTE: The isinstance test here handles mixed lists of unicode/string
15151506
# NOTE: But the decode will break on any non-string values
15161507
# NOTE: Or could raise a ``UnicodeDecodeError``
@@ -1520,7 +1511,7 @@ def _decode(self, infile, encoding):
15201511

15211512
def _decode_element(self, line):
15221513
"""Decode element to unicode if necessary."""
1523-
if isinstance(line, six.binary_type) and self.default_encoding:
1514+
if isinstance(line, bytes) and self.default_encoding:
15241515
return line.decode(self.default_encoding)
15251516
else:
15261517
return line
@@ -1532,7 +1523,7 @@ def _str(self, value):
15321523
Used by ``stringify`` within validate, to turn non-string values
15331524
into strings.
15341525
"""
1535-
if not isinstance(value, six.string_types):
1526+
if not isinstance(value, str):
15361527
# intentially 'str' because it's just whatever the "normal"
15371528
# string type is for the python version we're dealing with
15381529
return str(value)
@@ -1786,7 +1777,7 @@ def _quote(self, value, multiline=True):
17861777
return self._quote(value[0], multiline=False) + ','
17871778
return ', '.join([self._quote(val, multiline=False)
17881779
for val in value])
1789-
if not isinstance(value, six.string_types):
1780+
if not isinstance(value, str):
17901781
if self.stringify:
17911782
# intentially 'str' because it's just whatever the "normal"
17921783
# string type is for the python version we're dealing with
@@ -2111,7 +2102,7 @@ def write(self, outfile=None, section=None):
21112102
if not output.endswith(newline):
21122103
output += newline
21132104

2114-
if isinstance(output, six.binary_type):
2105+
if isinstance(output, bytes):
21152106
output_bytes = output
21162107
else:
21172108
output_bytes = output.encode(self.encoding or
@@ -2353,7 +2344,7 @@ def reload(self):
23532344
This method raises a ``ReloadError`` if the ConfigObj doesn't have
23542345
a filename attribute pointing to a file.
23552346
"""
2356-
if not isinstance(self.filename, six.string_types):
2347+
if not isinstance(self.filename, str):
23572348
raise ReloadError()
23582349

23592350
filename = self.filename

0 commit comments

Comments
 (0)