This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: passing negative values through modules
Type: behavior Stage: resolved
Components: Versions: Python 3.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: SilentGhost, coldy028, steven.daprano, terry.reedy
Priority: normal Keywords:

Created on 2019-05-10 03:15 by coldy028, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (10)
msg342049 - (view) Author: David Collins (coldy028) Date: 2019-05-10 03:15
program_data.py file contains a list 

import list_function
 
str_list4 = ['i', 't']
str_list4 = list_function.insert_value(str_list4, 's', -1)
print(str_list4)


list_function.py file 

def insert_value(my_list, value, insert_position):
    counter = 0
    print('Question 5')
    print(my_list, value, insert_position)
    for index in my_list:
        counter += 1

when passing the negative number in insert_position between the two modules this causes

 str_list4 = list_function.insert_value(str_list4, 's', -1)

  File "D:\part A\list_function.py", line 85, in insert_value
    for index in my_list:

TypeError: 'NoneType' object is not iterable

my_list now becomes lost, if the negative value is changed to positive this clears up . 

if you assign the -1 to a variable or a contstant it does not matter 
it still causes the same issue. 

however if you are running this code in the same module it works fine. this only seems to appear when attempting to pass between 2 modules a negative number.
msg342050 - (view) Author: David Collins (coldy028) Date: 2019-05-10 03:16
I have tested this in the Mac and PC versions of IDLE as well as in Spyder using Ipython.
msg342056 - (view) Author: SilentGhost (SilentGhost) * (Python triager) Date: 2019-05-10 05:51
This bug tracker is for development of CPython, please ask your question on python-help mailing list, IRC or other similar forums.
msg342057 - (view) Author: David Collins (coldy028) Date: 2019-05-10 05:53
This is an issue with python

On Fri, 10 May 2019 at 3:52 pm, SilentGhost <report@bugs.python.org> wrote:

>
> Change by SilentGhost <ghost.adh@runbox.com>:
>
>
> ----------
> components:  -IDLE
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <https://bugs.python.org/issue36872>
> _______________________________________
>
msg342058 - (view) Author: David Collins (coldy028) Date: 2019-05-10 05:53
Not the coding

On Fri, 10 May 2019 at 3:53 pm, David Collins <coldy028@gmail.com> wrote:

> This is an issue with python
>
> On Fri, 10 May 2019 at 3:52 pm, SilentGhost <report@bugs.python.org>
> wrote:
>
>>
>> Change by SilentGhost <ghost.adh@runbox.com>:
>>
>>
>> ----------
>> components:  -IDLE
>>
>> _______________________________________
>> Python tracker <report@bugs.python.org>
>> <https://bugs.python.org/issue36872>
>> _______________________________________
>>
>
msg342059 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2019-05-10 07:17
David, I'm pretty sure that SilentGhost is correct. You are misreading the error message: it has nothing to do with the negative index.

The problem is that your `insert_value` function returns None, not the list. I believe that what you have done is tested the function once, with a positive index and then tried it again with a negative index:

    # this works fine, the first time
    str_list4 = list_function.insert_value(str_list4, 's', 1)
    # but fails the second time
    str_list4 = list_function.insert_value(str_list4, 's', -1)

The reason is that functions returns None by default, so you have replaced str_list4 with None. Then on the second call to the function, this line fails:

    for index in my_list:

because my_list is None. When Python gives you an error message, PLEASE READ IT because the interpreter does not lie, it knows what caused the failure:

    TypeError: 'NoneType' object is not iterable

Python is used by hundreds of thousands of people and they probably would have noticed a severe, fundamental flaw like the inability to pass negative numbers to other modules by now. As a beginner, 99.99% of the "bugs" you find will be in your own code, not the language.

(It has been said that the difference between a beginner and an expert is that the beginner assumes every bug is the language's fault, and an expert knows that nearly every bug is his own fault.)

As SilentGhost says, this list is not a help-desk. Please don't follow up with extra questions here, I won't answer. If you want help or advice, please subscribe to the tutor mailing list

https://mail.python.org/mailman/listinfo/tutor

where there will be plenty of people happy to help.

If you still believe that your code is correct, and you've found a bug that has escaped thousands of full-time Python programmers (it does happen...) then please take the time to read this:

http://www.sscce.org/

and follow the advice given there. It's written for Java, not Python ,but the advice applies to any language.

Thank you.
msg342064 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2019-05-10 09:21
David, the tracker 'component' is intended to be, for bug reports, the component of Python that you think has a bug.  When you run your code with IDLE and you get an exception displayed, that almost certainly means that IDLE is working as intended: it ran your code with python and displayed the error reported by python.  The fact that you got the same error when running without IDLE (and this is a good thing to try) demonstrates that the error is not from IDLE.
msg342065 - (view) Author: David Collins (coldy028) Date: 2019-05-10 09:22
So what your saying is that python is unable to pass a negative number between modules and you don’t think that this is an issue . 

Sent from Mail for Windows 10

From: Terry J. Reedy
Sent: Friday, 10 May 2019 7:21 PM
To: coldy028@gmail.com
Subject: [issue36872] passing negative values through modules

Terry J. Reedy <tjreedy@udel.edu> added the comment:

David, the tracker 'component' is intended to be, for bug reports, the component of Python that you think has a bug.  When you run your code with IDLE and you get an exception displayed, that almost certainly means that IDLE is working as intended: it ran your code with python and displayed the error reported by python.  The fact that you got the same error when running without IDLE (and this is a good thing to try) demonstrates that the error is not from IDLE.

----------
assignee: terry.reedy -> 

_______________________________________
Python tracker <report@bugs.python.org>
<https://bugs.python.org/issue36872>
_______________________________________
msg342066 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2019-05-10 09:42
Robert, when posting to this tracker by email, please remove the quote of the previous post.  It duplicates the post itself.

I said exactly what I said, which explained why marking the issue for IDLE was a mistake.  (The same error is a weekly occurrence, by beginners, on stackoverflow.com.)

That aside, you are not passing values through or between modules.  You are passing arguments to a function, which is an object separate from both modules.

I ran your code and got the expected error-free output:

Question 5
['i', 't'] s -1

Steven explained the bug in your code which makes the last print act different from what you probably expect.  Reread what he wrote until you understand.  If I do what he suggested you must have done, I get the error you got.
msg342069 - (view) Author: David Collins (coldy028) Date: 2019-05-10 10:17
Sorry for being so abrupt you are correct . 
The code I was working from was a university professors and not my own, I understood better thanks steve. I wasn’t passing a return value yet and the professors work was overwriting the list. 

I do apologise. 
Thanks for you support.
History
Date User Action Args
2022-04-11 14:59:15adminsetgithub: 81053
2019-05-10 10:17:58coldy028setmessages: + msg342069
2019-05-10 09:42:52terry.reedysetmessages: + msg342066
2019-05-10 09:22:47coldy028setmessages: + msg342065
2019-05-10 09:21:07terry.reedysetassignee: terry.reedy ->
messages: + msg342064
2019-05-10 07:17:04steven.dapranosetnosy: + steven.daprano
messages: + msg342059
2019-05-10 05:53:38coldy028setmessages: + msg342058
2019-05-10 05:53:22coldy028setmessages: + msg342057
2019-05-10 05:52:14SilentGhostsetcomponents: - IDLE
2019-05-10 05:51:48SilentGhostsetstatus: open -> closed

type: compile error -> behavior

nosy: + SilentGhost
messages: + msg342056
resolution: not a bug
stage: resolved
2019-05-10 03:16:40coldy028setmessages: + msg342050
2019-05-10 03:15:16coldy028create