Skip to content

Commit ebd2adb

Browse files
authored
Merge pull request #3815 from mwichmann/more-py2-drops
Drop some more Py2 compat things
2 parents b70f085 + 2cdc9dd commit ebd2adb

File tree

13 files changed

+21
-55
lines changed

13 files changed

+21
-55
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ RELEASE VERSION/DATE TO BE FILLED IN LATER
6565
- Make sure cProfile is used if profiling - SCons was expecting
6666
the Util module to monkeypatch in cProfile as profile if available,
6767
but this is no longer being done.
68+
- Some Python 2 compatibility code dropped
6869

6970
From Simon Tegelid
7071
- Fix using TEMPFILE in multiple actions in an action list. Previously a builder, or command

SCons/Node/FS.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ class EntryProxy(SCons.Util.Proxy):
434434

435435
# In PY3 if a class defines __eq__, then it must explicitly provide
436436
# __hash__. Since SCons.Util.Proxy provides __eq__ we need the following
437-
# see: https://docs.python.org/3.1/reference/datamodel.html#object.__hash__
437+
# see: https://docs.python.org/3/reference/datamodel.html#object.__hash__
438438
__hash__ = SCons.Util.Delegate('__hash__')
439439

440440
def __get_abspath(self):

SCons/Node/Python.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def read(self):
129129
self.built_value = self.value
130130
return self.built_value
131131

132-
def get_text_contents(self):
132+
def get_text_contents(self) -> str:
133133
"""By the assumption that the node.built_value is a
134134
deterministic product of the sources, the contents of a Value
135135
are the concatenation of all the contents of its sources. As
@@ -141,24 +141,16 @@ def get_text_contents(self):
141141
contents = contents + kid.get_contents().decode()
142142
return contents
143143

144-
def get_contents(self):
145-
"""
146-
Get contents for signature calculations.
147-
:return: bytes
148-
"""
149-
text_contents = self.get_text_contents()
150-
try:
151-
return text_contents.encode()
152-
except UnicodeDecodeError:
153-
# Already encoded as python2 str are bytes
154-
return text_contents
144+
def get_contents(self) -> bytes:
145+
"""Get contents for signature calculations."""
146+
return self.get_text_contents().encode()
155147

156148
def changed_since_last_build(self, target, prev_ni):
157149
cur_csig = self.get_csig()
158150
try:
159151
return cur_csig != prev_ni.csig
160152
except AttributeError:
161-
return 1
153+
return True
162154

163155
def get_csig(self, calc=None):
164156
"""Because we're a Python value node and don't have a real

SCons/Script/__init__.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,7 @@
3636

3737
import collections
3838
import os
39-
40-
try:
41-
from StringIO import StringIO
42-
except ImportError:
43-
from io import StringIO
39+
from io import StringIO
4440

4541
import sys
4642

SCons/SubstTests.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -541,9 +541,7 @@ def test_subst_syntax_errors(self):
541541
scons_subst('$foo.bar.3.0', env)
542542
except SCons.Errors.UserError as e:
543543
expect = [
544-
# Python 2.3, 2.4
545-
"SyntaxError `invalid syntax (line 1)' trying to evaluate `$foo.bar.3.0'",
546-
# Python 2.5
544+
# Python 2.5 and later
547545
"SyntaxError `invalid syntax (<string>, line 1)' trying to evaluate `$foo.bar.3.0'",
548546
]
549547
assert str(e) in expect, e

SCons/Tool/clang.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,7 @@ def generate(env):
8484
# clang -dumpversion is of no use
8585
with pipe.stdout:
8686
line = pipe.stdout.readline()
87-
if sys.version_info[0] > 2:
88-
line = line.decode()
87+
line = line.decode()
8988
match = re.search(r'clang +version +([0-9]+(?:\.[0-9]+)+)', line)
9089
if match:
9190
env['CCVERSION'] = match.group(1)

SCons/Tool/clangxx.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,7 @@ def generate(env):
9292
# clang -dumpversion is of no use
9393
with pipe.stdout:
9494
line = pipe.stdout.readline()
95-
if sys.version_info[0] > 2:
96-
line = line.decode()
95+
line = line.decode()
9796
match = re.search(r'clang +version +([0-9]+(?:\.[0-9]+)+)', line)
9897
if match:
9998
env['CXXVERSION'] = match.group(1)

SCons/Tool/textfile.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ def _do_subst(node, subs):
7474
if 'b' in TEXTFILE_FILE_WRITE_MODE:
7575
try:
7676
contents = bytearray(contents, 'utf-8')
77-
except UnicodeDecodeError:
78-
# contents is already utf-8 encoded python 2 str i.e. a byte array
77+
except TypeError:
78+
# TODO: this should not happen, get_text_contents returns text
7979
contents = bytearray(contents)
8080

8181
return contents

SCons/UtilTests.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,7 @@ def get_children(node):
193193
try:
194194
node, expect, withtags = self.tree_case_1()
195195

196-
if sys.version_info.major < 3:
197-
IOStream = io.BytesIO
198-
else:
199-
IOStream = io.StringIO
200-
196+
IOStream = io.StringIO
201197
sys.stdout = IOStream()
202198
print_tree(node, get_children)
203199
actual = sys.stdout.getvalue()
@@ -249,11 +245,6 @@ def get_children(node):
249245
def test_is_Dict(self):
250246
assert is_Dict({})
251247
assert is_Dict(UserDict())
252-
253-
# os.environ is not a dictionary in python 3
254-
if sys.version_info < (3, 0):
255-
assert is_Dict(os.environ)
256-
257248
try:
258249
class mydict(dict):
259250
pass

SCons/Utilities/sconsign.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,6 @@ def default_mapper(entry, name):
9898
val = eval("entry." + name)
9999
except AttributeError:
100100
val = None
101-
if sys.version_info.major >= 3 and isinstance(val, bytes):
102-
# This is a dirty hack for py 2/3 compatibility. csig is a bytes object
103-
# in Python3 while Python2 bytes are str. Hence, we decode the csig to a
104-
# Python3 string
105-
val = val.decode()
106101
return str(val)
107102

108103

@@ -327,8 +322,8 @@ def __call__(self, fname):
327322
sys.stderr.write("sconsign: ignoring invalid `%s' file `%s': %s\n"
328323
% (self.dbm_name, fname, e))
329324
exc_type, _, _ = sys.exc_info()
330-
if exc_type.__name__ == "ValueError" and sys.version_info < (3,0,0):
331-
sys.stderr.write("Python 2 only supports pickle protocols 0-2.\n")
325+
if exc_type.__name__ == "ValueError":
326+
sys.stderr.write("unrecognized pickle protocol.\n")
332327
return
333328

334329
if Print_Directories:

0 commit comments

Comments
 (0)