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

Fix 'NoneType object is not subscriptable' error #3286

Conversation

davidculley
Copy link
Contributor

You can't access the first item of a list if you happen to get None instead of a list.

This pull request fixes a

TypeError: 'NoneType' object is not subscriptable

by ensuring the returned value is indeed a list and not None.

Fixes TypeError 'NoneType' object is not subscriptable
If the key is not in the dictionary, we want to raise a KeyError rather
than returning None. That way, we can distinguish between whether the
value was None or the key was not found.
…object-is-not-subscriptable

Merged to include 88b5064 to fix pipeline.
@dae
Copy link
Member

dae commented Jul 21, 2024

Is this an error you were seeing in the wild?

@davidculley
Copy link
Contributor Author

No, my intention was to fix the type errors that Pyright reports.

Since I use type checkers and linters quite extensively, I'd like them to be happy with the code so that the critical problems can't go unnoticed.

After some more research, it seems that when you download an add-on from https://ankiweb.net/shared/download/{number}, you are redirected to 'https://ankiweb.net/svc/shared/download-addon/{number}. And that latter URL contains t=, minpt=, maxpt= and bidx= between the ? and #.

I now realize the safeguard I implemented is useful only if any of these four keys t, minpt, maxpt or bidx does not return a value. I can simplify the code if it's overengineered.

@dae dae merged commit a5a39c9 into ankitects:main Aug 4, 2024
1 check passed
@davidculley davidculley deleted the feature/fix-nonetype-object-is-not-subscriptable branch August 4, 2024 18:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants