Skip to content

Commit

Permalink
[gyb] Remove Python 2 (swiftlang#42046)
Browse files Browse the repository at this point in the history
dduan authored Mar 28, 2022
1 parent 5f99c31 commit fdae97a
Showing 2 changed files with 5 additions and 16 deletions.
2 changes: 1 addition & 1 deletion utils/gyb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env python2.7
#!/usr/bin/env python3
import gyb
gyb.main()
19 changes: 4 additions & 15 deletions utils/gyb.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# GYB: Generate Your Boilerplate (improved names welcome; at least
# this one's short). See -h output for instructions

@@ -11,18 +11,7 @@
import textwrap
import tokenize
from bisect import bisect


try:
from StringIO import StringIO
except ImportError:
from io import StringIO


try:
basestring
except NameError:
basestring = str
from io import StringIO


def get_line_starts(s):
@@ -732,15 +721,15 @@ def execute(self, context):
# If we got a result, the code was an expression, so append
# its value
if result is not None \
or (isinstance(result, basestring) and result != ''):
or (isinstance(result, str) and result != ''):
from numbers import Number, Integral
result_string = None
if isinstance(result, Number) and not isinstance(result, Integral):
result_string = repr(result)
elif isinstance(result, Integral) or isinstance(result, list):
result_string = str(result)
else:
result_string = StringIO(result).read()
result_string = result
context.append_text(
result_string, self.filename, self.start_line_number)

0 comments on commit fdae97a

Please sign in to comment.