Skip to content
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

string module requires bytes type for maketrans, but calling method on regular string does not #49925

Closed
MechPaul mannequin opened this issue Apr 2, 2009 · 5 comments
Assignees
Labels
docs Documentation in the Doc dir

Comments

@MechPaul
Copy link
Mannequin

MechPaul mannequin commented Apr 2, 2009

BPO 5675
Nosy @birkenfeld, @rhettinger, @benjaminp, @ezio-melotti

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = 'https://github.com/birkenfeld'
closed_at = <Date 2009-05-31.21:39:03.758>
created_at = <Date 2009-04-02.23:54:34.597>
labels = ['docs']
title = 'string module requires bytes type for maketrans, but calling method on regular string does not'
updated_at = <Date 2009-05-31.21:39:03.757>
user = 'https://bugs.python.org/MechPaul'

bugs.python.org fields:

activity = <Date 2009-05-31.21:39:03.757>
actor = 'georg.brandl'
assignee = 'georg.brandl'
closed = True
closed_date = <Date 2009-05-31.21:39:03.758>
closer = 'georg.brandl'
components = ['Documentation']
creation = <Date 2009-04-02.23:54:34.597>
creator = 'MechPaul'
dependencies = []
files = []
hgrepos = []
issue_num = 5675
keywords = []
message_count = 5.0
messages = ['85280', '85290', '85904', '88610', '88612']
nosy_count = 5.0
nosy_names = ['georg.brandl', 'rhettinger', 'benjamin.peterson', 'ezio.melotti', 'MechPaul']
pr_nums = []
priority = 'normal'
resolution = 'works for me'
stage = None
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue5675'
versions = ['Python 3.1']

@MechPaul
Copy link
Mannequin Author

MechPaul mannequin commented Apr 2, 2009

I was making a simple Caesarian cipher when this issue came up.

#Following code here

>>> import string
>>> CAESER_SHIFT = 13
>>> TranslationTableUpper = [string.ascii_uppercase[(index +
CAESER_SHIFT) % 26] for index in range(26)]
>>> TranslationTableLower = [string.ascii_lowercase[(index +
CAESER_SHIFT) % 26] for index in range(26)]
>>> TranslationTableCipher = ''.join(TranslationTableUpper +
TranslationTableLower)
>>> TranslationTableRegular = string.ascii_uppercase[0:27] +
string.ascii_lowercase[0:27]
>>> Trans = ''.maketrans(TranslationTableCipher, TranslationTableRegular)
>>> print(Trans)
{65: 78, 66: 79, 67: 80, 68: 81, 69: 82, 70: 83, 71: 84, 72: 85, 73: 86,
74: 87, 75: 88, 76: 89, 77: 90, 78: 65, 79: 66, 80: 67, 81: 68, 82: 69,
83: 70, 84: 71, 85: 72, 86: 73, 87: 74, 88: 75, 89: 76, 90: 77, 97: 110,
98: 111, 99: 112, 100: 113, 101: 114, 102: 115, 103: 116, 104: 117, 105:
118, 106: 119, 107: 120, 108: 121, 109: 122, 110: 97, 111: 98, 112: 99,
113: 100, 114: 101, 115: 102, 116: 103, 117: 104, 118: 105, 119: 106,
120: 107, 121: 108, 122: 109}
>>> #Okay... so maketrans() is working okay when calling it on an empty
string, buuuut if called from the string module...
>>> Trans = string.maketrans(TranslationTableCipher,
TranslationTableRegular)
    Trans = string.maketrans(TranslationTableCipher,
TranslationTableRegular)
  File "D:\Python31\lib\string.py", line 55, in maketrans
    raise TypeError("maketrans arguments must be bytes objects")
TypeError: maketrans arguments must be bytes objects

@MechPaul MechPaul mannequin added the interpreter-core (Objects, Python, Grammar, and Parser dirs) label Apr 2, 2009
@benjaminp
Copy link
Contributor

This seems to have been intentional. I'm assigning it to Georg since he
made the commit.

@birkenfeld
Copy link
Member

This is (kind of) intentional. string.maketrans operates on bytes, not
string objects. However, this is quite confusing, so I added
bytes.maketrans() now in py3k, and deprecated string.maketrans(). (r71521)

@rhettinger
Copy link
Contributor

The bytearray.maketrans() method isn't documented yet.

@rhettinger rhettinger added docs Documentation in the Doc dir and removed interpreter-core (Objects, Python, Grammar, and Parser dirs) labels May 31, 2009
@rhettinger rhettinger reopened this May 31, 2009
@birkenfeld
Copy link
Member

Should be fixed in r73086.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir
Projects
None yet
Development

No branches or pull requests

3 participants