[issue17466] I can't make assignments to a list.

2013-03-19 Thread Ezio Melotti

Changes by Ezio Melotti ezio.melo...@gmail.com:


--
stage:  - committed/rejected

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue17466
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17466] I can't make assignments to a list.

2013-03-18 Thread Georgiy Treyvus

New submission from Georgiy Treyvus:

The conditions under which this bug occurs I can't explain. I will provide as 
much other information as I can.

This is an issue with both Python2 and Python3. More specifically Python 2.7.3 
and Python 3.2.3 as those are what come with the Fedora 17 repositories. Not 
that it matters I made sure my program is written portably and so works on 
both. This involved stunts like:

if sys.version_info[0]==2:
input=raw_input

Getting back to the point since strings in Python are immutable I instead have 
code that tries to assign a character string to a list of one character strings 
at a given index in that list. Now normally this works quite splendidly. For 
example:

[georgiy@PANTHER mess]$ python
Python 2.7.3 (default, Jul 24 2012, 10:05:38) 
[GCC 4.7.0 20120507 (Red Hat 4.7.0-5)] on linux2
Type help, copyright, credits or license for more information.
 l=list('test')
 l
['t', 'e', 's', 't']
 l[0]='b'
 l
['b', 'e', 's', 't']
 
[georgiy@PANTHER mess]$ python3
Python 3.2.3 (default, Jun  8 2012, 05:36:09) 
[GCC 4.7.0 20120507 (Red Hat 4.7.0-5)] on linux2
Type help, copyright, credits or license for more information.
 l=list('test')
 l
['t', 'e', 's', 't']
 l[0]='b'
 l
['b', 'e', 's', 't']
 
[georgiy@PANTHER mess]$ 

See all is well.

However when I attempt to do the same exact thing namely assign a one character 
string to a list of one character strings at a given index in that list I get 
an error.

Here's what happens when I run my program:

[georgiy@PANTHER mess]$ python gcipher.py

Enter a command. Valid ones are encrypt, decrypt, and exit.
command: encrypt

Enter plaintext. Only alphabetic characters allowed.
plaintext: secretmessagehere

Enter the encryption key. Only alphabetic characters allowed.
key: secretkeyhere

The encrypted version of your input with the given key is:
Traceback (most recent call last):
  File gcipher.py, line 214, in module
print(encrypt(inText,encryptionKey))
  File gcipher.py, line 127, in encrypt
letters[index]=letterAdd(letters[index],keystream[index])
TypeError: 'str' object does not support item assignment
[georgiy@PANTHER mess]$ python3 gcipher.py

Enter a command. Valid ones are encrypt, decrypt, and exit.
command: encrypt

Enter plaintext. Only alphabetic characters allowed.
plaintext: secretmessagehere

Enter the encryption key. Only alphabetic characters allowed.
key: secretkeyhere

The encrypted version of your input with the given key is:
Traceback (most recent call last):
  File gcipher.py, line 214, in module
print(encrypt(inText,encryptionKey))
  File gcipher.py, line 127, in encrypt
letters[index]=letterAdd(letters[index],keystream[index])
TypeError: 'str' object does not support item assignment
[georgiy@PANTHER mess]$ 


Anyway here is the final proof that we have a bug here and that I am not a 
complete moron that assigned to a string. It says there's a problem on line 
127. Well here are are few very relevant lines 120-126 right before 127 you 
might want to take a look at:

assert(type(plaintext)==str)
letters=list(plaintext) 
assert(type(letters)==list)
assert(type(letters[0])==str)
assert(len(letters[0])==1)
for roundNumber in range(17):
for index in range(plaintextLength):

The point is that all the assertions in the above assert statements held true. 
No AssertionErrors were raised. What was instead raised is a TypeError because 
Python thought I was assigning to an index in a string. Yet clearly right 
before that we have asserted that the variable letters is bound to a list 
type. And in line 127 I was assigning a one character string to an index in 
letters which again is a list and not a string.

Please look into this. If you need more information let me know and I will do 
my best to provide it. If you want I can also provide you folks with the 
complete source code if you feel it will help you. (I do warn in advance that 
it is quite messy/hacky/unPythonic to the point of me quite possibly becoming 
the laughingstock of the Python developer community. Of course considering the 
rather complicated nature of the transformations made on text during 
(en|de)cryption I'd like to see any critics do it better. Please do not laugh 
too hard when I show it.)

--
components: Interpreter Core
messages: 184501
nosy: wfatp
priority: normal
severity: normal
status: open
title: I can't make assignments to a list.

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue17466
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17466] I can't make assignments to a list.

2013-03-18 Thread Ezio Melotti

Ezio Melotti added the comment:

Have you tried to print letters and see what it is?  Have you verified that 
the asserts are executed?
You are probably doing something wrong, and it would be better to ask this on 
python-list.

--
nosy: +ezio.melotti

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue17466
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17466] I can't make assignments to a list.

2013-03-18 Thread Georgiy Treyvus

Georgiy Treyvus added the comment:

Yes the assert statements are executed. They are not in any sort of if block or 
anything like that. When the encrypt function is called and it was in the above 
examples the assert statements execute period. They really don't have much else 
of a choice. Look at the attached source code and see for yourself.

--
Added file: http://bugs.python.org/file29451/gcipher.py

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue17466
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17466] I can't make assignments to a list.

2013-03-18 Thread Mark Dickinson

Mark Dickinson added the comment:

doQuadraticDistortion returns a string.  Closing as invalid.

--
nosy: +mark.dickinson
resolution:  - invalid
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue17466
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17466] I can't make assignments to a list.

2013-03-18 Thread Mark Dickinson

Mark Dickinson added the comment:

Sorry; that was a bit terse.  To elaborate:  on the first iteration of your for 
loop in the 'encrypt' function, you're correct that letters has type 'list'.  
But on the second iteration, it'll have type 'str', because the line 
letters=doQuadraticDistortion(letters) returns a string.  Try moving the 
asserts inside the for loop and you'll see them fail.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue17466
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17466] I can't make assignments to a list.

2013-03-18 Thread Georgiy Treyvus

Georgiy Treyvus added the comment:

wait why was this closed?

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue17466
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17466] I can't make assignments to a list.

2013-03-18 Thread Georgiy Treyvus

Georgiy Treyvus added the comment:

ok will try

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue17466
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17466] I can't make assignments to a list.

2013-03-18 Thread Georgiy Treyvus

Georgiy Treyvus added the comment:

@Mark: You're right. Sorry for the erroneous bug report.

--
resolution: invalid - 
status: closed - open

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue17466
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17466] I can't make assignments to a list.

2013-03-18 Thread Amaury Forgeot d'Arc

Changes by Amaury Forgeot d'Arc amaur...@gmail.com:


--
resolution:  - invalid
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue17466
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com