Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b2ecc2c

Browse files
committed
Get rid of keyword list and use keyword.iskeyword() function (which I wasn't aware of previously).
1 parent 744f67f commit b2ecc2c

1 file changed

Lines changed: 3 additions & 7 deletions

File tree

Mac/scripts/gensuitemodule.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import types
1414
import StringIO
1515
import macfs
16+
import keyword
1617

1718
from Carbon.Res import *
1819

@@ -816,12 +817,6 @@ def compiledataflags(flags):
816817
bits.append(`i`)
817818
return '[%s]' % string.join(bits)
818819

819-
# Set of Python keywords (as of Python 2.2)
820-
illegal_ids = ["and", "elif", "global", "or", "assert", "else", "if", "pass",
821-
"break", "except", "import", "print", "class", "exec", "in", "raise",
822-
"continue", "finally", "is", "return", "def", "for", "lambda", "try",
823-
"del", "from", "not", "while", "yield"]
824-
825820
def identify(str):
826821
"""Turn any string into an identifier:
827822
- replace space by _
@@ -841,7 +836,7 @@ def identify(str):
841836
else:
842837
rv = rv + '_%02.2x_'%ord(c)
843838
ok = ok2
844-
if rv in illegal_ids:
839+
if keyword.iskeyword(rv):
845840
rv = '_' + rv
846841
return rv
847842

@@ -850,3 +845,4 @@ def identify(str):
850845
if __name__ == '__main__':
851846
main()
852847
sys.exit(1)
848+
print identify('for')

0 commit comments

Comments
 (0)