Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pylint warning - unsubscriptable-object

with the below code snipped in visual studio code editor

a = b.get('c') if b else None
d = a[1] if a else None

pylint is giving the following warning in the second line for a[1].Is it correct to show the warning? Shouldn't the check for None cover it ?

a: NoneType
Value 'a' is unsubscriptable pylint(unsubscriptable-object)
like image 488
user3206440 Avatar asked Jul 27 '26 10:07

user3206440


1 Answers

pylint is either not detecting the right type, and you can suppress the warning via:

d = a[1] if a else None  # pylint: disable=unsubscriptable-object

or (since var b isn't in your post), it's correct, and b.get('c') returns an unsubscriptable type, for example:

b = {"c": 1}
a = b.get('c') if b else None
# a = 1, 1 is not subscriptable
like image 190
Jay Mody Avatar answered Jul 28 '26 23:07

Jay Mody



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!