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
PyLint reports "no assignment is done" but variable is changed in the scope of the procedure #9522
Comments
Thanks @motib79.
Here is where ticker = {1: 2}
def remove_ticker_from_list(stock_index):
global ticker
ticker = "NULL_STOCK"
remove_ticker_from_list('x')
print(ticker)
NULL_STOCK Perhaps the documentation could be updated to make it more clear? |
Thanks for the comments.
Ticker is a list. And modified in the scope of the procedure. Therefore I
believe global assignment is required as like in case of any other variable
changes. Looks like PyLint does not recognize list change as a change that
require global assignment .
…On Thu, 28 Mar 2024, 15:54 Mark Byrne, ***@***.***> wrote:
Thanks @motib79 <https://github.com/motib79>.
Using global for 'ticker' but no assignment is done - in other words, the global
ticker line is not necessary and can be removed.
Here is where global would be necessary:
ticker = {1: 2}
def remove_ticker_from_list(stock_index):
global ticker
ticker = "NULL_STOCK"
remove_ticker_from_list('x')print(ticker)
NULL_STOCK
Perhaps the documentation
<https://pylint.readthedocs.io/en/stable/user_guide/messages/warning/global-variable-not-assigned.html>
could be updated to make it more clear?
—
Reply to this email directly, view it on GitHub
<#9522 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/BFVJFIJONZTXW2QURDFDPUDY2QHHDAVCNFSM6AAAAABFJGADIKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAMRVGI2DENZRGA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
@motib79 I think that is the same situation for list or dict. (venv312) markbyrne@Marks-Air-2 programming % cat example.py
ticker = [1, 2, 3]
def remove_ticker_from_list(stock_index):
ticker[stock_index]="NULL_STOCK"
remove_ticker_from_list(0)
print(ticker)
(venv312) markbyrne@Marks-Air-2 programming % python example.py
['NULL_STOCK', 2, 3] |
Ok, thanks for the clarification.
…On Fri, 29 Mar 2024, 15:36 Mark Byrne, ***@***.***> wrote:
@motib79 <https://github.com/motib79> I think that is the same situation
for list or dict.
I think this is your example (expanded a bit to show the list definition
outside the function).
Python is happy with this and global isn't needed here because you are
not re-assigning ticker but rather some element contained within ticker.
Global would be needed if ticker were a string, for example, because the
assignment inside the function wouldn't affect ticker which is defined
outside the function:
(venv312) ***@***.*** programming % cat example.py ticker = [1, 2, 3]
def remove_ticker_from_list(stock_index):
ticker[stock_index]="NULL_STOCK"
remove_ticker_from_list(0)print(ticker)
(venv312) ***@***.*** programming % python example.py
['NULL_STOCK', 2, 3]
—
Reply to this email directly, view it on GitHub
<#9522 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/BFVJFILKBCMV473TY7EWLNLY2VG4TAVCNFSM6AAAAABFJGADIKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAMRXGE4DMMBYGE>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Bug description
Configuration
No response
Command used
Pylint output
Expected behavior
do not report this error
Pylint version
OS / Environment
Win10
Additional dependencies
No response
The text was updated successfully, but these errors were encountered: