New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SR-7211] ImportError: cannot import name 'maketrans'. Python 3 doesn't have 'maketrans' function. #49759
Comments
Comment by Kushal K S V S (JIRA) I think this should be the case for Python 3 diff --git a/stdlib/public/core/Integers.swift.gyb b/stdlib/public/core/Integers.swift.gyb index a2a02b8c93..3900bc9080 100644
+++ b/stdlib/public/core/Integers.swift.gyb @@ -17,7 +17,7 @@ from SwiftIntTypes import all_integer_types, int_max_bits, should_define_truncating_bit_pattern_init from SwiftFloatingPointTypes import getFtoIBounds -from string import maketrans, capitalize +from string import capitalize from itertools import chain Number of bits in the Builtin.Word type@@ -2490,7 +2490,7 @@ ${operatorComment(x.nonMaskingOperator, True)}
} -% reversedOperator = x.operator.translate(maketrans('<>', '><')) +% reversedOperator = x.operator.translate(str.maketrans('<>', '><')) % isRightShift = '>' in x.operator @_inlineable // FIXME(sil-serialize-all) @inline(__always) |
Comment by Kushal K S V S (JIRA) Also capitalize isn't supported on python3 |
Comment by Kushal K S V S (JIRA) So, there are other errors coming up if compiled using python 3. So, I think there should be an indication in the documentation that python 2 must be used. To solve the issue, I created a virtual environment with python 2.7 and then built swift in that virtual environment. Please update the README. Thank You |
Thanks![]( We definitely should update the Readme. Additionally, if you want to make a patch that works in both Python 2 and Python 3, we'd be happy to take it) |
Comment by Kushal K S V S (JIRA) Sure. I'll work on that. |
Comment by Kushal K S V S (JIRA) I am still getting acquainted with swift. I'd like to know the build script option(s) required for this. I don't want everything to build again or somethings to miss. Thank You |
The basic invocation you have should build everything (and should be able to drop |
Comment by Kushal K S V S (JIRA) I have a doubt. ?? ********************?? ?? Expected Passes : 4248?? Is there anything I have to configure ? |
Additional Detail from JIRA
md5: eac4cd925d62f3dfb4cef600730cc2c6
Issue Description:
When I do a clean build i.e. by running the command
utils/build-script -c
this is the error.
File "/Volumes/SSD-KSVSK/swift-source/swift/stdlib/public/core/Integers.swift.gyb", line 20, in <module>
{{ from string import maketrans, capitalize}}ImportError: cannot import name 'maketrans'
Python 3 doesn't have the maketrans function. Instead they have static maketrans methods.Now
str
,bytes
, andbytearray
each have their ownmaketrans
andtranslate
methods with intermediate translation tables of the appropriate type.The text was updated successfully, but these errors were encountered: