Skip to content

Commit c677844

Browse files
committed
[gyb] Provide Python 2 and 3 compatable exception syntax
In Python 2 the syntax to catch exceptions was: except (Exception1, Exception2), target: In Python 3 the syntax to catch exceptions is: except (Exception1, Exception2) as target: This newer Python 3 syntax is also available in 2.6 and 2.7. Therefore, it is preferred for compatibility reasons. Additionally, the target no longer can be a tuple. This patch refactors the exception handeling code to be the newer Python 3 exception catch syntax.
1 parent 86650bb commit c677844

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

utils/gyb.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ def tokenizePythonToUnmatchedCloseCurly(sourceText, start, lineStarts):
138138
if nesting < 0:
139139
return tokenPosToIndex(tokenStart, start, lineStarts)
140140

141-
except tokenize.TokenError, (message, errorPos):
141+
except tokenize.TokenError as error:
142+
(message, errorPos) = error.args
142143
return tokenPosToIndex(errorPos, start, lineStarts)
143144

144145
return len(sourceText)
@@ -327,7 +328,7 @@ def splitGybLines(sourceLines):
327328

328329
lastTokenText,lastTokenKind = tokenText,tokenKind
329330

330-
except tokenize.TokenError, (message, errorPos):
331+
except tokenize.TokenError:
331332
return [] # Let the later compile() call report the error
332333

333334
if lastTokenText == ':':

0 commit comments

Comments
 (0)