-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix %c string and bytes interpolation (#10869)
According to [PEP461](https://www.python.org/dev/peps/pep-0461/), conversion type %c performs differently for string and bytes. In addition, `b'%c’ % str` is not supported in Python3. ## Test Plan CPython Python3: ```py ss = 'a' bb = b'a' ii = 97 ff = 97.0 print('%c' % ss) # print('%c' % '') # TypeError: %c requires int or char # print('%c' % 'aa') # TypeError: %c requires int or char # print('%c' % bb) # TypeError: %c requires int or char print('%c' % ii) # print('%c' % ff) # TypeError: %c requires int or char # print(b'%c' % ss) # TypeError: %c requires an integer in range(256) or a single byte # print(b'%c' % '') # TypeError: %c requires an integer in range(256) or a single byte # print(b'%c' % 'aa') # TypeError: %c requires an integer in range(256) or a single byte print(b'%c' % bb) print(b'%c' % ii) # print(b'%c' % ff) # TypeError: %c requires an integer in range(256) or a single byte ``` CPython Python2: ```py print('%c' % ss) # print('%c' % '') # TypeError: %c requires int or char # print('%c' % 'aa') # TypeError: %c requires int or char print('%c' % bb) print('%c' % ii) # print('%c' % ff) # TypeError: integer argument expected, got float print(b'%c' % ss) # print('%c' % '') # TypeError: %c requires int or char # print('%c' % 'aa') # TypeError: %c requires int or char print(b'%c' % bb) print(b'%c' % ii) # print(b'%c' % ff) # TypeError: integer argument expected, got float ```
- Loading branch information
1 parent
524c924
commit b3b3242
Showing
3 changed files
with
51 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters